% function to implement region growing
% BW=region(A,seedx,seedy)
% input parameters
% A image to implement the region growing
% seedx & seedy coordenates of the seed output parameters
% BW is the black&white image
function [BW] = myregiongrowing(A,seedx,seedy)

value=A(seedx,seedy);
amplitudT = 40;
[x y]=find(A<=(value + amplitudT/2)&A>=(value - amplitudT/2));
BW=zeros(size(A));
for i=1:length(x)
 BW(x(i),y(i))=1;
end

%figure, imagesc(BW), colormap gray
cc = bwconncomp(BW);
labeled = labelmatrix(cc);
regionLabel=labeled(seedx,seedy);
clear x y BW
BW=zeros(size(A));
[x y]=find(labeled==regionLabel);
for i=1:length(x)
 BW(x(i),y(i))=1;
end
