3

我有一个三相图像,我使用自动阈值(multithresh)和“imquantize”函数对其进行了分割。在没有任何过滤操作的情况下,我确实在图像中有很多洞。然而,当我使用中值滤波器时,这些漏洞会减少,尽管尽管进行了滤波,但仍有相当多的漏洞。 原始图像

过滤后的分割图像

从这一点应用“填充”功能会导致“过度填充”,如下图红色圆圈部分所示。 填充孔图像

代码如下:

%# Read in image
I = imread(‘original_image.jpg');
figure, imshow(I),axis off, title('Original Image');

%# Filter image
I = medfilt2(I);
% figure, imshow(I), title('Median-filtered image')

%# Segment image
thresh  = multithresh(I, 2);
BW      = imquantize(I, thresh);    
figure, imshow(BW,[]),axis off, title('Segmented Image'); 

%# Fill holes
BW2     = imfill(BW,'holes');    
figure, imshow(BW2, []); title('Filled holes image');

我只是想知道是否有更好的方法来处理这种情况。您认为使用“multithresh”和“imquantize”功能对分割是否足够好?分水岭可以做得更好吗?这里甚至有必要吗?

一般来说,请问我可以做些什么来提高输出图像的质量?

我问的原因是因为如果你缩放原始图像的“imshow”,你会注意到大部分黑色相接触固体(白色相)。然而,自动分割并不能准确地捕捉到这一点,因为分割的图像在固相周围有中间(灰色)相环。我该如何处理?

非常感谢您的预期帮助/建议。

4

1 回答 1

1

你的方法是否足够好很大程度上取决于你想在这里实现什么。例如,边界需要多平滑?

针对您的具体问题:您的量化图像具有三个级别,0(黑色)、1(灰色)和 2(白色)。您似乎想关闭灰色区域中的小黑洞。为此,只需创建一个仅包含灰色像素的单独二进制图像,然后组合回您的多级图像(您不应该将其称为 BW,因为 Matlab 文档在任何地方都将其用于二进制图像,如果您应该保持一致能够)。

% pull out the gray "channel"
grayPixels = BW==1; % will have ones everywhere there's gray, and 0 otherwise

% to close holes up to a maximum size, invert the image (holes become islands) 
% and eliminate small islands with bwareaopen
invGray = ~grayPixels;
invGray = bwareaopen(invGray,100); % closes holes up to 100pix size - adjust
grayPixels = ~invGray; % imshow to view result

% merge gray channel back in. Note we want black->gray, 
% but we don't want white->gray. 
% Since black/gray/white are 0/1/2, if we take the maximum of the gray 
% (which is 0/1) and your "BW" (which is 0/1/2), we replace 0 in BW with 1 
% wherever we have closed a hole

BW = max(BW,double(grayPixels);
imshow(BW,[]);

同样,您可以bwareaopen在“黑色”通道上运行,以消除此处和那里的白点。

您可以将“白色”通道类似地拉出BW大球形颗粒的分水岭,您很可能会得到一个很好的结果(如果白色颗粒是您所追求的)。


如果你想让白色颗粒周围的灰色细边消失,你可以尝试形态学打开。基本上,您将灰色区域缩小几个像素(侵蚀),然后将其重新增长几个像素(膨胀)。一条细细的灰线将完全消失,因此不会再长出任何东西。

% take the gray "channel" again (after closing the small holes)
grayPixels = BW == 1;
grayPixelsOpened = imopen(grayPixels,strel('disk',3)); % play with the radius 3 to get the desired result

% everything that used to be gray and is no longer so needs to be turned black 
% in the original image
BW(grayPixels~=grayPixelsOpened) = 0;

会有一些权衡,因为灰色阶段的弯月面将不再那么尖锐。如果需要,您可以通过黑色通道的后续打开来恢复一些。

于 2017-01-05T13:10:49.397 回答