You are on page 1of 16

Q 1

Write a program to display the negative of an image.

a=imread('C:\Users\Desktop\lena.png'); subplot(2,2,1); imshow(a); title('original image'); b=rgb2gray(a); subplot(2,2,2); imshow(b); title('gray scale image'); c=255-a; subplot(2,2,3); imshow(c); title('negative of image'); d=255-b; subplot(2,2,4); imshow(d); title('negaative of gray scale image'); OUTPUT:

1|Page

Q 2 Write a program to display log transformation of an image.

a=imread('C:\Users\Desktop\lena.png'); subplot(2,2,1); imshow(a); title('original image'); b=im2double(a); subplot(2,2,2); imshow(b); title('double of an image'); c=log(1+b); subplot(2,2,3); imshow(c); title('log of an image'); d=log2(1+b); subplot(2,2,4); imshow(d); title('log to the base 2');

OUTPUT:

2|Page

Q 3 Write a program to display the antilog transformation of an image.

a=imread('C:\Users\Desktop\lena.png'); subplot(2,2,1); imshow(a); title('original image'); b=im2double(a); subplot(2,2,2); imshow(b); title('Double of image'); c=log10(1+b); subplot(2,2,3); imshow(c); title('log10 of an image'); d=exp(b)/10; subplot(2,2,4); imshow(d); title('antilog of an image');

OUTPUT:

3|Page

Q 4 Write a program to display a filtered image after passing it to a ideal low pass filter.
a=imread('C:\Users\Desktop\lena2.png'); b=double(a); [m n]=size(a); d0=input('enter the cut off frequency'); for u=1:1:m for v=1:1:n d=((u-m/2)^2+(v-n/2)^2)^0.5; if(d<d0) H(u,v)=1; else H(u,v)=0; end end end fouriertrans=fft2(b,size(H,1),size(H,2)); shiftedfouriertrans=fftshift(fouriertrans); x=shiftedfouriertrans.*H; X=abs(ifft2(x)); filtered_image=uint8(X); filtered_image = filtered_image(1:size(a, 1), 1:size(a, 2)); subplot(2,2,1); imshow(a); title('original image'); subplot(2,2,2); imshow(filtered_image); title('Filtered Image'); subplot(2,2,3); imshow(H); title('Ideal low pass filter'); subplot(2,2,4); mesh(H),colormap(gray); title'Ideal low pass frequency response';

OUTPUT:

4|Page

Q 5 Write a program to display a filtered image after passing it to a ideal high pass filter.
a=imread('C:\Users\Desktop\lena2.png'); b=double(a); [m n]=size(a); d0=input('enter the cut off frequency'); for u=1:1:m for v=1:1:n d=((u-m/2)^2+(v-n/2)^2)^0.5; if(d<d0) H(u,v)=0; else H(u,v)=1; end end end fouriertrans=fft2(b,size(H,1),size(H,2)); shiftedfouriertrans=fftshift(fouriertrans); x=shiftedfouriertrans.*H; X=abs(ifft2(x)); filtered_image=uint8(X); filtered_image = filtered_image(1:size(a, 1), 1:size(a, 2)); subplot(2,2,1); imshow(a); title('original image'); subplot(2,2,2); imshow(filtered_image); title('Filtered Image'); subplot(2,2,3); imshow(H); title('Ideal high pass filter'); subplot(2,2,4); mesh(H),colormap(gray); title'Ideal high pass frequency response';

OUTPUT:

5|Page

