I = imread('miti8.png');
RSI=imresize(I,0.5);
ID = imadjust(RSI,[0.7 0.7 0; 0.8 0.8 1],[]);
RS= imcrop(ID,[0.5 65.5 378 439]);
GSI=rgb2gray(RS);
figure
imshow(GSI)
J = imnoise(GSI,'salt & pepper',0.1);
K = medfilt2(J);
figure
imshow(K)
IB = imbinarize(K,0.2)
BR = bwareaopen(IB,150);
figure
imshow(BR);
BW = edge(BR,'Roberts');
figure
imshow(BW);
stats=regionprops('table',BR,'Centroid',...
'Extrema','Perimeter')
[H,theta,rho] = hough(BW,'RhoResolution',0.1,'ThetaResolution',0.03);
figure
imshow(imadjust(mat2gray(H)),[],...
'XData',theta,...
'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)')
ylabel('\rho')
axis on
axis normal
hold on
colormap(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(BW,theta,rho,P,'FillGap',30,'MinLength',50);
figure, imshow(BW), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green');
len(k) = norm(lines(k).point1 - lines(k).point2);
end