Does anyone know how I could find out the number of ends an arbitrary shape has e.g. an 'x' or a straight line. I use regionprops -> pixelList to extract a the points describing the shape from a BW image.
Thanks for the answer, this will work but it would be much better for me if I could use the x and y vectors rather than the binary image. Do you know if this is possible?
In your question you say you have a binary image.. I have no idea what you mean byx and y vectors. What do these x and y vectors represent, where do they come from.
Ah, alright. If the binary image has not been skeletonised before the call toregionprop then it's going to bevery difficult to find the end points from the coordinate vectors. If the image has beem skeletonised beforeregionprops then the end points are those pixels with just one neighbours.
One way of finding pixels with just one neighbours would be to compute the cheesboard distance matrix between all the pixels (withpdist2 if you have the stats toolbox, manually otherwise), keep only the ones in that matrix. The end points are those pixels with just one one in the row (or column), e.g.:
pixels = [1 1;1 2; 2 3; 3 3];
chessdist = max(abs(pixels(:, 1) - pixels(:, 1)'), abs(pixels(:, 2) - pixels(:, 2)')); %requires R2016b or later, or use pdist2
endpoints = pixels(sum(chessdist == 1) == 1, :)
But honestly, usingbwmorph would be simpler. If the image is no longer available, I would recreate it from the list of pixels:
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
0 Comments
Sign in to comment.