gpt4 book ai didi

matlab - 在 MATLAB 中去除图像的背景和测量特征

转载 作者:太空宇宙 更新时间:2023-11-03 19:36:16 27 4
gpt4 key购买 nike

我正在尝试测量此图像中显示的每个粒子的面积:

enter image description here

我设法使用此处显示的 MSER 获得每个粒子的一般形状:

enter image description here

但我无法删除背景。我尝试使用 MATLAB 的 imfill,但它并没有填充所有的粒子,因为有些粒子在边缘被切断了。关于如何摆脱背景或以其他方式找到粒子区域的任何提示?干杯。

编辑:这就是 imfill 的样子:

enter image description here

编辑 2:这是用于获取大纲的代码。我用了this对于 MSER。

%Compute region seeds and elliptial frames.
%MinDiversity = how similar to its parent MSER the region is
%MaxVariation = stability of the region
%BrightOnDark is used as the void is primarily dark. It also prevents dark
%patches in the void being detected.
[r,f] = vl_mser(I,'MinDiversity',0.7,...
'MaxVariation',0.2,...
'Delta',10,...
'BrightOnDark',1,'DarkOnBright',0) ;

%Plot region frames, but not used right now
%f = vl_ertr(f) ;
%vl_plotframe(f) ;

%Plot MSERs
M = zeros(size(I)) ; %M = no of overlapping extremal regions

for x=r'
s = vl_erfill(I,x) ;
M(s) = M(s) + 1;
end

%Display region boundaries
figure(1) ;
clf ; imagesc(I) ; hold on ; axis equal off; colormap gray ;

%Create contour plot using the values
%0:max(M(:))+.5 is the no of contour levels. Only level 0 is needed so
%[0 0] is used.

[c,h]=contour(M,[0 0]) ;;
set(h,'color','r','linewidth',1) ;

%Retrieve the image data from the contour image
f = getframe;
I2 = f.cdata;

%Convert the image into binary; the red outlines are while while the rest
%is black.
I2 = all(bsxfun(@eq,I2,reshape([255 0 0],[1 1 3])),3);
I2 = imcrop(I2,[20 1 395 343]);

imshow(~I2);

最佳答案

建议的解决方案/技巧和代码

看来你可以在这里使用M。您可以在此处使用的一个技巧是在图像 M 的所有边界上填充零,然后填充它的孔。这将负责填充之前接触边界的 Blob ,因为现在由于零填充,不会有任何 Blob 接触边界。

因此,在您拥有 M 之后,您可以添加此代码 -

%// Get a binary version of M
M_bw = im2bw(M);

%// Pad zeros all across the grayscale image
padlen = 2; %// length of zeros padding
M_pad = padarray(M_bw,[padlen padlen],0);

%// Fill the holes
M_pad_filled = imfill(M_pad,'holes');

%// Get the background mask after the holes are gone
background_mask = ~M_pad_filled(padlen+1:end-padlen,padlen+1:end-padlen);

%// Overlay the background mask on the original image to show that you have
%// a working background mask for use
I(background_mask) = 0;
figure,imshow(I)

结果

输入图像-

enter image description here

前景掩码(这将是 ~background_mask)-

enter image description here

输出图像-

enter image description here

关于matlab - 在 MATLAB 中去除图像的背景和测量特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27014766/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com