matlab实现分水岭算法处理图像分割
2016-04-10 14:19
731 查看
此程序为优化后的分水岭算法,避免了图像过分割
[plain] view plain copy
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);
实验结果:
from: http://blog.csdn.net/abcjennifer/article/details/6669074
[plain] view plain copy
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);
实验结果:
from: http://blog.csdn.net/abcjennifer/article/details/6669074
相关文章推荐
- Matlab size函数
- matlab reshape函数
- matlab中实现Gabor滤波器
- MATLAB曲线绘制
- Matlab中image、imagesc和imshow函数用法解析
- matlab size
- Matlab读取视频并处理成帧保存
- MATLAB下高效使用内存
- matlab 的cell 与 matrix
- 关于matlab GUI的popupmenu
- Matlab并行编程方法
- MATLAB谢菲尔德遗传算法工具箱使用
- 谁再说Matlab速度慢,我跟谁急
- matlab分割字符串(split)
- 《数字图像处理原理与实践(MATLAB版)》一书之代码Part5
- matlab中cell2mat函数不能生成矩阵的问题
- matlab
- Matlab adaptive quadrature
- 形态学处理
- 数据的输入与输出以及程序流控制语句