Вы находитесь на странице: 1из 10

Report for Lab Challenge 3

Digital Image Processing (IT 523)


Date: 13th November, 2006
Submitted By:
Shah Hina Rajiv (200611032)
Atul Bhatia (200611024)
Nitin Rawat (200611025)
Problem 1:

The laplacian operator is defined as

▼2 f= d2f/dx2 + d2f/dy2. - A

In digital or discrete domain the derivatives are replaced by the differences. Thus here when we talk of
digital images then

df/dx becomes f(x+1,y)-f(x,y)


where x and y are the spatial coordinates of the digital image. Similarly the second order derivative is

d2f/dx2 = f(x+1,y) + f(x-1,y) - 2f(x,y)

d2f/dy2. =f(x,y+1) + f(x,y-1)- 2f(x,y).

Putting the above two values in A , we get

▼2 f= d2f/dx2 + d2f/dy2. = f(x+1,y) + f(x-1,y) - 2f(x,y) + f(x,y+1) + f(x,y-1)- 2f(x,y).


= f(x+1,y) + f(x-1,y) - 4f(x,y) + f(x,y+1) + f(x,y-1). -B

0 1 0
1 -4 1
0 1 0
Implementation of B at a particular location (x,y) is equivalent of convolving it with the given kernel
and the laplacian of the whole image is carried out by passing the mask over the entire image and
replacing the value at x,y by the convolution result.
Thus as we can see that the defination of the
laplacian operator demands that the kernel is of the above order, that is why the sum of all individual
elements of the kernel is zero.

If we consider the terms df/dxdy in the definition of d2f/dx2 and d2f/dy2 ,then our kernel will be of the
type

1 1 1
1 -8 1
1 1 1
Then also the sum off all the elements of kernel is zero.

If the sum of all the elements in the kernel is not 0 then if we onvolve the kernel with the image of
uniform intensity or grey level,then also i will get a non zero value. As laplaian is an approximation of
second order derivative we must get non zero values where there are transition in greylevel value. So
our approximation will be wrong if sum of all elements in the kernel is not zero.

Output of applying the laplacian operator in spatial domain

Original Image Image obtained by applying Laplacian operator


Problem 3:
A faulty sensor like the one we had modeled in the first lab challenge would produce salt and pepper
noise. This noise is best dealt with the order statistics filters. Various filters that can be used for the
purpose are Median Filter, Min Filter, Max Filter and Adaptive Median Filter. All of these filters
actually pick up a value in the neighborhood of the pivot pixel and replace the pixel with that value.
Like in median filter the pixel under consideration is replaced by the median value in the neighborhood
of the pixel. Similarly, in Min filter and in Max filter the pixel is replaced by the minimum and the
maximum values respectively in the neighborhood. The Min filter best deals with Salt noise as it
considers the minimum value while the Max filter deals best with pepper noise. Both Salt and pepper
noise are dealt with the median filter. Other filters that can also be used are Midpoint filter, alpha
trimmed median filter, etc.

Results of applying median and adaptive median filters are as follows:

Image with salt and pepper noise Result of applying Adaptive Median Result of applying median filter with
Filter with Smax = 7 3x3 mask
Median filter is a non-linear filter.
Actually finding a median is itself not a linear operation. Hence the filter is a non linear filter.
Adaptive median filter would be used in applications where density of salt and pepper noise is
unpredictable. The size of the kernel is dependent on the noise distribution. For dense noise distribution
the kernel size is desired to be large (as the number of impulses will be high). While for lower density
the kernel size can be small.

Problem 2:
We have taken the image and have applied Gaussian filter on it which is having zero mean and a finite
variance. Here the image taken by us is the checkerboard pattern.

Original image

Basically Gaussian filter acts like a low pass filter which basically performs averaging. Hence when
the Gaussian filter is applied to the image it results in the blurring of the details in the image. Now if
the Gaussian filter is applied again and again it results in more blurring in the image. Figure shows the
application of Gaussian filter 10000 times on the above image.

Output of applying Gaussian filter 10000 times


But we apply more and more times Gaussian filter after some time the blurring is no more increased
with its application. Hence after particular amount of blurring no more blurring takes place with the
application of Gaussian filter. Gaussian filter can be applied in the frequency domain also. For that we
have calculated the FFT of the original image and apply Gaussian filter on it. The results are shown in
the following diagrams. Shows the FFT of the original image.

FFT of original image

Now we apply Gaussian filter to FFT of the image. The result is shown in the diagram given below.

The result when Gaussian filter is applied once

More application of Gaussian filter on the FFT of the image gives the result as follows:-

output of application of Gaussian filter no. of times


The output is coming to be a straight line. Which is basically the shifted version of the original FFT
obtained.

Problem 4:
We have taken a image, which is shown below:-

Original image
Now we apply firstly Gaussian filter which results in blurring of the image. After that we apply
laplacian filter which basically results in edge detection. The output after application of the two filters
is shown below.

Applying Gaussian first Applying Laplacian first


Now we will firstly apply the laplacian filter which detect edges. After that we apply Gaussian filter.
The output is shown in the above figure.
We see that the output is not coming to be same under the two cases. The output is more closure to
original when we firstly apply Gaussian filter and then laplacian. Hence we concluded that the output is
not same in the two cases, i.e. The Gaussian of laplacian and laplacian of Gaussian does not results in
the same output.

Problem 5:
Yes there exists a function whose Fourier transform is the function itself. It is the Gaussian function.
The Fourier transform of the Gaussian function is Gaussian.

PROOF:
We know that the Gaussian function is given by

