% region filling
clc;
close all;
clear all;
% Input
A=[0 0 0 0 0 0 0
0 0
1 1 0 0 0
0 1
0 0 1 0 0
0 1
0 0 1 0 0
0 0
1 0 1 0 0
0 0
1 0 1 0 0
0 1
0 0 0 1 0
0 1
0 0 0 1 0
0 1
1 1 1 0 0
0 0
0 0 0 0 0];
figure(1),clf,colormap('gray') % CLF-> Clear current figure
subplot(1,3,1),imagesc(A); % IMAGESC-> Scale data and display
as image.
Ac = ones(size(A)) - A; % Ac --> A's complement
B = [0 1 0; 1 1 1; 0 1 0]; %
Restructuring Element
x = zeros(size(A));
x(3,3)=1;
% Start Point
k=0;
flag_region_found = 0;
while flag_region_found ~= 1,
k =
k+1;
subplot(1,3,2),imagesc(x);
%drawnow-> Flush pending graphics events.
xnew = and(dilate(x,B),Ac);
%
DILATE --> Perform dilation on binary image.
x
xnew
xnew-x
sum(xnew-x)
sum(sum(xnew-x))
if
sum(sum(xnew-x))== 0,
flag_region_found = 1;
else
x=xnew;
%
disp(['iteration # ' int2str(k)]);
end
pause(.6)
end
y = x+A;
subplot(1,3,3),imagesc(y);
0 comments:
Confused? Feel free to ask
Post a Comment