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/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm
looking for components to remove: 100%|██████████| 6/6 [00:00<00:00, 8053.06it/s]
../../_images/notebooks_preprocessing_connectedcomponents_1_1.png
[ ]: