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!