我正在使用分水岭算法来尝试分割触摸核 . 典型图像可能如下所示:
或者:
我正在尝试使用此代码应用分水岭算法:
show(RGB_img)
%Convert to grayscale image
I = rgb2gray(RGB_img);
%Take structuring element of a disk of size 10, for the morphological transformations
%Attempt to subtract the background from the image: top hat is the
%subtraction of the open image from the original
%Morphological transformation to subtract background noise from the image
%Tophat is the subtraction of an opened image from the original. Remove all
%images smaller than the structuring element of 10
I1 = imtophat(I, strel('disk', 10));
%Increases contrast
I2 = imadjust(I1);
%show(I2,'contrast')
%Assume we have background and foreground and assess thresh as such
level = graythresh(I2);
%Convert to binary image based on graythreshold
BW = im2bw(I2,level);
show(BW,'C');
BW = bwareaopen(BW,8);
show(BW,'C2');
BW = bwdist(BW) <= 1;
show(BW,'joined');
%Complement because we want image to be black and background white
C = ~BW;
%Use distance tranform to find nearest nonzero values from every pixel
D = -bwdist(C);
%Assign Minus infinity values to the values of C inside of the D image
% Modify the image so that the background pixels and the extended maxima
% pixels are forced to be the only local minima in the image (So you could
% hypothetically fill in water on the image
D(C) = -Inf;
%Gets 0 for all watershed lines and integers for each object (basins)
L = watershed(D);
show(L,'L');
%Takes the labels and converts to an RGB (Using hot colormap)
fin = label2rgb(L,'hot','w');
% show(fin,'fin');
im = I;
%Superimpose ridgelines,L has all of them as 0 -> so mark these as 0(black)
im(L==0)=0;
clean_img = L;
show(clean_img)
无论出于何种原因_1112820_整个图像变暗 . 这个相同的代码块已经处理了一些其他图像,所有这些图像都更像是这些图像 . 但是,我以为我用 BW = bwdist(BW) <= 1;
补偿了这一点 . 我真的知道发生了什么 . 任何帮助都会很棒!
PS . 这是 BW = bwareaopen(BW,8);
之后的图片
1 回答
在礼帽之前,您应该执行关闭和打开以减少噪音 .
如果在嘈杂的图像上执行区域打开,最终可能会在黑白图像上显示结果 .
所以它会是:
关闭并开放
Top-Hat
如果仍有需要开放区域
阈值
侵蚀和膨胀分别找到内部和外部标记
流域(从不使用没有标记的分水岭) .