資源簡介
分水嶺算法是現在醫學圖像分割的經典算法,具有非常高的參考價值
代碼片段和文件信息
?
rgb?=?imread(‘E:\MATLAB\work\src\(10).jpg‘);%讀取原圖像
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)‘)
%2.?直接使用梯度模值進行分水嶺算法:(往往會存在過的分割的情況,效果不好)
L?=?watershed(gradmag);%直接應用分水嶺算法
Lrgb?=?label2rgb(L);%轉化為彩色圖像
figure;?imshow(Lrgb)?%顯示分割后的圖像
title(‘Watershed?transform?of?gradient?magnitude?(Lrgb)‘)
%3.分別對前景和背景進行標記:本例中使用形態學重建技術對前景對象進行標記,首先使用開操作,開操作之后可以去掉一些很小的目標。
se?=?strel(‘disk‘?20);%圓形結構元素
Io?=?imopen(I?se);%形態學開操作
figure;?subplot(121)
imshow(Io)?%顯示執行開操作后的圖像
title(‘Opening?(Io)‘)
Ie?=?imerode(I?se);%對圖像進行腐蝕
Iobr?=?imreconstruct(Ie?I);%形態學重建
subplot(122);?imshow(Iobr)?%顯示重建后的圖像
title(‘Opening-by-reconstruction?(Iobr)‘)
Ioc?=?imclose(Io?se);%形態學關操作
figure;?subplot(121)
imshow(Ioc)?%顯示關操作后的圖像
title(‘Opening-closing?(Ioc)‘)
Iobrd?=?imdilate(Iobr?se);%對圖像進行膨脹
Iobrcbr?=?imreconstruct(imcomplement(Iobrd)?...
????imcomplement(Iobr));%形態學重建
Iobrcbr?=?imcomplement(Iobrcbr);%圖像求反
subplot(122);?imshow(Iobrcbr)?%顯示重建求反后的圖像
title(‘Opening-closing?by?recons
- 上一篇:最小距離分類
- 下一篇:EMD實現的MATLAB代碼
評論
共有 條評論