www.pudn.com > watershed.rar > watershed2.m, change:2012-05-19,size:279b


f=imread('baboon.gif'); 
h=fspecial('sobel'); 
fd=double(f); 
g=sqrt(imfilter(fd,h,'replicate').^2+... 
       imfilter(fd,h','replicate').^2); 
L=watershed(g); 
wr=L==0; 
g2=imclose(imopen(g,ones(3,3)),ones(3,3)); 
L2=watershed(g2); 
wr2=L2==0; 
f2=f; 
f2(wr2)=255; 
imshow(f2);