Get edge points from a hough line

1 Ansicht (letzte 30 Tage)
mikel lasa
mikel lasa am 26 Okt. 2020
Kommentiert: Steve Eddins am 27 Okt. 2020
Hello,
After processing an image, I get 5 lines using houghlines. These lines arent perfect fited to the original image, so my intention is to get edge points near my line ( 2 or 3 pixel distance) and then, using those points, make a least square fitting.
My problem is that having the equation y=mx+n of my houghlines, I dont know how to get the nearest points of those lines.
Hope you can understand my explanation.
Regards,

Akzeptierte Antwort

Steve Eddins
Steve Eddins am 26 Okt. 2020
I think I understand your question. Here is one possibility.
  1. Using the function intline from the DIPUM Toolbox, create a binary image containing foreground pixels along the line given by houghlines. (The DIPUM Toolbox contains the MATLAB code from the book Digital Image Processing Using MATLAB, 3rd ed.)
  2. Dilate that binary image using imdilate and a structuring element with the desired radius (2 or 3 pixels). You could use a circular structuring element, although with a radius that small, it won't really be close to a circle.
  3. Use a logical AND operator (&) with your dilated binary image and your edge image to identify the edge pixels that are close to the line identified by houghlines.
  2 Kommentare
mikel lasa
mikel lasa am 26 Okt. 2020
hello Steve,
Thanks for your answer. Im quite new to matlab so I'm not sure how to do this (I understand your explanation). I tried to do the dilate without succes, can you help me with the code?
this is my code:
clc;clear;close all;
impath = 'metal-parts-01.png';
img = imread(impath);
figure()
imshow(img)
figure()
imhist(img)
%% filtro canny
F1= edge(img,'Canny',0.5,0.3);
figure()
imshowpair(img, F1, 'montage');
title(' Canny')
%% hough
[A,theta,rho] = hough (F1);
figure()
imshow(imadjust(rescale(A)),'XData',theta,'YData',rho, 'InitialMagnification','fit')
title(' transformada de hough')
xlabel('\theta'), ylabel('\rho'); axis on, axis normal, hold on; colormap(gca,hot);
%% picos
peaks = houghpeaks(A,5,'Threshold',5);
figure()
imshow(A,[],'XData',theta,'YData',rho,'InitialMagnification','fit');
title(' picos hough')
xlabel('\theta'), ylabel('\rho'); axis on, axis normal, hold on; plot(theta(peaks(:,2)),rho(peaks(:,1)),'s','color','white');
%% lineas (lines)
lines = houghlines (F1,theta,rho,peaks);
figure()
imshow(img), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment len = norm(lines(k).point1 - lines(k).point2); if ( len > max_len) max_len = len; xy_long = xy;
end
%% circulos (circles)
LowD = 6; LowL =25;
HighD =25; HighL = 80;
[centersL,radiiL]=imfindcircles(img,[LowL HighL],'ObjectPolarity','bright','Sensitivity',0.95);
[centersD,radiiD]=imfindcircles(img,[LowD HighD],'ObjectPolarity','dark','Sensitivity',0.90);
figure()
imshow(img), hold on
viscircles(centersD,radiiD);
viscircles(centersL,radiiL);
Steve Eddins
Steve Eddins am 27 Okt. 2020
To try the solution I suggested, you'll need to create a binary image that has foreground pixels along the lines returned by houghlines. That is what the intline function is for. Once you have that binary image, you can call imdilate to perform the dilation.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by