Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Faculty: Mahesh Anand S.

Lab Practice Exercise

Digital Image Processing using MatLab

1. Convert the input image into its negative by point transformation.

a= imread('cameraman.tif');
L=256;
s=L-1-a;
imshow(s)

2. Perform log transform to enhance the Fourier transform of the given


cameraman.tif image and show the spectrum before and after log transform.

a=imread('cameraman.tif');
b=fft2(double(a));
bc=fftshift(b);
figure(1);
imshow(bc)
bc1=log(1+abs(bc));
figure(2);
imshow(bc1,[])

Winter 2008-2009 Third Year B.Tech (ECE)


Faculty: Mahesh Anand S. Lab Practice Exercise

Note: log transform can also implemented using power law transform equation as
gamma=0.3 %should be less than 1
S=c.*(r+0.1)^gamma;

3. Perform upsampling and downsampling to zoom and shrink the given


cameraman.tif image and show the result.

y=imread('cameraman.tif');
imview(y)
[m n] = size(y);
a=m/2;
b=n/2;
for k=1:8
for i=1:a
for j=1:b
y1(i,j)=y(i*2,j*2); % Downsampling - Shrinking
end
end
end
clear y;
y=y1;
figure;
imview(y1);
clear y1;

Winter 2008-2009 Third Year B.Tech (ECE)


Faculty: Mahesh Anand S. Lab Practice Exercise

% Image Zooming
y=imread('cameraman.tif');
imview(y)
[m n] = size(y);
for k=1:4
for i=1:m
for j=1:n
y1(i*2,j*2)=y(i,j);
y1(i*2-1,j*2-1)=y1(i*2,j*2);
y1(i*2-1,j*2)=y1(i*2,j*2);
y1(i*2,j*2-1)=y1(i*2,j*2);
end
end
end
clear y;
y=y1;
figure;
imview(y1);
clear y1;

Inference: Zoomed image showing checkerboard pattern

Winter 2008-2009 Third Year B.Tech (ECE)


Faculty: Mahesh Anand S. Lab Practice Exercise

4. Demonstration of logical AND and OR operation with cameraman.tif image

clear all
a=imread('cameraman.tif');
[m, n]=size(a);
for i=1:m
for j=1:n
if(((i>=35)&(i<110))&((j>90)&(j<140)))
d(i,j)=255;
e(i,j)=0;
else
d(i,j)=0;
e(i,j)=255;
end
end
end
imshow(d);title('AND Mask');
figure;
imshow(e);title('OR Mask');
f=bitand(uint8(a),uint8(d));
g=bitor(uint8(a),uint8(e));
figure;
imshow(f);title('ANDed Output');
figure;
imshow(g);title('ORed Output');

Winter 2008-2009 Third Year B.Tech (ECE)


Faculty: Mahesh Anand S. Lab Practice Exercise

5.

Winter 2008-2009 Third Year B.Tech (ECE)

You might also like