www.pudn.com > sobel+hough.rar > main.m, change:2007-06-26,size:1199b


clc,clear all 
 
I=imread('013.gif'); 
imshow(I); 
%title('原图'); 
 
[M,N,l] = size(I); 
if l>1 
    I = rgb2gray(I); 
end 
I=medfilt2(I); 
for i=1:M 
  for j=1:N 
    F(i,j)=0;F1(i,j)=0;F2(i,j)=0;F3(i,j)=0; 
  end 
end  
%F=zeros(M,N); 
for x=1:M 
    for y=1:N 
       if I(x,y)>150 
            F(x,y)=255; 
        else  
            F(x,y)=0; 
        end 
    end 
end 
figure; 
imshow(F); 
%title('二值化'); 
 
 
 
for x=2:M-1                     %sobel算法具体实现 
    for y=2:N-1 
        if ( abs( F(x+1,y-1)+2*F(x+1,y)+F(x+1,y+1)-F(x-1,y-1)-2*F(x-1,y)-F(x-1,y+1) ) + abs(  F(x-1,y-1)+2*F(x,y-1)+F(x+1,y-1)-F(x-1,y+1)-2*F(x,y+1)-F(x+1,y+1) )  )>980 
            F2(x,y)=255; 
        else  
            F2(x,y)=0; 
        end 
    end 
end 
figure; 
imshow(F2);                      %sobel算法具体实现 
 
 
 
 
% BW=edge(F2); 
BW=im2bw(F2,0.7); 
step_r = 1; 
step_angle = 0.1; 
minr = 10; 
maxr = 30; 
thresh = 0.7; 
[hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,minr,maxr,thresh); 
F3=hough_circle; 
%subplot(221),imshow(I),title('原图') 
%subplot(222),imshow(BW),title('边缘') 
%subplot(223),imshow(hough_circle),title('检测结果') 
figure; 
imshow(F3);