How to find the midpoint between two curves in an image

조회 수: 3 (최근 30일)
Suraj Sudhakar
Suraj Sudhakar 2022년 7월 27일
댓글: Suraj Sudhakar 2022년 8월 10일
I have attached the image of the curve, I would like to extract the midpoint between the curve. (Ideally, the thickness of the given curve is constant). I tried extracting the gradient direction and using the line along the gradient direction to extract the midpoint, but the gradient direction is not perfectly tangential due to the discrete nature of the iimage
for (points in the upper line)
%get the gradient
gx=(bw(i+1,j)-bw(i-1,j))/2;
gy=(bw(i,j+1)-bw(i,j-1))/2;
theta=atan(gy/gx);
m = sin(theta); %slope of the line
%use the slope and known initial point (and assumption that thickness is constant to get a midpoint)
%issue is gradient can only take a few directions, hence getting wrong results
Wanted to know if there is any better way of doing this

채택된 답변

Akira Agata
Akira Agata 2022년 8월 7일
How abou the following?
% Load image
I = imread('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1079075/curve.PNG');
% Binarize the image
I = rgb2gray(I);
BW = imbinarize(I);
% Apply bwdist
J = bwdist(~BW);
% Find maximum position for each row
[~, pt] = max(J, [], 2);
% Create the output image
pt_ind = sub2ind(size(BW), 1:size(BW, 1), pt');
BW2 = false(size(BW));
BW2(pt_ind) = true;
% Let's check!
figure
imshowpair(BW, BW2)
  댓글 수: 3
yanqi liu
yanqi liu 2022년 8월 9일
yes,sir,if we make to U shape,may be just use
I = imread('curve2.png');
I = rgb2gray(I);
BW = imbinarize(I);
J = bwdist(~BW);
BW2 = J>max(J(:))*0.8;
figure
imshowpair(BW, BW2)
Suraj Sudhakar
Suraj Sudhakar 2022년 8월 10일
That works, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by