0% found this document useful (0 votes)
34 views10 pages

Write A Matlab Code For Obtaining Digital Negative of An Image

The document provides MATLAB code examples for performing various image processing techniques: 1) Obtaining a digital negative of an image. 2) Implementing intensity slicing without and with background. 3) Adding gaussian and salt & pepper noise. 4) Sharpening an image using a high pass filter. 5) Performing histogram stretching. 6) Dilating, eroding, opening, and closing operations. 7) Performing a 1D Fourier transformation.

Uploaded by

einstein_avin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views10 pages

Write A Matlab Code For Obtaining Digital Negative of An Image

The document provides MATLAB code examples for performing various image processing techniques: 1) Obtaining a digital negative of an image. 2) Implementing intensity slicing without and with background. 3) Adding gaussian and salt & pepper noise. 4) Sharpening an image using a high pass filter. 5) Performing histogram stretching. 6) Dilating, eroding, opening, and closing operations. 7) Performing a 1D Fourier transformation.

Uploaded by

einstein_avin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

Write a matlab code for obtaining digital negative of an image

>> clear all


>> i=imread('C:\Users\D106\Desktop\New folder (2)\forest.jpg');
>> aa1=255-i;
>> imshow(i);
>> imshow(uint8(aa1));

2. Write a matlab code for implementing intensity slicing without background


>> clear all
>>i=imread('C:\Users\D106\Desktop\New folder (2)\rose.jpg');
>>a1=double(i);
>>[row col]=size(a1);
>>for i=1:1:row
for j=1:1:col
if (a1(i,j)<=100&& a1(i,j)<=150)
a1(i,j)= 255;
else
a1(i,j)=0;
end
end
end
>> figure(1)
>> imshow(i)
>> figure(2)
>> imshow(uint8(a1))

3. Write a matlab code for implementing intensity slicing with background


>> clear all
>>i=imread('C:\Users\D106\Desktop\New folder (2)\rose.jpg');
>>a1=double(i);
>>[row col]=size(a1);
>>for i=1:1:row
for j=1:1:col
if (a1(i,j)<=100&& a1(i,j)<=150)
a1(i,j)= 255;
else
a1(i,j)=a1(i,j);
end
end
end
>> figure(1)
>> imshow(i)
>> figure(2)
>> imshow(uint8(a1))

4. Matlab code for implementing gaussian noise


>> clear all
>>a=imread('C:\Users\D106\Desktop\New folder (2)\rose.jpg');
>>aa=imnoise(a,'gaussian');
>>a1=double(aa);
>>[row col]=size(a1);
>>w=[1 1 1; 1 1 1; 1 1 1]/9
>>for i=2:1:row-1
for j=2:1:col-1
a2(i,j)= w(1)*a1(i-1,j-1)+ w(2)*a1(i-1,j)+ w(3)*a1(i-1,j+1)+ w(4)*a1(i,j-1)+
w(5)*a1(i,j)+ w(6)*a1(i,j+1)+ w(7)*a1(i+1,j-1)+ w(8)*a1(i+1,j)+
w(9)*a1(i+1,j+1);
end
end
>> figure(1)
>> imshow (aa)
>> figure(2)
>> imshow(uint8(a2))

5. Matlab code for implementing salt and pepper noise


>> clear all
>>i=imread('C:\Users\D106\Desktop\New folder (2)\rose.jpg');
>>imshow(i);
>>j=imnoise(i,'salt & pepper');
>>imshow(j);
>>a=double(j);
>>b=a;
>>[row col]=size(a);
>>for x=2:1:row-1
for y=2:1:col-1
a1=[a(x-1,y-1) a(x-1,y) a(x-1,y+1) a(x,y-1) a(x,y) a(x,y+1) a(x+1,y-1) a(x+1,y)
a(x+1,y+1)];
a2=sort(a1);
med=a2(5);
b(x,y)=med;
end
end
>> figure(1)
>> imshow(uint8(j))
>> figure(2)
>> imshow(uint8(b))

6. Write matlab code for sharpening an image using high pass filter
>> clear all
>>aa=imread('C:\Users\D106\Desktop\New folder (2)\rose.jpg');
a=double(aa);
[row col]=size(a);
w=[-1 -1 -1; -1 8 -1; -1 -1 -1]
>> for i=2:1:row-1
for j=2:1:col-1
a1(i,j)= w(1)*a(i-1,j-1)+ w(2)*a(i-1,j)+ w(3)*a(i-1,j+1)+ w(4)*a(i,j-1)+
w(5)*a(i,j)+ w(6)*a(i,j+1)+ w(7)*a(i+1,j-1)+ w(8)*a(i+1,j)+ w(9)*a(i+1,j+1);
end
end
>> for i=2:1:row-1
for j=2:1:col-1
if(a1(i,j)<0)
a1(i,j)=0;
end
if(a1(i,j)>255)
a1(i,j)=a(i,j)/a;
end
end
>> imshow(uint8(aa));

>> imshow(uint8(a1));

7. Write a MATLAB code for histogram Stretching


>> clear all
>> clc
>> a=imread('C:\Users\D106\Desktop\New folder (2)\forest.jpg');
>> aa=imadjust (a, stretchlim(a), []);
>> figure(1)
>> imshow(uint8(a))
>> figure(2)
>> imshow(uint8(aa))

8. Write a Matlab code for dilation and erosion of image


>> clear all
>> clc
>> a=imread(im1.jpg);
>> aa=double(a);
>> [row col]=size9a0;
>> w=[1 1 1; 1 1 1; 1 1 1]
>> a1=imdilate(aa,w);
>> a2=imerode(aa,w);
>> figure(1)
>> imshow(uint8(a));
>> figure(2)
>> imshow(uint8(a1));
>> figure(3)
>> imshow(uint8(a2));

9. Write a matlab code to perform opening and closing operation in an image


>> clear all
>> clc
>> a=imread(bw1.jpg)
>> aa=double(a);
>> [row col]=size(a);
>> w=[1 1 1 ; 1 1 1 ; 1 1 1 ];
>> a1=imerode(aa,w);
>> a2=imerode(a1,w);
>> figure(1)
>> imshow(uint8(a));
>> figure(2)
>> imshow(uint8(a2));

10. Write a matlab code for performing 1D fourier Transformation


>> clear all
>> clc
>> a=input(enter the value of a : );
>> x=input(enter the value of x : );
>> u=-5:0.5:5;
>> a=sin(pi*u*x);
>> b=pi*u*x;
>> f=(a*x)*(a/b);
%plotting
plot(u, (f))

You might also like