{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":99552,"databundleVersionId":13190393,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Published on July 28, 2025. By Prata, Marília (mpwolke)","metadata":{}},{"cell_type":"markdown","source":"#### Don't run that 1st snippet: it will freeze your Kaggle Notebook","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport plotly.graph_objs as go\n\nimport warnings\nwarnings.simplefilter(action='ignore', category=Warning)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-07-28T22:18:34.780276Z","iopub.execute_input":"2025-07-28T22:18:34.780426Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"_kg_hide-input":true,"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"![](https://www.cell.com/cms/10.1016/j.patter.2023.100709/asset/7dc829ab-8923-4eef-9bf2-36a85c4b6471/main.assets/gr3_lrg.jpg)Cell Press","metadata":{}},{"cell_type":"markdown","source":"## Competition Citation\n\n@misc{rsna-intracranial-aneurysm-detection,\n\n    author = {Jeff Rudie, Evan Calabrese, Robyn Ball, Peter Chang, Rennie Chen, Errol Colak, Maria Correia de Verdier,  Luciano Prevedello, Tyler Richards, Rachit Saluja, Greg Zaharchuk, Jason Sho, Maryam Vazirabad and . RSNA 2025 Intracranial Aneurysm Detection. https://kaggle.competitions/rsna-2025-intracranial-aneurysm-detection, 2025. Kaggle},\n    \n    title = {RSNA Intracranial Aneurysm Detection},\n    year = {2025},\n    \n    howpublished = {\\url{https://kaggle.com/competitions/rsna-intracranial-aneurysm-detection}},\n    note = {Kaggle}\n}","metadata":{}},{"cell_type":"markdown","source":"## RSNA Intracranial Aneurysm (IA) Detection\n\n\"Intracranial aneurysms (IA) affect around 3% of the global population. Unfortunately, up to 50% of these aneurysms are only diagnosed after they rupture, which can result in severe illness or death. Worldwide, intracranial aneurysms cause approximately 500,000 deaths each year, and roughly half of the victims are younger than 50.\n\nIn this competition, hosted by RSNA with the American Society of Neuroradiology (ASNR), the Society of Neurointerventional Surgery (SNIS), and the European Society of Neuroradiology (ESNR), you'll create ML models to detect and precisely locate intracranial aneurysms across various types of medical images, including CTA, MRA, and T1 post-contrast and T2-weighted MRI. The challenge includes real clinical variation, with data from different institutions, scanners and imaging protocols that will test your model’s ability to generalize.\n\nYour work will pave the way for automated solutions to accurately and efficiently diagnose brain aneurysms across a wide range of brain imaging, which will ultimately save lives by enabling earlier intervention--before a catastrophic aneurysm rupture.\"\n\nhttps://www.kaggle.com/competitions/rsna-intracranial-aneurysm-detection","metadata":{}},{"cell_type":"markdown","source":"## Libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nimport glob, pylab, pandas as pd\nimport pydicom\n\nimport warnings\nwarnings.simplefilter(action='ignore', category=Warning)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:52:40.382663Z","iopub.execute_input":"2025-07-28T23:52:40.382963Z","iopub.status.idle":"2025-07-28T23:52:40.962526Z","shell.execute_reply.started":"2025-07-28T23:52:40.382941Z","shell.execute_reply":"2025-07-28T23:52:40.961623Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Prediction of cerebral aneurysm rupture risk by machine learning algorithms\n\n### Citation:\n\nHabibi MA, Fakhfouri A, Mirjani MS, Razavi A, Mortezaei A, Soleimani Y, Lotfi S, Arabi S, Heidaresfahani L, Sadeghi S, Minaee P, Eazi S, Rashidi F, Shafizadeh M, Majidi S. **Prediction of cerebral aneurysm rupture risk by machine learning algorithms**: a systematic review and meta-analysis of 18,670 participants. Neurosurg Rev. 2024 Jan 6;47(1):34. doi: 10.1007/s10143-023-02271-2. PMID: 38183490.\n\n\"It is possible to identify **unruptured intracranial aneurysms** (UIA) using machine learning (ML) algorithms, which can be a life-saving strategy, especially in high-risk populations. To better understand the importance and effectiveness of ML algorithms in practice, a systematic review and meta-analysis were conducted to predict cerebral aneurysm rupture risk.\"\n\n\"PubMed, Scopus, Web of Science, and Embase were searched without restrictions until March 20, 2023. Eligibility criteria included studies that used ML approaches in patients with cerebral aneurysms confirmed by DSA, CTA, or MRI.\"\n\n\"Out of 35 studies included, 33 were cohort, and 11 used digital subtraction angiography (DSA) as their reference imaging modality. Middle cerebral artery (MCA) and anterior cerebral artery (ACA) were the commonest locations of aneurysmal vascular involvement-51% and 40%, respectively.\"\n\n\"The aneurysm morphology was saccular in 48% of studies. Ten of 37 studies (**27%) used deep learning** techniques such as CNNs and ANNs. **Meta-analysis** was performed on 17 studies: sensitivity of 0.83 (95% confidence interval (CI), 0.77-0.88); specificity of 0.83 (95% CI, 0.75-0.88); positive DLR of 4.81 (95% CI, 3.29-7.02) and the negative DLR of 0.20 (95% CI, 0.14-0.29); a diagnostic score of 3.17 (95% CI, 2.55-3.78); odds ratio of 23.69 (95% CI, 12.75-44.01).\"\n\n\"ML algorithms can effectively predict the risk of rupture in cerebral aneurysms with good levels of accuracy, sensitivity, and specificity. However, further research is needed to enhance their diagnostic performance in predicting the rupture status of IA.\"\n\nhttps://pubmed.ncbi.nlm.nih.gov/38183490/","metadata":{}},{"cell_type":"code","source":"import cv2\n\nimport glob\nimport time\nimport random\n\nimport nibabel as nib\nfrom glob import glob\nfrom tqdm import tqdm\nfrom pydicom.pixel_data_handlers.util import apply_voi_lut\n\npydicom.__version__, nib.__version__","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:06:47.272024Z","iopub.execute_input":"2025-07-29T00:06:47.272352Z","iopub.status.idle":"2025-07-29T00:06:47.829118Z","shell.execute_reply.started":"2025-07-29T00:06:47.272331Z","shell.execute_reply":"2025-07-29T00:06:47.828569Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## test: No more data to show (3 rows)","metadata":{}},{"cell_type":"code","source":"test = pd.read_csv('../input/rsna-intracranial-aneurysm-detection/kaggle_evaluation/test.csv')\ntest.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T22:40:44.905683Z","iopub.execute_input":"2025-07-28T22:40:44.905998Z","iopub.status.idle":"2025-07-28T22:40:44.955164Z","shell.execute_reply.started":"2025-07-28T22:40:44.905978Z","shell.execute_reply":"2025-07-28T22:40:44.954343Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### train_localizers file \n\n\"This file provides localization data for the aneurysms in the training set. For each aneurysm, it provides the specific image (SOPInstanceUID) and the coordinates near the aneurysm's center.\"\n\n**SeriesInstanceUID** - A unique identifier for each scan series, corresponding to that in train.csv.\n\n**SOPInstanceUID** - A unique identifier for a specific image within a series.\n\n**coordinates** - The xy-coordinates of the center of the aneurysm in the image.\n\n**location** - A text description of the aneurysm's location.\"\n\nhttps://www.kaggle.com/competitions/rsna-intracranial-aneurysm-detection/data?select=train_localizers.csv","metadata":{}},{"cell_type":"code","source":"localizers = pd.read_csv('../input/rsna-intracranial-aneurysm-detection/train_localizers.csv')\nlocalizers.head(2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T22:48:11.641503Z","iopub.execute_input":"2025-07-28T22:48:11.641768Z","iopub.status.idle":"2025-07-28T22:48:11.659623Z","shell.execute_reply.started":"2025-07-28T22:48:11.641746Z","shell.execute_reply":"2025-07-28T22:48:11.658676Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Distribution of Intracranial Aneurysm (IA) Location\n\nThe series have been labeled in **thirteen locations** for the **presence of aneurysms**. They included spatial localization labels for all aneurysms and vessel segmentations for a subset of the cases.","metadata":{}},{"cell_type":"code","source":"#By Pedro Andrade https://www.kaggle.com/code/pbizil/datahackers-managers-radiografia-dos-gestores\n\nloc_counts = localizers[\"location\"].value_counts().head(13)#Try different values of head\nsns.set(style=\"white\")\nplt.figure(figsize=(8, 6))\n#x=loc_counts.index, y=loc_counts.values\nax = sns.barplot(x=loc_counts.index, y=loc_counts.values, color=sns.color_palette(\"Reds\", n_colors=5)[3])\nplt.title(\"Distribution of IA Location\", fontsize=16)\nplt.xlabel(\"Tags\", fontsize=12)\nplt.ylabel(\"Frequency\", fontsize=12)\nplt.xticks(rotation=45, fontsize=11)\nplt.yticks(fontsize=11)\nsns.despine()\n\n#+2 is good if chart is vertical. +20 worked for horizontal\nfor i, v in enumerate(loc_counts.values):\n    ax.text(i, v + 2, str(v), ha='center', va='bottom', fontsize=10)\n\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T22:59:58.677435Z","iopub.execute_input":"2025-07-28T22:59:58.677684Z","iopub.status.idle":"2025-07-28T22:59:58.983239Z","shell.execute_reply.started":"2025-07-28T22:59:58.677665Z","shell.execute_reply":"2025-07-28T22:59:58.982229Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Modality'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:12:48.236543Z","iopub.execute_input":"2025-07-28T23:12:48.236808Z","iopub.status.idle":"2025-07-28T23:12:48.243208Z","shell.execute_reply.started":"2025-07-28T23:12:48.236788Z","shell.execute_reply":"2025-07-28T23:12:48.24257Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## train file","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('../input/rsna-intracranial-aneurysm-detection/train.csv')\ntrain.tail()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T22:48:27.219748Z","iopub.execute_input":"2025-07-28T22:48:27.220123Z","iopub.status.idle":"2025-07-28T22:48:27.241976Z","shell.execute_reply.started":"2025-07-28T22:48:27.220099Z","shell.execute_reply":"2025-07-28T22:48:27.241149Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## train info()","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:35:50.481428Z","iopub.execute_input":"2025-07-28T23:35:50.489814Z","iopub.status.idle":"2025-07-28T23:35:50.549651Z","shell.execute_reply.started":"2025-07-28T23:35:50.489668Z","shell.execute_reply":"2025-07-28T23:35:50.548123Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.describe().loc[['mean','min','max']].T","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:37:48.921493Z","iopub.execute_input":"2025-07-28T23:37:48.921794Z","iopub.status.idle":"2025-07-28T23:37:48.950492Z","shell.execute_reply.started":"2025-07-28T23:37:48.921774Z","shell.execute_reply":"2025-07-28T23:37:48.949874Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Define our numerical cols","metadata":{}},{"cell_type":"code","source":"numerical_cols =['PatientAge',\n 'Left Infraclinoid Internal Carotid Artery',\n 'Right Infraclinoid Internal Carotid Artery',\n 'Left Supraclinoid Internal Carotid Artery',\n 'Right Supraclinoid Internal Carotid Artery',\n 'Left Middle Cerebral Artery',\n 'Right Middle Cerebral Artery',\n 'Anterior Communicating Artery',\n 'Left Anterior Cerebral Artery',\n 'Right Anterior Cerebral Artery',\n 'Left Posterior Communicating Artery',\n 'Right Posterior Communicating Artery',\n 'Basilar Tip',\n 'Other Posterior Circulation',\n 'Aneurysm Present']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:39:56.296719Z","iopub.execute_input":"2025-07-28T23:39:56.297474Z","iopub.status.idle":"2025-07-28T23:39:56.302243Z","shell.execute_reply.started":"2025-07-28T23:39:56.297456Z","shell.execute_reply":"2025-07-28T23:39:56.300476Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Heatmap","metadata":{}},{"cell_type":"code","source":"# OutlierPandas https://www.kaggle.com/code/abhyudaya456/s5e6-eda-for-predicting-optimal-fertilizers/notebook \nplt.figure(figsize=(16,8))\nsns.heatmap(train[numerical_cols].corr(), annot=True, cmap='summer')\nplt.title(\"Correlation Between Numerical Features\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:40:18.468604Z","iopub.execute_input":"2025-07-28T23:40:18.46891Z","iopub.status.idle":"2025-07-28T23:40:19.1427Z","shell.execute_reply.started":"2025-07-28T23:40:18.46889Z","shell.execute_reply":"2025-07-28T23:40:19.141708Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Histograms\n\nPatient Age is more affected are **above 60**. Which isn't a surprise since after 60 we'll face more health issues.\n\nSecond row, show what arteries are more affected in an IA?","metadata":{}},{"cell_type":"code","source":"#Original figsize 15,10\ntrain[numerical_cols].hist(figsize=(20,15), bins=30, color='Green', edgecolor='black')\nplt.suptitle(\"Histogram of Numeric Features\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:42:31.8068Z","iopub.execute_input":"2025-07-28T23:42:31.807124Z","iopub.status.idle":"2025-07-28T23:42:34.67877Z","shell.execute_reply.started":"2025-07-28T23:42:31.807105Z","shell.execute_reply":"2025-07-28T23:42:34.677964Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## That chart wasn't my intention. Anyway...","metadata":{}},{"cell_type":"code","source":"#By Shivam811 https://www.kaggle.com/code/shivams811/sms-spam-detection-97-67-acc-1-0-ps/notebook\n\nsns.histplot(train[train['Aneurysm Present'] == 0])\nsns.histplot(train[train['Aneurysm Present'] == 1], color='red')\nplt.title(\"Presence of IA Distribution\");","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:14:15.82159Z","iopub.execute_input":"2025-07-28T23:14:15.822036Z","iopub.status.idle":"2025-07-28T23:14:17.113478Z","shell.execute_reply.started":"2025-07-28T23:14:15.821992Z","shell.execute_reply":"2025-07-28T23:14:17.11277Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Medical Imaging Series of the brain modalities\n\nThe competition data comprises several thousand expertly-curated medical imaging series of the brain from a variety of modalities, including **CTA, MRA, and T1 post-contrast and T2-weighted MRI.** \n\n**Computed Tomography Angiography** (CTA)\n\n**Magnetic Resonance Angiography** (MRA)\n\n**Magnetic resonance imaging** (MRI)","metadata":{}},{"cell_type":"code","source":"#By Pedro Andrade https://www.kaggle.com/code/pbizil/datahackers-managers-radiografia-dos-gestores\n\nmod_counts = train[\"Modality\"].value_counts().head(13)#Try different values of head\nsns.set(style=\"white\")\nplt.figure(figsize=(8, 6))\n#x=loc_counts.index, y=loc_counts.values\nax = sns.barplot(x=mod_counts.index, y=mod_counts.values, color=sns.color_palette(\"Greens\", n_colors=5)[3])\nplt.title(\"Medical Imaging Series Modalities\", fontsize=16)\nplt.xlabel(\"Tags\", fontsize=12)\nplt.ylabel(\"Frequency\", fontsize=12)\nplt.xticks(rotation=45, fontsize=11)\nplt.yticks(fontsize=11)\nsns.despine()\n\n#+2 is good if chart is vertical. +20 worked for horizontal\nfor i, v in enumerate(mod_counts.values):\n    ax.text(i, v + 20, str(v), ha='center', va='bottom', fontsize=10)\n\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:45:33.873647Z","iopub.execute_input":"2025-07-29T00:45:33.873957Z","iopub.status.idle":"2025-07-29T00:45:34.05736Z","shell.execute_reply.started":"2025-07-29T00:45:33.873936Z","shell.execute_reply":"2025-07-29T00:45:34.056458Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## len dcm images","metadata":{}},{"cell_type":"code","source":"#Code by Abdul Basit https://www.kaggle.com/code/abdulbasitniazi/enetb7-explained-98-fine-tuning-eda\n\ntrain_images = glob.glob('../input/rsna-intracranial-aneurysm-detection/series/**/*.dcm')\nprint(\"Total number of images: \", len(train_images))\n\ntrain_images = pd.Series(train_images)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-28T23:59:54.4813Z","iopub.execute_input":"2025-07-28T23:59:54.48162Z","iopub.status.idle":"2025-07-29T00:00:00.171561Z","shell.execute_reply.started":"2025-07-28T23:59:54.481599Z","shell.execute_reply":"2025-07-29T00:00:00.170673Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#By Marco Vasquez E https://www.kaggle.com/code/marcovasquez/basic-eda-data-visualization/notebook\n\nfig=plt.figure(figsize=(15, 10))\ncolumns = 5; rows = 4\nfor i in range(1, columns*rows +1):\n    ds = pydicom.dcmread(train_images[i])#Original was dcmread(train_images_dir + train_images[i])\n    fig.add_subplot(rows, columns, i)\n    plt.imshow(ds.pixel_array, cmap=plt.cm.bone)\n    fig.add_subplot","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:00:06.932768Z","iopub.execute_input":"2025-07-29T00:00:06.933047Z","iopub.status.idle":"2025-07-29T00:00:10.003263Z","shell.execute_reply.started":"2025-07-29T00:00:06.933032Z","shell.execute_reply":"2025-07-29T00:00:10.002513Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### File type of image","metadata":{}},{"cell_type":"code","source":"print(ds) # this is file type of image","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:01:32.06751Z","iopub.execute_input":"2025-07-29T00:01:32.068467Z","iopub.status.idle":"2025-07-29T00:01:32.075801Z","shell.execute_reply.started":"2025-07-29T00:01:32.068443Z","shell.execute_reply":"2025-07-29T00:01:32.07504Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"im = ds.pixel_array\nprint(type(im))\nprint(im.dtype)\nprint(im.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:02:16.477889Z","iopub.execute_input":"2025-07-29T00:02:16.478459Z","iopub.status.idle":"2025-07-29T00:02:16.483008Z","shell.execute_reply.started":"2025-07-29T00:02:16.478439Z","shell.execute_reply":"2025-07-29T00:02:16.482315Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## One DICOM image, let's use the pylab.imshow() method:","metadata":{}},{"cell_type":"code","source":"#Marco Vasquez E https://www.kaggle.com/code/marcovasquez/basic-eda-data-visualization/notebook\n\npylab.imshow(im, cmap=pylab.cm.gist_gray)\npylab.axis('on');","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:02:30.38069Z","iopub.execute_input":"2025-07-29T00:02:30.380996Z","iopub.status.idle":"2025-07-29T00:02:30.572166Z","shell.execute_reply.started":"2025-07-29T00:02:30.380976Z","shell.execute_reply":"2025-07-29T00:02:30.571284Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Display one Raw nii file","metadata":{}},{"cell_type":"code","source":"#By David Roberts https://www.kaggle.com/competitions/rsna-2023-abdominal-trauma-detection/discussion/427795\n\nimport matplotlib.pylab as plt\nimport nibabel as nib\nimport shutil\n\n# Copy a random label file to /kaggle/working directory (without .nii file extension)\nsrc = '/kaggle/input/rsna-intracranial-aneurysm-detection/segmentations/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii'\ndst = '/kaggle/working/1.2.826.0.1.3680043.8.498.10035643165968342618460849823699311381.nii'\n\nshutil.copyfile(src, dst);\n\n# Check the shape\nimg = nib.load(dst).get_fdata()\nprint(img.shape)\n\n# Plot a single frame from the middle of the stack\nplt.imshow(img[:,:,10]) #Original was 150\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:11:26.217268Z","iopub.execute_input":"2025-07-29T00:11:26.22028Z","iopub.status.idle":"2025-07-29T00:11:29.923413Z","shell.execute_reply.started":"2025-07-29T00:11:26.220255Z","shell.execute_reply":"2025-07-29T00:11:29.922636Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Let's plot nii slices","metadata":{}},{"cell_type":"code","source":"#By Innat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\nmrscans = sorted(\n    glob(\n        '../input/rsna-intracranial-aneurysm-detection/segmentations/*/*'\n    )\n)\n\n# num of segmentation mask\nlen(mrscans)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:14:11.159063Z","iopub.execute_input":"2025-07-29T00:14:11.159351Z","iopub.status.idle":"2025-07-29T00:14:11.294194Z","shell.execute_reply.started":"2025-07-29T00:14:11.159322Z","shell.execute_reply":"2025-07-29T00:14:11.29347Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Innat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\ndef read_nibabel(path):\n    return nib.load(path).get_fdata()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:14:55.437109Z","iopub.execute_input":"2025-07-29T00:14:55.43741Z","iopub.status.idle":"2025-07-29T00:14:55.441689Z","shell.execute_reply.started":"2025-07-29T00:14:55.437389Z","shell.execute_reply":"2025-07-29T00:14:55.440962Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Innat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\ndef multi_dim_plot(multi_dim_array, id, num_slices=49): #Original was 64\n    fig = plt.figure(figsize=(30, 30))\n    plt.title(\n        f'Plotting first {num_slices} slices of {id}', \n        fontdict = {'fontsize' : 20}\n    )\n    plt.yticks([])\n    plt.xticks([])\n    \n    xy = int(np.sqrt(num_slices))\n    for i in range(num_slices):\n        ax = fig.add_subplot(xy, xy, i + 1)\n        plt.imshow(multi_dim_array[..., :num_slices][..., i])\n        plt.axis(\"off\")\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:15:20.604405Z","iopub.execute_input":"2025-07-29T00:15:20.604674Z","iopub.status.idle":"2025-07-29T00:15:20.610108Z","shell.execute_reply.started":"2025-07-29T00:15:20.604657Z","shell.execute_reply":"2025-07-29T00:15:20.609168Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Innat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\nfrom random import sample\nimport nibabel as nib\n\nfor msk in sample(mrscans, 2):\n    m = read_nibabel(msk)\n    multi_dim_plot(m, id=msk.split('/')[-1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:15:38.653399Z","iopub.execute_input":"2025-07-29T00:15:38.653668Z","iopub.status.idle":"2025-07-29T00:15:50.734697Z","shell.execute_reply.started":"2025-07-29T00:15:38.653651Z","shell.execute_reply":"2025-07-29T00:15:50.733906Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Innat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\ndef multi_dim_plot(multi_dim_array, id, num_slices=25): #Original was 64\n    fig = plt.figure(figsize=(30, 30))\n    plt.title(\n        f'Plotting first {num_slices} slices of {id}', \n        fontdict = {'fontsize' : 20}\n    )\n    plt.yticks([])\n    plt.xticks([])\n    \n    xy = int(np.sqrt(num_slices))\n    for i in range(num_slices):\n        ax = fig.add_subplot(xy, xy, i + 1)\n        plt.imshow(multi_dim_array[..., :num_slices][..., i])\n        plt.axis(\"off\")\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:16:15.097642Z","iopub.execute_input":"2025-07-29T00:16:15.097921Z","iopub.status.idle":"2025-07-29T00:16:15.103323Z","shell.execute_reply.started":"2025-07-29T00:16:15.097903Z","shell.execute_reply":"2025-07-29T00:16:15.102455Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Innat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda\n\nfrom random import sample\nimport nibabel as nib\n\nfor msk in sample(mrscans, 2):\n    m = read_nibabel(msk)\n    multi_dim_plot(m, id=msk.split('/')[-1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-29T00:16:36.509565Z","iopub.execute_input":"2025-07-29T00:16:36.509874Z","iopub.status.idle":"2025-07-29T00:16:50.18708Z","shell.execute_reply.started":"2025-07-29T00:16:36.509819Z","shell.execute_reply":"2025-07-29T00:16:50.186326Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Are you done MPwolke? Yes, I'm: Draft Session: 2h:21m","metadata":{}},{"cell_type":"markdown","source":"#Acknowledgements:\n\nPedro Andrade https://www.kaggle.com/code/pbizil/datahackers-managers-radiografia-dos-gestores\n\nShivams811 https://www.kaggle.com/code/shivams811/sms-spam-detection-97-67-acc-1-0-ps/notebook\n\nOutlierPandas https://www.kaggle.com/code/abhyudaya456/s5e6-eda-for-predicting-optimal-fertilizers/notebook\n\nAbdul Basit https://www.kaggle.com/code/abdulbasitniazi/enetb7-explained-98-fine-tuning-eda\n\nMarco Vasquez E https://www.kaggle.com/code/marcovasquez/basic-eda-data-visualization/notebook\n\nDavid Roberts https://www.kaggle.com/competitions/rsna-2023-abdominal-trauma-detection/discussion/427795\n\nInnat https://www.kaggle.com/code/ipythonx/cervical-spine-fracture-detection-quick-eda","metadata":{}}]}