我想对这幅图像中的水稻进行图像分割,采取了基于控制标记的距离变换分水岭分割程序如下rgb = imread('C:UserschenxuanDesktop稻子原图.jpg');
if ndims(rgb) == 3
I = rgb2gray(rgb);
else
I = rgb;
end
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
L = watershed(gradmag);
wr=L==0;%分水岭脊线
subplot(121),imshow(rgb),subplot(122),imshow(wr)
rm=imregionalmin(I);whos rm
figure,imshow(rm)
im2=imextendedmin(I,27);
figure,imshow(im2)
fim=I;fim(im2)=175;figure,imshow(fim)%以灰 {MOD}来显示这些“局部最小区域”
fim=I;fim(im2)=175;figure,imshow(fim,[])
temp=bwdist(im2);%距离变换
figure,imshow(temp,[])
Lim=watershed(temp);
em=Lim==0;
figure,imshow(em) %em=external marker,外部标记符
whos em
max(em(:))
temp=bwdist(~im2);figure,imshow(temp,[])
Lim=watershed(temp);em=Lim==0;figure,imshow(em)
I(em)=255;figure,imshow(I,[])
fim(em)=255;figure,imshow(I,[])
g2=imimposemin(g,im2|em);
g2=imimposemin(gradmag ,im2|em);
L2=watershed(g2);
f2=I;f2(L2==0)=255;
figure,imshow(f2,[])
可是结果分割并不理想
-
-
-
一周热门 更多>