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/python_jsonschema_objects/__init__.py:53: UserWarning: Schema version http://json-schema.org/draft-04/schema not recognized. Some keywords and features may not be supported.
  self.schema["$schema"]
../../_images/notebooks_preprocessing_connectedcomponents_1_1.png
[ ]: