{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Install itk-spcn and itkwidgets, if necessary\n", "import sys\n", "necessary = False\n", "if necessary:\n", " !{sys.executable} -m pip install itk-spcn\n", " !{sys.executable} -m pip install itkwidgets" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Import needed packages\n", "from urllib.request import urlretrieve\n", "import os\n", "\n", "# Import itk, which includes itk-spcn.\n", "import itk\n", "from itkwidgets import view" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Fetch input images, if we don have them already.\n", "input_image_filename = 'Easy1.png'\n", "input_image_url = 'https://data.kitware.com/api/v1/file/576ad39b8d777f1ecd6702f2/download'\n", "if not os.path.exists(input_image_filename):\n", " urlretrieve(input_image_url, input_image_filename)\n", "\n", "reference_image_filename = 'Hard.png'\n", "reference_image_url = 'https://data.kitware.com/api/v1/file/57718cc48d777f1ecd8a883f/download'\n", "if not os.path.exists(reference_image_filename):\n", " urlretrieve(reference_image_url, reference_image_filename)\n", " \n", "output_image_filename = 'HardWithEasy1Colors.png'\n", "\n", "# The pixels are RGB triplets of unsigned char. The images are 2 dimensional.\n", "PixelType = itk.RGBPixel[itk.UC]\n", "ImageType = itk.Image[PixelType, 2]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Invoke the functional, eager interface for ITK\n", "input_image = itk.imread(input_image_filename, PixelType)\n", "reference_image = itk.imread(reference_image_filename, PixelType)\n", "eager_normalized_image = itk.structure_preserving_color_normalization_filter(\n", " input_image,\n", " reference_image,\n", " color_index_suppressed_by_hematoxylin=0,\n", " color_index_suppressed_by_eosin=1)\n", "itk.imwrite(eager_normalized_image, output_image_filename)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3f03f6a7e49440668e975aa026027775", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Viewer(geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=