www.pudn.com > edgeExtraction.rar > sobelEdge.m, change:2012-03-20,size:681b


function edgeImg = sobelEdge( origImg ) 
%UNTITLED Summary of this function goes here 
%sobel㹫ʽ 
%fx=f(x-1,y+1)+2f(x,y+1)+f(x+1,y+1)-f(x-1,y-1)-2(x,y-1)-f(x+1,y-1) 
%fy=f(x+1,y+1)+2f(x+1,y)+f(x+1,y-1)-f(x-1,y-1)-2(x-1,y-1)-f(x+1,y-1) 
%G[f(x,y)]=|fx(x,y)|+|fy(x,y)| 
%   Detailed explanation goes here 
meanImg = (origImg(:,:,1)+origImg(:,:,2)+origImg(:,:,3))/3; 
fx1 = meanImg(1:end,3:end) - meanImg(1:end,1:end-2); 
fx = fx1(1:end-2,1:end) + fx1(2:end-1,1:end)*2 + fx1(3:end,1:end); 
fy1 = meanImg(3:end,1:end) - meanImg(1:end-2,1:end); 
fy = fy1(1:end,1:end-2) + fy1(1:end,2:end-1) + fy1(1:end,3:end); 
edgeImg = abs(fx)+abs(fy); 
edgeImg(find(edgeImg~=0))=255; 
end