diff --git a/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb b/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb index 471281eec..cbff1e7ad 100644 --- a/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb +++ b/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/ConvertNumPyArrayToitkImage.ipynb @@ -1,8 +1,18 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "d1bdfc3b", + "metadata": {}, + "source": [ + "# Bridging ITK image data with NumPy array\n", + "\n", + "This example illustrates interfacing ITK Image data with NumPy array." + ] + }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "25e89adb", "metadata": {}, "outputs": [], @@ -20,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "7cdd2254", "metadata": {}, "outputs": [], @@ -34,32 +44,10 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "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": "d16464423b044ccd94ccee34479657a0", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Viewer(geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=" - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "array = itk.GetArrayFromImage(itk_image, ttype=ImageType)\n", "print(f'Array size = {array.shape}')\n", @@ -119,18 +77,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "4efdcf7d", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Size = itkSize2 ([221, 257])\n" - ] - } - ], + "outputs": [], "source": [ "itk_image_convert = itk.GetImageFromArray(np.ascontiguousarray(array))\n", "region = itk_image_convert.GetLargestPossibleRegion()\n", diff --git a/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/Documentation.rst b/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/Documentation.rst index 2886ffafe..142becb2b 100644 --- a/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/Documentation.rst +++ b/src/Bridge/NumPy/ConvertNumPyArrayToitkImage/Documentation.rst @@ -1,25 +1,32 @@ :name: ConvertNumPyArrayToitkImage Interface ITK with NumPy Array -============================= +=============================== .. index:: single: Image - single: instantiate Synopsis -------- -This example illustrates interfacing ITK Image data with NumPy array. While doing this, there are two key issues to -to keep in mind. One, the order of indexes is different between ITK image data class and NumPy array. -Second, there are two ways to access ITK image data as a NumPy array. i) Get direct access to memory with the data called -"View" functions (array_view_from_image and image_view_from_array), or ii) Copy the data (array_from_image and image_from_array). -If the view functions are used, the data can't be modified. +This example illustrates interfacing ITK Image data with NumPy array. +While doing this, there are two key issues to keep in mind. One, the order of +indexes is different between ITK image data class and NumPy array. +Second, there are two ways to access ITK image data as a NumPy array. +i) Get direct access to memory with the data called"View" functions, or +ii) Copy the data using array_from_image function. If the view functions are used, +the data can't be modified. Results ------- +The size of the ITK image data read from the input file = itkSize2 ([221, 257]) -NA +The size of the NumPy array viewed from itk::Image = (257, 221) +The size of the NumPy array copied from itk::Image = (257, 221) +ITK image data size after convesion from NumPy = itkSize2 ([221, 257]) + +ITK image data pixel value at [2,1] = 6 +NumPy array pixel value at [2,1] = 8 Code diff --git a/src/Bridge/NumPy/index.rst b/src/Bridge/NumPy/index.rst new file mode 100644 index 000000000..2a74450f8 --- /dev/null +++ b/src/Bridge/NumPy/index.rst @@ -0,0 +1,7 @@ +NumPy +====== + +.. toctree:: + :maxdepth: 1 + +ConvertNumPyArrayToitkImage/Documentation.rst \ No newline at end of file diff --git a/src/Bridge/index.rst b/src/Bridge/index.rst index e0adec6f4..606409cef 100644 --- a/src/Bridge/index.rst +++ b/src/Bridge/index.rst @@ -5,3 +5,4 @@ Bridge :maxdepth: 2 VtkGlue/index.rst + NumPy/index.rst