I have a problem. I'm currently doing some image processing of different objects. I have already thresholded, made edge detection and labelled the different objects using bwlabel. Now since my final aim is to grasp different objects by a robotic arm, my task is to search around the borders/contours of different objects in order to find regions of minimum curvature in the image in order to be able to have a stable grasp/contact.
My problem is that to achieve this, I need to go pixel by pixel around the object border/contour in order to be able to evaluate it. Pls check this image link which explains what I need:
http://drop.io/curvature_computation
As can be seen from this link, P(x[i] , y[i]) is the current pixel on the border to be evaluated while P(x[i+k], y[i+k]) is another pixel on the border (5 pixels after the current pixel where k=5).
When using regionprops 'PixelList' I noticed that the pixels (x,y) coordinates are not listed according to the next pixel on the contour but are listed column by column which is not what I need since I cannot evaluate them in the manner explained above.
Please any suggestions would be appreciated?
Thanks
Kenneth
Thanks
Kenneth
% bwboundaries returns a cell array, where each cell
% contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original
% grayscale image using the coordinates returned by bwboundaries.
subplot(3, 3, 6); imagesc(originalImage); title('Outlines, from
bwboundaries()'); axis square;
hold on;
boundaries = bwboundaries(binaryImage);
for k = 1 : numberOfBlobs
thisBoundary = boundaries{k}; % Stuff into a double array.
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
Hi, thanks for your reply
I think I didn't explain myself clearly. I'm not using a binary image in bwboundaries but a matrix L where 0 = background, 1 = 1st object, 2 = 2nd object.....this still worked well with the following code:
B = bwboundaries(L,8, 'noholes')
for counter = 1:num
tB = B{counter}
end
Now what I'll need is that tB (i.e. the array name) changes with every object i.e. tB1 represents object 1 and tB2 represents object 2. When trying this:
tB{counter}= B{counter}
matlab gives me an error. Sorry for such a basic question but I cannot implement it...what I'll need is just a change in string name.
Thnaks Kenneth
The error message is: In an assignment A(I) = B, the number of elements in B and
I must be the same. Any idea why??
Thanks
Kenneth
unfortunately, this snippet
- shows bad ML coding habits
- EVAL
- creating variables in a loop
- and cannot run, to boot...
there is no need to put the content of your already nice array B into individual variables...
just use logical and or linear indexing...
also, look at this
us
Secondly, if you have the labeled image, then you ALREADY HAVE the
binary image because you needed that in order to get the labeled
image. If you got rid of the binary image (by using clear) then you
can get it back by doing this:
binaryImage = labeledImage > 0;
Regards,
ImageAnalyst
Yes ok, you're right there was no need to seperate variable names. However I don't see the need for using a binary image instead of RGB image (which still works)!! What's the difference?? In my program I initially used the binary image which was then labelled and filtered (by eliminating labelled objects <= 5 pixels) where an RGB image was used to identify different objects (with different colours)....why do I need to go back to my initial binary image??
Thanks Kenneth
If you do it (and it can be done if you unwisely decide to attempt
it), it won't be in a single-line call, like my call to bwboundaries.
It will take dozens or hundreds of lines of code. There are several
ways to find boundaries on a labeled image, but the easiest would be
to just convert the image to binary before you start. But then if
you're going to do that then why not just call bwboundaries() on that
binary image?
You say "an RGB image was used to identify different objects (with
different colours)." Just to clarify, the identification of different
objects was done by the labeling function which created an integer
image where each blob's pixels was given a single number. So you have
islands (blobs) where everywhere in it is 1, and it's 2 for the next
blob, and it's 3 for the next blob. No colors involved so far - just
integers. You can convert this to a color image where each blobs is
pseudocolored with a different color using the function call
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); %
pseudo random color labels
This will color the blobs for display and in that sense identify them,
but does not identify them in the sense of being used "to identify
different objects." Just wanted to clarify that, if not for you then
for others.
Regards,
ImageAnalyst
Hi
Thanks for your clarification...you are right ....that's what I really meant.
I tried using B = bwboundaries(L,8, 'noholes') where L is a labelled matrix and also tried B = bwboundaries(binaryimage,8,'noholes') and when I debug the coordinates of the object contours in variable B are exactly the same for both solutions. I know it's strange but I checked and re-checked :/
Thanks Kenneth