![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545602/image.png)
How to detect & fitting curvature from the binary image?
9 views (last 30 days)
Show older comments
I have a binary image, and I want to detect & draw curvature from the image.
This is my original image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545407/image.png)
This is what I want.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545412/image.png)
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 Comments
Accepted Answer
Mathieu NOE
on 21 Nov 2023
hello
this would be my suggestion, based on this Fex submission :
result
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1545602/image.png)
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');
2 Comments
More Answers (1)
Image Analyst
on 21 Nov 2023
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 Comments
Image Analyst
on 23 Nov 2023
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.
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!