|
16 | 16 | {
|
17 | 17 | "cell_type": "markdown",
|
18 | 18 | "metadata": {
|
19 |
| - "id": "N92pMd7ig0ZS", |
20 |
| - "jp-MarkdownHeadingCollapsed": true, |
| 19 | + "incorrectly_encoded_metadata": "id=\"N92pMd7ig0ZS\" jp-MarkdownHeadingCollapsed=true", |
21 | 20 | "tags": []
|
22 | 21 | },
|
23 | 22 | "source": [
|
|
76 | 75 | "outputs": [],
|
77 | 76 | "source": [
|
78 | 77 | "import os\n",
|
79 |
| - "import sys\n", |
80 | 78 | "\n",
|
81 | 79 | "# Upgrade pip, just in case.\n",
|
82 | 80 | "!{sys.executable} -m pip install --upgrade -q pip"
|
|
210 | 208 | "# Download a \"Shared Cart\" containing 6 scans from PROSTATEx\n",
|
211 | 209 | "# that has been previously created via the TCIA website \n",
|
212 | 210 | "# (https://nbia.cancerimagingarchive.net).\n",
|
213 |
| - "cartName = \"nbia-17571668146714049\"\n", |
| 211 | + "cart_name = \"nbia-17571668146714049\"\n", |
214 | 212 | "\n",
|
215 | 213 | "# retrieve cart metadata\n",
|
216 |
| - "cart_data = nbia.getSharedCart(cartName)\n", |
| 214 | + "cart_data = nbia.getSharedCart(cart_name)\n", |
217 | 215 | "\n",
|
218 | 216 | "# download the series_uids list and return dataframe of metadata\n",
|
219 | 217 | "df = nbia.downloadSeries(cart_data)\n",
|
|
318 | 316 | "# Ideally this would have been accomplished using MONAI's transforms\n",
|
319 | 317 | "# for data pre-processing / augmentation instead of using a separate\n",
|
320 | 318 | "# function.\n",
|
321 |
| - "def prostate_crop( img ):\n", |
322 |
| - " boundary = [int(crop_size*0.2) for crop_size in img.GetLargestPossibleRegion().GetSize()]\n", |
| 319 | + "def prostate_crop(img):\n", |
| 320 | + " boundary = [int(crop_size * 0.2) for crop_size in img.GetLargestPossibleRegion().GetSize()]\n", |
323 | 321 | " new_image = itk.CropImageFilter(Input=img, BoundaryCropSize=boundary)\n",
|
324 | 322 | " return new_image\n",
|
325 | 323 | "\n",
|
| 324 | + "\n", |
326 | 325 | "mr_image_prep = prostate_crop(mr_image)\n",
|
327 | 326 | "seg_image_prep = prostate_crop(seg_image)\n",
|
328 | 327 | "\n",
|
|
456 | 455 | "outputs": [],
|
457 | 456 | "source": [
|
458 | 457 | "# Read the result image that was written into the output_dir.\n",
|
459 |
| - "result_image = itk.imread(os.path.join( output_dir, os.path.split(mr_dir)[1], os.path.split(mr_dir)[1] + \"_trans.nii.gz\"))" |
| 458 | + "result_image = itk.imread(os.path.join(output_dir, os.path.split(mr_dir)[\n", |
| 459 | + " 1], os.path.split(mr_dir)[1] + \"_trans.nii.gz\"))" |
460 | 460 | ]
|
461 | 461 | },
|
462 | 462 | {
|
|
473 | 473 | "# image to match the physical properties of the original input data.\n",
|
474 | 474 | "interpolator = itk.NearestNeighborInterpolateImageFunction.New(seg_image)\n",
|
475 | 475 | "result_image_resampled = itk.resample_image_filter(Input=result_image,\n",
|
476 |
| - " Interpolator=interpolator,\n", |
477 |
| - " reference_image=seg_image_prep, \n", |
478 |
| - " use_reference_image=True)" |
| 476 | + " Interpolator=interpolator,\n", |
| 477 | + " reference_image=seg_image_prep, \n", |
| 478 | + " use_reference_image=True)" |
479 | 479 | ]
|
480 | 480 | },
|
481 | 481 | {
|
|
488 | 488 | "outputs": [],
|
489 | 489 | "source": [
|
490 | 490 | "# View the image with results overlaid in an interactive 2D slice viewer.\n",
|
491 |
| - "viewerB = view(image=mr_image_prep, label_image=result_image_resampled)" |
| 491 | + "viewer_b = view(image=mr_image_prep, label_image=result_image_resampled)" |
492 | 492 | ]
|
493 | 493 | },
|
494 | 494 | {
|
|
501 | 501 | },
|
502 | 502 | "outputs": [],
|
503 | 503 | "source": [
|
504 |
| - "viewerB.set_image_color_map(\"Grayscale\")\n", |
505 |
| - "viewerB.set_label_image_blend(0.5)\n", |
506 |
| - "viewerB.set_image_color_range([100,500])\n", |
507 |
| - "viewerB.set_view_mode('ZPlane')\n", |
508 |
| - "viewerB.set_ui_collapsed(False)" |
| 504 | + "viewer_b.set_image_color_map(\"Grayscale\")\n", |
| 505 | + "viewer_b.set_label_image_blend(0.5)\n", |
| 506 | + "viewer_b.set_image_color_range([100, 500])\n", |
| 507 | + "viewer_b.set_view_mode('ZPlane')\n", |
| 508 | + "viewer_b.set_ui_collapsed(False)" |
509 | 509 | ]
|
510 | 510 | },
|
511 | 511 | {
|
|
528 | 528 | "# 1 = ideal prostate, but model called non-prostate (red)\n",
|
529 | 529 | "# 2 = model called prostate, but ideal called non-prostate (purple)\n",
|
530 | 530 | "# 3 = modeal and ideal agreed (green)\n",
|
531 |
| - "compare_model_expert = np.where(result_array!=1,0,2) + np.where(expert_array!=2,0,1)\n", |
| 531 | + "compare_model_expert = np.where(result_array != 1, 0, 2) + np.where(expert_array != 2, 0, 1)\n", |
532 | 532 | "compare_image = itk.GetImageFromArray(compare_model_expert.astype(np.float32))\n",
|
533 | 533 | "compare_image.CopyInformation(seg_image_prep)\n",
|
534 | 534 | "\n",
|
535 |
| - "viewerC = view(image=mr_image_prep, label_image=compare_image)" |
| 535 | + "viewer_c = view(image=mr_image_prep, label_image=compare_image)" |
536 | 536 | ]
|
537 | 537 | },
|
538 | 538 | {
|
|
544 | 544 | "outputs": [],
|
545 | 545 | "source": [
|
546 | 546 | "# Switch to an interactive slice view so that labels are more easily seen.\n",
|
547 |
| - "viewerC.set_label_image_blend(0.6)\n", |
548 |
| - "viewerC.set_image_color_map(\"Grayscale\")\n", |
549 |
| - "viewerC.set_view_mode(\"ZPlane\")\n", |
550 |
| - "viewerC.set_image_color_range([100,500])\n", |
551 |
| - "viewerC.set_ui_collapsed(False)" |
| 547 | + "viewer_c.set_label_image_blend(0.6)\n", |
| 548 | + "viewer_c.set_image_color_map(\"Grayscale\")\n", |
| 549 | + "viewer_c.set_view_mode(\"ZPlane\")\n", |
| 550 | + "viewer_c.set_image_color_range([100, 500])\n", |
| 551 | + "viewer_c.set_ui_collapsed(False)" |
552 | 552 | ]
|
553 | 553 | },
|
554 | 554 | {
|
|
590 | 590 | "provenance": []
|
591 | 591 | },
|
592 | 592 | "kernelspec": {
|
593 |
| - "display_name": "medical-image-ai:Python", |
| 593 | + "display_name": "Python 3 (ipykernel)", |
594 | 594 | "language": "python",
|
595 |
| - "name": "conda-env-medical-image-ai-py" |
| 595 | + "name": "python3" |
596 | 596 | },
|
597 | 597 | "language_info": {
|
598 | 598 | "codemirror_mode": {
|
|
604 | 604 | "name": "python",
|
605 | 605 | "nbconvert_exporter": "python",
|
606 | 606 | "pygments_lexer": "ipython3",
|
607 |
| - "version": "3.9.15" |
| 607 | + "version": "3.8.13" |
608 | 608 | }
|
609 | 609 | },
|
610 | 610 | "nbformat": 4,
|
|
0 commit comments