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ことを選択していると思います。すべてのピクセル値が 400 未満であるため、その範囲では肉眼では黒く見えます。imshow[1, 65025]

于 2016-08-22T17:12:03.657 に答える