Obtain clusters#

Calculate clusters#

Extract clusters (‘islands’ of connected pixels with the same value).

_images/clusters.svg

clusters.py

import GooseEYE
import numpy as np

# generate image
img = GooseEYE.dummy_circles((500, 500), periodic=True)

# clusters
labels = GooseEYE.clusters(img, periodic=False)

# clusters, if the image is periodic
labels_periodic = GooseEYE.clusters(img, periodic=True)

Calculate clusters and centers#

_images/clusters_centers.svg

clusters_centers.py

import GooseEYE
import numpy as np

# generate image
img = GooseEYE.dummy_circles((500, 500), periodic=True)

# clusters
labels = GooseEYE.clusters(img, periodic=False)
names = np.unique(labels)
centers = GooseEYE.labels_centers(labels, names, periodic=False)

# clusters, if the image is periodic
labels_periodic = GooseEYE.clusters(img, periodic=True)
names_periodic = np.unique(labels_periodic)
centers_periodic = GooseEYE.labels_centers(labels_periodic, names_periodic, periodic=True)

Dilate clusters (differently)#

_images/clusters_dilate.svg

clusters_dilate.py

import GooseEYE
import numpy as np

# generate image
img = np.zeros((21, 21), dtype="bool")
img[4, 4] = True
img[14, 15] = True
img[15, 15] = True
img[16, 15] = True
img[15, 14] = True
img[15, 16] = True

# clusters
C = GooseEYE.clusters(img)

# dilate
CD = GooseEYE.dilate(C)

Note

There is an additional example to show the effect of periodicity: clusters_dilate_periodic.py clusters_dilate_periodic.svg