Code covered by the BSD License  

Highlights from
Closing

image thumbnail

Closing

by

 

It is a basic of image processing tool which consist opening and closing.

closing.m
clc;
clear all;
close all;
z=uigetfile('*.*','Select an image file');
a=imread(z);
% b=isrgb(a);
% if( b==1)
    a=rgb2gray(a);
% end
s=[255 255 255 ; 255 255 255 ; 255 255 255];
 
r=size(a,1);
c=size(a,2);
for i=2:r-1
    for j=2:c-1
        if (a(i-1,j-1)==s(1) || a(i-1,j)==s(2) || a(i-1,j+1)==s(3) || a(i,j-1)==s(4) || a(i,j)==s(5) || a(i,j+1)==s(6) || a(i+1,j-1)==s(7) || a(i+1,j)==s(8) || a(i+1,j+1)==s(9))
            new(i,j)=255;
        else
            new(i,j)=0;
        end
    end
end
 
r=size(new,1);
c=size(new,2);
 
for i=2:r-1
    for j=2:c-1
  if (new(i-1,j-1)==s(1) && new(i-1,j)==s(2) && new(i-1,j+1)==s(3) && new(i,j-1)==s(4) && new(i,j)==s(5) && new(i,j+1)==s(6) && new(i+1,j-1)==s(7) && new(i+1,j)==s(8) && new(i+1,j+1)==s(9))
            new1(i,j)=255;
        else
            new1(i,j)=0;
        end
    end
end





subplot(121)
imshow(a);
title('Original Image');
subplot(122)
imshow(new1);
title('Resultant Image');

Contact us