How to detect & fitting curvature from the binary image?
조회 수: 12 (최근 30일)
이전 댓글 표시
I have a binary image, and I want to detect & draw curvature from the image.
This is my original image.
This is what I want.
Since the positions of arcs and straight lines in a binary image are not constant and thousands of images must be processed, I want to detect the pixel location without specifying it.
I did some searches, but not sure where should I start.
I would appreciate it if you could recommend some things to study.
Thank you.
댓글 수: 0
채택된 답변
Mathieu NOE
2023년 11월 21일
hello
this would be my suggestion, based on this Fex submission :
result
code :
filename = 'image.png';
tmp = imread(filename);
inpict = im2double(rgb2gray(tmp));
[m,n] = size(inpict);
% find values above threshold
[y,x] = find(inpict>0.5);
% flip y direction (on the data)
y = m-y;
% take unique values
[y,ia,ic] = unique(y);
x = x(ia);
% smooth the data with smoothn
% FEX : https://fr.mathworks.com/matlabcentral/fileexchange/25634-smoothn?s_tid=srchtitle
z = smoothn({x,y},1e3,'robust');
xs = z{1};
ys = z{2};
subplot(1,2,1)
imshow(inpict);
subplot(1,2,2)
plot(x,y,'*k',xs,ys,'r');
추가 답변 (1개)
Image Analyst
2023년 11월 21일
See my solution to your duplicate question:
If you want, you could split the curve up into right half and left half but I assumed that the "thing" is actually some single surface with a rod sticking into it so both sides would probably have the same curvature so I just fit both sides to one polynomial.
댓글 수: 2
Image Analyst
2023년 11월 23일
You could certainly split mine up into right and left sides. Note that @Mathieu NOE still had the spike in there, and it uses a File Exchange program, and smooths the data locally, while mine ignores the spike, uses only built-in functions, and fits the entire surface to a smooth polynomial rather than just smoothing locally. It just depends on how you prefer to do it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!