Vous êtes sur la page 1sur 15

Report for Lab Challenge 2

Digital Image Processing (IT-523)


Date: 31st October, 2006
Submitted by:
Atul Bhatia (200611024)
Hina Shah (200611032)
Nitin Rawat (200611025)
Problem 1:
Aims of the problem:

To analyze real lines in discrete grid in our digital image by considering
intersection of lines in N2
• To establish a relation of the line in N2 and Diophantine Equations
Every intersecting line in R2 does not necessarily intersect in our discrete. In discrete grid
of the image each position is characterized by a member of N2 that can be from (0,0) to
(M,N) where M can be the width of the image and N height of the image. So a real line in
R2 when represented in the discrete grid is approximated to elements of N2.
As an example, consider the following image which contains some lines:

The lines m, n and p seem to be intersecting line l.


Now zooming (by 8x) each of the areas of intersection we see the following results:

a. b. c.
Figure (a) shows the intersection of real lines l and m in N2. As can be seen here the lines
are actually not intersecting in N2 although they will intersect in R2. Points of line l in N2
near the so called intersection are: (88, 86) and (89, 87). While points of line m in N2 near
the so called intersection are: (88, 87) and (89, 86).

Figure (b) shows the intersection of real lines l and n. Points of line l in N2 near the so
called intersection are: (124, 116) and (125, 117). While points of line n in N2 near the so
called intersection are: (124, 117) and (125, 116).

Figure (c) shows the intersection of line l and p. These two lines actually intersect in N2
as can be seen in the image. The point of intersection is (152, 140).

Each of the lines is a set in N2 and the intersection of two lines would mean that two lines
have one element in common. As seen in Figure (a) conventional intersection of set
(Please note that (0,0) is taken as the top left corner of the original image.)

Diophantine Equations:
Diophantine Equations is an indeterminate polynomial equation that only allows the
variables to be integers [1]. Lines in N2 can be represented by a Diophantine equation of
type
ax + by = c
where x and y are integer variables and c is the greatest common divisor of a and b and
both of them are also integers. This is a linear Diophantine equation.
As an example consider a pair of Diophantine Equations as::
7x + 18y = 208
x + y = 25
Solving the two equations for lines above, the point of intersection comes out to be
(22,3).Image showing both lines and their intersection is as
follows:

x+y=25
(22,3)

7x+18y=208

(0,0)

a b
Figure (a) shows two lines of respective equations, while Figure (b) is the zoomed
version of the intersected area. The point of intersection has a gray value of 64 and is
marked within the circle. The intersection point as discussed earlier is (22,3) .

Actually, proper solutions for second equation are points like (40, -4), (22,3), (4,10),
(-14, 17), (-32, 24), etc. What is shown in the image is a line joining all these points, by
creating a path between the points by 8- neighborhood (please refer definition 2.2 in [3]).
The path has points that have been obtained by approximating the values of (x,y)
obtained for each possible x here.

Now let us have an example of two linear Diophantine equations which do not have a
perfect intersection point:
7x + 18y = 208
2x + 3y = 1
The intersection point for these two lines does not turn out to be an integer. So these two
lines would not intersect in our discrete grid of N2 for the image. Instead the intersection
point will be approximated to some integer pair. The actual intersection occurs at point
(-40.4, 27.667)

2x+18y=208 approximations

(0,0)

2x+3y=1

a. b.

Figure (a) shows the two lines formed by Diophantine equations given above. As seen
before the point of intersection is not a member of N2 , but rather is (-40.4, 27.267). This
point has been approximated to (-40, 27) in figure (b) above. Other intersections that are
visible in the figure are also nothing but simple approximation of such values in R2 to
values in N2.
Problem 2
Aims of the Problem: To rotate a solid object by 45 degrees with respect to the center of
gravity of the object.
Solid object that we first would be considering is a rectangle. The original image to be
transformed (rather rotated) is given below. The center of gravity of the square is
coordinate (100, 100).

In order to perform the rotation around the coordinate


