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!