Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .binder/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
itk-elastix>=0.12.0
itk-elastix>=0.17.1
itkwidgets>=0.32.0
jupyterlab>=2.2.0
imageio
Expand Down
90 changes: 70 additions & 20 deletions examples/ITK_Example09_PointSetAndMaskTransformation.ipynb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 9. Point set and Mask Transformation"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -19,6 +21,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -57,6 +60,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -65,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -77,6 +81,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -85,25 +90,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Import Mask\n",
"moving_mask = itk.imread('data/CT_3D_lung_moving_mask.mha', itk.F)"
"# Note: Version v0.17.0 and onwards supports various image types for elastix and transformix functions/objects\n",
"moving_mask = itk.imread('data/CT_3D_lung_moving_mask.mha', itk.UC)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Mask image is a binary image, therefore the FinalBSplineInterpolationOrder should be 0\n",
"result_transform_parameters.SetParameter('FinalBSplineInterpolationOrder','0')\n"
"result_transform_parameters.SetParameter('FinalBSplineInterpolationOrder','0')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -112,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -123,6 +130,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -131,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -148,13 +156,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Segmentation Transformation Evaluation"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -163,7 +173,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -180,12 +190,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# Import groundtruth segmentation\n",
"fixed_mask = itk.imread('data/CT_3D_lung_fixed_mask.mha', itk.F)\n",
"fixed_mask = itk.imread('data/CT_3D_lung_fixed_mask.mha', itk.UC)\n",
"\n",
"# Cast itk images to numpy arrays and round result image to boolean array.\n",
"fixed_mask_np = np.asarray(fixed_mask)\n",
Expand All @@ -194,23 +204,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dice loss: 0.9862246731348647\n"
]
}
],
"source": [
"print(\"Dice loss:\",dice_loss(fixed_mask_np, result_mask_np))"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c76e48b027c84e37963cf1e02ee8a702",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AppLayout(children=(HBox(children=(Label(value='Link:'), Checkbox(value=False, description='cmap'), Checkbox(v…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"compare(fixed_mask, result_moving_mask)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -219,7 +253,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -231,6 +265,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -239,7 +274,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -262,17 +297,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3a044dd051e04f2f92d3dae77639590e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Viewer(geometries=[], gradient_opacity=0.22, point_set_colors=array([[0.8392157, 0. , 0. ]], dtype…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"view(moving_image, point_sets=[result_point_set])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -286,7 +336,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.9.0"
}
},
"nbformat": 4,
Expand Down
Loading