(100, 100), it would be first required to translate the
object to origin (0,0) and then rotate it by 45 degrees
and then again translate the rotated object back to
(100,100) origin position.
The transformations of objects are done actually using
series of matrix multiplications. Transformations done
in this way are called affine transforms [4]. For
example our case would need 3 matrix multiplications
as the following steps are required:
1. Translating to the origin (0,0)
2. Rotate by 45 degrees
3. Translate back to origin (100, 100)
If the coordinate is given in terms of a matrix of the form X=[x y 1], then various
transformation matrices are given as follows:
Translation by tx and ty :
T=[1 0 0
0 1 0
tx t y 1 ]
hence X*T results in new coordinates w = x+ tx, z= y+ ty

Rotation by angle θ
R = [ cos θ sin θ 0
-sin θ cos θ 0
0 0 1]
Hence X*R results in new coordinates w=xcos θ - ysin θ, z = xsin θ + ycos θ

Therefore the combined matrix for the required composite transformation would be
T*R*T-1 which will be given as:

F = [ cos θ sin θ 0
-sin θ cos θ 0
tx’ ty’ 1]
where tx’ = tx(cos θ -1) - tysin θ
ty’ = txsin θ + ty(cos θ -1)

Hence, by performing X*F the new coordinates obtained are


x’ = xcos θ - ysin θ + tx’
y’ = xsin θ + ycos θ + ty’
Again the new coordinates obtained would be real numbers and hence would have to be
approximated to integer values. This would result into replication of several input pixels
into the same pixel position in the output. The effect of this can be seen in the image
obtained by direct matrix multiplication which is shown below:

Listing for obtaining this image is given Listing 2 in


the codes section.
The black pixels that are seen here in the rotated white
square are present as several input pixel positions are
mapped to a single pixel position, hence some are left
without any mapping, and hence are black.
The rotation also generates a problem of filling up the
extra pixels that have been created due to rotation.
Because now the line that was straight before would
not be straight and hence would take up more pixels
and hence a jagged edge would be created as a result
of the phenomenon. ([5] and [7])
In order to tackle with this problem, interpolation would be required to be performed.

Interpolation is performed by simply calculating the


value of the original pixels in the original image by
performing the inverse transform of the pixels that
have been obtained by rotation. This would give us an
approximation of what is obtained.

After this the rotation of the images seems to be a bit sophisticated process! This was a
case of a solid object. But if we had a different object with variations in pixel values then
one would have to take care of the nearest neighborhoods also in order to produce
accurate results.
Problem 3:
Aims of the problem:
• To take an image of size NxN, and decimate it by a factor of 2.
• Interpolate the image of size N/2 x N/2 to the original size using various
interpolation techniques like bilinear, spline and bicubic.
• To increase the decimation factor by 4 and 8 and then to try to obtain the original
image.
• To comment on super resoluction

For the exercise we consider the following original image:

Image used for the problem. Original size is 1024 x 1024


Decimating by a factor of 2, 4and 8 following images are obtained:
Image obtained by decimating the original image by a factor or 2 (size 512 x 512)

Result of decimation by factor 4 (size 256 x 256) Result of decimation by factor 8 (128x128)
We have used 3 interpolation methods in order to convert the image of size 512x512 to
its original size. (i.e. 1024x1024), we used 3 types of interpolation methods : nearest
neighbor method, bilinear method and bicubic.
While nearest neighbor simply replicates the value of the nearest neighbor of the pixel,
bilinear method uses the weighted average of the nearest 2x2 neighborhood of known
pixels around the unknown pixel and bicubic method uses a neighborhood of size 4x4. [5]
Listing for the same has been provided in the codes section.
Results obtained cane be summarized as follows:

Nearest neighbor Bilinear Interpolation

Bicubic Interpolation
Zoomed part of each or these images is shown as follows:

Original Image Nearest Neighbor

Bilinear Interpolation Bicubic Interpolation

