<jupyter_start><jupyter_text>dbrainExtract the lateral ventricle from an MRI image of the brain.  DescriptionThis procedure extracts the lateral ventricle from an MRI image of the brain. This example was kindly provided by Prof. <NAME> from The Johns Hopkins University and appears in Goutsias and <NAME>, Morphological Methods for Biomedical Image Analysis, In the Handbook of Medical Imaging: Volume 3. Progress in Medical Image Processing and Analysis, <NAME> and <NAME> (Eds.)(To Appear). SPIE Optical Engineering Press, May 2000.<jupyter_code>import numpy as np
from PIL import Image
import ia870 as ia<jupyter_output><empty_output><jupyter_text>ReadingThe MRI image of a brain slice is read.<jupyter_code>a_pil = Image.open('data/mribrain.tif')
a_pil<jupyter_output><empty_output><jupyter_text>Ventricle detection IThe ventricle is enhanced using an opening with a disk of radius 10 followed by a reconstruction.<jupyter_code>a = np.array(a_pil)
b = ia.iaopen(a,ia.iasedisk(10));
c = ia.iainfrec(b,a);
Image.fromarray(ia.iagshow(b).transpose(1, 2, 0))
Image.fromarray(ia.iagshow(c).transpose(1, 2, 0))<jupyter_output><empty_output><jupyter_text>Ventricle detection IIThe result of the open by reconstruction is subtracted from the original image. Note that the three operations: open, reconstruction and the subtraction could be done at once using the mmopenrecth (open by reconstruction top-hat) function. On the right, the enhanced ventricle is thresholded.<jupyter_code>d = ia.iasubm(a,c);
Image.fromarray(ia.iagshow(d).transpose(1, 2, 0))
e = ia.iathreshad(d, 50)
Image.fromarray(ia.iagshow(e).transpose(1, 2, 0))<jupyter_output><empty_output><jupyter_text>Selecting the ventricleFinally, the ventricle is selected as the connected object with area larger than 70 pixels. For visualization purposes, the result of the segmentation is overlayed on the original brain image.<jupyter_code>f= ia.iaareaopen(e,70);
Image.fromarray(ia.iagshow(f).transpose(1, 2, 0))
Image.fromarray(ia.iagshow(a, f).transpose(1, 2, 0))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0935672514619883, 'fraction_numerical': 0.017543859649122806, 'mean_word_length': 6.631970260223048, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '597666', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 716, 'n_tokens_neox': 649, 'n_words': 219, 'path': 'dbrain.ipynb', 'repo_name': 'robertoalotufo/ia870p3', 'size': '2075'}