基于matlab的图像hough变换

代码:

>> f=imread('house.jpg');
>> o=f;
>>f=rgb2gray(f);
>> f=im2double(f);
>> figure();
>> subplot(231);imshow(o);title('原图');
>> [m,n]=size(f);
 for i=3:m-2
     for j=3:n-2
       l(i,j)=-f(i-2,j)-f(i-1,j-1)-2*f(i-1,j)-f(i-1,j+1)-f(i,j-2)-2*f(i,j-1)+16*f(i,j)-2*f(i,j+1)-f(i,j+2)-f(i+1,j-1)-2*f(i+1,j)-f(i+1,j+1)-f(i+2,j);
     end
   end
>> subplot(232),imshow(l),title('LOG 算子提取图像边缘');
>> [m,n]=size(l);
>> for i=2:m-1
     for j=2:n-1
       %log算子提取边缘后,对结果进行均值滤波以去除噪声,为下一步hough变换提取直线做准备
         y(i,j)=l(i-1,j-1)+l(i-1,j)+l(i-1,j+1)+l(i,j-1)+l(i,j)+l(i,j+1)+l(i+1,j-1)+l(i+1,j)+l(i+1,j+1);
         y(i+j)=y(i,j)/9;
     end
  end
>> subplot(2,3,3),imshow(y),title('均值滤波后');


>> %二值化
>> q=im2uint8(y);
>> [m,n]=size(q);
>> for i=1:m
    for j=1:n
if q(i,j)>80;
        q(i,j)=255;
     else 
        q(i,j)=0;
     end
     end
end
>> subplot(23

你可能感兴趣的:(matlab图像处理)