資源簡介
matlab編寫的分水嶺算法實驗代碼,用于圖像分割處理,針對連接在一起的物體圖像,進行分割效果較好
代碼片段和文件信息
rgb?=?imread(‘F:\matlab\圖片\2222.jpg‘);
I=rgb2gray(rgb);
subplot(231)imshow(rgb)?title(‘原圖‘);
hy?=?fspecial(‘sobel‘);
hx?=?hy‘;
Iy?=?imfilter(double(I)?hy?‘replicate‘);
Ix?=?imfilter(double(I)?hx?‘replicate‘);
gradmag?=?sqrt(Ix.^2?+?Iy.^2);
subplot(232)imshow(gradmag[])?title(‘梯度幅值圖像‘);
?
?
se?=?strel(‘disk‘?20);
Ie?=?imerode(I?se);
Iobr?=?imreconstruct(Ie?I);
%subplot(333)imshow(Iobr)?title(‘基于開的重建圖像‘);
Iobrd?=?imdilate(Iobr?se);
Iobrcbr?=?imreconstruct(imcomplement(Iobrd)?imcomplement(Iobr));
Iobrcbr?=?imcomplement(Iobrcbr);
fgm?=?imregionalmax(Iobrcbr);
subplot(233)imshow(Iobrcbr)?title(‘基于開閉的重建圖像‘);
%subplot(335);?imshow(fgm);?title(‘局部極大圖像‘);
It1?=?rgb(:?:?1);
It2?=?rgb(:?:?2);
It3?=?rgb(:?:?3);
It1(fgm)?=?255;?It2(fgm)?=?0;?It3(fgm)?=?0;
I2?=?cat(3?It1?It2?It3);
%subplot(234);?imshow(I2);?title(‘局部極大
評論
共有 條評論