IM=getimage(handles.axes4);
threshold=2100
filteredImage=IM;
BW = filteredImage < threshold;
[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);
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');
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(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');