Why hough transform is detecting only 1 horizontal line in the image ?
1 次查看(过去 30 天)
显示 更早的评论
Here is my code:
sx_norm = sx/max(sx(:));
sx_norm = movmean(sx_norm,5,2); %remove discontinuities by moving average
N = size(sx,2);
SE = strel('line',N,0); %line of length
BW = imbinarize(sx_norm);
BW =imerode(BW,SE); %morphological opening
%imagesc(BW)
%hough transform
[H,T,R] = hough(BW);
% %imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
% xlabel('\theta'), ylabel('\rho');
%hold on;
P = houghpeaks(H,5,'threshold',ceil(0.8*max(H(:)))); %detect peaks in the transform domain corresponding to the lines
% x = T(P(:,2)); y = R(P(:,1));
% plot(x,y,'s','color','white');
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',61);
store = [];
figure, imagesc(BW), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
%detecting horizontal lines
deltaY = xy(2,2)- xy(1,2);
deltaX = xy(2,1)-xy(1,1);
angle = atan2(deltaY, deltaX) * 180 / pi;
if (angle == 0) %detect horizontal lines
store = [store;lines(k).point1(2)]; %get y axis location
% 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');
end
end
%select the middle line
lin_loc = round((store(1)+store(end))/2);%store(find(sx_sum(store) == max(sx_sum(store))));
0 个评论
回答(1 个)
Harsha Priya Daggubati
2020-3-26
Hi,
Can you elaborate on what you are trying to achieve and how is your output deviating from the expected output? It would be of much more help if you can attach the images you are working on.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!