diff --git a/examples/integrations/itkwasm/DICOM_SEG.ipynb b/examples/integrations/itkwasm/DICOM_SEG.ipynb new file mode 100644 index 00000000..6879bda1 --- /dev/null +++ b/examples/integrations/itkwasm/DICOM_SEG.ipynb @@ -0,0 +1,217 @@ +{ + "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": null, + "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.0a49\" rich s5cmd itkwasm-dicom" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "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\n", + "import numpy as np\n", + "from rich import print" + ] + }, + { + "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": 3, + "id": "aOnyE_7hllIl", + "metadata": { + "id": "aOnyE_7hllIl", + "tags": [] + }, + "outputs": [], + "source": [ + "%%capture\n", + "# 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", + "!s5cmd --no-sign-request --endpoint-url https://s3.amazonaws.com cp \"s3://idc-open-data/d3d3f9a5-c90a-4763-9a4b-089aab391438/*\" CT_DICOM_series\n", + "\n", + "# Segmentation of this series downloaded from TCIA, IDC, BAMF under the AIMI Annotations initiative (https://zenodo.org/doi/10.5281/zenodo.8345959)\n", + "!s5cmd --no-sign-request --endpoint-url https://s3.amazonaws.com cp \"s3://idc-open-data/410e0c21-29e1-45e2-9c6b-15ae592e571b/*\" SEG_DICOM_series" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "a6472390-89a1-4235-8d79-f5d05b749867", + "metadata": {}, + "outputs": [], + "source": [ + "ct_image_files = glob.glob('CT_DICOM_series/*')\n", + "ct_image, sorted_file_names = read_image_dicom_file_series(ct_image_files)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "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: 126\n", + "Total frames with unique IPP: 76\n", + "Total overlapping frames: 50\n", + "Origin: [-348.177, -348.177, -442.83]\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 = glob.glob('./SEG_DICOM_series/*.dcm')[0]\n", + "seg_image, seg_info = read_segmentation(seg_file_name)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "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(\"8ecc7da1-6131-48ba-a982-b34c65148188\")" + ], + "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)" + ] + } + ], + "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.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}