How can I measure the length of these line segments in this image mask?

9 ビュー (過去 30 日間)
Masood Salik
Masood Salik 2021 年 2 月 4 日
コメント済み: darova 2021 年 2 月 5 日
I have a binary image (BW_roi.mat attached) like this. And I wanted to measure the length of every line segment.
I tried the solution given in this link hough-transform. But it does not work out for me. It just measured the length of some lines as shown below.
I tried the other code
boundaries = bwboundaries(BW);
patchno=1
b = boundaries{patchno}; % Extract N by 2 matrix of (x,y) locations.
x = b(:, 1);
y = b(:, 2);
It though give me points (x,y) that make up these polygons. But how can I get the length of the sides of these patches?

回答 (1 件)

yanqi liu
yanqi liu 2021 年 2 月 5 日
clc; clear all; close all;
load BW_ROI.mat
b = BW_roi_nodot;
b = ~b;
% measure the length of every line segment
% b([1 end],:) = 1;
% b(:,[1 end]) = 1;
b = logical(b);
b2 = imfill(b, 'holes');
b3 = b2 - b;
b3 = logical(b3);
b4 = imclose(b3, strel('disk', 5));
b5 = imopen(b2, strel('square',7));
b6 = b2 - b5;
b6 = logical(b6);
[L, num] = bwlabel(b3);
stats = regionprops(L,'ConvexHull');
figure; imshow(BW_roi_nodot); hold on;
for i = 1 : num
p = stats(i).ConvexHull;
plot(p(:,1), p(:,2),'LineWidth',2);
end
  1 件のコメント
Masood Salik
Masood Salik 2021 年 2 月 5 日
The code directly give us the boundries of the part. We don't need further refinement.
boundaries = bwboundaries(BW_roi_nodot);
I need a code or algoritam that find the vertices of the polygons, generated by bwboundries. Then afterward I can find the lengths easily.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by