DIGITAL IMAGE PROCESSING LAB NEIL MATHEW – 7CS4 – Y3305 - A2324710002 INDEX Date S.No & Title & Page No Sign Q1 WRITE A PROGRAM TO DISPLAY THE NEGATIVE OF AN IMAGE. 3 Q2 WRITE A PROGRAM TO DISPLAY LOG TRANSFORMATION OF AN IMAGE. 4 Q3 WRITE A PROGRAM TO DISPLAY THE ANTILOG TRANSFORMATION OF AN IMAGE. 5 Q4 WRITE A PROGRAM TO DISPLAY A FILTERED IMAGE AFTER PASSING IT TO A IDEAL LOW PASS FILTER. 6 Q5 WRITE A PROGRAM TO DISPLAY A FILTERED IMAGE AFTER PASSING IT TO A IDEAL HIGH PASS FILTER. 8 Q6 WRITE A PROGRAM TO DISPLAY A FILTERED IMAGE AFTER PASSING IT TO A BUTTERWORTH LOW PASS FILTER. 10 Q7 WRITE A PROGRAM TO DISPLAY A FILTERED IMAGE AFTER PASSING IT TO A GAUSSIAN LOW PASS FILTER. 12 Q8 WRITE A PROGRAM TO PERFORM LAPLACE TRANSFORM OF AN IMAGE. 14 Q9 WRITE A PROGRAM TO CALCULATE THE GRADIENT OF THE IMAGE. 16 Q10 WRITE A PROGRAM TO PERFORM ARITHMETIC OPERATIONS ON AN IMAGE. 17 Q11 WRITE A PROGRAM TO FIND THE THRESHOLD IMAGE AT ANY THRESHOLD POINT. 19 Q12 WRITE A PROGRAM TO PERFORM BUTTERWORTH HIGH PASS FILTER ON AN IMAGE. 20 Q13 WRITE A PROGRAM TO PERFORM GAUSSIAN HIGH PASS FILTER ON AN IMAGE. 22 Q14 WRITE A PROGRAM TO PERFORM EROSION, DILATION, BOUNDARY EXTRACTION ON AN IMAGE. 24 Q1 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: Q2 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: Q3 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: Q4 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=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: Q12 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: Q13 Write a program to perform gaussian 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'); 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: Q14 Write a program to perform erosion, dilation, boundary extraction on an image. originalBW = imread('circles.png'); se = strel('disk',11); erodedBW = imerode(originalBW,se); dilateBW = imdilate(originalBW,se); bw1 = imdilate(erodedBW,se); bw2 = imerode(dilateBW,se); boundary = originalBW - erodedBW; hm1 = bwhitmiss subplot(3,3,1); imshow(originalBW); title('Original'); subplot(3,3,2); imshow(erodedBW); title('Original Eroded'); subplot(3,3,3); imshow(dilateBW); title('Original Dilated'); subplot(3,3,4); imshow(bw1); title('Opening'); subplot(3,3,5); imshow(bw2); title('Closing'); subplot(3,3,6); imshow(boundary); title('Boundary'); OUTPUT: