% 入口图像为 BW,出口图像为f
%optimize from main_optimize, merely select 2 lines, one has positive
%slope,the other has negative slope
clear all,close all
BW=imread(‘D:\Images\NEW\img4b9faef664e03.jpg’);
figure,imshow(BW);
BW=rgb2gray(BW);
%thresh=[0.01,0.17];
thresh=[0.01,0.10];
sigma=2;%定义高斯参数
f = edge(double(BW),’canny’,thresh,sigma);
figure,subplot(121);
imshow(f,[]);
title(‘canny Edge Detect Result’);
[H, theta, rho]= hough(f, 0.1);%cos(theta)*x+sin(theta)*y=rho
%imshow(theta,rho,H,[],’notruesize’),axis on,axis normal
%xlabel(‘\theta’),ylabel(‘rho’);
[r,c]=houghpeaks(H,10);
hold on
lines=houghlines(f,theta,rho,r,c);
subplot(122);
imshow(f,[]),title(‘Hough Transform Detec