f(z)=(1/2пσ2 )exp{(z-μ)2/2σ2}
where z is the pixel value, the term μ signifies mean and sigma standard deviation.
Let us leave the constants and treat the function in time domain. So we have

f(t)=exp{-t2/2σ2}
now the Fourier transform is given by

F(w)=∫ f(t)exp(-j2пft)dt

Now d/dt(f(t))= -t/2σ2f(t)

now apply the property of differentiation in time domain on the left hand side and that of differentiation
in frequency domain in right hand side. We get

jwF(w)=1/σ2(d/jdwF(w))

on rearranging
∫ (d/dw F(w))/F(w)= ∫ -wσ2

on taking the limit from 0 to w on both the sides we get

ln F(w) – ln F(0)=1/2σ2w2 .
thus
F(w)=F(0)exp{-1/2σ2w2)

now F(0)=∫ exp{-t2/2σ2}dt the limit being from -∞ to +∞ is

√ (2пσ)

after which we get F(w)= √ (2пσ) exp{-1/2σ2w2)

Hence proved.

Problem 6:
Changing of the histogram would result into changing of the dynamic range and hence change in the
frequencies of the values of the image.
Histogram equalization is the process in which the histogram of the image is stretched throughout the
dynamic range.
The transformation is done by the following formula:

p(xi) is the probability of occurrence of level i in the image. L is the maximum value. ni is the
frequency of level i and n is the total number of pixels in the image. C(i) gives the cumulative
frequency of all the gray levels till gray level i. This cumulative frequency distribution actually results
into the final output as given in third equation.
Once yi is obtained, the probabilities of all the values will be spread across the histogram, i.e. the
histogram is now actually stretched across the dynamic range. Hence performing histogram
equalization again on the image would mean again generating the same cumulative distribution as just
obtained. Hence histogram would remain as it is and hence histogram equalization is idempotent.
Results:

Original Image Histogram of the original image


On equalization following results are obtained:
Equalized image Histogram of the equalized image

Histogram of the equalization of the already equalized image

References:
1. Digital Image Processing- Rafael C. Gonzales
2. Digital Image Processing Using Matlab
3. www.wikipedia.com
Listings for the problems:

Listing 1:
%Lab Challenge 3: Problem 1
clear;
I = imread('Fig4.20(a).jpg');
f = fspecial('laplacian', 0);
J = imfilter(I, f, 'replicate');
K = I-J;
figure, imshow(K);

Listing 2:
%Lab Challenge 3: Problem 2
I = imread('checkerboard_50x50.bmp');
F = fft2(double(I));
imshow(log(1+abs(fftshift(F))), []);
figure, imshow(I);
f = fspecial ('gaussian', [3 3], 5)
n=5;
J=I;
K=F;
for j=1:10000
J = imfilter(J, f, 'replicate');
K = imfilter(F, f, 'replicate');
end

figure, imshow(log(1+abs(fftshift(K))), []);


figure, imshow(J);
F = fft(double(J));
figure, imshow(log(1+abs(fftshift(F))), []);

Listing 3:
%Lab Challenge 3: Problem 2
clear;
I = imread('Fig5.04(i).jpg');
[M,N] = size(I);
arr = zeros(1, 9, 'uint8');
J = zeros(size(I), 'uint8');
%Implementing Median Filter....
for i=2:M-1
for j=2:N-1
k=1;
for l=-1:1
for m=-1:1
arr(k)= I(i+l, j+m);
k=k+1;
end
end
arr = sort(arr);
J(i,j) = arr(5);
end
end
imshow(J);
Smax = input('Enter Maximum Window Size (An Odd Number):=> ');
K = adpmedian(I, Smax);
figure, imshow(K);

Listing for adpmedian:


function f = adpmedian(g, Smax)
%Smax must be an odd, positive integer greater than 1
if(Smax <=1) | (Smax/2 == round(Smax/2)) | (Smax ~=round(Smax))
error('Smax must be an oddinteger > 1.');
end

[M, N] = size(g);

f=g;
f(:) = 0;
alreadyProcessed = false(size(g));

%Begin filtering
for k=3:2:Smax
zmin = ordfilt2(g, 1, ones(k,k), 'symmetric');
zmax = ordfilt2(g, k*k, ones(k,k), 'symmetric');
zmed = medfilt2(g, [k k], 'symmetric');
processUsingLevelB = (zmed>zmin) & (zmax > zmed) & ~alreadyProcessed;
zB = (g>zmin) & (zmax>g);
outputZxy = processUsingLevelB & zB;
outputZmed = processUsingLevelB & ~zB;
f(outputZxy) = g(outputZxy);
f(outputZmed) = zmed(outputZmed);
alreadyProcessed = alreadyProcessed | processUsingLevelB;
if all(alreadyProcessed(:))
break;
end
end

f(~alreadyProcessed) = zmed(~alreadyProcessed);

(Code taken from Digital Image Processing using Matlab )

Listing 4:
%Lab Challenge 3: Problem 4
I = imread('Fig4.20(a).jpg');

f = fspecial('gaussian', 5)
h = fspecial('laplacian',0)

J = imfilter(I, f, 'replicate');
imshow(J);
K = I-imfilter(J, h, 'replicate');
figure, imshow(K);

L = I-imfilter(I, h, 'replicate');
figure, imshow(L);
K = imfilter(L, f, 'replicate');
figure, imshow(K);

Listing 5:
%Lab Challenge 3: Problem 6
I = imread('Fig3.15(a)1top.jpg');
imhist(I, 255); figure;
J=histeq(I);
imshow(J);
figure, imhist(J);
J= histeq(J);
figure, imhist(J);

Вам также может понравиться