how do extract data of the bwtraceboundaries function

Using the very helpful example from this site on bwtraceboundaries function, it probably sounds easy but how do I then extract only the green values as a number, and perform the same on another image, and compare the two green data. This is code I used as my reference:
BW = imread('blobs.png');
imshow(BW,[]);
s=size(BW);
for row = 2:55:s(1)
for col=1:s(2)
if BW(row,col),
break;
end
end
contour = bwtraceboundary(BW, [row, col], 'W', 8, 50,...
'counterclockwise');
if(~isempty(contour))
hold on;
plot(contour(:,2),contour(:,1),'g','LineWidth',2);
hold on;
plot(col, row,'gx','LineWidth',2);
else
hold on; plot(col, row,'rx','LineWidth',2);
end
end
many thanks

 Respuesta aceptada

Image Analyst
Image Analyst el 21 de Abr. de 2013
Explain to me why you want bwtraceboundaries(). I've never seen a use for it. When I want to get the boundary coordinates of a binary image filled with blobs, I just use bwboundaries() - it's so much easier. Why aren't you using that?
Anyway, I don't know what you mean as the "green number". Do you mean the contour values you plotted in green? If so, then what's to extract. You already have them. They're in the variable contour, which you plotted in green.
By the way, you don't need to call hold on twice. Once you call it, it stays on until you turn it off or reset the axes.

6 comentarios

Kbhatti86
Kbhatti86 el 21 de Abr. de 2013
i have an image where i specifically want all the '1' values and to highlight them in green and it is a silhouette of a hand and i just need the variable contour information in green which i can compare with another image, so then i can use the distance function to calculate the difference
Then use bwboundaries(), as I thought.
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
Kbhatti86
Kbhatti86 el 21 de Abr. de 2013
thank you just let me ask you numberofboundaries is the number of 1 around the image as a total right?
It's the total number of inner and outer closed boundaries. See my Blobs Demo in my File Exchange. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Kbhatti86
Kbhatti86 el 21 de Abr. de 2013
many thanks i totally understand the principle of it, has helped me a lot
Could you mark it as "Accepted" then?

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by