Although none of the images are exactly same as the original image, there is a noticeable
difference between the interpolated images.
Nearest Neighbor method uses simple replication, hence the image appears to be rougher.
This is the reason why one sees the jagged edges at the boundary of the petals
Bilinear method is much smoother than the nearest neighbor method as it tried to use a
value that is near to its nearest neighbor and lies between the values of the unknown
pixel’s neighbors.
Bicubic linear interpolation is computationally expensive, but this tries to take up a large
neighborhood and hence results into a more detailed and a smoother image.

SUPER RESOLUTION
Low resolution in the image occurs due to lower spatial sampling frequency,
which produces distortion in the image due to high frequency components. This cases lost
in the information due to high frequency components such as edges and textures.
Degradation can also be caused by camera motion or out of focus. Thus image captured
with low resolution camera suffers from aliasing, blurring and presence of noise. Super-
resolution (SR) refers to the process of producing a high spatial resolution image from
several low resolution images, thereby increasing the maximum spatial frequency and
removing the degradations that arise during the image capturing process using a low
resolution camera. In fact, the super-resolution process extrapolates the high frequency
components and minimizes aliasing and blurring.
In order to obtain super-resolution we must look for non redundant information
among the various frames in an image sequence. The most obvious method for this seems
to be to capture multiple low resolution observations of the same scene through subpixel
shifts due to the camera motion. These subpixel shifts can occur due to the controlled
motion in imaging systems, e.g., a landsat satellite captures images of the same area on
the earth every eighteen days as it orbits around it.

Different types of cues used for super resolution are”:


motion, blurr, zoom, photometry, learning based techniques
Problem 4:

Aims:
• To find the possible configurations in which two ellipses can act as elliptic gears.
• To create an animated sequence of rotation of elliptic gears

There are 2 possible configurations in which given two polynomials would act as elliptic
gears.

First configuration takes the following form:

Here both the ellipses would move against each


other in order to act as elliptic gears.
Hence the major axes of both the ellipses as well as
the minor axes of both the ellipses are rotating. The
rotation of both ellipses will be in different
directions. Hence, if one ellipse rotates in clockwise
direction, the other would rotate in anticlockwise
direction. The distance between the shown focal
points remains constant throughout. (The image has
been taken from [6])

A change to this configuration is keeping the major


axis of one ellipse stationary and the other major
axis is rotating.
As seen in the adjacent figure [8]. The horizontally lying
ellipse would not move. The other ellipse moves around
this driver gear. Again, while the distance between the
two focal points of the two ellipses remains constant
here (as shown in the figure), the major axis is the only
one that is rotating. Hence the focal point in the
horizontally lying gear is the pivot and the other ellipse
moves with respect to this focal point only.

In the other configuration the distance between the centers of the two ellipses remains the
same.
References:
1. www.wikipedia.com/wiki/Diophantine_equation
2. Introduction to Diophantine Equations – Tom Davis
http://www.geometer.org/mathcircles/
3. Digital Topology, A.Rosenfield, American Mathematical Monthly 86: 621-630
4. Digital Image Processing Using Matlab® – Rafael C. Gonzales, Section 5.11
(Chapter 5).
5. http://www.cambridgeincolour.com/tutorials/image-interpolation.htm
6. http://mathworld.wolfram.com/Ellipse.html
7. Matlab Documentation
8. http://www.ies.co.jp/math/java/conics/elgear/elgear.html

Codes:
Listing 1 for Problem 1:

% listing for Problem 1, Lab Challenge 2


I=zeros(200, 200, 'uint8');
I(:,:) = 255; %creating a white background
%creating the visual X and Y axis
I(100, :) = 0;
I(:, 100) = 0;

% plotting two lines


% in this case the lines plotted are:
% 2x + 3y = 1 (this is visible as a black line)
% 7x + 18y = 208 (this is visible as a gray line)
% after finding the y coordinate for the respective x coordinate
% calculated coordinates are tranferred to the new origin (100,100)
for x=-50:50
y = (1 - 2*x)/3;
I(uint8(100-y), uint8(100+x)) = 0;
y = (208 - 7*x)/18;
I(uint8(100-y), uint8(100+x)) = 128;
end
imshow(I);
Listing 2 for Problem 2

% Listing for Problem 2, Lab Challenge 2


% Creating the original image
I = zeros(200, 200, 'uint8');

I(:,:) = 0;
for i=50:150
for j=50:150
I(i,j) = 255;
end
end
imshow(I); figure;

%creating image which will contain the rotated object


J = zeros(200, 200, 'uint8');

tx=-100; %parameter for translation in x direction


ty=-100; %parameter for translation in y direction
theta = pi/4; %angle for rotation

% Composite translation matrix


% Derivation of this matrix is explained in the documentation
T= [ cos(theta) sin(theta) 0
-sin(theta) cos(theta) 0
tx*cos(theta)-ty*sin(theta)-tx tx*sin(theta)+ty*cos(theta)-ty 1];

%Performing the final matrix multiplication


for i=50:150
for j=50:150
Y = [i j 1]*T;
J(uint8(Y(1)),uint8(Y(2))) = 255;
end
end

imshow(J); figure;

% Performing interpolation to obtain the proper values from the


% original image....
Tinv = inv(T);

for i= 2:199
for j= 2:199
Y = [i j 1]*Tinv;
if 2<=uint8(Y(1)) && uint8(Y(1))<=199 && 2<=uint8(Y(2)) &&
uint8(Y(2))<=199
J(i,j) = I(uint8(Y(1)),uint8(Y(2)));
end
end
end

imwrite(J, 'result.bmp');
imshow(J);
Listing for Problem 3 (Decimation)
%Listing for Porblem 3, Lab challenge 2

I = imread('rose.jpg'); %Read the original image

%Decimation is done by removing the unwanted columns from the original


%image. For example while decimating by a factor of 4 all the rows and
%columns which are at a distance of 4 are only taken into consideration
to
%for the new image. Hence per one pixel we are actually removing the
%informaton of some 4 pizels on each of the pixel's side, i.e. 4 above,
4
%below 4 each on left and right sides.

%decimation by a factor of 2
J= zeros(size(I,1)/2, size(I,2)/2, 'uint8');

k=1;
for i=1:2:size(I,1)
l=1;
for j = 1:2:size(I,2)
J(k,l) = I(i,j);
l=l+1;
end
k=k+1;
end

imwrite(J,'rose_decimate2.bmp');
imshow(J); figure;

%decimation by a factor of 4
J= zeros(size(I,1)/4, size(I,2)/4, 'uint8');

k=1;
for i=1:4:size(I,1)
l=1;
for j = 1:4:size(I,2)
J(k,l) = I(i,j);
l=l+1;
end
k=k+1;
end

imwrite(J,'rose_decimate4.bmp');
imshow(J); figure;

%decimation by a factor of 8
J= zeros(size(I,1)/8, size(I,2)/8, 'uint8');

k=1;
for i=1:8:size(I,1)
l=1;
for j = 1:8:size(I,2)
J(k,l) = I(i,j);
l=l+1;
end
k=k+1;
end

imwrite(J,'rose_decimate8.bmp');
imshow(J);

% Read the image for interolation


I = imread('rose_decimate2.bmp');
% Parameters for scaling by a factor of 2 (i.e. zooming by 2
sx=2; %Scale parameter in x direction
sy=2; %Scale paramter in y direction

% Transformation matrix for Scaling


T = [ 2 0 0
0 2 0
0 0 1 ];

tform=maketform('affine', T);
%Perform scaling using 'Nearest Neighbor' method
g= imtransform(I, tform, 'nearest');
imwrite(g,'nearest_interpolated.bmp');

%Perform scaling using 'Bilinear' method


g= imtransform(I, tform, 'bilinear');
imwrite(g,'bilinear_interpolated.bmp');

%Perform scaling using 'Bicubic' method


g= imtransform(I, tform, 'bicubic');
imwrite(g,'bicubic_interpolated.bmp');