1

我正在使用分水岭算法来尝试分割接触核。一个典型的图像可能看起来像:在此处输入图像描述 或者这样:在此处输入图像描述

我正在尝试使用以下代码应用分水岭算法:

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)

C = ~BW;在整个图像变暗之后无论出于何种原因。这个相同的代码块已经在少数其他图像上工作过,所有这些图像都更“坚固”或不像这些那样粗糙。但是,我认为我用BW = bwdist(BW) <= 1;. 我已经尝试了很多,但我真的不知道发生了什么。任何帮助都会很棒!

附言。这是之后的图像BW = bwareaopen(BW,8); 图片说明在这里

4

1 回答 1

0

在礼帽之前,您应该执行关闭和打开以减少噪音。

如果您在嘈杂的图像上执行区域打开,您最终可能会在黑白图像上得到结果。

所以它会是:

  1. 关闭和打开
  2. 礼帽
  3. 如有必要,开放区域
  4. 阈值化
  5. 腐蚀和膨胀分别找到内部和外部标记
  6. 分水岭(切勿使用没有标记的分水岭)。
于 2016-09-13T18:51:38.333 回答