Please suggest some solution to this code if any mistakes
古いコメントを表示
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:m
for j=1:n
if x1(i,j)<= T0
u1=u1+x1(i,j);
cnt1=cnt1+1;
else
u2=u2+x1(i,j);
cnt2=cnt2+1;
end
end
end
u1=u1/cnt1;
u2=u2/cnt2;
T=(u1+u2)/2;
Err=abs(T-T0);
if Err > 0.0001
T0=T;
end
end
y=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
end
end
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
2 件のコメント
Doug Hull
2013 年 3 月 19 日
You need to tell us typical inputs to run it.
Image Analyst
2013 年 3 月 19 日
Or learn how to use the debugger and find the error yourself. See Doug's excellent tutorial: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
採用された回答
その他の回答 (1 件)
Walter Roberson
2013 年 3 月 19 日
You start with
[m,n]=size(f);
seed=[m/2,n/2]
If the image is an odd size, then m/2 or n/2 will not be integers.
You initialize pg = seed, and then cp = pg, so when you index region(cp(k)) you would be attempting to index region at a non-integer.
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!