Fit image datapoints to curve
4 views (last 30 days)
Show older comments
I'm trying to control a robot from an ultrasonic greyscale image. So far I've used Sobel filtering to get a binary image, and Hough transform to detect line segments.
Now I want to create a control output to make the midpoints of the detected Houghlines aline most accurately with the drawn arc. The robot can move in the X and Y direction as well as rotate. The reference values I get from the code beneath contains [x-coordinate of midpoint, y-coordinate of midpoint, angle of the line segment, distance from midpoint to arc]. Does anyone know how to obtain the optimal rotation and movement to aline the points with the arc?
I = imread('Weld_ultrasound.png');
I = rgb2gray(I);
BW2 = edge(I,'Sobel','nothinning');
[H,T,R] = hough(BW2,'Theta',-90:1:89);
P = houghpeaks(H,20,'threshold',ceil(0.2*max(H(:))));
lines = houghlines(BW2,T,R,P,'FillGap',5,'MinLength',250);
function ref = Houghlines2ref(lines)
min_dist = 950; % Set minimum distance
max_dist = 1050; % Set maximum distance
ref = []; % [angle,distance]
for i = 1:length(lines)
mid = (lines(i).point1+lines(i).point2)/2;
if sqrt(mid(1)^2+mid(2)^2) <= min_dist
ref = [ref; [mid,lines(i).theta, (sqrt(mid(1)^2+mid(2)^2) - min_dist)]];
elseif sqrt(mid(1)^2+mid(2)^2) >= max_dist
ref = [ref; [mid,lines(i).theta,(sqrt(mid(1)^2+mid(2)^2) - max_dist)]];
end
end
I = imread('Weld_Ultrasound.png');
I = rgb2gray(I);
figure, imshow(I), hold on
if isempty(ref) == 1
return
else
for k = 1:length(ref(:,1))
p0 = [ref(k,1),ref(k,2)];
[X,Y] = pol2cart(deg2rad(ref(k,3)),-ref(k,4));
xy = [p0; p0+[X,Y]];
plot(p0(1),p0(2),'rs')
plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green'); % Plot referance vectors
end
end
t = linspace(0,0.5*pi,128); % Plot arc
x = [0 1000*cos(t) 0];
y = [0 1000*sin(t) 0];
hold on
plot( x, y, 'r' )
end
Thanks
Original image;
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!