|

楼主 |
发表于 2023-3-27 20:53:38
|
显示全部楼层
Matlab7主函数
- <font style="background-color: rgb(255, 255, 255);">clc
- clear all%读图显示
- I = imread('line.jpg');
- subplot(2,2,1); imshow(I);
- %灰度化
- I_gray = rgb2gray(I);
- subplot(2,2,2); imshow(I_gray);
- %二值化
- I_bw = I_gray<200;
- subplot(2,2,3);imshow(I_bw,[]);
- %hough变换
- [H,theta,rho] = hough1(I_bw);
- %画图
- [m_H,n_H] = find(H == max(max(H)));
- % rho = x cos(theta)+ ysin(theta);
- % y =(rho-x* cos(theta))/sin(theta);
- [m,n] = size(I_bw);
- x = 0: n;
- y = (rho(m_H) - x* cos(theta(n_H)/180*pi))/sin(theta(n_H)/180*pi);
- subplot(2,2,4); imshow(I_gray);
- hold on ;
- plot (x,y,'-r');
- axis([0,n,0,m]);</font>
复制代码 |
|