-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd9658d
commit e5c65dd
Showing
13 changed files
with
2,517 additions
and
106 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Visualization of MRI Data and Labelmaps" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This notebook contains a tutorial for visualizing medical images, in particular MRI data and Labelmaps. For this purpose we are going to use the library [SimpleITK](https://github.com/SimpleITK/SimpleITK)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"tags": [ | ||
"hide-cell" | ||
] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import numpy as np\n", | ||
"import SimpleITK as sitk" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Dataset visualization" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"First we will load the MRI data, which is made up of 2D images stacked to form a 3D volume. This is saved in the NIfTI format. We will use the `sitk.ReadImage` function to load the data. The data is then converted to a numpy array using the `sitk.GetArrayFromImage` function. The array has a three-dimensional shape, along which the MRI images are stored. We will use the `show_slices` function to visualize the slices of the MRI data." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"path_to_mri = os.path.join(\"../..\", \"data\", \"mri\", \"00001.nii\")\n", | ||
"mri_1 = sitk.ReadImage(path_to_mri)\n", | ||
"mri_1_data = sitk.GetArrayFromImage(mri_1)\n", | ||
"print(f\"{mri_1_data.shape=}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Since we are interested in the transversal view of the hand, the function displays the images stored in the second dimension of the array. The function takes as input the data to slice, the start index and the number of images to display as well as the step size. The colormap is set to gray." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from armscan_env.util.visualizations import show_slices\n", | ||
"\n", | ||
"show_slices(data=mri_1_data, start=mri_1_data.shape[1] - 1, end=25, lap=5, cmap=\"gray\")\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Label dataset" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Next we will load the label data, which is also saved in the NIfTI format. The labelmaps have been created by manually segmenting the relevant tissues in the MRI data. This segmentation has been performed using [ImFusion](https://www.imfusion.com/). The labelmaps are saved in the same coordinate system as the MRI data. Since they are saved in the same way as the MRI images, we can use the same functions to load and visualize them." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"path_to_mri = os.path.join(\"../..\", \"data\", \"labels\", \"00001_labels.nii\")\n", | ||
"mri_1_label = sitk.ReadImage(path_to_mri)\n", | ||
"mri_1_label_data = sitk.GetArrayFromImage(mri_1_label)\n", | ||
"print(f\"{mri_1_label_data.shape =}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"What is shown in the images, are the labeled tissues, hence bones, tendons, median nerve and ulnar artery." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"show_slices(mri_1_label_data, mri_1_label_data.shape[1] - 1, 25, 5)\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The labels are nothing else then standard values given to each tissue:\n", | ||
"- 0: background\n", | ||
"- 1: bones\n", | ||
"- 2: tendons\n", | ||
"- 3: ulnar artery\n", | ||
"- 4: median nerve" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"Max value in mri labeled data: \", np.max(mri_1_label_data))\n", | ||
"print(\"Max value in mri data: \", np.max(mri_1_data))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "med_im", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.