Connected Component Manipulation

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

[1]:
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()
/opt/buildhome/python3.7/lib/python3.7/site-packages/nilearn/datasets/__init__.py:96: FutureWarning: Fetchers from the nilearn.datasets module will be updated in version 0.9 to return python strings instead of bytes and Pandas dataframes instead of Numpy arrays.
  "Numpy arrays.", FutureWarning)
looking for components to remove: 100%|██████████| 6/6 [00:00<00:00, 5661.60it/s]
../../_images/notebooks_preprocessing_connectedcomponents_1_1.png
[ ]: