This method gets image and threshold as arugments and gets the mouse click coordinates as the seed to proceed. Here, starting from the seed the intensity values of each pixel is compared with its neighbours and if it is within the threshold, it'll be marked as one.
Matlab Code
function regionGrowing(name,T)
im=rgb2gray(imread(name));
im=im2double(im);
[r,c]=size(im);
A=zeros(r,c); % segmented mask
F=[]; % frontier list
subplot(1,2,1);
imshow(im);
title('Original');
s=uint16(ginput(1)); % get the click coordinates
s=[s(2),s(1)]; % [row,col]
A(s(1),s(2))=1;
F=[F;s];
while(~isempty(F)) % if frontier is empty
n=neighbours(F(1,1),F(1,2),r,c); % 4 neighbourhood
for i=1:size(n,1)
if(abs(im(F(1,1),F(1,2))-im(n(i,1),n(i,2)))<T && A(n(i,1),n(i,2))~=1)% less than threshold & not already segmented
A(n(i,1),n(i,2))=1;
F=[F;n(i,1),n(i,2)];
end
end
F(1,:)=[];
end
subplot(1,2,2);
imshow(A);
title(sprintf('Threshold: %0.4f',T));
end
function out=neighbours(s1,s2,r,c)
out=[];
if(s2>1), out=[out;s1,s2-1]; end
if(s1>1), out=[out;s1-1,s2]; end
if(s1<r), out=[out;s1+1,s2]; end
if(s2<c), out=[out;s1,s2+1]; end
end
Output
The segmented region is shown in white.