資源簡介
基于距離變換的分水嶺分割算法,該算法可以實現對粘連物體的分割。
代碼片段和文件信息
rgb?=?imread(‘pears.png‘);%讀取原圖像
I?=?rgb2gray(rgb);%轉化為灰度圖像
figure;?subplot(121)%顯示灰度圖像
imshow(I)
text(732501‘Image?courtesy?of?Corel‘...
?????‘FontSize‘7‘HorizontalAlignment‘‘right‘)
hy?=?fspecial(‘sobel‘);%sobel算子
hx?=?hy‘;
Iy?=?imfilter(double(I)?hy?‘replicate‘);%濾波求y方向邊緣
Ix?=?imfilter(double(I)?hx?‘replicate‘);%濾波求x方向邊緣
gradmag?=?sqrt(Ix.^2?+?Iy.^2);%求摸
subplot(122);?imshow(gradmag[])?%顯示梯度
title(‘Gradient?magnitude?(gradmag)‘)
L?=?watershed(gradmag);%直接應用分水嶺算法
Lrgb?=?label2rgb(L);%轉化為彩色圖像
figure;?imshow(Lrgb)?%顯示分割后的圖像
title(‘Watershed?transform?of?gradient?magnitude?(Lrgb)‘)
se?=?strel(‘disk‘?20);%圓形結構元素
Io?=?imopen(I?se);%形態學開操作
figure;?subplot(121)
imshow(Io)?%顯示執行開操作后的圖像
title(‘Opening?(Io)‘)
Ie?=?imerode(I?se);%對圖像進行腐蝕
Iobr?=?imreconstruct(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2889??2010-06-19?14:26??Watershed?algorithm.m
-----------?---------??----------?-----??----
?????????????????2889????????????????????1
評論
共有 條評論