加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

matlab实现分水岭算法处理图像分割

(2013-11-13 15:07:42)
分类: matlab
 

此程序为优化后的分水岭算法,避免了图像过分割

   
I= imread('D:\Images\pic_loc\1870405130305041503.jpg');      
  1. imshow(I);  
  2. h=fspecial('sobel'); %h fspecial(type) creates two-dimensional filter of the specified type. fspecial returns as  
  3.                      %a correlation kernel, which is the appropriate form to use with imfilter. type is string having one of these values.   
  4. fd=double(I);%double使数据变成双精度  
  5. g=sqrt(imfilter(fd,h,'replicate').^2+imfilter(fd,h','replicate').^2);  
  6. figure;  
  7. imshow(g);  
  8. g2=imclose(imopen(g,ones(3,3)),ones(3,3));  
  9. figure;  
  10. imshow(g2);  
  11. im=imextendedmin(g2,10);    
  12. Lim=watershed(bwdist(im)); %watershed分水岭算法 Lim的值greater than or equal to 0,等于0是分水岭脊像素  
  13. em=Lim==0;  
  14. g3=imimposemin(g2,im|em);  
  15. g4=watershed(g3);  
  16. figure;  
  17. imshow(g4);  
  18. g5=I;  
  19. g5(g4==0)=255;  
  20. figure;  
  21. imshow(g5);  
I= imread('D:\Images\pic_loc\1870405130305041503.jpg');    
imshow(I);
h=fspecial('sobel'); %h = fspecial(type) creates a two-dimensional filter h of the specified type. fspecial returns h as
                     %a correlation kernel, which is the appropriate form to use with imfilter. type is a string having one of these values. 
fd=double(I);%double使数据变成双精度
g=sqrt(imfilter(fd,h,'replicate').^2+imfilter(fd,h','replicate').^2);
figure;
imshow(g);
g2=imclose(imopen(g,ones(3,3)),ones(3,3));
figure;
imshow(g2);
im=imextendedmin(g2,10);   %
Lim=watershed(bwdist(im)); %watershed分水岭算法 Lim的值greater than or equal to 0,等于0是分水岭脊像素
em=Lim==0;
g3=imimposemin(g2,im|em);
g4=watershed(g3);
figure;
imshow(g4);
g5=I;
g5(g4==0)=255;
figure;
imshow(g5);

实验结果:

http://hi.csdn.net/attachment/201108/8/2686350_1312783305cJDX.jpg

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有