function region=eregiongrowing(f)region=cell(size(f)); %Region matrix with same size of image,storing the labels of grown region
[m,n]=size(f);seed=[m/2,n/2];%position of seed(x,y)
rcount=1;%counter to keep track of current region being grown
i=1;j=1;pg=seed;%pg is stack to sore pixels to grow
x1=im2single(f);%Adaptive Threshold code start;
Err = 1;T0=(max(max(x1))+min(min(x1)))/2;while Err > 0.0001,u1=0;u2=0;cnt1=0;cnt2=0;for i=1:mfor j=1:nif x1(i,j)<= T0u1=u1+x1(i,j);cnt1=cnt1+1;elseu2=u2+x1(i,j);cnt2=cnt2+1;endendendu1=u1/cnt1;u2=u2/cnt2;T=(u1+u2)/2;Err=abs(T-T0);if Err > 0.0001T0=T;endendy=im2bw(f,T0);%threshold end
L=bwlabel(y,8);% labelling of region
h=f(:,:,1);s=f(:,:,2);v=f(:,:,3);while ~isempty(pg)%while pg is not empty
cp=pg;% cp -8 neighbours
double(cp); i=i-1; for k=1:8 if region(cp(k))~=L;%if region(cp(k)is not labelled
%code to find similarity using Euclidean distance
for i=1:8 for j=1:8 Dh=(h(x+i,y+j,1)-h(x,y,1)).^2; Ds=(s(x+i,y+j,2)-s(x,y,2)).^2; Dv=(v(x+i,y+j,1)-v(x,y,1)).^2; end end d=sqrt(Dh+Ds+Dv); if(d<T)% threshold value founded in adaptive threshold
region(cp(k))=rcount; i=i+1; pg=cp(k); else j=j+1; bp=cp(k);% bp is stack to store boundary pixels of grown region
end end endend while ~isempty(bp); j=j-1; rcount=rcount-1; i=1; pg(i)=seed; end
Getting Following message
??? Subscript indices must either be real positive integers or logicals.
Error in ==> eregiongrowing at 48 if region(cp(k))~=L;%if region(cp(k)is not labelled
Please Check the code and tell
me whether I am doing some mistakes anywhere in the code,if so please suggest
the solution
Best Answer