Problem trying to access labeled portion of images (updated 7/5)

조회 수: 4 (최근 30일)
Ryan
Ryan 2012년 7월 3일
unique(diff(unique(endpts_labeled)))
ans =
1
2
ORIGINAL QUESTION:
I am getting a rare error running the following code on an image of 1px thick skeleton segments:
V(V<=0) = 0; V(V>0) = 1; % Segments <=2 pixels are removed as well earlier
[K n] = bwlabel(V,8);
props = regionprops(K,'Perimeter');
tort = zeros(1,n);
endpts = bwmorph(K,'endpoints');
endpts_labeled = immultiply(K,endpts);
for m = 1:n
[rows,cols] = find(endpts_labeled==m);
p1 = [rows(1),cols(1)]; % Error happens here!!
p2 = [rows(2),cols(2)];
d = sqrt((p1(1)-p2(1))^2+(p1(2)-p2(2))^2);
c = props(m,1).Perimeter/2;
tort(m) = c/d;
end
The error happens when the loop tries to access rows(1) when the numel(rows) = 0. That case should never happen though. This error happened one in every 3 or 4 runs previously when I was using a non-labeled version of the image to find the endpoints, but now that I am using the labeled image to find the endpoints, it is only happening once in a blue moon and I cannot figure out why.
  댓글 수: 1
Ryan
Ryan 2012년 7월 5일
I have updated the question with the .mat data file. I did not add dbstop if error before this happened.

댓글을 달려면 로그인하십시오.

채택된 답변

Anton Semechko
Anton Semechko 2012년 7월 6일
편집: Anton Semechko 2012년 7월 7일
The error occurs for m=559. If you look at the object:
figure, imshow(K==559)
set(gca,'xlim',[481 580],'ylim',[500 600])
you will see that its a loop that does not have any end points. This is what ultimately causes the error.
  댓글 수: 4
Ryan
Ryan 2012년 7월 7일
I will upload the image to show you on Monday at the soonest. There is a chance I suppose for loops because the skeleton is coming from an inf- thin with bwmorph, but I do a thicken and re-thin to eliminate them.
Anton Semechko
Anton Semechko 2012년 7월 7일
편집: Anton Semechko 2012년 7월 7일
That will be a different question ... I believe this one can be closed

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2012년 7월 4일
편집: Image Analyst 2012년 7월 4일
I don't know how this could happen. If rows is null, then endpts_labeled==m is completely false. And if that's true, then n must be zero and so the loop never gets entered. That is a contradiction. Try "dbstop if error" and then when it errors, see what n is. Alternatively you can try this (untested)
endpts_labeled = int32(zeros(size(K)));
endpts_labeled(endpts) = K(endpts);
instead of this:
endpts_labeled = immultiply(K,endpts);
in case the immultiply is giving you slight mismatches as referred to in the FAQ http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
  댓글 수: 2
Ryan
Ryan 2012년 7월 4일
Will do. I'll update this next time it catches it.
Geoff
Geoff 2012년 7월 4일
Make sure you dump all your variables to a MAT file next time numel(rows) is zero =)

댓글을 달려면 로그인하십시오.


Ryan
Ryan 2012년 7월 6일
편집: Ryan 2012년 7월 6일
I switched to .* over immultiply() and I haven't run into the error message again. This may not mean I am out of the woods yet, but for anyone else out there that may encounter a similar issue, I wanted the possible solution to be documented.
  댓글 수: 3
Steve Eddins
Steve Eddins 2012년 7월 6일
K contains all integers, and endpts contains only 0s and 1s. There shouldn't be any quantization error going on here.
Ryan
Ryan 2012년 7월 6일
Do you have an idea as to what would be causing the error then?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by