Borrar filtros
Borrar filtros

Help with detecting "Cross feature" using Hough transform

4 visualizaciones (últimos 30 días)
Jason
Jason el 4 de Mayo de 2020
Editada: Jason el 4 de Mayo de 2020
Hello, I have followed the examples to try and find the cross hairs in the image on the left (also attached)
The code I have used is below, but its not picked up the lines at all. I have used the example in the help.
Thanks for any suggestions
Jason
IM=getimage(handles.axes4); %Get Image from axes component (12 bit grayscale)
%Binarise witgh a fixed threshold for now
threshold=2100
filteredImage=IM;
BW = filteredImage < threshold;
%Hough Transform
[H,theta,rho] = hough(BW,'RhoResolution',0.5,'Theta',-90:0.5:89);
figure
subplot(1,4,1);
myImshow(IM,3)
title('my Raw Image');
subplot(1,4,2);
myImshow((BW),1)
title('Binary Image');
subplot(1,4,3);
imshow(imadjust(rescale(H)),'XData',theta,'YData',rho,...
'InitialMagnification','fit');
title('Hough transform');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(gca,hot);
%find the peaks in the hough transform using houghpeaks
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
subplot(1,4,3); hold on
plot(x,y,'s','color','black');
%Find lines in image using houghlines
lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',7);
subplot(1,4,4)
myImshow(IM,3), 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 beginnings and ends of lines
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
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
  1 comentario
Jason
Jason el 4 de Mayo de 2020
Editada: Jason el 4 de Mayo de 2020
OK..I have made some progress
1:I smoothed my raw image using medfilt
IM = medfilt2(IM,[10 10])
2: On the binary image, I removed some blobs using
BW = bwareaopen(BW, 400)
3: I changed the threshold on the houghpeaks from 0.3 to 0.5
P = houghpeaks(H,5,'threshold',ceil(0.5*max(H(:))));
However Im still getting the lines at the extremes of the image. The recticle will never be such that the lines run thru the edges of the image. How to remove them? and also how to get the instersection point of the desired lines?
Thanks

Iniciar sesión para comentar.

Respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by