Professional Documents
Culture Documents
DIPP
DIPP
>> Im=imread('tulips.jpg');
>> imshow(Im);
>> s=size(Im);
>> disp(s);
112 288 3
>> avg=mean(Im(:));
>> minIntensity=min(Im(:));
>> maxIntensity=max(Im(:));
>>
>> disp('Average Intensity of the image is:');
Average Intensity of the image is:
>> disp(avg);
123.8232
>> I=imread('butterfly.jpg');
>> imshow(I);
>>
>> r=I(:,:,1);
>> figure;
>>
image(r),colormap([[0:1/255:1]',zeros(256,1),zeros(256,
1)]),colorbar;
>>
>> g=I(:,:,2);
>> figure;
>>
image(g),colormap([zeros(256,1),[0:1/255:1]',zeros(256,
1)]),colorbar;
>>
>> b=I(:,:,3);
>> figure;
>>
image(b),colormap([zeros(256,1),zeros(256,1),[0:1/255:
1]']),colorbar;
OUTPUT
3. Write a program to demonstrate the
following distance measure A) Euclidean
distance B) City block distance C) Chess
board distance
>> i1=imread('img8.jpg');
>> i2=imread('img10.jpg');
>> imshow(i1);
>> imshow(i2);
>> Aimg=imadd(i1,i2);
>> imshow(Aimg,[]);
>> Simg=imsubtract(i1,i2);
>> imshow(Simg,[]);
>> Mimg=immultiply(i1,i2);
>> imshow(Mimg,[]);
>> Dimg=imdivide(i1,i2);
>> imshow(Dimg,[]);
OUTPUT
5. Write a program to obtain a histogram of
gray scale image
>> i=imread('dog.jpg');
>> g=rgb2gray(i);
>> subplot(1,2,1);
>> imshow(g);
>>
>> subplot(1,2,2);
>> imhist(g);
OUTPUT
>> I=imread('cat.jpg');
>> I=rgb2gray(I);
>> imshow(I);
>> figure;
>> subplot(1,2,1);
>> imshow(I);
>> subplot(1,2,2);
>> imhist(I,64);
>>
>> J=histeq(I);
>> figure;
>> subplot(1,2,1);
>> imshow(j);
>> subplot(1,2,2);
>> J=histeq(I);
>> figure;
>> subplot(1,2,1);
>> imshow(J);
>> subplot(1,2,2);
>> imhist(J,64);
OUTPUT
7. Write a program to demonstrate the use of
logic operation A) AND B) OR C) NOT
>> a=imread('rose.jpg');
>> a=imresize(a,[512,512]);
>> a=rgb2gray(a);
>> a=im2bw(a);
>> subplot(2,3,1);
>> imshow(a);
>> title('Image 1');
>> b=imread('earl.jpg');
>> b=imresize(b,[512,512]);
>> b=rgb2gray(b);
>> b=im2bw(b);
>> subplot(2,3,2);
>> imshow(b);
>> title('Image 2');
>> na=not(a);
>> subplot(2,3,3);
>> imshow(na);
>> title('Not a');
>> nb=not(b);
>> subplot(2,3,4);
>> imshow(nb);
>> title('Not b');
>> aandb=and(na,nb);
>> subplot(2,3,5);
>> imshow(aandb);
>> title('a and b');
>> aorb=or(na,nb);
>> subplot(2,3,6);
>> imshow(aorb);
>> title('a or b');
OR
>> clc;
>> clear all;
>> close all;
>> a=ones(40);b=zeros(40);
>> c=[a b;b a];d=[b b;a a];
>> subplot(3,2,1);imshow(c);title('original image');
>> subplot(3,2,2);imshow(d);title('original image');
>> %NOT (take a compliment of c and display it
>> notimg=~c;
>>
subplot(3,2,3);imshow(notimg);title('Complimented
image C');
>> %AND operation(take AND of image c and image b
and display it
>> andimg=c&d;
>> subplot(3,2,4);imshow(andimg);title('Image C AND
image D');
>> %OR operation(Take OR of image c and image b
and display it)
>> subplot(3,2,5);
>> orimage=c|d;
>> imshow(orimage);title('Image C OR image D');
>>
OUTPUT
Or
PART-B
1.Demonstrate the following filters and
perform smoothening on an image A)
Minimum filter B) Maximum filter
>> I=imread('Nature.jpg');
>> BW=im2bw(I,0.6);
>> minf=@(x)min(x(:));
>> maxf=@(x)max(x(:));
>> min_img=nlfilter(BW,[3,3],minf);
>> max_img=nlfilter(BW,[3,3],maxf);
>> subplot(2,2,1),imshow(BW),title('Original Image');
>> subplot(2,2,2),imshow(min_img),title('Minimum
Image');
>> subplot(2,2,3),imshow(max_img),title('Maximum
Image');
OUTPUT
>> I=imread('nature.jpg');
>> f=fspecial('average',3);
>> bimg=imfilter(I,f);
>> nimg=imnoise(I,'salt & pepper',0.2);
>> med=fspecial('gaussian',7);
>> fimg=imfilter(nimg,med);
>> subplot(2,2,1),imshow(I),title('Original Image');
>> subplot(2,2,2),imshow(bimg),title('Blurred Image');
>> subplot(2,2,3),imshow(nimg),title('Noisy Image');
>> subplot(2,2,4),imshow(fimg),title('Filtered Image');
OUTPUT
>> y=imread('nature.jpg');
>> y=rgb2gray(y);
>> lab=[0 1 0;1 -4 1;0 1 0];
>> result=uint8(filter2(lab,y,'same'));
>> sharp=imsubtract(y,result);
>> subplot(2,2,1);
>> title('Original Image');
>> imshow(y);
>> subplot(2,2,2);
>> imshow(sharp);
>> title('Sharp Image');
>> subplot(2,2,3);
>> imshow(result);
>> title(‘laplician filter’);
OUTPUT
5.Write a program to demonstrate the
following neighbors of following pixels
1) 4 neighbors of pixel
2) 4 diagonal neighbors of a pixel
3) 8 neighbors of a pixel
>> clc;
>> clear all;
>> close all;
>> %to find neighbor of a given pixel
>> a=magic(5);
>> disp('a=');disp(a);
a=
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> i=imread('nature.jpg');
>> g=rgb2gray(i);
>> f=edge(g,'Canny');
>> subplot(1,2,1);imshow(f);title('Detected Edge');
>> subplot(1,2,2);imshow(i);title('Original Image');
>>
OUTPUT
>> i=imread('nature.jpg');
>> g=rgb2gray(i);
>> f=edge(g,'sobel');
>> subplot(1,2,1);imshow(f);title('Detected Edge');
>> subplot(1,2,2);imshow(i);title('Original Image');
>>
OUTPUT