基于形态学分水岭的分割算法实现.pptVIP

  • 50
  • 0
  • 约2.65千字
  • 约 14页
  • 2019-05-11 发布于天津
  • 举报
基于形态学分水岭的分割 ——算法实现 张立晓、李海彦 算法实现 代码如下 afm=imread(yingtao.jpg); figure; imshow(afm); se=strel(disk,15);%创建一个磁盘结构元素 Itop=imtophat(afm,se); Ibot=imbothat(afm,se);%对图像进行top-hat和bottom-hat变换,增强图像对比度 figure,imshow(Itop,[]); figure,imshow(Ibot,[]); Ienhance=imsubtract(imadd(Itop,afm),Ibot);%增大对象间的间隙 figure,imshow(Ienhance),title(original+top-hat -bottom-hat); %为了增加图像中对象和间隙的对比度,首先将top-hat变换得到的图像与原始图像相加,然后减去bottom-hat变换所得到的图像 算法实现 Iec=imcomplement(Ienhance);%增强照亮图像中的谷点 figure,imshow(Iec),title(complement of enhanced image); Iemin=imextendedmin(Iec,22); Iimpose=imimposemin(Iec,Iemin);%用来有效地检测谷点 figure,imshow(Iemin); figure,imshow(Iimpose); wat=watershed(Iimpose);%进行分水岭变换操作 figure,imshow(wat); bw = im2bw(wat, graythresh(wat));%转化为二值图像 l=bwlabel(bw); rgb=label2rgb(l);%转化为颜色矩阵 figure,imshow(rgb); 算法实现 算法中设计的函数 imread():读取图像; imshow():显示图像; afm=imread(yingtao.jpg); figure; imshow(afm); strel():由于在图像中所感兴趣的对象像一个磁盘,所以可以用strel函数创建一个磁盘结果元素,磁盘的大小可以用图像中对象的平均半径来估计。 se=strel(disk,15);%创建一个磁盘结构元素 算法实现 imtophat()和imbothat():函数可以分别返回原图像的top-hat变换和bottom-hat变换,主要用于增强图像的对比度,最小化通过分水岭变换得到的图像中谷点的个数。 Itop=imtophat(afm,se); Ibot=imbothat(afm,se);%对图像进行top-hat和 bottom-hat变换,增强图像对比度 figure,imshow(Itop,[]); figure,imshow(Ibot,[]); 算法实现 Imsubtract()和imadd():用来增大对象间的间隙,为了增加图像中对象和间隙的对比度,在该算法中,首先将top-hat变换所得到的图像与原始图像相加,然后再减去bottom-hat变换得到的图像。 Ienhance=imsubtract(imadd(Itop,afm),Ibot);%增大对象间的间隙 figure,imshow(Ienhance),title(original+top-hat -bottom-hat); 算法实现 Imcomplement()函数:用于增强照亮图像中的谷点,使得分水岭变换可有有效检测图像中的谷点。 Iec=imcomplement(Ienhance);%增强照亮图像中的谷点 figure,imshow(Iec),title(complement of enhanced image); 算法实现 Imextendedmin()和imimposemin()函数:在增强照亮谷点之后,用这两个函数来检测谷点。 Iemin=imextendedmin(Iec,22); Iimpose=imimposemin(Iec,Iemin);%用来有效地检测谷点 figure,imshow(Iemin); figure,imshow(Iimpose); 算法实现 watershed()函数:经过以上步骤的预处理之后,可以用该函数对使用imimposemin函数进行谷点检测后的图像impose进行分水岭

文档评论(0)

1亿VIP精品文档

相关文档