【发布时间】:2012-12-13 00:19:42
【问题描述】:
当我对任何图像进行分割时,它会返回一个图像,即具有背景和前景表示的二进制图像。 现在,如果我只想将图像的背景用于任何目的......怎么做......我的意思是在分割后我得到了一个二值图像现在如何识别(或获取)背景的值。? ??????
【问题讨论】:
当我对任何图像进行分割时,它会返回一个图像,即具有背景和前景表示的二进制图像。 现在,如果我只想将图像的背景用于任何目的......怎么做......我的意思是在分割后我得到了一个二值图像现在如何识别(或获取)背景的值。? ??????
【问题讨论】:
% Assume you have these variables:
% 'mask' - binary segmentation results, all 1's or 0's.
% 'img' - original image.
% 'bgImg' - Output, containing background only.
bgImg = zeros(size(img)); % Initialize to all zeros.
bg(mask) = img(mask); % Use logical indexing.
【讨论】:
我假设您有一张灰度图像。当您将分割目标设为 1 并将背景设为 0 时,只需执行元素矩阵乘法即可获得目标图像。这类似于掩蔽。如果你只想要背景,你可以做 (1 - Binary image) 并与原始图像进行类似的乘法。请记住,这是逐元素乘法,而不是矩阵乘法。
【讨论】:
如果你想测量前景/背景区域的统计数据,一个有趣的选择是regionprops
% img - variable containing original grey-scale image
% mask - binary mask (same size as img) with 0 - background 1 - foreground
% using regionprops to measure average intensity and weighted centroid,
% there are MANY more interesting properties ou can measure, use
% >> doc regionprops
% to discover them
st = regionprops( mask + 1, img, 'MeanIntensity', 'WeightedCentroid');
% get BG avg intensity:
fprintf(1, 'Avg intensity of background = %.2g\n', st(1).MeanIntensity );
【讨论】: