{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Working with NumPy Array Images" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import itk\n", "import numpy as np\n", "import imageio\n", "from itkwidgets import view, compare, checkerboard" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Images as NumPy arrays can be registered.\n", "\n", "Convert them to floating point arrays for registration." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.ndarray" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fixed = imageio.imread('data/CT_2D_head_fixed.mha')\n", "fixed = np.asarray(fixed).astype(np.float32)\n", "type(fixed)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.ndarray" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "moving = imageio.imread('data/CT_2D_head_moving.mha')\n", "moving = np.asarray(moving).astype(np.float32)\n", "type(moving)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "73d7960ef9194b41823abc916f85fad9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "AppLayout(children=(HBox(children=(Label(value='Link:'), Checkbox(value=False, description='cmap'), Checkbox(v…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compare(fixed, moving, ui_collapsed=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before registration, the moving image is not aligned with the fixed image." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6885b56476d74c1db2a58cedfe4da230", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Viewer(annotations=False, interpolation=False, rendered_image=