如何防止分水岭算法中封闭背景区域的不准确分割?
How to prevent inaccurate segmentation of enclosed background regions in Watershed Algorithm?
我正在使用分水岭算法来分割深色背景上的亮点。下面提供了代码及其生成的一些图像。
在第二张图片中,我用红色十字标记了被分割为 'cells' 的封闭背景区域(它们不是生物细胞,只是使用了这个词)- 这是不正确的,它们它们是背景的一部分,只是被 'cells' 包围。我看到这会创建一个错误的最小值,关于如何防止这种情况有什么帮助吗?
% Improve contrast, binarize
RFP_adjust = imadjust(RFP_blur, stretchlim(RFP_blur, 0.001));
figure, imshow(RFP_adjust), title('Contrast adjust');
RFP_binarized = imbinarize(RFP_adjust);
RFP_perimeters = bwperim(RFP_binarized);
% figure, imshow(RFP_binarized), title('Otsu thresholding');
%2B - SEGMENTATION BY WATERSHED METHOD
% Discover putative cell centroids and process
RFP_maxs = imextendedmax(RFP_adjust, 3000);
RFP_maxs = imclose(RFP_maxs, strel('disk',5));
RFP_maxs = imfill(RFP_maxs, 'holes');
RFP_maxs = bwareaopen(RFP_maxs, 5);
RFP_max_overlay = imoverlay(RFP_adjust, RFP_perimeters | RFP_maxs, [1 .3 .3]);
figure, imshow(RFP_max_overlay), title('Maxima');
% Obtain complement - maxima become low-points (required for watershed)
RFP_comp = imcomplement(RFP_adjust);
RFP_imposemin = imimposemin(RFP_comp, ~RFP_binarized | RFP_maxs);
figure, imshow(RFP_imposemin), title('Inverted Maxima');
% Apply watershed
RFP_watershed = watershed(RFP_imposemin);
mask = im2bw(RFP_watershed, 1);
overlay3 = imoverlay(RFP_adjust, mask, [1 .3 .3]);
figure, imshow(overlay3), title('Segmented cells');
% Segment
RFP_cc = bwconncomp(RFP_watershed);
RFP_label_matrix = labelmatrix(RFP_cc);
whos labeled;
RFP_label = label2rgb(RFP_label_matrix, @spring, 'c', 'shuffle');
figure, imshow(RFP_label), title('Cells segmented');
图片 0 - 标题为 'Maxima' 的图片的结果(即调整后的原始图片覆盖了最大值和轮廓)。
图片 1 - 标题为 'inverted maxima' 的图片的结果
图片 2 - 标题为 'Cells segmented' 的图片的结果
没有灵丹妙药,但您可以尝试一些事情。
一种是用非常大的圆盘过滤图像,创建看起来像背景的模糊图像。然后从原始图像中减去它。这往往会迫使实际背景为零。
另一个是 Otsu 阈值来分离前景和背景。这会创建一个二进制图像。然后使用设计成看起来像实际细胞的掩码进行形态学开运算。
我建议像 the example included for the watershed
function 中所做的那样:使用背景遮罩将这些像素设置为 Inf
,执行分水岭操作,然后将结果中的背景像素设置为 0 . 我相信您可以像这样更改代码的分水岭部分以实现此目的:
% Apply watershed
RFP_watershed = RFP_imposemin; % Added
RFP_watershed(~RFP_binarized) = Inf; % Added
RFP_watershed = watershed(RFP_watershed); % Modified
RFP_watershed(~RFP_binarized) = 0; % Added
mask = im2bw(RFP_watershed, 1);
overlay3 = imoverlay(RFP_adjust, mask, [1 .3 .3]);
figure, imshow(overlay3), title('Segmented cells');
我正在使用分水岭算法来分割深色背景上的亮点。下面提供了代码及其生成的一些图像。
在第二张图片中,我用红色十字标记了被分割为 'cells' 的封闭背景区域(它们不是生物细胞,只是使用了这个词)- 这是不正确的,它们它们是背景的一部分,只是被 'cells' 包围。我看到这会创建一个错误的最小值,关于如何防止这种情况有什么帮助吗?
% Improve contrast, binarize
RFP_adjust = imadjust(RFP_blur, stretchlim(RFP_blur, 0.001));
figure, imshow(RFP_adjust), title('Contrast adjust');
RFP_binarized = imbinarize(RFP_adjust);
RFP_perimeters = bwperim(RFP_binarized);
% figure, imshow(RFP_binarized), title('Otsu thresholding');
%2B - SEGMENTATION BY WATERSHED METHOD
% Discover putative cell centroids and process
RFP_maxs = imextendedmax(RFP_adjust, 3000);
RFP_maxs = imclose(RFP_maxs, strel('disk',5));
RFP_maxs = imfill(RFP_maxs, 'holes');
RFP_maxs = bwareaopen(RFP_maxs, 5);
RFP_max_overlay = imoverlay(RFP_adjust, RFP_perimeters | RFP_maxs, [1 .3 .3]);
figure, imshow(RFP_max_overlay), title('Maxima');
% Obtain complement - maxima become low-points (required for watershed)
RFP_comp = imcomplement(RFP_adjust);
RFP_imposemin = imimposemin(RFP_comp, ~RFP_binarized | RFP_maxs);
figure, imshow(RFP_imposemin), title('Inverted Maxima');
% Apply watershed
RFP_watershed = watershed(RFP_imposemin);
mask = im2bw(RFP_watershed, 1);
overlay3 = imoverlay(RFP_adjust, mask, [1 .3 .3]);
figure, imshow(overlay3), title('Segmented cells');
% Segment
RFP_cc = bwconncomp(RFP_watershed);
RFP_label_matrix = labelmatrix(RFP_cc);
whos labeled;
RFP_label = label2rgb(RFP_label_matrix, @spring, 'c', 'shuffle');
figure, imshow(RFP_label), title('Cells segmented');
图片 0 - 标题为 'Maxima' 的图片的结果(即调整后的原始图片覆盖了最大值和轮廓)。
图片 1 - 标题为 'inverted maxima' 的图片的结果
图片 2 - 标题为 'Cells segmented' 的图片的结果
没有灵丹妙药,但您可以尝试一些事情。
一种是用非常大的圆盘过滤图像,创建看起来像背景的模糊图像。然后从原始图像中减去它。这往往会迫使实际背景为零。
另一个是 Otsu 阈值来分离前景和背景。这会创建一个二进制图像。然后使用设计成看起来像实际细胞的掩码进行形态学开运算。
我建议像 the example included for the watershed
function 中所做的那样:使用背景遮罩将这些像素设置为 Inf
,执行分水岭操作,然后将结果中的背景像素设置为 0 . 我相信您可以像这样更改代码的分水岭部分以实现此目的:
% Apply watershed
RFP_watershed = RFP_imposemin; % Added
RFP_watershed(~RFP_binarized) = Inf; % Added
RFP_watershed = watershed(RFP_watershed); % Modified
RFP_watershed(~RFP_binarized) = 0; % Added
mask = im2bw(RFP_watershed, 1);
overlay3 = imoverlay(RFP_adjust, mask, [1 .3 .3]);
figure, imshow(overlay3), title('Segmented cells');