From 4151f1b5b0372acde1c529ed12f80421ed3bceb3 Mon Sep 17 00:00:00 2001 From: Andinet Enquobahrie Date: Fri, 20 May 2022 05:50:35 -0400 Subject: [PATCH] ENH: Update the notebook --- .../ConvertNumPyArrayToitkImage.ipynb | 74 ++++++++++++------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb b/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb index 017c9b60b..471281eec 100644 --- a/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb +++ b/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "id": "25e89adb", "metadata": {}, "outputs": [], @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "id": "7cdd2254", "metadata": {}, "outputs": [], @@ -34,19 +34,26 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 10, "id": "edf8512f", "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ITK image size = itkSize2 ([221, 257])\n" + ] + }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "190e62c3f558476fb9a1b0974ef324a7", + "model_id": "d16464423b044ccd94ccee34479657a0", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Viewer(geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=" ] @@ -88,7 +110,8 @@ } ], "source": [ - "array = itk.array_from_image(image)\n", + "array = itk.GetArrayFromImage(itk_image, ttype=ImageType)\n", + "print(f'Array size = {array.shape}')\n", "plt.gray()\n", "plt.imshow(array)\n", "plt.axis('off')" @@ -96,28 +119,23 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "id": "4efdcf7d", "metadata": {}, "outputs": [ { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "895794aa06334bde93c1ed191ca635ff", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Viewer(cmap=['Grayscale'], geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_…" - ] - }, - "metadata": {}, - "output_type": "display_data" + "name": "stdout", + "output_type": "stream", + "text": [ + "Size = itkSize2 ([221, 257])\n" + ] } ], "source": [ - "image = itk.image_from_array(array)\n", - "view(image, cmap='Grayscale', interpolation=False)" + "itk_image_convert = itk.GetImageFromArray(np.ascontiguousarray(array))\n", + "region = itk_image_convert.GetLargestPossibleRegion()\n", + "size = region.GetSize()\n", + "print(f'Size = {size}')" ] }, { @@ -131,9 +149,9 @@ ], "metadata": { "kernelspec": { - "display_name": "ITK env", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "itk-env" + "name": "python3" }, "language_info": { "codemirror_mode": {