From 463810366d9f2c5023a8f01cdfc5e298e5bf255c Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 23 Aug 2024 17:29:37 -0400 Subject: [PATCH] DOC: Add simple ITK-Wasm DICOM SEG example --- examples/integrations/itkwasm/.gitignore | 1 + examples/integrations/itkwasm/DICOM_SEG.ipynb | 244 ++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 examples/integrations/itkwasm/.gitignore create mode 100644 examples/integrations/itkwasm/DICOM_SEG.ipynb diff --git a/examples/integrations/itkwasm/.gitignore b/examples/integrations/itkwasm/.gitignore new file mode 100644 index 00000000..b8c4a834 --- /dev/null +++ b/examples/integrations/itkwasm/.gitignore @@ -0,0 +1 @@ +nsclc_radiogenomics \ No newline at end of file diff --git a/examples/integrations/itkwasm/DICOM_SEG.ipynb b/examples/integrations/itkwasm/DICOM_SEG.ipynb new file mode 100644 index 00000000..12187b8a --- /dev/null +++ b/examples/integrations/itkwasm/DICOM_SEG.ipynb @@ -0,0 +1,244 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "7d6a1a99-7979-41e5-9a3d-4c94918da61b", + "metadata": { + "id": "7d6a1a99-7979-41e5-9a3d-4c94918da61b" + }, + "source": [ + "# DICOM SEG\n", + "\n", + "This example demonstrates how to read DICOM CT volumes with and DICOM SEG, AI-generated segmentations, with [ITK-Wasm](https://wasm.itk.org). Data is pulled from the [NIH Imaging Data Commons (IDC)](https://portal.imaging.datacommons.cancer.go).\n", + "\n", + "You can run this notebook locally or with any of the following platforms: \n", + "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/InsightSoftwareConsortium/itkwidgets/blob/main/examples/integrations/itkwasm/DICOM_SEG.ipynb)\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/HEAD?labpath=examples%2Fintegrations%2Fitkwasm%2FDICOM_SEG.ipynb)\n", + "[![Open In SageMaker Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github.com/InsightSoftwareConsortium/itkwidgets/blob/main/examples/integrations/itkwasm/DICOM_SEG.ipynb)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c98ddf17-b608-448c-9253-cd7b806b96db", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "c98ddf17-b608-448c-9253-cd7b806b96db", + "outputId": "f0c84ed1-a871-42e5-bc6f-eec881e469a9", + "tags": [] + }, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "!{sys.executable} -m pip install -q \"itkwidgets[all]>=1.0a51\" idc-index itkwasm-dicom" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4120f9bf-e7f3-48a1-ab14-ce57b4d95621", + "metadata": { + "id": "4120f9bf-e7f3-48a1-ab14-ce57b4d95621", + "tags": [] + }, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "import glob\n", + "from itkwidgets import view\n", + "from itkwasm_dicom import read_segmentation, read_image_dicom_file_series" + ] + }, + { + "cell_type": "markdown", + "id": "fb85dba6-d7e3-4996-9f1d-7598b184ae50", + "metadata": { + "id": "fb85dba6-d7e3-4996-9f1d-7598b184ae50" + }, + "source": [ + "## Segmentation of lung cancer from CT series" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "aOnyE_7hllIl", + "metadata": { + "id": "aOnyE_7hllIl", + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2024-10-09 16:07:31,183 - Downloading from IDC v19 index\n", + "2024-10-09 16:07:31,362 - Identified matching SeriesInstanceUID: ['1.3.6.1.4.1.14519.5.2.1.4334.1501.193624308604131216732637940838']\n", + "2024-10-09 16:07:31,377 - Total free space on disk: 71.193706496 GB\n", + "2024-10-09 16:07:31,416 - Not using s5cmd sync as the destination folder is empty or sync or progress bar is not requested\n", + "2024-10-09 16:07:31,416 - Initial size of the directory: 0 bytes\n", + "2024-10-09 16:07:31,417 - Approximate size of the files that need to be downloaded: 138.68 MB\n", + "Downloading data: 100%|█████████████████████▉| 139M/139M [00:07<00:00, 18.2MB/s]\n", + "2024-10-09 16:07:39,025 - Successfully downloaded files to /home/paul/src/itkwidgets-stuff/itkwidgets/examples/integrations/itkwasm\n", + "2024-10-09 16:07:42,849 - Downloading from IDC v19 index\n", + "2024-10-09 16:07:43,019 - Identified matching SeriesInstanceUID: ['1.2.276.0.7230010.3.1.3.17436516.2700181.1720647744.757708']\n", + "2024-10-09 16:07:43,035 - Total free space on disk: 71.054655488 GB\n", + "2024-10-09 16:07:43,075 - Not using s5cmd sync as the destination folder is empty or sync or progress bar is not requested\n", + "2024-10-09 16:07:43,075 - Initial size of the directory: 0 bytes\n", + "2024-10-09 16:07:43,075 - Approximate size of the files that need to be downloaded: 0.41 bytes\n", + "Downloading data: 99%|█████████████████████▊| 406k/410k [00:06<00:00, 67.4kB/s]\n", + "2024-10-09 16:07:49,091 - Successfully downloaded files to /home/paul/src/itkwidgets-stuff/itkwidgets/examples/integrations/itkwasm\n" + ] + } + ], + "source": [ + "# CT series downloaded from TCIA / IDC, NSCLC Radiogenomics collection, https://www.cancerimagingarchive.net/collection/nsclc-radiogenomics/#citations\n", + "# Bakr, S., Gevaert, O., Echegaray, S., Ayers, K., Zhou, M., Shafiq, M., Zheng, H., Zhang, W., Leung, A., Kadoch, M., Shrager, J., Quon, A., Rubin, D., Plevritis, S., & Napel, S. (2017). Data for NSCLC Radiogenomics (Version 4) [Data set]. The Cancer Imaging Archive. https://doi.org/10.7937/K9/TCIA.2017.7hs46erv\n", + "!idc download 1.3.6.1.4.1.14519.5.2.1.4334.1501.193624308604131216732637940838\n", + "# Segmentation of this series downloaded from TCIA, IDC, BAMF under the AIMI Annotations initiative (https://zenodo.org/doi/10.5281/zenodo.8345959)\n", + "!idc download 1.2.276.0.7230010.3.1.3.17436516.2700181.1720647744.757708" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a6472390-89a1-4235-8d79-f5d05b749867", + "metadata": {}, + "outputs": [], + "source": [ + "ct_image_files = glob.glob('./nsclc_radiogenomics/AMC-010/1.3.6.1.4.1.14519.5.2.1.4334.1501.116565501097532779730890753589/CT_1.3.6.1.4.1.14519.5.2.1.4334.1501.193624308604131216732637940838/*')\n", + "ct_image, sorted_file_names = read_image_dicom_file_series(ct_image_files)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "0e588f46-01b4-4ae4-886b-63742d59984d", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Row direction: 1 0 0\n", + "Col direction: 0 1 0\n", + "Z direction: 0 0 1\n", + "Total frames: 76\n", + "Total frames with unique IPP: 76\n", + "Total overlapping frames: 0\n", + "Origin: [-348.177, -348.177, -454.93]\n", + "Slice extent: 245.25\n", + "Slice spacing: 3.26999\n", + "Image Orientation Patient set to : 1, 0, 0, 0, 1, 0\n", + "Identified 1 groups of non-overlapping segments\n" + ] + } + ], + "source": [ + "seg_file_name = './nsclc_radiogenomics/AMC-010/1.3.6.1.4.1.14519.5.2.1.4334.1501.116565501097532779730890753589/SEG_1.2.276.0.7230010.3.1.3.17436516.2700181.1720647744.757708/1e7767a6-46f6-4685-a248-ac0eec8a0b98.dcm'\n", + "seg_image, seg_info = read_segmentation(seg_file_name)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "264e1ce0-dd11-4197-a033-574d601cab50", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 567 + }, + "id": "264e1ce0-dd11-4197-a033-574d601cab50", + "outputId": "0dd9122e-599b-47ac-83ec-e2af41f1657e", + "tags": [] + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": [ + "window.connectPlugin && window.connectPlugin(\"1d0f8fe5-243c-4d72-a03e-fa937875270c\")" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "segthor_viewer = view(ct_image, label_image=seg_image)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41b3e608-70f9-4d87-a7ed-eb1ef7897cee", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}