From: Kenneth Galea on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <61ea651b-6322-46a6-9889-cc22e81be27a(a)u41g2000yqe.googlegroups.com>...
> Kenneth:
> You should be able to figure it out from this snippet of code pulled
> from my demo at
> http://www.mathworks.com/matlabcentral/fileexchange/25157
>
> % 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;
This is what i'm actually using but still gives me an error:
B = bwboundaries(L,8, 'noholes')
for counter = 1:num
eval(['tB_' num2str(counter)]) = B{counter}
end

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
From: us on
"Kenneth Galea"
> This is what i'm actually using but still gives me an error:
> B = bwboundaries(L,8, 'noholes')
> for counter = 1:num
> eval(['tB_' num2str(counter)]) = B{counter}
> end
>
> 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

http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

us
From: ImageAnalyst on
Kenneth:
You should leave the boundaries as a cell array just as bwboundaries
returns them. I'm not sure what you're trying to do with trying to
put them all into separate variables with different names - you're
just asking for trouble later.

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

From: Kenneth Galea on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <d0cbcd2d-c49f-4eff-a416-0de35f094a82(a)l30g2000yqb.googlegroups.com>...
> Kenneth:
> You should leave the boundaries as a cell array just as bwboundaries
> returns them. I'm not sure what you're trying to do with trying to
> put them all into separate variables with different names - you're
> just asking for trouble later.
>
> 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
From: ImageAnalyst on
On Jan 2, 10:21 am, "Kenneth Galea" <k.ga...(a)hotmail.com> wrote:
> 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
------------------------------------------------------------------------------------
Kenneth:
OK, tell me how you're going to find boundaries on a pseudocolored,
labeled image.

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