clear all;
clc
a= imread('Figure.jpeg');
imshow(a) ;
grey = rgb2gray (a);
bwa = im2bw (grey, 175/255);
se = strel('diamond',1) ;
bwb = edge(bwa,'canny');
[H,theta,rho] = hough(bwb);
figure
imshow(imadjust(rescale(H)),[],...
'XData',theta,...
'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)')
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));
plot(x,y,'s','color','black');
lines = houghlines(bwb,theta,rho,P,'FillGap',5,'MinLength',75);
figure, imshow(bwb), hold on
max_len = 0;
midpt(1,:) = (lines(1).point1 + lines(2).point1)/2;
midpt(2,:) = (lines(1).point2 + lines(2).point2)/2;
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');
plot (midpt(1,1),midpt(1,2),'o','linewidth',2,'color','blue');
plot (midpt(2,1),midpt(2,2),'o','linewidth',2,'color','blue');
plot (midpt(:,1),midpt(:,2),'linewidth',2,'color','blue');
hold on
end