From 806e6e821179bc80c1a72eb21c936dc626616e5e Mon Sep 17 00:00:00 2001 From: Brianna Major Date: Thu, 7 Dec 2023 10:32:25 -0500 Subject: [PATCH] TEST: Exclude failing cells from notebook tests for now Improved testing is a current work in progress (as discussed in issue #587). Until we resolve the outstanding issues no viewer is actually being created, so the queue that waits for cell completion before progressing causes all subsequent cells after the first viewer is created to fail. This temporarily ignores those cells in the CI tests. These changes should be removed after testing is fixed. --- .github/workflows/notebook-test.yml | 2 +- examples/Hello3DWorld.ipynb | 25 +- examples/NumPyArrayPointSet.ipynb | 4 +- .../MONAI/transform_visualization.ipynb | 2 +- .../integrations/PyImageJ/ImageJImgLib2.ipynb | 8 +- examples/integrations/dask/DaskArray.ipynb | 18 +- .../itk/IDC_Seg_Primer_Examples.ipynb | 14 +- .../itk/MulticomponentNumPy.ipynb | 8 +- .../integrations/itk/ThinPlateSpline.ipynb | 798 +++++++++--------- examples/integrations/itkwasm/3DImage.ipynb | 2 +- examples/integrations/xarray/DataArray.ipynb | 6 +- 11 files changed, 443 insertions(+), 444 deletions(-) diff --git a/.github/workflows/notebook-test.yml b/.github/workflows/notebook-test.yml index 986e5623..833f7808 100644 --- a/.github/workflows/notebook-test.yml +++ b/.github/workflows/notebook-test.yml @@ -34,4 +34,4 @@ jobs: - name: Test notebooks run: | - pytest --nbmake --nbmake-timeout=3000 examples/*.ipynb examples/integrations/**/*.ipynb + pytest --nbmake --nbmake-timeout=3000 examples/EnvironmentCheck.ipynb examples/Hello3DWorld.ipynb examples/NumPyArrayPointSet.ipynb examples/integrations/**/*.ipynb diff --git a/examples/Hello3DWorld.ipynb b/examples/Hello3DWorld.ipynb index de110481..c6fea030 100644 --- a/examples/Hello3DWorld.ipynb +++ b/examples/Hello3DWorld.ipynb @@ -119,9 +119,9 @@ }, { "cell_type": "code", - "execution_count": 5, - "id": "79deafd4-a8bf-4332-bda1-6dacf37e1ec9", - "metadata": {}, + "execution_count": null, + "id": "842e3626-658f-4a00-b4c9-59e3c79c77ba", + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "annotations = viewer.get_annotations_enabled()" @@ -129,21 +129,10 @@ }, { "cell_type": "code", - "execution_count": 6, - "id": "2f677bbb-91b1-4bf1-b4bf-1911ad1df326", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "id": "6b15413a-9bc1-42af-8fb0-7b583b0dc792", + "metadata": { "tags": ["skip-execution"] }, + "outputs": [], "source": [ "annotations" ] diff --git a/examples/NumPyArrayPointSet.ipynb b/examples/NumPyArrayPointSet.ipynb index 4765e40d..bc07061e 100644 --- a/examples/NumPyArrayPointSet.ipynb +++ b/examples/NumPyArrayPointSet.ipynb @@ -108,7 +108,7 @@ "cell_type": "code", "execution_count": 5, "id": "83dfad1a-7199-4647-81da-57ce7cb1088e", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "number_of_points_2 = 3000\n", @@ -121,7 +121,7 @@ "cell_type": "code", "execution_count": 6, "id": "5eac65f8-e50f-4ba6-bd27-4386739ca805", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "viewer.add_point_set(point_set_2)" diff --git a/examples/integrations/MONAI/transform_visualization.ipynb b/examples/integrations/MONAI/transform_visualization.ipynb index 65e6fe4e..f485c70a 100644 --- a/examples/integrations/MONAI/transform_visualization.ipynb +++ b/examples/integrations/MONAI/transform_visualization.ipynb @@ -271,7 +271,7 @@ "cell_type": "code", "execution_count": null, "id": "278dc2c6-9fcf-4d83-9894-4401e7348d34", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [] } diff --git a/examples/integrations/PyImageJ/ImageJImgLib2.ipynb b/examples/integrations/PyImageJ/ImageJImgLib2.ipynb index a1e14139..5bc5603e 100644 --- a/examples/integrations/PyImageJ/ImageJImgLib2.ipynb +++ b/examples/integrations/PyImageJ/ImageJImgLib2.ipynb @@ -92,7 +92,7 @@ "cell_type": "code", "execution_count": null, "id": "48b151f6-cfc4-4522-aa02-04c8301d3667", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "print(type(image))\n", @@ -108,7 +108,7 @@ "cell_type": "code", "execution_count": null, "id": "b4db443d-f430-484b-a738-11b493944d8e", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "# Invoke the Frangi vesselness op.\n", @@ -123,7 +123,7 @@ "cell_type": "code", "execution_count": null, "id": "1afc55a1-35d3-475d-83fa-9ec04fb6fa28", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "view(vessels)" @@ -133,7 +133,7 @@ "cell_type": "code", "execution_count": null, "id": "cbc436a7-5928-4017-b5d4-07f3ca21f3a0", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [] } diff --git a/examples/integrations/dask/DaskArray.ipynb b/examples/integrations/dask/DaskArray.ipynb index 45d5c7ca..fc02c524 100644 --- a/examples/integrations/dask/DaskArray.ipynb +++ b/examples/integrations/dask/DaskArray.ipynb @@ -143,7 +143,11 @@ "cell_type": "code", "execution_count": 5, "id": "d1792a9c-5120-4627-b7cb-ddf98f0451dd", - "metadata": {}, + "metadata": { + "tags": [ + "skip-execution" + ] + }, "outputs": [ { "data": { @@ -284,7 +288,11 @@ "cell_type": "code", "execution_count": 6, "id": "b37a638b-3c96-41fc-bc75-67ce22cfdcf4", - "metadata": {}, + "metadata": { + "tags": [ + "skip-execution" + ] + }, "outputs": [ { "data": { @@ -350,7 +358,11 @@ "cell_type": "code", "execution_count": null, "id": "6f20fc74-bd0d-4355-9f61-fe892a8a54cf", - "metadata": {}, + "metadata": { + "tags": [ + "skip-execution" + ] + }, "outputs": [], "source": [] } diff --git a/examples/integrations/itk/IDC_Seg_Primer_Examples.ipynb b/examples/integrations/itk/IDC_Seg_Primer_Examples.ipynb index fa1ee6b4..84089437 100644 --- a/examples/integrations/itk/IDC_Seg_Primer_Examples.ipynb +++ b/examples/integrations/itk/IDC_Seg_Primer_Examples.ipynb @@ -288,9 +288,7 @@ "cell_type": "code", "execution_count": 9, "id": "de4dfee3-1f5e-41d4-a599-02d1d9cbdf0e", - "metadata": { - "tags": [] - }, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "segthor_viewer.set_image_color_range([-1260, 2385])\n", @@ -321,9 +319,7 @@ "cell_type": "code", "execution_count": 10, "id": "03988ee1-90eb-4e75-99af-2c56d932fad9", - "metadata": { - "tags": [] - }, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [ "head_image_file = pooch.retrieve('https://data.kitware.com/api/v1/file/61b61cd74acac99f42a7ec84/download',\n", @@ -336,9 +332,7 @@ "cell_type": "code", "execution_count": 11, "id": "091d4d0e-fdc5-4034-b6a5-a4d7350b98d5", - "metadata": { - "tags": [] - }, + "metadata": { "tags": ["skip-execution"] }, "outputs": [ { "data": { @@ -394,7 +388,7 @@ "cell_type": "code", "execution_count": null, "id": "0f4633af-fd01-4ab5-8202-3fb642276040", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [] } diff --git a/examples/integrations/itk/MulticomponentNumPy.ipynb b/examples/integrations/itk/MulticomponentNumPy.ipynb index 33897be5..495d7510 100644 --- a/examples/integrations/itk/MulticomponentNumPy.ipynb +++ b/examples/integrations/itk/MulticomponentNumPy.ipynb @@ -147,7 +147,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [ { "name": "stdout", @@ -174,7 +174,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [ { "name": "stdout", @@ -194,7 +194,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [ { "data": { @@ -259,7 +259,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [] } diff --git a/examples/integrations/itk/ThinPlateSpline.ipynb b/examples/integrations/itk/ThinPlateSpline.ipynb index 71965937..8175f983 100644 --- a/examples/integrations/itk/ThinPlateSpline.ipynb +++ b/examples/integrations/itk/ThinPlateSpline.ipynb @@ -1,397 +1,401 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "e301a0a8-f895-41e9-a4f8-dc89537d4b56", - "metadata": {}, - "source": [ - "### Try this notebook in Google Colab, Binder or SageMaker!\n", - "\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/itk/ThinPlateSpline.ipynb)\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/HEAD?labpath=examples%2Fintegrations%2Fitk%2FThinPlateSpline.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/itk/ThinPlateSpline.ipynb)" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "d3191936-191e-4d8d-b797-4b5376f7caa9", - "metadata": {}, - "outputs": [], - "source": [ - "import sys, os\n", - "\n", - "!{sys.executable} -m pip install -q tqdm pooch \"itk>=5.3.0\" \"itkwidgets[all]>=1.0a29\"" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "67df7916-4a81-4880-b575-f65dfab17bd5", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "0.1.43ubuntu1 is an invalid version and will not be supported in a future release\n", - "1.1build1 is an invalid version and will not be supported in a future release\n", - "1.12.1-git20200711.33e2d80-dfsg1-0.6 is an invalid version and will not be supported in a future release\n" - ] - } - ], - "source": [ - "import itk\n", - "import pooch\n", - "import numpy as np\n", - "from itkwidgets import view, compare_images" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "dca03164-73f6-41fb-abd2-bb9b76f2fa74", - "metadata": {}, - "outputs": [], - "source": [ - "# Download data\n", - "files = pooch.retrieve(\n", - " url='https://bafybeidii6e4zhuswkhw7tm3dalmfw5yt4mja5yf3gb7t4jur3rdgdecve.ipfs.w3s.link/ipfs/bafybeidii6e4zhuswkhw7tm3dalmfw5yt4mja5yf3gb7t4jur3rdgdecve/DeformAVolumeWithAThinPlateSpline.zip',\n", - " known_hash='sha256:d267f9216d11c3f953b3a2601f38d1434ab97c17834dca0ad1b3ff558226c9c1',\n", - " processor=pooch.Unzip(), path=\"./\", fname=\"ThinPlateSpline\", progressbar=True)\n", - "file_path = os.path.commonpath(files)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "53b5b965-497e-46b7-8c14-d157ff5fed4f", - "metadata": {}, - "outputs": [], - "source": [ - "source_landmarks = os.path.join(file_path, \"SourceLandmarks.vtk\")\n", - "target_landmarks = os.path.join(file_path, \"TargetLandmarks.vtk\")\n", - "input_image = os.path.join(file_path, \"brainweb165a10f17.mha\")" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "2b3e6002-73f1-4971-8d43-b4a20681635b", - "metadata": {}, - "outputs": [], - "source": [ - "Dimension = 3\n", - "thin_plate_spline = itk.ThinPlateSplineKernelTransform[itk.D, Dimension].New()" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "f9bcdbb3-6140-4a0e-b654-446438761356", - "metadata": {}, - "outputs": [], - "source": [ - "source_landmarks_mesh = itk.meshread(source_landmarks)\n", - "# Cast points from float32 to float64\n", - "points = itk.array_from_vector_container(source_landmarks_mesh.GetPoints())\n", - "points = points.astype(np.float64)\n", - "source_landmarks = thin_plate_spline.GetSourceLandmarks()\n", - "source_landmarks.SetPoints(itk.vector_container_from_array(points.flatten()))" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "43d2f0b2-8268-424c-83c2-cc932e3ea598", - "metadata": {}, - "outputs": [], - "source": [ - "target_landmarks_mesh = itk.meshread(target_landmarks)\n", - "# Cast points from float32 to float64\n", - "points = itk.array_from_vector_container(target_landmarks_mesh.GetPoints())\n", - "points = points.astype(np.float64)\n", - "target_landmarks = thin_plate_spline.GetTargetLandmarks()\n", - "target_landmarks.SetPoints(itk.vector_container_from_array(points.flatten()))" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "717e7802-99a8-4b18-8335-6f753153286a", - "metadata": {}, - "outputs": [], - "source": [ - "thin_plate_spline.ComputeWMatrix()\n", - "\n", - "input_image = itk.imread(input_image)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "290df31a-3397-40da-9449-fea1b2b0da40", - "metadata": {}, - "outputs": [], - "source": [ - "deformed = itk.resample_image_filter(\n", - " input_image,\n", - " use_reference_image=True,\n", - " reference_image=input_image,\n", - " transform=thin_plate_spline,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "5c4666c9", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "window.connectPlugin && window.connectPlugin(\"59b59642-a9fa-4b5b-987b-dbb723b5de64\")" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "compare_images(fixed_image=input_image, moving_image=deformed, method='checkerboard', pattern=(5, 5, 2), swap_image_order=False)" - ] - }, - { - "cell_type": "markdown", - "id": "c24dc51f", - "metadata": {}, - "source": [ - "Besides `checkerboard`, method can be `green-magenta`, `cyan-red`, `cyan-magenta` or `blend`. If the method is `green-magenta` or `cyan-red`, matching images would be grayish white." - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "4389eba3", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "window.connectPlugin && window.connectPlugin(\"59b59642-a9fa-4b5b-987b-dbb723b5de64\")" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "compare_images(input_image, deformed, method='cyan-red')" - ] - }, - { - "cell_type": "markdown", - "id": "6d4bcac0", - "metadata": {}, - "source": [ - "If the viewer already has loaded images, you can give the image names to `compare_images`. The moving image must be the last added image. " - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "089c6db1", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "application/javascript": [ - "window.connectPlugin && window.connectPlugin(\"59b59642-a9fa-4b5b-987b-dbb723b5de64\")" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "viewer = view(image=input_image)\n", - "viewer.set_image(deformed, 'deformed')\n", - "viewer.compare_images('Image', 'deformed', image_mix=.4)" - ] - }, - { - "cell_type": "markdown", - "id": "38133552", - "metadata": {}, - "source": [ - "Stop comparing image by setting `method='disabled'` or use hamburger menu next to image name in graphical user interface." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cc71d7ce", - "metadata": {}, - "outputs": [], - "source": [ - "# viewer.compare_images(fixed_image='Image', moving_image='deformed', method='disabled')" - ] - } - ], - "metadata": { - "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.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e301a0a8-f895-41e9-a4f8-dc89537d4b56", + "metadata": {}, + "source": [ + "### Try this notebook in Google Colab, Binder or SageMaker!\n", + "\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/itk/ThinPlateSpline.ipynb)\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/InsightSoftwareConsortium/itkwidgets/HEAD?labpath=examples%2Fintegrations%2Fitk%2FThinPlateSpline.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/itk/ThinPlateSpline.ipynb)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d3191936-191e-4d8d-b797-4b5376f7caa9", + "metadata": {}, + "outputs": [], + "source": [ + "import sys, os\n", + "\n", + "!{sys.executable} -m pip install -q tqdm pooch \"itk>=5.3.0\" \"itkwidgets[all]>=1.0a29\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "67df7916-4a81-4880-b575-f65dfab17bd5", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "0.1.43ubuntu1 is an invalid version and will not be supported in a future release\n", + "1.1build1 is an invalid version and will not be supported in a future release\n", + "1.12.1-git20200711.33e2d80-dfsg1-0.6 is an invalid version and will not be supported in a future release\n" + ] + } + ], + "source": [ + "import itk\n", + "import pooch\n", + "import numpy as np\n", + "from itkwidgets import view, compare_images" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "dca03164-73f6-41fb-abd2-bb9b76f2fa74", + "metadata": {}, + "outputs": [], + "source": [ + "# Download data\n", + "files = pooch.retrieve(\n", + " url='https://bafybeidii6e4zhuswkhw7tm3dalmfw5yt4mja5yf3gb7t4jur3rdgdecve.ipfs.w3s.link/ipfs/bafybeidii6e4zhuswkhw7tm3dalmfw5yt4mja5yf3gb7t4jur3rdgdecve/DeformAVolumeWithAThinPlateSpline.zip',\n", + " known_hash='sha256:d267f9216d11c3f953b3a2601f38d1434ab97c17834dca0ad1b3ff558226c9c1',\n", + " processor=pooch.Unzip(), path=\"./\", fname=\"ThinPlateSpline\", progressbar=True)\n", + "file_path = os.path.commonpath(files)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "53b5b965-497e-46b7-8c14-d157ff5fed4f", + "metadata": {}, + "outputs": [], + "source": [ + "source_landmarks = os.path.join(file_path, \"SourceLandmarks.vtk\")\n", + "target_landmarks = os.path.join(file_path, \"TargetLandmarks.vtk\")\n", + "input_image = os.path.join(file_path, \"brainweb165a10f17.mha\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "2b3e6002-73f1-4971-8d43-b4a20681635b", + "metadata": {}, + "outputs": [], + "source": [ + "Dimension = 3\n", + "thin_plate_spline = itk.ThinPlateSplineKernelTransform[itk.D, Dimension].New()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "f9bcdbb3-6140-4a0e-b654-446438761356", + "metadata": {}, + "outputs": [], + "source": [ + "source_landmarks_mesh = itk.meshread(source_landmarks)\n", + "# Cast points from float32 to float64\n", + "points = itk.array_from_vector_container(source_landmarks_mesh.GetPoints())\n", + "points = points.astype(np.float64)\n", + "source_landmarks = thin_plate_spline.GetSourceLandmarks()\n", + "source_landmarks.SetPoints(itk.vector_container_from_array(points.flatten()))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "43d2f0b2-8268-424c-83c2-cc932e3ea598", + "metadata": {}, + "outputs": [], + "source": [ + "target_landmarks_mesh = itk.meshread(target_landmarks)\n", + "# Cast points from float32 to float64\n", + "points = itk.array_from_vector_container(target_landmarks_mesh.GetPoints())\n", + "points = points.astype(np.float64)\n", + "target_landmarks = thin_plate_spline.GetTargetLandmarks()\n", + "target_landmarks.SetPoints(itk.vector_container_from_array(points.flatten()))" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "717e7802-99a8-4b18-8335-6f753153286a", + "metadata": {}, + "outputs": [], + "source": [ + "thin_plate_spline.ComputeWMatrix()\n", + "\n", + "input_image = itk.imread(input_image)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "290df31a-3397-40da-9449-fea1b2b0da40", + "metadata": {}, + "outputs": [], + "source": [ + "deformed = itk.resample_image_filter(\n", + " input_image,\n", + " use_reference_image=True,\n", + " reference_image=input_image,\n", + " transform=thin_plate_spline,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "5c4666c9", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": "window.connectPlugin && window.connectPlugin(\"59b59642-a9fa-4b5b-987b-dbb723b5de64\")", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "compare_images(fixed_image=input_image, moving_image=deformed, method='checkerboard', pattern=(5, 5, 2), swap_image_order=False)" + ] + }, + { + "cell_type": "markdown", + "id": "c24dc51f", + "metadata": {}, + "source": [ + "Besides `checkerboard`, method can be `green-magenta`, `cyan-red`, `cyan-magenta` or `blend`. If the method is `green-magenta` or `cyan-red`, matching images would be grayish white." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "4389eba3", + "metadata": { + "scrolled": false, + "tags": ["skip-execution"] + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": "window.connectPlugin && window.connectPlugin(\"59b59642-a9fa-4b5b-987b-dbb723b5de64\")", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "compare_images(input_image, deformed, method='cyan-red')" + ] + }, + { + "cell_type": "markdown", + "id": "6d4bcac0", + "metadata": {}, + "source": [ + "If the viewer already has loaded images, you can give the image names to `compare_images`. The moving image must be the last added image. " + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "089c6db1", + "metadata": { + "scrolled": false, + "tags": ["skip-execution"] + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/javascript": "window.connectPlugin && window.connectPlugin(\"59b59642-a9fa-4b5b-987b-dbb723b5de64\")", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "viewer = view(image=input_image)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { "tags": ["skip-execution"] }, + "outputs": [], + "source": [ + "viewer.set_image(deformed, 'deformed')\n", + "viewer.compare_images('Image', 'deformed', image_mix=.4)" + ] + }, + { + "cell_type": "markdown", + "id": "38133552", + "metadata": {}, + "source": [ + "Stop comparing image by setting `method='disabled'` or use hamburger menu next to image name in graphical user interface." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc71d7ce", + "metadata": { "tags": ["skip-execution"] }, + "outputs": [], + "source": [ + "# viewer.compare_images(fixed_image='Image', moving_image='deformed', method='disabled')" + ] + } + ], + "metadata": { + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/integrations/itkwasm/3DImage.ipynb b/examples/integrations/itkwasm/3DImage.ipynb index 62be164d..be23ae61 100644 --- a/examples/integrations/itkwasm/3DImage.ipynb +++ b/examples/integrations/itkwasm/3DImage.ipynb @@ -125,7 +125,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [ { "data": { diff --git a/examples/integrations/xarray/DataArray.ipynb b/examples/integrations/xarray/DataArray.ipynb index be2d6f3e..19fed9d7 100644 --- a/examples/integrations/xarray/DataArray.ipynb +++ b/examples/integrations/xarray/DataArray.ipynb @@ -605,7 +605,7 @@ "cell_type": "code", "execution_count": 5, "id": "a8e4938c-e769-4f8e-97de-42dbb39caa1e", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [ { "data": { @@ -1109,7 +1109,7 @@ "cell_type": "code", "execution_count": 6, "id": "7b584e3a-6630-4f74-9f89-a95ba1b3af79", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [ { "data": { @@ -1189,7 +1189,7 @@ "cell_type": "code", "execution_count": null, "id": "40201a35-4dc6-40de-8af4-c227d7afa9dd", - "metadata": {}, + "metadata": { "tags": ["skip-execution"] }, "outputs": [], "source": [] }