Q 6 Write a program to display a filtered image after passing it to a Butterworth low pass filter.
a=imread('C:\Users\Desktop\lena2.png'); b=double(a); [m n]=size(a); d0=input('enter the cut off frequency'); n0=input('enter value of n'); for u=1:1:m for v=1:1:n d=((u-m/2)^2+(v-n/2)^2)^0.5; H(u,v)=1/(1+(d/d0))^2*n0; end end fouriertrans=fft2(b,size(H,1),size(H,2)); shiftedfouriertrans=fftshift(fouriertrans); x=shiftedfouriertrans.*H; X=abs(ifft2(x)); filtered_image=uint8(X); filtered_image = filtered_image(1:size(a, 1), 1:size(a, 2)); subplot(2,2,1); imshow(a); title'original image'; subplot(2,2,2); mesh(H),colormap(gray); title'butterworth low pass frequency response'; subplot(2,2,3); imshow(filtered_image); title'Filtered Image'; subplot(2,2,4); imagesc(H), colormap(gray); title'butterworth low pass filter';

OUTPUT:

6|Page

Q 7 Write a program to display a filtered image after passing it to a Gaussian low pass filter.
a=imread('C:\Users\Desktop\lena2.png'); b=double(a); [m n]=size(a); d0=input('enter the cut off frequency'); for u=1:1:m for v=1:1:n d=((u-m/2)^2+(v-n/2)^2)^0.5; H(u,v)=exp((-d*d)/(2*d0*d0)); end end fouriertrans=fft2(b,size(H,1),size(H,2)); shiftedfouriertrans=fftshift(fouriertrans); x=shiftedfouriertrans.*H; X=abs(ifft2(x)); filtered_image=uint8(X); filtered_image = filtered_image(1:size(a, 1), 1:size(a, 2)); subplot(2,2,1); imshow(a); title'original image'; subplot(2,2,2); mesh(H),colormap(gray); title'Gausian low pass frequency response'; subplot(2,2,3); imshow(filtered_image); title'Filtered Image'; subplot(2,2,4); imagesc(H), colormap(gray); title'gausian low pass filter';

OUTPUT:

7|Page

Q 8 Write a program to perform laplace transform of an image. clc; a=imread('C:\Users\Desktop\lena color.png'); z=im2double(a); s=del2(z); s1=3*s; s2=z-s1; subplot(2,2,1); imshow(a); title('Original image'); subplot(2,2,2); imshow(s); title('Laplace of an image'); subplot(2,2,3); imshow(s2); title('Sharpen image');

OUTPUT:

8|Page

Q 9 Write a program to calculate the gradient of the image.

clc; a=imread('C:\Users\Desktop\lena color.png'); z=im2double(a); s=gradient(z); s1=4*s; s2=z-s1; subplot(2,2,1); imshow(a); title('original'); subplot(2,2,2); imshow(s); title('gradient of an image'); subplot(2,2,3); imshow(s2); title('Sharpen image'); OUTPUT:

9|Page

Q 10 Write a program to perform arithmetic operations on an image. a=imread('C:\Users\Desktop\lena.png'); b=imread('C:\Users\Desktop\lena color.png'); subplot(3,3,1); imshow(a); title'image1'; subplot(3,3,2); imshow(b); title'image2'; c=a+b; subplot(3,3,3); imshow(c); title'added image'; d=b-a; subplot(3,3,4); imshow(d); title'substracted image'; e=a.*5; subplot(3,3,5); imshow(e); title'multiplied image'; f=b./2; subplot(3,3,6); imshow(f); title'divided image'; OUTPUT:

10 | P a g e

Q 11 Write threshold point.

program

to

find

the

threshold

image

at

any

a=imread('C:\Users\Desktop\lena color.png'); b=a; k=120; [m,n]=size(a); fori=1:m for j=1:n if(a(i,j)>=k) b(i,j)=255; else (a(i,j)<=1) b(i,j)=0; end end end subplot(2,2,1) imshow(a) title('original image'); subplot(2,2,2) imshow(b); title('changed image'); OUTPUT:

11 | P a g e

Q 12 Write a program to perform butterworth high pass filter on an image. a=imread('C:\Users\Desktop\lena2.png'); b=double(a); [m n]=size(a); d0=input('enter the cut off frequency'); n0=input('enter value of n'); for u=1:1:m for v=1:1:n d=((u-m/2)^2+(v-n/2)^2)^0.5; H(u,v)=1/(1+(d0/d))^2*n0; end end fouriertrans=fft2(b,size(H,1),size(H,2)); shiftedfouriertrans=fftshift(fouriertrans); x=shiftedfouriertrans.*H; X=abs(ifft2(x)); filtered_image=uint8(X); filtered_image = filtered_image(1:size(a, 1), 1:size(a, 2)); subplot(2,2,1); imshow(a); title'original image'; subplot(2,2,2); mesh(H),colormap(gray); title'butterworth high pass frequency response'; subplot(2,2,3); imshow(filtered_image); title'Filtered Image'; subplot(2,2,4); imagesc(H), colormap(gray); title'butterworth high pass filter'; OUTPUT:

12 | P a g e

Q 13 Write a program to perform gaussian high pass filter onan Image. a=imread('C:\Users\Desktop\lena2.png'); b=double(a); [m n]=size(a); d0=input('enter the cut off frequency'); for u=1:1:m for v=1:1:n d=((u-m/2)^2+(v-n/2)^2)^0.5; H(u,v)=1-exp((-d*d)/(2*d0*d0)); end end fouriertrans=fft2(b,size(H,1),size(H,2)); shiftedfouriertrans=fftshift(fouriertrans); x=shiftedfouriertrans.*H; X=abs(ifft2(x)); filtered_image=uint8(X); filtered_image = filtered_image(1:size(a, 1), 1:size(a, 2)); subplot(2,2,1); imshow(a); title'original image'; subplot(2,2,2); mesh(H),colormap(gray); title'Gausian high pass frequency response'; subplot(2,2,3); imshow(filtered_image); title'Filtered Image'; subplot(2,2,4); imagesc(H), colormap(gray); title'gausian high pass filter'; OUTPUT:

13 | P a g e

Q 14 Write a program to add and remove the noise

a=imread('C:\Documents and Settings\student.E1-1LA308\Desktop\lena1.png'); b = imnoise(a,'salt & pepper',0.02); subplot(3,3,1); imshow(a),title('original'); subplot(3,3,2); imshow(b),title('adding salt and pepper noise'); c = imnoise(a,'gaussian',0.02,0.01); subplot(3,3,4); imshow(c),title('adding gaussian noise'); d = imnoise(a,'speckle',0.02) subplot(3,3,6); imshow(d),title('adding speckle noise'); e = imnoise(a,'poisson') subplot(3,3,8); imshow(e),title('adding poisson noise'); f1 = medfilt2(b,[3 3]); subplot(3,3,3); imshow(f1),title('median filter (salt and pepper noise removed)'); f2 = filter2(fspecial('average',3),c)/255; subplot(3,3,5); imshow(f2),title('mean average filter (gaussian noise removed)'); f4 = filter2(fspecial('average',3),d)/255; subplot(3,3,7); imshow(f4),title('mean average filter (speckle noise removed)'); f5 = medfilt2(e,[3 3]); subplot(3,3,9); imshow(f5),title('median filter (poisson noise removed)');

14 | P a g e

OUTPUT:

15 | P a g e

Q 15 Write a program for erosion and dilation of an image. a= imread('C:\Documents and Settings\student.E1-1LA308\Desktop\this1.png'); %b = imnoise(a,'salt & pepper',0.01); subplot(3,3,1); imshow(a),title('original'); %subplot(3,3,2); %imshow(b),title('adding salt and pepper noise'); c = strel('arbitrary',eye(5)); d = imerode(a,c); subplot(3,3,2); imshow(d),title('errosion'); e= imdilate(d,c); subplot(3,3,3); imshow(e),title('dilation'); d = imdilate(d,c); subplot(3,3,4); imshow(d); title('after opening'); d = imdilate(d,c); subplot(3,3,5); imshow(d); title('after closing'); OUTPUT:

16 | P a g e

You might also like