31 Be Comp A Dsip 11
31 Be Comp A Dsip 11
31 Be Comp A Dsip 11
Theory:
Zooming:
Zooming simply means enlarging a picture in a sense that the details in the image became more
visible and clear. Zooming an image has many wide applications ranging from zooming through a
camera lens, to zoom an image on internet etc.
For example
is zoomed into
Optical Zoom:
The optical zoom is achieved using the movement of the lens of your camera. An optical zoom is
actually a true zoom. The result of the optical zoom is far better then that of digital zoom. In optical
zoom, an image is magnified by the lens in such a way that the objects in the image appear to be
closer to the camera. In optical zoom the lens is physically extend to zoom or magnify an object.
Digital Zoom:
Digital zoom is basically image processing within a camera. During a digital zoom, the centre of the
image is magnified and the edges of the picture got crop out. Due to magnified centre, it looks like
that the object is closer to you.
During a digital zoom, the pixels got expand, due to which the quality of the image is compromised.
The same effect of digital zoom can be seen after the image is taken through your computer by using
an image processing toolbox / software, such as Photoshop.
The following picture is the result of digital zoom done through one of the following methods given
below in the zooming methods.
Zooming methods:
Although there are many methods that does this job, but we are going to discuss the most common of
them here.
They are listed below.
Introduction:
It is also known as Nearest neighbour interpolation. As its name suggest, in this method, we just
replicate the neighbouring pixels. This algorithm works on the same principle.
Working:
In this method we create new pixels form the already given pixels. Each pixel is replicated in this
method n times row wise and column wise and you got a zoomed image.
For example:
If you have an image of 2 rows and 2 columns and you want to zoom it twice or 2 times using pixel
replication, here how it can be done.
For a better understanding, the image has been taken in the form of matrix with the pixel values of the
image.
1 2
3 4
The above image has two rows and two columns, we will first zoom it row wise.
When we zoom it row wise, we will just simple copy the rows pixels to its adjacent new cell.
Here how it would be done.
1 1 2 2
3 3 4 4
As you can see that in the above matrix, each pixel is replicated twice in the rows.
The next step is to replicate each of the pixel column wise, that we will simply copy the column pixel
to its adjacent new column or simply below it.
Here how it would be done.
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
As it can be seen from the above example, that an original image of 2 rows and 2 columns has been
converted into 4 rows and 4 columns after zooming. That means the new image has a dimensions of
(Original image rows * zooming factor, Original Image cols * zooming factor)
One of the advantage of this zooming technique is, it is very simple. You just have to copy the pixels
and nothing else.
The disadvantage of this technique is that image got zoomed but the output is very blurry. And as the
zooming factor increased, the image got more and more blurred. That would eventually result in
fully blurred image.
Method 2: Zero order hold
Introduction
Zero order hold method is another method of zooming. It is also known as zoom twice. Because it can
only zoom twice. We will see in the below example that why it does that.
Working
In zero order hold method, we pick two adjacent elements from the rows respectively and then we
add them and divide the result by two, and place their result in between those two elements. We first
do this row wise and then we do this column wise.
For example
Lets take an image of the dimensions of 2 rows and 2 columns and zoom it twice using zero order
hold.
1 2
3 4
1 1 2
3 3 4
As we take the first two numbers: (2 + 1) = 3 and then we divide it by 2, we get 1.5 which is
approximated to 1. The same method is applied in the row 2.
1 1 2
2 2 3
3 3 4
We take two adjacent column pixel values which are 1 and 3. We add them and got 4. 4 is then
divided by 2 and we get 2 which is placed in between them. The same method is applied in all the
columns.
As you can see that the dimensions of the new image are 3 x 3 where the original image dimensions
are 2 x 2. So it means that the dimensions of the new image are based on the following formula
(2(number of rows) minus 1) X (2(number of columns) minus 1)
One of the advantage of this zooming technique, that it does not create as blurry picture as compare
to the nearest neighbour interpolation method. But it also has a disadvantage that it can only run on
the power of 2. It can be demonstrated here.
Consider the above image of 2 rows and 2 columns. If we have to zoom it 6 times, using zero order
hold method, we cannot do it. As the formula shows us this.
It could only zoom in the power of 2 2,4,8,16,32 and so on.
Even if you try to zoom it, you can not. Because at first when you will zoom it two times, and the
result would be same as shown in the column wise zooming with dimensions equal to 3x3. Then you
will zoom it again and you will get dimensions equal to 5 x 5. Now if you will do it again, you will
get dimensions equal to 9 x 9.
Whereas according to the formula of yours the answer should be 11x11. As (6(2) minus 1) X (6(2)
minus 1) gives 11 x 11.
Method 3: K-Times zooming
Introduction:
K times is the third zooming method we are going to discuss. It is one of the most perfect zooming
algorithm discussed so far. It caters the challenges of both twice zooming and pixel replication. K in
this zooming algorithm stands for zooming factor.
Working:
For example:
Suppose you have an image of 2 rows and 3 columns, which is given below. And you have to zoom it
thrice or three times.
15 30 15
30 15 30
K in this case is 3. K = 3.
The number of values that should be inserted is k-1 = 3-1 = 2.
Take the first two adjacent pixels. Which are 15 and 30.
Subtract 15 from 30. 30-15 = 15.
Divide 15 by k. 15/k = 15/3 = 5. We call it OP.(where op is just a name)
Add OP to lower number. 15 + OP = 15 + 5 = 20.
Add OP to 20 again. 20 + OP = 20 + 5 = 25.
We do that 2 times because we have to insert k-1 values.
Now repeat this step for the next two adjacent pixels. It is shown in the first table.
After inserting the values, you have to sort the inserted values in ascending order, so there remains a
symmetry between them.
It is shown in the second table
Table 1.
15 20 25 30 20 25 15
30 20 25 15 20 25 30
Table 2.
The same procedure has to be performed column wise. The procedure include taking the two
adjacent pixel values, and then subtracting the smaller from the bigger one. Then after that, you have
to divide it by k. Store the result as OP. Add OP to smaller one, and then again add OP to the value
that comes in first addition of OP. Insert the new values.
Here what you got after all that.
15 20 25 30 25 20 15
20 21 21 25 21 21 20
25 22 22 20 22 22 25
30 25 20 15 20 25 30
The best way to calculate the formula for the dimensions of a new image is to compare the
dimensions of the original image and the final image. The dimensions of the original image were 2 X
3. And the dimensions of the new image are 4 x 7.
The formula thus is:
(K (number of rows minus 1) + 1) X (K (number of cols minus 1) + 1)
CODE:
clear all;
close all;
clc;
b=imread('cameraman.tif');
s=size(b);
c=[];
d=[];
zoom=input('enter zooming factor');
for n=1:s(1,1)
for p=1:zoom
c=[c;b(n,:)];
end
end
for m=1:s(1,2)
for p=1:zoom
d=[d,c(:,m)];
end
end
imshow(d);
Output : Original IMAGE After zooming in
Learning Outcomes: The student should have the ability to implement Image Zooming
Course Outcomes: Upon completion of the course students will be able to understand & implement
Image Zooming