From: Hugh Thompson on 9 Nov 2009 16:29 Hello, I'm having weird trouble with the function bwboundaries. It seems straightforward enough, and all works well until I try to plot the boundaries. All the examples I've seen use something like this: [B, L] = bwboundaries(Ibw, 'noholes'); hold on for k=1:length(B) boundary = B(k) plot(boundary(2,:), boundary(1,:), 'w', 'LineWidth', 2) end But when I try to do that I get an error that 'index exceeds matrix dimensions'. I have one object in my picture that I'm trying to trace (that is, I hope. There is a small smudge that I don't think will interfere). What is going on?? Any help will be really appreciated!
From: ImageAnalyst on 9 Nov 2009 16:34 Hugh: You're using parentheses instead of braces. Try it like how I do it in this tutorial/demo: http://www.mathworks.com/matlabcentral/fileexchange/25157 which is like this: boundaries = bwboundaries(binaryImage); for k = 1 : numberOfBlobs thisBoundary = boundaries{k}; % Note: braces, NOT parentheses. plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2); end Regards, ImageAnalyst
From: Hugh Thompson on 10 Nov 2009 16:40 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <8ff27ca0-4ebc-439a-b0e8-c408184bb0ea(a)p35g2000yqh.googlegroups.com>... > Hugh: > You're using parentheses instead of braces. Try it like how I do it > in this tutorial/demo: > http://www.mathworks.com/matlabcentral/fileexchange/25157 > > which is like this: > > boundaries = bwboundaries(binaryImage); > for k = 1 : numberOfBlobs > thisBoundary = boundaries{k}; % Note: braces, NOT parentheses. > plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2); > end > > > Regards, > ImageAnalyst Thanks again, ImageAnalyst! That finally did it. But now I ran into another problem: I want to use PixelList to get the coordinates of the pixels in my blob (which in my case is a sort of wavy line. I don't want all the pixels, just enough to form a continuous line). I'm guessing I have to so something like 'skel' with bwmorph and then use regoinprops(...'PixelList'). But using 'skel' on the labeled image gives a completely disjoint image. The outline is there, but it is just tiny dots that are not connected. I can't find anything else to do... Any ideas?? Thanks ever so much, Hugh
From: ImageAnalyst on 10 Nov 2009 18:35 Hugh: You use bwmorph(binaryImage, 'skel') on the binary image, not the labeled image. It doesn't give a broken skeleton. You're just seeing it that way because it's being zoomed out. I know - I have this same issue. It looks broken but it's not. Try saving the image with imwrite() and then calling it up with imtool() and zooming way in so you can see the pixels and you'll see they're 8-connected. Or just look at your skeleton image in the Variable Editor and you'll see they're 8-connected. Regards, ImageAnalyst
From: Hugh Thompson on 11 Nov 2009 05:37
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <a9d612a2-e0a8-4250-ac6d-287ad57ee821(a)v37g2000vbb.googlegroups.com>... > Hugh: > You use bwmorph(binaryImage, 'skel') on the binary image, not the > labeled image. It doesn't give a broken skeleton. You're just seeing > it that way because it's being zoomed out. I know - I have this same > issue. It looks broken but it's not. Try saving the image with > imwrite() and then calling it up with imtool() and zooming way in so > you can see the pixels and you'll see they're 8-connected. Or just > look at your skeleton image in the Variable Editor and you'll see > they're 8-connected. > Regards, > ImageAnalyst Oh, wow, thanks once more! I never dreamed they were actually connected, they were so far apart. Incidentally, 'thin' worked better than 'skel', which left lots of stray spikes connected to the line. I followed your blob example and it was extremely helpful. I have just one question, though: I did what you did to get the largest blob. I kept increasing the threshold until I had just the line I wanted and none of the other noisy blobs dotted around the picture. But assuming I want this technique to work for all pictures, where the main 'blob' may be smaller, is there a way to find the largest blob? I can't seem to be able to find the correct syntax. Can't thank you enough, ImageAnalyst! Hugh |