{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Define Content of Interest with Image Masks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Often, some content in the images may not correspond. For example, there may be background content or noisy areas. A mask defined on the fixed and/or moving image can be used to exclude these regions at a pixel level from the similarity metric computations. This improves the robustness of registration.\n", "\n", "For more information, see Section 5.4, \"Masks\" of the [Elastix Manual](http://elastix.isi.uu.nl/download/elastix-5.0.0-manual.pdf)." ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "import itk\n", "from itkwidgets import view, compare" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "# Lung SEM slices\n", "# Grothausmann, R., Knudsen, L., Ochs, M., and Mühlfeld, C.: Digital 3D reconstructions\n", "# using histological serial sections of lung tissue including the alveolar\n", "# capillary network. American Journal of Physiology - Lung Cellular and Molecular\n", "# Physiology 312(2), L243–L257 (2017). doi: 10.1152/ajplung.00326.2016\n", "fixed = itk.imread('data/lung_sem/2016_12_02_0101_s00_01.png', itk.F)\n", "moving = itk.imread('data/lung_sem/2016_12_02_0101_s00_02.png', itk.F)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are inconsistent dirt particles in each slice. Let's exclude these with a mask." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6a9cf64c1f8442ab938853ea5c0f0f70", "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": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3945015b073c4681a5ca64160bb79c4a", "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": [ "MaskImageType = itk.Image[itk.UC, 2]\n", "fixed_mask = itk.binary_threshold_image_filter(fixed,\n", " lower_threshold=80.0,\n", " inside_value=1,\n", " ttype=(type(fixed), MaskImageType))\n", "compare(fixed, fixed_mask)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c79ea51ca8854d44827a01af9f111a30", "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": [ "moving_mask = itk.binary_threshold_image_filter(moving,\n", " lower_threshold=80.0,\n", " inside_value=1,\n", " ttype=(type(moving), MaskImageType))\n", "compare(moving, moving_mask)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "parameters = itk.ParameterObject.New()\n", "parameters.ReadParameterFile('data/lung_sem/ParameterFile.txt')" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "registered = itk.elastix_registration_method(fixed, moving,\n", " parameter_object=parameters,\n", " fixed_mask=fixed_mask, moving_mask=moving_mask)" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "99959b78b0a340cd9572c22a5efaff79", "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, registered, ui_collapsed=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }