Digital image processing Lab manual

April 4, 2018 | Author: Anubhav Shrivastava | Category: Electronic Filter, Discrete Fourier Transform, Computer Graphics, Signal Processing, Algorithms


Comments



Description

DIGITAL IMAGE PROCESSING LABName: Anubhav Shrivastava Roll Number: 1005210009 B.Tech [2014 Batch] Computer Science and engineering, Final Year, To write a program to illustrate the effect of Square Averaging filter of different masks on an image. To write a program to filter image using a high pass filter. 3) Taking the complex conjugate of the transform. To write a program to apply liner and log transformation on image. To write a program to find negative of an image. SIGN 10 11 12 13 To write a program to observe the effect of order-statistics filter like Median Filter of size 3x3 on an image corrupted by salt & pepper noise. To write a program to illustrate bit plane slicing.INDEX NO 1 2 3 4 5 6 7 8 9 SUBJECT To write a program to display an image and its histogram. 4) Computing the inverse DFT. To write a program for the display of Image in Grayscale. To write a program to learn Image Segmentation Processing.and 5) Multiplying the real part of the result by (-1)^(x+y) 14 . To write a program to show edge detection. Green and Blue. To write a program to illustrate Gray level(Intensity) slicing. To write a program to show histogram equalization. Computing the DFT. Red. To write a program to show Image Enhancement. To write a MATLAB program to observe the result of applying the following steps on the given image. 1) Multiplying the given image by (1)^x+y. I=rgb2gray(A). imshow(I) figure. imhist(I) . I=im2double(I).Practical -1 AIM : To write a program to display an image and its histogram. A=imread('shivani. MATLAB PROGRAM : clc.jpg'). q)=255I(p.. MATLAB PROGRAM : %% % Clearing History clear all force close all %% %% % This program finds Negative of Image %% %% % Importing image into Workspace I=imread('person. % By using formula s=L-1-r % Where L is no. %% %% % Computing size of image. %% %% % Converting Image from RGB into gray I=rgb2gray(I).first row wise then column wise for q=1:n for p=1:m I2(p.2 AIM : To write a program to find negative of an image. of gray Levels of image % and r is Intensity end end %% %% % Displaying Negative of Original Image figure . m rows and n columns [m n]=size(I). %% %% % Displaying image using imshow imshow(I)..jpg').q). %% %% % Operations .Practical . subimage(I).jpg'.title('Negative Image').2.title(' Negative image').'jpg').2. %% %% % writing averaged file to disk imwrite(I2.title(' Original image'). . %% %% % Both Images in Single Window figure subplot(1.subimage(I2). disp('Image Negated and written to disk with name I_Negative. subplot(1.imshow(I2).jpg').1).2).'I_Negative. 2)=z. subplot(3. tempb(:. tempb(:.3)=z.:. tempg(:. image2=rgb2gray (image1).:.3 AIM : To write a program for thedisplay of Image in Grayscale.1) imshow(tempr) title('RED') tempg=image1.jpg').3. tempr=image1.3) imshow(tempb) title('BLUE') 32 .1)=z.:.2)=z.2) imshow(tempg) title('GREEN') tempb=image1.:.c). z=zeros(r. Green and Blue MATLAB PROGRAM : clc image1=imread('India.1)=z.:. tempr(:. Red. tempg(:. subplot(3. subplot(3.3.3.Practical .4) imshow(image2) title('GRAYSCALE') [r c d]=size (image1). tempr(:. subplot(3.:.3)=z.3. j-255) = 1. end end .j) >128) f(i. subplot(4.2.2) imshow(c) title('GrayScale') [m n]=size(c). else f(i. else d(i.n/2) h = zeros(m/2.n/2) for i=1:m/2 for j=1:n/2 if(c(i. d = zeros(m.1) imshow(b) title('Resized') c = rgb2gray(b).2. subplot(4.j) = 1.j-255) = 0.j)>128) d(i.j) = 0.2.4) imshow(e) title('1/4th Segment') for i=1:m/2 for j=n/2:n if(c(i.jpg') b = imresize(a. end end end subplot(4. else e(i. MATLAB PROGRAM : a = imread('India.j) = 1.j) = 0.4 AIM : To write a program to learn Image Segmentation Processing.j) >128) e(i.n) %Conversion to Binary Image for i=1:m for j=1:n if(c(i.Practical .n/2) g = zeros(m/2. [512 512]).n/2) f = zeros(m/2.3) imshow(d) title('Binary') %Processing on Segmentation e = zeros(m/2.2. end end end subplot(4. end subplot(4.2.5) imshow(f) title('1/2th Segment') . end end end subplot(4. else h(i-255. else g(i-255.j-255) = 1.2.6) imshow(g) title('3/4th Segment') for i=m/2:m for j=n/2:n if(c(i.for i=m/2:m for j=1:n/2 if(c(i. end end end subplot(4.2.7) imshow(h) title('4th Segment') .j-255) = 0.j) >128) h(i-255.j) = 0.j) = 1.j) >128) g(i-255. 2.jpg').7) imshow(f).2.2.Practical – 5 AIM : To write a program to show Image Enhancement. c = imresize(b. a = imread('India. title('Power Law Transformation') .2.1 0. title('Adjustment') %Contrast Stretching f = imadjust(c. subplot(4. subplot(4.5 0.[].[0.2. subplot(4.256]).2. title('Contast Stretching') f = imadjust(c.4) imshow(d).[].0.[256. title('Original') b = rgb2gray(a). title('Graycale') %negetive of Image d = imcomplement(c) subplot(4.3) imshow(c). subplot(4. subplot(4.3).[1 2]) imshow(a).[].[0.[]).2.6) imshow(f). subplot(4. title('Negetive') %Log Transformation const=0.9].[]. MATLAB PROGRAM : clc.5]. title('Log Transformation') %adjust f = imadjust(c.2.8) imshow(f).3). e = const*log(1+ double(c)).5) imshow(e). .imshow(img1) title('Image after histogram equalization'). else add(i) = add(i-1) + pdf(i). MATLAB PROGRAM : clc. end end pdf=count*(1/(a(1)*a(2))) add=zeros(1.6 AIM : To write a program to show histogram equalization.256). clear all. for i = 1:256 if (i == 1 ) add(i)=pdf(i).256).j)= add(x+1).j). end end figure() imhist(img) title('Histogram of original image').j)+1)+1.imshow(img) title('Original image'). count=zeros(1. figure().tif').j)+1)= count(img(i. img=imread('lena. figure() imhist(img1) title('Equalized Histogram') figure(). for i = 1:1:a(1) for j = 1:1:a(2) count(img(i. close all.Practical . a=size(img). end end for i = 1:1:a(1) for j = 1:1:a(2) x=img(i. img1(i. q)<=b(r)) I6(p. for p=1:m for q=1:n if (I(p.xlabel(a(r)).Practical ..q)<=b % I(p.1). MATLAB PROGRAM : %% %% % This is for Gray level(Intensity) slicing with background %% %% % ClearHistory clear all Close all %% %% % Importing image to Workspace RGB=imread('person. else I6(p..title('Gray Level slicing with background').imshow(I6). %% %% % Converting image into gray computing size I=rgb2gray(RGB). %% L=255.q)>= a(r) & I(p.q)= L=255 for a<=I(p.q) for otherwise } for r=1:length(a) b(r)=a(r)+20. %% % Creating Array a for formulating [A.q). %pause(0.B] such % that. end end end figure.close all force end .q)=L.jpg') .q)=I(p. B-A=20 a=0:30:(max(max(I))-20) %% and values of a for further %% % { I(p. [m n]=size(I).q)= I(p.7 AIM : To write a program to illustrate Gray level(Intensity) slicing. b2 logical(bitget(c. % Get all eight bitpl anes logical(bitget(c. imshow(b3). title('b7') . clf imshow(c). imshow(b5). clear all. c = imread('lena. imshow(b7).1)) . imshow(b4).2)). clf b0 = = = = logical(bitget(c. b4 logical(bitget(c. clf subplot(221). b3 logical(bitget(c.tif'). title('b6') subplot(224). b5 logical(bitget(c.8)). title('Original image').6)). figure(1). title('b0') subplot(222). title('b1') subplot(223).8 AIM : To write a program to illustrate bit plane slicing. imshow(b2). imshow(b6). b7 = = = = subplot(221). b6 logical(bitget(c. title('b3') figure(3).4)). title('b2') subplot(224). imshow(b1). b1 logical(bitget(c.7)).3)). close all.Practical . title('b4') subplot(222). MATLAB PROGRAM : clc. imshow(b0). title('b5') subplot(223). figure(2).5)). ONES(3.3)) implements a 3-by-3 % minimum filter.3)) implements a % 3-by-3 maximum filter.-1 8 -1. %B=ORDFILT2(A.w)). title('edge detected output 2'). .ordfilt2(i.3. 0 1 0]) % replaces each element in A by the maximum of its north.5)).ones(5. -1 -1 -1] j = abs(imfilter(double(i).Width r = p.DOMAIN)B=ORDFILT2(A.1.5.04*max(j(:)) j = j >= T.9 AIM : To write a program to show edge detection.3. title('input image').tif'). close all. clc. east.ones(5.3*max(s(:)) S = s >= T.3.tif').[0 1 0. 1 0 1.ONES(3.1). subplot(1.Practical . subplot(1. imshow(j).1. subplot(1. title('edge detected output 1').3). imshow(S). and west neighbors. i = imread('lena. imshow(i). MATLAB PROGRAM : clf. % south. w = [-1 -1 -1.Height s = imsubtract(ordfilt2(i. B=ORDFILT2(A. B=ORDFILT2(A. T = 0. T = 0.ONES(3.25. and B=ORDFILT2(A.4.3)) implements a3-by-3 % median filter.9.5))).2). %second method for isolated point detection p = imfinfo('circuit.ORDER. q = p. filtr. imagesc(xf8).'same'). MATLAB PROGRAM : clear. colormap gray.'jpg') % save as *jpg file . filtr(2. %read picture as int8 matrix x=single(X(50:200. % display imwrite(xf8. filtr(2.title('oryginal: cropped and converted to single'). imagesc(xf8). % crop and convert int8 to single figure. % display x=x/max(max(x)). colormap gray.filtr.2)=9 % define another high-pass filter xf=conv2(x. filtr(2.2)=8'). %normalizacja [0. colormap gray.2)=8 % define high-pass filter xf=conv2(x.'fgp8.50:200)).title('filtr=ones(3). imwrite(xf.jpg'. %filtracja xf8=uint8(256*xf).'fgp9.jpg'.1] filtr=-ones(3).2)=9'). %convert result to uint8 figure.title('filtr=-ones(3).jpg'). %filtracja xf8=uint8(256*xf). filtr(2. X=imread ('lena. imagesc(x).10 AIM : To write a program to filter image using a high pass filter.'jpg') % save as *jpg file %return filtr=-ones(3). %convert result to uint8 figure.Practical .'same'). subimage(I).5.18. Here c=L/log10(1+L) I3=im2double(I).title(' Original image'). %% %% % Linear transformation y=m*x+c .title(' Log Transformed image').2.11 AIM : To write a program to apply liner and log transformation on image. here m=0.5 and c=0 figure imshow(I2). %% %% % Converting from RGB to GRAY I=rgb2gray(I).2. MATLAB PROGRAM : %% % Clear History clear all close all %% %% % Importing Image in Workspace I=imread('person. m=0. %% %% % Log transformation s=c*log10(1+r) .% Linear transformation y=m*x+c .title('Linear Transformed image . here m=2 and c=0 I1=2.jpg').% Log Transformation s=c*log10(1+r) %Here c=L/log10(1+L) and r=Intensity of Image figure imshow(uint8(I4)).subimage(uint8(I4)).*I4).title(' Original image'). I4=round(104.Practical .% Linear transformation y=m*x+c . %% % Linear transformation y=m*x+c . here m=0.1).*I.5 '). %% % Displaying image imshow(I). m=2'). I3=255. %% %% % Both Images in Single Window figure subplot(1.5 and c=0 I2=0. . here m=2 and c=0 figure imshow(I1). I4=log10(1+I3).title(' Linear Transformed image .2).*I. subplot(1.*I3.title(' Log Transformed image'). 9).Ha9). sa=size(A) subplot(2.2.15). subplot(2. subplot(2. MATLAB PROGRAM : % Matlab program <image_averaging.15. Ia15=imfilter(A.Ha3).tif'). clea r all. imshow(Ia9).4) imshow(Ia15).Ha15).2. title('Image smoothened by filter of size 15x15').2.2. clos e all.2) imshow(Ia3). Ha9= fspecial('average'.1) imshow(A).9. Ia9=imfilter(A. title('Image smoothened by filter of size 9x9'). clc. title('Image smoothened by filter of size 3x3').Practical . Ia3=imfilter(A.m> % This program is used to observe the results of smoothing due to square averaging filters of size m=3. Ha15= fspecial('average'. . subplot(2. Ha3= fspecial('average'.12 AIM : To write a program to illustrate the effect of Square Averaging filter of different masks on an image. A=imread('lena.3). title('The Original Image').3). tif'). subplot(2. I=imread('pcb. title('Fig a:The original image: X-ray image of circuit board'). figure(1). clear all. title('Fig c:Filtered Image with a 3x3 mask on Fig(b)').2. In=imread('pcbn. close all. figure(2). imshow(I).Practical .13 AIM : To write a program to observe the effect of order-statistics filter like Median Filter of size 3x3 on an image corrupted by salt & pepper noise. subplot(2.2. Im = medfilt2(In). .3) imshow(Im). MATLAB PROGRAM : clc.tif').1) imshow(In) title('Fig b:Original image(a)corrupted by salt & pepper noise'). figure(2).'). Computing the inverse DFT. for x=1:1:M for y=1:1:N t=(-1)^(x+y). close all. L = medfilt2(I. y=N.Practical . Taking the complex conjugate of the transform. clc. YC = conj(Y).*t. s=size(A).*t. imshow(I) title('Fig a:The Output image after applying the given steps.y)=Y1(x. 3. b(x. end end Y = fft2(double(b)). 1.and Multiplying the real part of the result by (-1)^(x+y) MATLAB PROGRAM : % This program is used to observe the change that occurs in %the given image after following the steps given above.y).tif'). 2. end end figure(1). I(x. N=s(2). 5.y). . clear all.y)=A(x. Multiplying the given image by (-1)^x+y.[3 3]). Computing the DFT. Y1 = ifft2(double(YC)). for x=1:1:M for y=1:1:N t=(-1)^(x+y). M=s(1). 4. x=M. imshow(L) title('Fig b:Smoothened image by applying median filter on Fig a'). A=imread('dip.14 AIM : To write a MATLAB program to observe the result of applying the following steps on the given image.
Copyright © 2024 DOKUMEN.SITE Inc.