检测几乎被包围的背景区域
Detecting almost surrounded background areas
我正在对摩擦样本进行图像处理。我正在从图像中分割磨损轨迹,但有一个反复出现的问题:
将阈值设置得太低会导致完全失败。将其设置得太高(如图所示)会导致多个区域几乎但未完全被标签包围。它们弄乱了我用来估计轨道宽度的距离变换,应该被检测到并合并到标签中。
我已经使用形态学操作来提高标签的质量,但由于图像其余部分的一些副作用,我不希望使结构元素变大。标签的曲率阻止我使用凸包。标签的大部分阻止我使用标签的坚固性作为指标。不需要的内部物体没有被标签完全包围,因此无法通过欧拉特性等检测到。
有什么好的方法可以检测 'almost completely' 被前景物体包围的背景物体吗?
我使用 watershed
将背景划分为单独的区域,然后 bwboundaries
检测有多少区域的边界与前景对象共享:
% generate example image
bw = im2double(rgb2gray(imread('example.jpg'))) == 1;
% dilate binary object to overlap watershed boundaries
bwDil = imdilate(bw,ones(5));
% get watershed labels
D = bwdist(bw);
D = -D;
D(bw) = -Inf;
L = watershed(D);
% get binary regions and remove fg object
R = (L > 0);
R(bw) = 0;
% get boundaries of all regions
BR = bwboundaries(R);
% set boundary ratio - if a regio's shares more boundary with fg object
% than this threshold it considered surrounded
boundaryRatio = zeros(numel(BR),1);
ratioThresh = 0.6;
mask = false(size(bw));
% go through region boundaries and add them to mask if above tresh
for ii = 1:numel(BR)
ind = sub2ind(size(bw),BR{ii}(:,1),BR{ii}(:,2));
boundaryRatio(ii) = nnz(bwDil(ind))/numel(ind);
if boundaryRatio(ii) > ratioThresh
mask(ind) = 1;
end
end
% fill mask
mask = imfill(mask,4,'holes');
% plot
subplot(121);
imshow(bw);
title('fg')
rgb = double(cat(3,mask,bw,bw));
subplot(122);
imshow(rgb);
title('fg with surrounded bg')
我正在对摩擦样本进行图像处理。我正在从图像中分割磨损轨迹,但有一个反复出现的问题:
将阈值设置得太低会导致完全失败。将其设置得太高(如图所示)会导致多个区域几乎但未完全被标签包围。它们弄乱了我用来估计轨道宽度的距离变换,应该被检测到并合并到标签中。
我已经使用形态学操作来提高标签的质量,但由于图像其余部分的一些副作用,我不希望使结构元素变大。标签的曲率阻止我使用凸包。标签的大部分阻止我使用标签的坚固性作为指标。不需要的内部物体没有被标签完全包围,因此无法通过欧拉特性等检测到。
有什么好的方法可以检测 'almost completely' 被前景物体包围的背景物体吗?
我使用 watershed
将背景划分为单独的区域,然后 bwboundaries
检测有多少区域的边界与前景对象共享:
% generate example image
bw = im2double(rgb2gray(imread('example.jpg'))) == 1;
% dilate binary object to overlap watershed boundaries
bwDil = imdilate(bw,ones(5));
% get watershed labels
D = bwdist(bw);
D = -D;
D(bw) = -Inf;
L = watershed(D);
% get binary regions and remove fg object
R = (L > 0);
R(bw) = 0;
% get boundaries of all regions
BR = bwboundaries(R);
% set boundary ratio - if a regio's shares more boundary with fg object
% than this threshold it considered surrounded
boundaryRatio = zeros(numel(BR),1);
ratioThresh = 0.6;
mask = false(size(bw));
% go through region boundaries and add them to mask if above tresh
for ii = 1:numel(BR)
ind = sub2ind(size(bw),BR{ii}(:,1),BR{ii}(:,2));
boundaryRatio(ii) = nnz(bwDil(ind))/numel(ind);
if boundaryRatio(ii) > ratioThresh
mask(ind) = 1;
end
end
% fill mask
mask = imfill(mask,4,'holes');
% plot
subplot(121);
imshow(bw);
title('fg')
rgb = double(cat(3,mask,bw,bw));
subplot(122);
imshow(rgb);
title('fg with surrounded bg')