Sunday, 19 July 2015

MATLAB PROGRAM FOR MORPHOLOGICAL OPERATIONS



 /*MATLAB PROGRAM FOR  MORPHOLOGICAL OPERATIONS*/

clc
clear all
a=imread('circles.png');
subplot(3,3,1);
imshow(a);
b=double(a);
[row,col]=size(b);
for i=1:row
for j=1:col
if(b(i,j)==255)
b(i,j)=1;
end
end
end
c=[0 1 0;
    1 1 1;
    0 1 0];
k=1;i=2;j=2;
for i=2:255
for j=2:255
d(k)=(c(2,2)||b(i,j));
      k=k+1;
d(k)=(c(1,2)||b(i,j-1));
     k=k+1;
d(k)=(c(3,2)||b(i+1,j));
     k=k+1;
d(k)=(c(2,3)||b(i,j+1));
     k=k+1;
f(i,j)=max(d);
     k=1;
end
end
title('ORIGINAL IMAGE');
subplot(3,3,2);
imshow(f);
SE = strel('square',3);
BW2 = imdilate(b,SE);

title('DILATED IMAGE');
subplot(3,3,3);
imshow(BW2);
k=1;i=2;j=2;
for i=2:255
for j=2:255
p(k)=(c(2,2)&&b(i,j));
      k=k+1;
p(k)=(c(1,2)&&b(i-1,j));
      k=k+1;
p(k)=(c(2,1)&&b(i,j-1));

k=k+1;
p(k)=(c(3,2)&&b(i+1,j));
     k=k+1;
p(k)=(c(2,3)&&b(i,j+1));
     k=k+1;
q(i,j)=min(p);
     k=1;
end
end
title('DILATE FUNCTION');
subplot(3,3,4);
imshow(q);
SE = strel('square',3);
BW3 = imerode(b,SE);
title('ERODED IMAGE');
subplot(3,3,5);
imshow(BW3);
title('ERODE FUNCTION');
m=imerode(b,SE);
x=imdilate(m,SE);
subplot(3,3,6);
imshow(x);
title('OPENING');
m=imopen(b,SE);
subplot(3,3,7);
imshow(m);
title('OPEN FUNCTION');

x2=imdilate(b,SE);
m2=imerode(x2,SE);
subplot(3,3,8);
imshow(m2);
title('CLOSING');
u=imclose(b,SE);
subplot(3,3,9);
imshow(u);
title('CLOSE FUNCTION');


OUTPUT:-


 /*MATLAB PROGRAM FOR  MORPHOLOGICAL OPERATIONS*/

clc
clear all
a=imread('circles.png');
subplot(3,3,1);
imshow(a);
b=double(a);
[row,col]=size(b);
for i=1:row
for j=1:col
if(b(i,j)==255)
b(i,j)=1;
end
end
end
c=[0 1 0;
    1 1 1;
    0 1 0];
k=1;i=2;j=2;
for i=2:255
for j=2:255
d(k)=(c(2,2)||b(i,j));
      k=k+1;
d(k)=(c(1,2)||b(i,j-1));
     k=k+1;
d(k)=(c(3,2)||b(i+1,j));
     k=k+1;
d(k)=(c(2,3)||b(i,j+1));
     k=k+1;
f(i,j)=max(d);
     k=1;
end
end
title('ORIGINAL IMAGE');
subplot(3,3,2);
imshow(f);
SE = strel('square',3);
BW2 = imdilate(b,SE);

title('DILATED IMAGE');
subplot(3,3,3);
imshow(BW2);
k=1;i=2;j=2;
for i=2:255
for j=2:255
p(k)=(c(2,2)&&b(i,j));
      k=k+1;
p(k)=(c(1,2)&&b(i-1,j));
      k=k+1;
p(k)=(c(2,1)&&b(i,j-1));

k=k+1;
p(k)=(c(3,2)&&b(i+1,j));
     k=k+1;
p(k)=(c(2,3)&&b(i,j+1));
     k=k+1;
q(i,j)=min(p);
     k=1;
end
end
title('DILATE FUNCTION');
subplot(3,3,4);
imshow(q);
SE = strel('square',3);
BW3 = imerode(b,SE);
title('ERODED IMAGE');
subplot(3,3,5);
imshow(BW3);
title('ERODE FUNCTION');
m=imerode(b,SE);
x=imdilate(m,SE);
subplot(3,3,6);
imshow(x);
title('OPENING');
m=imopen(b,SE);
subplot(3,3,7);
imshow(m);
title('OPEN FUNCTION');

x2=imdilate(b,SE);
m2=imerode(x2,SE);
subplot(3,3,8);
imshow(m2);
title('CLOSING');
u=imclose(b,SE);
subplot(3,3,9);
imshow(u);
title('CLOSE FUNCTION');


OUTPUT:-





No comments:

Post a Comment