# Which image filter acts like "surface tension"?

I'm looking for an image filter that does the following operation:

In my first image, I have two spheres. After applying the filter, I'd like to have them "glued together" which something that kind of resembles surface tension.

Remarks:

• The image will be 2D/3D, with the signed distance to the surface of the spheres encoded as grayscale.
• It would be great if it is something that's already in Numpy / Scipy.
• I know that people do similiar stuff on meshes, but I'd like to have it as an image filter.

Example images (sorry for the different formats):

• morphological dilation might appeal. Sep 16 '17 at 6:48

A morphological closing is a combination of dilation followed by erosion; typical image processing operations available in most image processing libraries.

SciPy has a "simple" binary closing method which does this on binary images. By experimenting with different structuring elements you can close smaller or bigger gaps.

I think that you could use a Gaussian Filter.

The following Python code does something similar to what you show in your images.

from __future__ import division
import numpy as np
from scipy.ndimage.filters import gaussian_filter, laplace
import matplotlib.pyplot as plt

y, x = np.mgrid[-2:2:101j, -2:2:101j]
z = np.maximum(0, 0.2 - (x + 0.5)**2 - y**2) +\
np.maximum(0, 0.2 - (x - 0.5)**2 - y**2)
z2 = gaussian_filter(z, sigma=7)

plt.figure(figsize=(8, 4))
plt.subplot(1, 2, 1)
plt.contourf(x, y, z)
plt.subplot(1, 2, 2)
plt.contourf(x, y, z2)
plt.savefig("gaussian_filter.png")


The results is the following The caveat is the selection of sigma. That parameter would determine how spread is the Gaussian filter.

• It does agglomerate the nearby bodies, but it does look more like a diffusion than a surface tension phenomena. Surface tension would in a way "conserve the volume" of the original spheres while maintaining a sharp interface. Still a good starting point.
– BlaB
Sep 15 '17 at 12:38
• @BlaB, that's true, but to generate a new surface you would need to move material from one side to the other. Sep 15 '17 at 13:38