Problem to run nested for loop.

I am facing problem to run a nested for loop. I think the else operator is not working. Why this is happening?? Is there any way out?? Please check the code given below. The image file is attached.
I=imread('map.png');
pim=im2bw(I,0.05);
pim2 = double(cat(3, pim, pim, pim)); %RGB format of path image
I1=rgb2gray(I);
BW = roicolor(I1,20,225);
landim=bwareaopen(BW,20);
s = regionprops(landim, 'centroid');
centroids = cat(1, s.Centroid);
centroid=floor(centroids);
cc = bwconncomp(landim);
n=cc.NumObjects;
for i=1:n
for j=2:n
if abs(centroid(i,1)-centroid(j,1))<10
centroid(i,1)=centroid(j,1);
end
if abs(centroid(i,2)-centroid(j,2))<10
centroid(i,2)=centroid(j,2);
end
end
end
disp(centroid)
order=zeros(n,2);
finalorder=zeros(20,2);
f=1;
for i=1:n
rgb=impixel(I,centroid(i,1),centroid(i,2));
if rgb(1)+rgb(2)>440
start=centroid(i,:);
order(1,:)=start;
elseif 130<rgb(1)<210 && 60<rgb(2)<130 && 15<rgb(3)<50
finish=centroid(i,:);
order(n,:)=finish;
else
f=f+1;
order(f,:)=centroid(i,:);
end
end
disp(order)

2 件のコメント

roro6992
roro6992 2014 年 1 月 18 日
The matrix order is not coming out correct. But i cant find any flaws in the code..please help..
Amit
Amit 2014 年 1 月 18 日
where is the image file? you said it attached?

回答 (1 件)

Image Analyst
Image Analyst 2014 年 1 月 18 日

0 投票

This is not proper syntax in most languages, including MATLAB:
if 130<rgb(1)<210 && 60<rgb(2)<130 && 15<rgb(3)<50
You need to split it up so you are comparing only two things:
if 130<rgb(1) && rgb(1) <210 && 60<rgb(2) && rgb(2)<130 && 15<rgb(3) && rgb(3)<50

5 件のコメント

Mischa Kim
Mischa Kim 2014 年 1 月 18 日
Did not see your answer...
Image Analyst
Image Analyst 2014 年 1 月 18 日
She didn't attach map.png so I could fully debug it. I instantly say that so I reported it. There are probably additional errors I didn't mention. They didn't say what the expected "matrix order" of f is , nor why it's "not coming out correct", so I can't really provide a full answer (yet). Of course I won't need to if the poster simply views this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
roro6992
roro6992 2014 年 1 月 19 日
Sorry Image Analyst. Heres the map.png file. Please check it!!
roro6992
roro6992 2014 年 1 月 19 日
Its done. The code runs now. My syntax was wrong actually. Thanx image analyst!
Image Analyst
Image Analyst 2014 年 1 月 19 日
Can you mark it as "Accepted" then?

この質問は閉じられています。

質問済み:

2014 年 1 月 18 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by