www.gusucode.com > 《matlab图像处理与界面编程宝典》秦襄培 编著,每章的MATLAB源代码程序 > 第23章/代码23-3.txt

    
I = imread('circuit.tif');
rotI = imrotate(I,33,'crop'); % 图像旋转,该函数具体用法在本书13.3.3有介绍。
fig1 = imshow(rotI);          % 显示处理后的图像。
BW = edge(rotI,'canny');        % 图像边界探测 
figure,                         % 新建窗口
imshow(BW);                     % 显示图像
 [H,theta,rho] = hough(BW);
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');