{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Connected Component Manipulation\n", "The Brainlit package contains some functions to manipulate connected components. This is usually done on binary images, especially labels." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from brainlit.preprocessing import getLargestCC, removeSmallCCs\n", "from skimage import data\n", "import matplotlib.pyplot as plt\n", "\n", "img = data.binary_blobs(512, 0.1, n_dim = 2, volume_fraction = 0.5, seed=10)\n", "largest_cc = getLargestCC(img)\n", "large_cc = removeSmallCCs(img, 10000)\n", "\n", "\n", "plt.figure()\n", "plt.subplot(1,3,1)\n", "plt.imshow(img)\n", "plt.title(\"Original Image\")\n", "plt.axis(\"Off\")\n", "plt.subplot(1,3,2)\n", "plt.imshow(largest_cc)\n", "plt.title(\"Largest CC\")\n", "plt.axis(\"Off\")\n", "plt.subplot(1,3,3)\n", "plt.imshow(large_cc)\n", "plt.title(\"Small CCs Removed\")\n", "plt.axis(\"Off\")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "file_extension": ".py", "kernelspec": { "display_name": "Python 3.7.6 64-bit ('scipydev': conda)", "name": "python37664bitscipydevcondaa561a5f26f384a3d8eec296dbbf704a7" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "name": "python", "version": "3.7.6-final" }, "mimetype": "text/x-python", "name": "python", "npconvert_exporter": "python", "pygments_lexer": "ipython3", "version": 3 }, "nbformat": 4, "nbformat_minor": 2 }