Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Digital Image Processing
- Practical
- Name: Anwesha Sanyal
- Roll No: 3906
- Practical-1(Reading and Displaying)
- pkg load image;
- I=imread("Panda.jpg");
- imshow(I);
- Practical-2 (Resize an image)
- resizedI = imresize(I,0.25);
- figure
- imshow(resizedI)
- Practical-3 (Gray scale image)
- J = rgb2gray(I);
- Figure
- imshow(J);
- Practical-4 (Black & White image)
- figure imshow(im2bw(I));
- Practical-5 (Color temperature of image)
- r = size(I,1);
- c = size(I,2);
- R =zeros(r,c,3);
- G = zeros(r,c,3);
- B = zeros(r,c,3);
- R( : , : ,1) = I( : , : ,1);
- G( : , : ,2) = I( : , : ,2);
- B( : , : ,3) = I( : , : ,3);
- figure imshow(uint8(R));
- figure imshow(uint8(G));
- figure imshow(uint8(B));
- Practical-6 (Negative of an image)
- Image = imread(' Panda.jpg ');
- J = rgb2gray(Image);
- subplot(1,3,1);
- imshow(J);
- negativeImage = 255-J; subplot(1,3,2); imshow(negativeImage);
- for row=1:size(J,1)
- for col=1:size(J,2)
- negativeimage(row,col,:)=255-J(row,col,:); end
- end
- subplot(1,3,3); imshow(negativeimage);
- Practical-7 (Stretching of an image)
- subplot(1,2,1) imshow(Image);
- J = imadjust(Image,stretchlim(Image),[]); subplot(1,2,2);
- imshow(J);
- Practical-8 (Applying filter on an image)
- lap =[0,1,0;1,-4,1;0,1,0]; output=imfilter(I,lap); subplot(2,2,1);
- imshow(output);
- filteredImage = imadd(I,output); subplot(2,2,2); imshow(filteredImage);
- l = [0,-1,0;-1,4,-1;0,-1,0]; output2=imfilter(I,l); subplot(2,2,3);
- imshow(output2);
- filteredImage2 = imadd(I,output2); subplot(2,2,4); imshow(filteredImage2);
- Practical-9 (Prewitt Filter)
- subplot(2,3,1);
- imshow(I);
- title('Original Image');
- prewitt_H = [-1,-1,-1;0,0,0;1,1,1]; output_H = imfilter(I,prewitt_H); subplot(2,3,2); imshow(output_H);
- title('prewitt_H');
- filteredImage_H =imadd(I,output_H);
- subplot(2,3,3); imshow(filteredImage_H); title('filteredImage_H');
- prewitt_V = [-1,0,1;-1,0,1;-1,0,1]; output_V = imfilter(I,prewitt_V); subplot(2,3,4);
- imshow(output_V);
- title('prewitt_V');
- filteredImage_V=imadd(I,output_V); subplot(2,3,5);
- imshow(filteredImage_V); title('filteredImage_V');
- filtered_img=imadd(I,output_H); filtered_image=imadd(filtered_img,output_V); subplot(2,3,6);
- imshow(filtered_image);
- title('prewitt');
- Practical-10 (Zooming an image)
- imshow(Image); title("zoomed image"); zoom(2);
- Practical-11 (Translating an image)
- pkg load image
- i = imread(' Panda.jpg ');
- subplot(1,2,1);
- imshow(i);
- title("Original image");
- set(gca, "Visible", "on"); j = imtranslate(i, [20,-40]); subplot(1,2,2); imshow(j);
- title("translated Image");
- set(gca, "Visible", "on");
- Practical-12 (Shrinking an image)
- f = input('Enter the shrinking factor: ');
- s = size(A);
- s1 = s/f;
- k = 1;
- l = 1;
- for i=1:s1
- for j=1:s1
- B(i,j) = A(k,l); l = l+f;
- end
- l = 1;
- k=k+f;
- end
- subplot(1,2,1); imshow(A);
- title("Original image");
- subplot(1,2,2); imshow(B); title("shrinkled image");
- Practical-13 (Salt & pepper noise)
- pkg load image
- i=imread(' Panda.jpg ');
- subplot(2,2,1);
- imshow(i);
- title('Original Image');
- J = imnoise(i,'salt & pepper', 0.05);
- subplot(2,2,2);
- imshow(J);
- title('Noisy Image');
- ##remove salt and pepper noise using averaging filter
- H = fspecial('average',[3,3]);
- Kaverage = imfilter(J,H);
- subplot(2,2,3);
- imshow(Kaverage);
- title('Noise Free Image');
- ##remave salt and pepper noise usign median filter
- i = rgb2gray(J);
- Kmedian = medfilt2(i);
- subplot(2,2,4);
- imshow(Kmedian);
- title('Noise free Image after median filter');
- Practical-14 (Rotating an image)
- j = imrotate(i, 90);
- imshow(j);
- Practical-15
- subplot(1,3,1);
- imshow(i);
- title("Input image");
- g = rgb2gray(i);
- subplot(1,3,2);
- imshow(g);
- title("Gray Imgae");
- f_transform = double(g);
- f_transform1 = double(g);
- h = fspecial('prewitt');
- pre1 = uint8(round(filter2(h,g)));
- subplot(1,3,3);
- imshow(pre1);
- title("prewitt image");
- Practical-16 (Laplacian filter)
- subplot(1,3,1);
- imshow(I);
- title("original image");
- lap = [0,1,0;1,-4,1;0,1,0];
- output = imfilter(I,lap);
- subplot(1,3,2);
- imshow(output);
- title("lap image");
- filteredimage = imadd(I, output);
- subplot(1,3,3);
- imshow(filteredimage);
- title("filtered image");
- Practical-17 (Histogram equalisation)
- imhist(i);
- J = histeq(i); imhist(J); imshow(J);
- Practical-18 (Erosion of image)
- i = uint8(i); subplot(1,3,1); imshow(i);
- i = im2bw(i); i= double(i); subplot(1,3,2); imshow(i);
- se = [0,1,0;1,1,1;0,1,0]; se = strel("square", 3); erodedI = imerode(i, se); subplot(1,3,3); imshow(i);
- Practical-19 (Edge detection of an image)
- I=rgb2gray(i);
- BW3 = edge(I,"roberts"); subplot(2,2,1); imshow(I);
- title("original");
- BW1 = edge (I,"prewitt"); subplot(2,2,2); imshow(BW1); title("prewitt");
- BW2 = edge(I,"sobel"); subplot(2,2,3); imshow(BW2);
- title("sobel");
- BW3 = edge(I,"roberts"); subplot(2,2,4); imshow(BW3);
- title("roberts");
- Practical-20 (Dilation of image)
- i = uint8(i);
- subplot(2,2,1);
- imshow(i);
- i = im2bw(i);
- i= double(i);
- subplot(2,2,2);
- imshow(i);
- se = [0,1,0;1,1,1;0,1,0];
- se = strel("square", 3);
- erodedI = imerode(i, se);
- subplot(2,2,3);
- imshow(i);
- dilateI = imdilate(erodedI, se);
- subplot(2,2,4);
- imshow(i);
- Practical-21
- pkg load image
- sth=imread(' Panda.jpg');
- r = size(sth,1);
- c = size(sth,2);
- sth = double(sth);
- sum = 0;
- for i = 1:r
- for j = 1:c
- sum = sum + sth(i,j,:);
- end
- end
- disp(sum)
- disp(sum/(r*c))
- J = imadjust(sth,stretchlim(sth),[]);
- figure;
- imshow(J);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement