Connected Component ManipulationΒΆ

The Brainlit package contains some functions to manipulate connected components. This is usually done on binary images, especially labels.

[ ]:
import numpy as np
from brainlit.preprocessing import getLargestCC, removeSmallCCs
from skimage import data
import matplotlib.pyplot as plt

img = data.binary_blobs(512, 0.1, n_dim=2, volume_fraction=0.5, seed=10)
largest_cc = getLargestCC(img)
large_cc = removeSmallCCs(img, 10000)


plt.figure()
plt.subplot(1, 3, 1)
plt.imshow(img)
plt.title("Original Image")
plt.axis("Off")
plt.subplot(1, 3, 2)
plt.imshow(largest_cc)
plt.title("Largest CC")
plt.axis("Off")
plt.subplot(1, 3, 3)
plt.imshow(large_cc)
plt.title("Small CCs Removed")
plt.axis("Off")
plt.show()
[ ]: