資源簡介
應用標記符控制分水嶺分割 有效解決了分水嶺算法在圖像分割中的過分割問題

代碼片段和文件信息
%對一組腦部CT圖像共94張進行改進分水嶺算法運算
for?i=0:93
numcdstring=num2str(i);
if?length(numcdstring)==1
????serials=strcat(‘head_image_100‘numcdstring‘_1001‘);
else
????serials=strcat(‘head_image_10‘numcdstring‘_1001‘);
end
filename=strcat(serials‘.bmp‘);??
f=imread(filename);
%f=rgb2gray(t);
%subplot(231);
%imshow(f);
%title(‘原始圖像‘);
%計算梯度圖
f=double(f);
hv=fspecial(‘prewitt‘);??%應用prewitt算子銳化圖像?
hh=hv.‘;
gv=abs(imfilter(fhv‘replicate‘));??%replicate表示圖像大小通過復制外邊界的值來擴展
gh=abs(imfilter(fhh‘replicate‘));
g=sqrt(gv.^2+gh.^2);
%計算距離函數
%subplot(232);
df=bwdist(f);????%?求出其他點跟當前點的距離
%imshow(uint8(df*8));
%title(‘原始圖像的距離變換‘);
%計算外部約束
L=watershed(df);
em=L==0;
%subplot(233);
%imshow(em);
%title(‘標記外部約束‘);
%計算內部約束
im=imextendedmax(f20);
%subplot(234);
%imshow(im);
%title(‘標記內部約束‘);
%重構梯度圖
?g2=imimposemin(gim|em);
?%subplot(235);
?%imshow(g2);
?%title(‘由標記內外部約束重構的梯度圖‘);
?%watershed算法分割
?L2=watershed(g2);
?wr2=L2==0;
?%subplot(236);
?f(wr2)=255;
?f=uint8(f);
?%imshow(f);
?%title(‘分割結果‘);
?imwrite(fstrcat(serials‘改進分水嶺算法分割圖‘‘.bmp‘));
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1248??2009-09-17?11:08??watershedgjsz.m
-----------?---------??----------?-----??----
?????????????????1248????????????????????1
評論
共有 條評論