Skip to content

Commit

Permalink
Almost final notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
nesh committed Dec 1, 2020
1 parent d1744a6 commit 980c768
Showing 1 changed file with 100 additions and 49 deletions.
149 changes: 100 additions & 49 deletions Rad Path Fusion Final.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"from holoviews import opts\n",
"import numpy as np\n",
"import pandas as pd\n",
"import utils as rad\n",
"from pathlib import Path\n",
"pn.extension()\n",
"hv.extension('bokeh')"
]
Expand Down Expand Up @@ -62,13 +64,12 @@
"metadata": {},
"outputs": [],
"source": [
"mri_folder_path = f'data/Prostate Fused-MRI-Pathology/aaa0051/07-02-2000-PELVISPROSTATE-97855/4.000000-T2 AXIAL SM FOV-36207'\n",
"pathology_img_path = 'data/pathology/aaa 0051 BSlice.tif'\n",
"pathology_annotated_img_path = 'data/pathology/aaa 0051 BSlice annotated.tif'\n",
"mri_folder_path = f'data/patient87/Prostate Fused-MRI-Pathology/aaa0087/09-01-2000-PELVISPROSTATE-81724/5.000000-T2 AXIAL SM FOV-30095'\n",
"pathology_img_path = f'data/patient87/pathology/aaa0087 F2F3F1F4.tif'\n",
"pathology_annotated_img_path = 'data/patient87/pathology/masks/aaa0087 F2F3F1F4.trace.tif'\n",
"\n",
"# mri_folder_path = 'data/patient87/Prostate Fused-MRI-Pathology/aaa0087/09-01-2000-PELVISPROSTATE-81724/5.000000-T2 AXIAL SM FOV-30095'\n",
"# pathology_img_path = '/Users/neshdev/radpathfusion/data/patient87/pathology/aaa0087 A1A2A3A4.tif'\n",
"# pathology_annotated_img_path\n"
"print(\"pathology_img_path exists:\", Path(pathology_img_path).exists())\n",
"print(\"pathology_annotated_img_path exists:\", Path(pathology_annotated_img_path).exists())"
]
},
{
Expand All @@ -78,15 +79,6 @@
"**Warning**: This might take a while depening on the size of the image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import utils as rad"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -97,16 +89,6 @@
"pathology_annotated_source = rad.Image.load(pathology_annotated_img_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# pathology_source = cv2.imread(pathology_img_path)\n",
"# pathology_annotated_source = cv2.imread(pathology_annotated_img_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -219,28 +201,21 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fixed = landmarks_viewer.fixed_image(in_origin=rad.Origin.TOP_LEFT)"
]
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"moving = landmarks_viewer.moving_image(in_origin=rad.Origin.TOP_LEFT)"
]
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"annotated = (pathology_annotated_source.copy_attributes(landmarks_viewer.moving_image(in_origin=rad.Origin.TOP_LEFT))\n",
" .update(interpolation='INTER_AREA'))"
]
"source": []
},
{
"cell_type": "code",
Expand All @@ -254,6 +229,31 @@
")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Intermediate landmark visualization\n",
"\n",
"The following 6 plots show the intermediate steps of both the landmarks and the images:\n",
"\n",
"1. Visualize only the MRI and the landmarks\n",
"2. Visualize only the pathology and the affined landmarks\n",
"3. Visualize only the Thin Plate Splines and the moved landmarks\n",
"4. Visualize both the MRI and the affined Pathology image and the Pathology affined landmarks\n",
"5. Visualize both the MRI and the Thin Plate Splines Pathology image and the Pathology Thin Plate Spline landmarks\n",
"6. Visualize several components: the MRI, the Thin Plate Splin Pathology,the Pathology affined landmarks and the Pathology Thin Plate Spline landmarks\n",
"\n",
"Finally, we will show all 6 of these charts at the same time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Visualize only the MRI and the landmarks"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -263,6 +263,13 @@
"visualize(tps_viewer.mri_with_fixed_points())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Visualize only the pathology and the affined landmarks"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -272,6 +279,13 @@
"visualize(tps_viewer.pathology_with_affine_points())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Visualize only the Thin Plate Splines and the moved landmarks"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -281,6 +295,13 @@
"visualize(tps_viewer.pathology_with_tps_points())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Visualize the MRI, the affined Pathology image and the Pathology affined landmarks"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -291,12 +312,10 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"visualize(tps_viewer.mri_with_affine_and_tps_overlay())"
"## 5. Visualize the MRI, the Thin Plate Splines Pathology image and the Pathology Thin Plate Spline landmarks"
]
},
{
Expand All @@ -308,29 +327,40 @@
"visualize(tps_viewer.mri_with_tps_overlay())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Visualize several components: the MRI, the Thin Plate Spline Pathology image, the Pathology affined landmarks and the Pathology Thin Plate Spline landmarks"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tps_viewer.panel()"
"visualize(tps_viewer.mri_with_affine_and_tps_overlay())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"tps_viewer.panel()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Image Alignment Visualization\n",
"\n",
"The below visualization shows the final transformations of the image registration done in the previous steps. In this visualization, you can see the pathology and mri image overlayed on top of each other. Additionally, you can control the transparency of each layer."
"The below visualization shows the final transformations of the image registration done in the previous steps. In this visualization, you can see the pathology and mri image overlayed on top of each other. Additionally, you can control the transparency of each layer. \n",
"\n",
"**Note:** controlling the alpha might take a while for the image to update"
]
},
{
Expand All @@ -339,7 +369,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"overlay_viewer = rad.TpsOverlayVisualizer(\n",
" fixed=landmarks_viewer.fixed_image(in_origin=rad.Origin.TOP_LEFT), \n",
" warped=landmarks_viewer.moving_image(in_origin=rad.Origin.TOP_LEFT), \n",
Expand All @@ -349,21 +378,43 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"save_path = \"\"\n",
"landmarks_viewer.fixed_image(in_origin=rad.Origin.TOP_LEFT)"
"# Saving the data\n",
"\n",
"In this final part of the notebook, we will be saving the data so that the points can be refrenced/loaded.\n",
"\n",
"Update the value in `save_path` to the destination you would like your data saved"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"save_path = \"data/output\"\n",
"save_path = Path(save_path)\n",
"def save(path):\n",
" save_path.mkdir(exist_ok=True)\n",
" \n",
" fixed = landmarks_viewer.fixed_image(in_origin=rad.Origin.TOP_LEFT)\n",
" moving = landmarks_viewer.moving_image(in_origin=rad.Origin.TOP_LEFT)\n",
" annotated = (pathology_annotated_source.copy_attributes(landmarks_viewer.moving_image(in_origin=rad.Origin.TOP_LEFT))\n",
" .update(interpolation='INTER_AREA'))\n",
" tps_moving = rad.tps.TpsAlgorithm(moving_img=moving, fixed_img=fixed).warp()\n",
" tps_moving_annotated = rad.tps.TpsAlgorithm(moving_img=annotated, fixed_img=fixed).warp()\n",
" \n",
" \n",
" fixed.save(save_path,\"fixed\")\n",
" moving.save(save_path,\"moving\")\n",
" annotated.save(save_path,\"annotated\")\n",
" tps_moving.save(save_path,\"tps_moving\")\n",
" tps_moving_annotated.save(save_path,\"tps_moving_annotated\")\n",
" \n",
"save(save_path)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 980c768

Please sign in to comment.