Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Does anyone know how I could find out the number of ends an arbitrary shape has e.g. an 'x' that is displayed in an image.

3 ビュー (過去 30 日間)
MP
MP 2017 年 7 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.

回答 (1 件)

Guillaume
Guillaume 2017 年 7 月 13 日
sum(bwmorph(bwmorph(yourbinaryimage, 'skel'), 'endpoints'))
Should give you what you want. For more information, see bwmorph.
  4 件のコメント
Jan
Jan 2017 年 7 月 13 日
編集済み: Jan 2017 年 7 月 13 日
The values are coming from regionprops->PixelList .
@MP: And now you are looking for coordinates in X and Y, which have less then 2 4- or 8-connected neighbors only. Correct?
Guillaume
Guillaume 2017 年 7 月 14 日
Ah, alright. If the binary image has not been skeletonised before the call to regionprop then it's going to be very difficult to find the end points from the coordinate vectors. If the image has beem skeletonised before regionprops 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 (with pdist2 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, using bwmorph would be simpler. If the image is no longer available, I would recreate it from the list of pixels:
img = zeros(max(pixels(:, 2)), max(pixels(:, 1)));
img(sub2ind(size(img), pixels(:, 2), pixels(:, 1))) = 1;
[endpoints(:, 2), endpoints(:, 1)] = find(bwmorph(bwmorph(img, 'skel'), 'endpoints'))

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by