%标记符控制的分水岭分割
f=imread('gel-image.tif');%读取图像
subplot(4,2,1),imshow(f),title('二值图像')
h=fspecial('sobel');%滤波器类型为sobel
fd=double(f);%转化为double型
g=sqrt(imfilter(fd,h,'replicate').^2+...
imfilter(fd,h','replicate').^2);%幅度梯度
L=watershed(g);%分水岭变换
wr=L==0;%分水岭脊线
subplot(4,2,2),imshow(wr),title('分水岭变换图像')
rm=imregionalmin(g);%获得局部最小区域的位置
subplot(4,2,3),imshow(rm),title('局部最小区域')
im=imextendedmin(f,2);%获得深内部最小区域位置
fim=f;
fim(im)=175;%在原图像上以灰度气泡的形式叠加扩展的局部最小区域位置
subplot(4,2,4),imshow(fim),title('内部标记符')
Lim=watershed(bwdist(im));%距离变换的分水岭变换
em=Lim==0;%分水岭脊线
subplot(4,2,5),imshow(em),title('外部标记符')
g2=imimposemin(g,im|em);%修改后的梯度幅度
subplot(4,2,6),imshow(g2),title('梯度幅值')
L2=watershed(g2);%修改后的分水岭变换
f2=f;%原图像
wr2=L2==0;5;%分水岭脊线
f2(wr2)=255;%在原图像上叠加分水岭脊线
subplot(4,2,7),imshow(f2),title('分割结果')
标记符控制的分水岭分割
最新推荐文章于 2022-07-28 22:00:00 发布