Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 检测几乎被包围的背景区域_Matlab_Image Processing_Image Segmentation - Fatal编程技术网

Matlab 检测几乎被包围的背景区域

Matlab 检测几乎被包围的背景区域,matlab,image-processing,image-segmentation,Matlab,Image Processing,Image Segmentation,我在做摩擦学样品的图像处理。我正在从图像中分割磨损轨迹,但有一个反复出现的问题: 将阈值设置得过低会导致完全失败。将其设置得过高(如图中所示)会导致多个区域几乎被标签包围,但并未完全被标签包围。它们弄乱了我用来估计轨迹宽度的距离变换,应该被检测并合并到标签上 我使用了形态学操作来提高标签的质量,但不希望由于图像其余部分的一些副作用而使结构元素变大。标签的曲率使我无法使用凸面外壳。标签的体积使我无法使用标签的坚固性作为指示器。不需要的内部对象没有被标签完全包围,因此无法通过欧拉特征等进行检测 有

我在做摩擦学样品的图像处理。我正在从图像中分割磨损轨迹,但有一个反复出现的问题:

将阈值设置得过低会导致完全失败。将其设置得过高(如图中所示)会导致多个区域几乎被标签包围,但并未完全被标签包围。它们弄乱了我用来估计轨迹宽度的距离变换,应该被检测并合并到标签上

我使用了形态学操作来提高标签的质量,但不希望由于图像其余部分的一些副作用而使结构元素变大。标签的曲率使我无法使用凸面外壳。标签的体积使我无法使用标签的坚固性作为指示器。不需要的内部对象没有被标签完全包围,因此无法通过欧拉特征等进行检测


有什么好方法可以检测被前景对象“几乎完全”包围的背景对象吗?

我使用
分水岭
将背景划分为单独的区域,然后
bwBounders
检测一个区域的边界有多少与前景对象共享:

% 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')

您没有提供原始数据,因此很难测试方法,但我认为这对您的情况很有帮助