如何平滑分段的斑点? [英] How can I smooth the segmented blob?

查看:71
本文介绍了如何平滑分段的斑点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在分段的斑点上出现了一些闪烁(清晰的线条).如何减少它们以使边界更平滑?为了更加清晰,我将图像附加了输入和预期输出.

I am getting some flickers (sharp lines) along the segmented blob. How can I reduce them to make the boundary smoother? For more clarity, I have attached the image with input and expected output.

请注意,这是一个二进制图像,我没有原始图像(灰色).输入为二进制.

Note that, it is a binary image and I have no raw image (gray). The input is binary.

我尝试了高斯模糊,但是该方法使我的形状变小了.

I have tried Gaussian blur but the method makes my shape smaller.

mask = ndimage.filters.gaussian_filter(mask, 0.5, order=0, output=None, mode='reflect', cval=0.0, truncate=5.0)

推荐答案

展开 MBo的答案:

开口处应带有圆盘结构元件(内核),以防止方向偏向.

The opening should be applied with a disk structuring element (kernel) to prevent directional bias.

磁盘的大小决定了要删除的工件数量.下面是来自OP(左)和5个打开结果的示例图像,其直径分别为7、9、11、13和15个像素.在我看来,对于这种情况,最好使用13或15像素,尽管在15像素时也可能会删除更多的细节.过滤噪声始终是消除噪声和保留细节之间的折衷方案.去除的噪音越多,去除的细节也越多.

The size of the disk dictates how much of the artifacts are removed. Below is the example image from the OP (left) and 5 opening results, with diameters of 7, 9, 11, 13 and 15 pixels. It seems to me that either 13 or 15 pixels are best for this case, though at 15 pixels there might be more detail being removed as well. Filtering noise is always a compromise between removing noise and preserving detail. The more noise is removed, the more detail is removed as well.

SciPy ndimage具有开口 ,将其与磁盘结构元素一起应用,请执行以下操作:

SciPy ndimage has an opening, to apply it with a disk structuring element do as follows:

diameter = 15
radius = diameter // 2
x = np.arange(-radius, radius+1)
x, y = np.meshgrid(x, x)
r = x**2 + y**2
se = r < radius**2
ndimage.binary_opening(img, se)

在此代码中,我们首先创建一个1D数组x,该数组指示到中间的距离. np.meshgrid接受此数组,并创建两个包含x和y坐标且其原点位于图像中间的2D数组(图像).下一行计算r,即到原点的平方距离.最后,我们可以获得结构元素se作为原点radius内的所有像素.

In this code, we first create a 1D array x that indicates the distance from the middle. np.meshgrid takes this array and creates two 2D arrays (images) containing the x and y coordinates with the origin in the middle of the image. The next line computes r, the squared distance to the origin. Finally we can obtain the structuring element se as all pixels within radius of the origin.

OpenCV可能有更简单的方法来应用磁盘开口.我建议使用SciPy ndimage,因为这是OP中使用的.

It is possible that OpenCV has an easier way of applying an opening with a disk. I'm suggesting SciPy ndimage because that is what is used in OP.

这篇关于如何平滑分段的斑点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