0

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

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

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;整个图像变暗之后。我相信这是因为图像像素都是 -inf 或一些较小的负数。这是有办法解决这个问题的,如果是这样,我可以在我的代码中进行哪些更改以使该算法正常工作?我已经尝试了很多,但我真的不知道发生了什么。任何帮助都会很棒!

4

1 回答 1

2

问题出在你的show命令上。正如您在评论中所说,这imshow在引擎盖下使用。如果你imshow直接尝试,你会看到你也得到一个黑色的图像。但是,如果您以适当的限制调用它:

imshow(clean_img,[min(clean_img(:)), max(clean_img(:))])

你会看到你期望看到的一切。

一般来说,出于这个原因,我通常更喜欢 imagesc。imshow对代表什么范围做出任意判断,我通常懒得跟上它。我认为在您的情况下,您的最终图像是uint16如此imshow选择代表 range [1, 65025]。由于您的所有像素值都低于 400,因此在该范围内,它们在肉眼看来是黑色的。

于 2016-08-22T17:12:03.657 回答