PROGRAM - 1
Write a program in MAT Lab to convert Gray Scale image to Binary Image.
close all;
clear all;
I=imread('camera128.bmp');
BW = im2bw(I, 0.5);
figure,imshow(I);
figure,imshow(BW);
PROGRAM – 2
Write a program in MAT Lab for finding Negative of an Image.
close all;
clear all;
I=imread('a.bmp');
imview(I);
for i=1:160
for j=1:160
I(i,j)=255-I(i,j);
end
end
imview(I);
PROGRAM – 3
Write a program in MAT Lab for Histogram Equalization.
I=imread('a.bmp');
imview(I);
for i=0:255
count=0;
for j=1:160
for k=1:160
if(I(j,k)==i)
count=count+1;
end
end
end
I2(i+1)=count;
end
for i=1:256
I2(i)=I2(i)/(160*160);
end
for i=2:256
I2(i)=I2(i)+I2(i-1);
end
for i=1:256
I2(i)=I2(i)*255;
I2(i)=int16(I2(i));
end
I3=I;
for i=0:255
for j=1:160
for k=1:160
if(I(j,k)==i)
I3(j,k)=I2(i+1);
end
end
end
end
imview(I3);
imhist(I3);
PROGRAM - 4
Write a program in MAT Lab for Image Averaging.
close all;
clear all;
I = imread('camera128.bmp');
subplot(2,2,1);
imshow(I); title('Original Image');
H = fspecial('motion',20,45);
MotionBlur = imfilter(I,H,'replicate');
subplot(2,2,2);
imshow(MotionBlur);title('Motion Blurred Image');
H = fspecial('disk',10);
blurred = imfilter(I,H,'replicate');
subplot(2,2,3);
imshow(blurred); title('Blurred Image');
H = fspecial('unsharp');
sharpened = imfilter(I,H,'replicate');
subplot(2,2,4);
imshow(sharpened); title('Sharpened Image');
PROGRAM - 5
Write a program in MAT Lab for Image Subtraction.
clear, close all;
I = imread('camera128.bmp');
imview(I)
background = imopen(I,strel('disk',15));
imview(background)
I2 = imsubtract(I,background);
imview(I2)
PROGRAM - 6
WAP in MAT Lab for Gaussian Low pass Filter.
close all;
clear all;
x=imread('Fig4.11(a).jpg');
subplot(211);imshow(x,[]);title('Original Image');
dimension=size(x);
D0=15;
x=double(x);
M=dimension(1);
N=dimension(2);
filt=zeros(M,N); % filter
for i=1:M
for j=1:N
filt(i,j)=exp(-((i-M/2).^2+(j-N/2).^2)/(2*(D0^2)));;
end
end
freq_im=fft2(x);
freq_im=fftshift(freq_im);
y=(1/(M*N))*freq_im; % 1/MN should
be added by the user
filt_im=y.*filt;
new_freq=ifftshift(filt_im);
new_im=ifft2(new_freq,M,N);
subplot(212);imshow(new_im,[]);title('Low Pass Image');
PROGRAM - 7
WAP in MAT Lab for Gaussian High pass Filter.
close all;
clear all;
x=imread('Fig4.11(a).jpg');
subplot(211);imshow(x,[]);title('Original
Image');
dimension=size(x);
D0=100;
x=double(x);
M=dimension(1);
N=dimension(2);
filt=zeros(M,N); % filter
for i=1:M
for j=1:N
filt(i,j)=exp(-((i-M/2).^2+(j-N/2).^2)/(2*(D0^2)));;
end
end
freq_im=fft2(x);
freq_im=fftshift(freq_im);
y=(1/(M*N))*freq_im; % 1/MN should be added by the user
filt_im=y.*(1-filt);
new_freq=ifftshift(filt_im);
new_im=real(ifft2(new_freq,M,N));
subplot(212);imshow(new_im,[]);title('High
Pass Image')
PROGRAM - 8
WAP in MAT Lab for Homomorphic Filtering.
close all
clc
clear all
d=10;
order=2;
im=double(imread('tun.jpg'));
subplot(121)
imshow(im./255);
[r c]=size(im);
homofil(im,d,r,c,order);
function homofil(im,d,r,c,n)
A=zeros(r,c);
for i=1:r
for j=1:c
A(i,j)=(((i-r/2).^2+(j-c/2).^2)).^(.5);
H(i,j)=1/(1+((d/A(i,j))^(2*n)));
end
end
alphaL=.0999;
aplhaH=1.01;
H=((aplhaH-alphaL).*H)+alphaL;
H=1-H;
im_l=log2(1+im);
im_f=fft2(im_l);
im_nf=H.*im_f;
im_n=abs(ifft2(im_nf));
im_e=exp(im_n);
subplot(122)
imshow((im_e),[])
PROGRAM - 9
WAP in MAT Lab for Edge Detection.
close all;
clear all;
I = imread('a.bmp');
figure,imshow(I);
BW1 = edge(I,'sobel');
BW2 = edge(I,'canny');
figure,imshow(BW1)
figure, imshow(BW2)
PROGRAM - 10
WAP in MAT Lab for Erosion of an Image.
close all;
clear all;
I = imread('camera128.bmp');
se = strel('ball',5,5);
I2 = imerode(I,se);
imshow(I), title('Original')
figure, imshow(I2), title('Eroded')
PROGRAM - 11
WAP in MAT Lab for Dilation of an Image.
close all;
clear all;
I = imread('camera128.bmp');
se = strel('ball',5,5);
I2 = imdilate(I,se);
imshow(I), title('Original')
figure, imshow(I2), title('Dilated')
No comments:
Post a Comment