How to find coordinates from an image?

I have several images like above from a survey. I need to find the coordinates of the laser ring from each image and plot them as 3D image.
I tried to binarize the image and used bwskel make smoother (i.e. 1 pixel laser circle for coordinates) but the skeleton image is not as smooth as I expected. Could anyone please help me? I appreciate any help.
Thank you very much.

Answers (1)

You could use sgolayfilt() with a 2 or 3rd order polynomial to identify outliers and replace them. Or maybe just use filloutliers().

5 Comments

Thank you for your answer. I will try to do that and post the results.
If you know for a fact that the path is a circle, then you could fit the coordinates to a circle using the FAQ:
function [xc,yc,R,a] = circfit(x,y)
%CIRCFIT Fits a circle in x,y plane
%
% [XC, YC, R, A] = CIRCFIT(X,Y)
% Result is center point (yc,xc) and radius R. A is an optional
% output describing the circle's equation:
%
% x^2+y^2+a(1)*x+a(2)*y+a(3)=0
% by Bucher izhak 25/oct/1991
n=length(x); xx=x.*x; yy=y.*y; xy=x.*y;
A=[sum(x) sum(y) n;sum(xy) sum(yy) sum(y);sum(xx) sum(xy) sum(x)];
B=[-sum(xx+yy) ; -sum(xx.*y+yy.*y) ; -sum(xx.*x+xy.*y)];
a=A\B;
xc = -.5*a(1);
yc = -.5*a(2);
R = sqrt((a(1)^2+a(2)^2)/4-a(3));
Also, which of the many rings do you want? You might threshold and use bwareafilt() to take just the largest region. You could just fit all the x and y from find() -- no need to skeletonize since it's a fit.
binaryImage = bwareafilt(binaryImage, 1); % Take ring with largest area.
[y, x] = find(binaryImage); % Of just one of the rings. Note: it's y,x NOT x,y
[xc, yc, R, a] = circfit(x,y)
viscircles([xc, yc], R);
The laser ring is measuring the deflected pipe geometry from inside. Therefore, the fit would be more ellipse than a circle. Is there any way to fit an ellipe in the image? Thank you for your time.
I tried writing code from the first paper. It proceedes by finding the ends of major axis first but the laser image does not always have ends of the major or minor axis. It depends on the nature of deflection of the pipe. I am trying to write from second paper but it is proving to be even more complex. Do you have any demo, by any chance, that could help me?
Again, thank you for your time and help.

Sign in to comment.

Products

Release

R2018b

Asked:

on 5 Jan 2021

Commented:

on 6 Jan 2021

Community Treasure Hunt

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

Start Hunting!