Find contour width in x and y through contour center point
8 ビュー (過去 30 日間)
古いコメントを表示
Hi,
How can I find the width in x and y of each contour. The width in x and y goes through the center of the contour (see image below).
Thanks.
[X,Y,Z] = peaks;
v = [1,1];
contour(X,Y,Z,v)
0 件のコメント
採用された回答
Image Analyst
2022 年 10 月 7 日
What kind of data do you have? A digital image with a line drawing in it? If so just use regionprops to compute the Centroid, then use find() to find the first and last line pixel at the Centroid.
mask = grayImage < 128;
mask = bwareafilt(mask, 1);
props = regionprops(mask, 'Centroid')
middleRow = round(props.Centroid(2))
middleCol = round(props.Centroid(1))
width = find(mask(middleRow, :), 1, 'last') - find(mask(middleRow, :), 1, 'first')
height = find(mask(:, middleCol), 1, 'last') - find(mask(:, middleCol), 1, 'first')
5 件のコメント
Image Analyst
2022 年 10 月 8 日
Why? What's the use case? To me it seems just like what a homework problem would be. If so, you can't turn in my code as your own so I'll give you some hints. See if you can continue it and solve it yourself:
s = load('data.mat')
x = s.xdata
y = s.ydata
plot(x, y, 'b.-', 'LineWidth', 2, 'MarkerSize', 30);
grid on;
polyin = polyshape(x, y);
[xCentroid, yCentroid] = centroid(polyin)
hold on;
plot(xCentroid, yCentroid, 'r+', 'LineWidth', 2, 'MarkerSize', 250)
figure
subplot(2, 1, 1);
plot(x, 'r.-', 'LineWidth', 2, 'MarkerSize', 30)
grid on;
yline(xCentroid, 'g', 'LineWidth', 2);
subplot(2, 1, 2);
plot(y, 'b.-', 'LineWidth', 2, 'MarkerSize', 30)
grid on;
yline(yCentroid, 'g', 'LineWidth', 2);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!