Skip to main content

This performs structure preserving color normalization on an image using a reference image.

Project description

ITKColorNormalization

Apache 2.0 License DOI Build, test, package status

Overview

This Insight Toolkit (ITK) module performs Structure Preserving Color Normalization on an H & E image using a reference image. The module is in C++ and is also packaged for Python.

H & E (hematoxylin and eosin) are stains used to color parts of cells in a histological image, often for medical diagnosis. Hematoxylin is a compound that stains cell nuclei a purple-blue color. Eosin is a compound that stains extracellular matrix and cytoplasm pink. However, the exact color of purple-blue or pink can vary from image to image, and this can make comparison of images difficult. This routine addresses the issue by re-coloring one image (the first image supplied to the routine) using the color scheme of a reference image (the second image supplied to the routine). The technique requires that the images have at least 3 colors, such as red, green, and blue (RGB).

Structure Preserving Color Normalization is a technique described in Vahadane et al., 2016 and modified in Ramakrishnan et al., 2019. The idea is to model the color of an image pixel as something close to pure white, which is reduced in intensity in a color-specific way via an optical absorption model that depends upon the amounts of hematoxylin and eosin that are present. Non-negative matrix factorization is used on each analyzed image to simultaneously derive the amount of hematoxylin and eosin stain at each pixel and the image-wide effective colors of each stain.

The implementation in ITK accelerates the non-negative matrix factorization by choosing the initial estimate for the color absorption characteristics using a technique mimicking that presented in Arora et al., 2013 and modified in Newberg et al., 2018. This approach finds a good solution for a non-negative matrix factorization by first transforming it to the problem of finding a convex hull for a set of points in a cloud.

The lead developer of InsightSoftwareConsortium/ITKColorNormalization is Lee Newberg.

Try it online

We have set up a demonstration of this using Binder that anyone can try. Click here: Binder

Installation for Python

PyPI Version

ITKColorNormalization and all its dependencies can be easily installed with Python wheels. Wheels have been generated for macOS, Linux, and Windows and several versions of Python, 3.5, 3.6, 3.7, and 3.8. If you do not want the installation to be to your current Python environment, you should first create and activate a Python virtual environment (venv) to work in. Then, run the following from the command-line:

pip install itk-spcn

Launch python, import the itk package, and set variable names for the input images

import itk
input_image_filename = 'path/to/image_to_be_normalized'
reference_image_filename = 'path/to/image_to_be_used_as_color_reference'

Usage in Python

The following example transforms this input image

Input image to be normalized

using the color scheme of this reference image

Reference image for normalization

to produce this output image

Output of spcn_filter

Functional interface to ITK

You can use the functional, eager interface to ITK to choose when each step will be executed as follows. The input_image and reference_image are processed to produce normalized_image, which is the input_image with the color scheme of the reference_image. The color_index_suppressed_by_hematoxylin and color_index_suppressed_by_eosin arguments are optional if the input_image pixel type is RGB or RGBA. Here you are indicating that the color channel most suppressed by hematoxylin is 0 (which is red for RGB and RGBA pixels) and that the color most suppressed by eosin is 1 (which is green for RGB and RGBA pixels); these are the defaults for RGB and RGBA pixels.

input_image = itk.imread(input_image_filename)
reference_image = itk.imread(reference_image_filename)

eager_normalized_image = itk.structure_preserving_color_normalization_filter(
    input_image,
    reference_image,
    color_index_suppressed_by_hematoxylin=0,
    color_index_suppressed_by_eosin=1)

itk.imwrite(eager_normalized_image, output_image_filename)

ITK pipeline interface

Alternatively, you can use the ITK pipeline infrastructure that waits until a call to Update() or Write() before executing the pipeline. The function itk.StructurePreservingColorNormalizationFilter.New() uses its argument to determine the pixel type for the filter; the actual image is not used there but is supplied with the spcn_filter.SetInput(0, input_reader.GetOutput()) call. As above, the calls to SetColorIndexSuppressedByHematoxylin and SetColorIndexSuppressedByEosin are optional if the pixel type is RGB or RGBA.

input_reader = itk.ImageFileReader.New(FileName=input_image_filename)
reference_reader = itk.ImageFileReader.New(FileName=reference_image_filename)

spcn_filter = itk.StructurePreservingColorNormalizationFilter.New(Input=input_reader.GetOutput())
spcn_filter.SetColorIndexSuppressedByHematoxylin(0)
spcn_filter.SetColorIndexSuppressedByEosin(1)
spcn_filter.SetInput(0, input_reader.GetOutput())
spcn_filter.SetInput(1, reference_reader.GetOutput())

output_writer = itk.ImageFileWriter.New(spcn_filter.GetOutput())
output_writer.SetInput(spcn_filter.GetOutput())
output_writer.SetFileName(output_image_filename)
output_writer.Write()

Note that if spcn_filter is used again with a different input_image, for example from a different reader,

spcn_filter.SetInput(0, input_reader2.GetOutput())

but the reference_image is unchanged then the filter will use its cached analysis of the reference_image, which saves about half the processing time.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

itk_spcn-0.1.5-cp39-cp39-win_amd64.whl (369.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

itk_spcn-0.1.5-cp39-cp39-manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9

itk_spcn-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

itk_spcn-0.1.5-cp38-cp38-win_amd64.whl (370.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

itk_spcn-0.1.5-cp38-cp38-manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8

itk_spcn-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

itk_spcn-0.1.5-cp37-cp37m-win_amd64.whl (367.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

itk_spcn-0.1.5-cp37-cp37m-manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.7m

itk_spcn-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

itk_spcn-0.1.5-cp36-cp36m-win_amd64.whl (367.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

itk_spcn-0.1.5-cp36-cp36m-manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.6m

itk_spcn-0.1.5-cp36-cp36m-macosx_10_9_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

Details for the file itk_spcn-0.1.5-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 369.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5360ad5b94f4da82bca01f9bd16ed875b89966b4f395e68145396c60e5c044e3
MD5 0356b7040894fdfb0e2b43bfe09d90cf
BLAKE2b-256 cf86e8366f6aafc16c1db89dae8ea0bc2026d28d1faf2dad4a00e1224df35055

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f1442b0753a261fd24cb3606cf207608cd5fba46bdb39a27fdf975e7133ace5a
MD5 ac8765c7c8f72cda39ec4ff09115f08e
BLAKE2b-256 37dc9b55834ecbb88f238b5a0f22ded5a4c48645f3061527131d0d4d0dafdfb5

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3f8fe8a5222a19bd49ae7956abc792b94dd32e765a41ea72b44b78c054166ab3
MD5 3d252ed3b4995b1fd7bbe0086d78b3c2
BLAKE2b-256 055bec84689711d53cb597db1049dab1485e9e121ab3038052251fba678847e8

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 370.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 32de672f16051afdbd0019cff2069ec94c9e4c8217447d9e2f7dbc5034366187
MD5 8e1e40a7a90e79d7bfb7f3777f62183e
BLAKE2b-256 9fde0bc0e9fc08e41e59e69801433afdf52a3204ae9cd9050cb2187563d832c0

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f983aed97868830eeba54541aa08d4878ce53fb277768d13f52219320e3661d
MD5 e1eac747d59280abdb164551ca590678
BLAKE2b-256 be482f4fd5a1b34839088f1a33d8e7d0f7d9a10d8ced9f985932c2a07d6f04ce

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6ac62041cb1995573e2f07ca08f24fb7a94ebef27ad15579dd30411b72f0454b
MD5 c2f6fa7b28d05faa3f8115df5ceb8c7f
BLAKE2b-256 7fb383796fec594a337c2237c9c14c7b7abc0923cb969d3ed52336fbca67b9b8

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 367.8 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 76b23e1b2ae5be4c48d8987d4fdb74db2ad86b35e1b3ba14b165321eac62316c
MD5 8ab2530e26631f7faff9c3891f534a92
BLAKE2b-256 4dd6828ca320e6ce5d4f148ea0852794c8e19e6ae74ad6332b397d7611de5cd6

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6646e5846d71800306b99b01dd7eab880729d90fe2fcfef60359eaabef3a61ca
MD5 e320b716e4019fc747eb1d4ae48275b5
BLAKE2b-256 2a8e9ba6e8354bf305050d32911384bc6fd9b6f7fffdda044e1879d7e5a17f68

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 853c7c63e419f0ce018974e1e461c02f1da6ec52c9c2e857182a10ddc8ec4c39
MD5 cc61f0e52476c0caf2b57be9264f1b54
BLAKE2b-256 8027d38b8aa72b19bd5a3cb956bf6744c8efc85a2abe82da7e7143f5c29d57e6

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 367.7 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 4a9fd0b3d2673126bc7d7b460cc591ffce593dd02cd86ed20542ffbce52e1677
MD5 e6a8052ce7b7bd438cdd666e3fd7d194
BLAKE2b-256 77951114e28957dba7dca5d66899351c5fba107e85243819e5ab7f73536993c8

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5557e638b93421a1395ac6bafb786ba8954b5557462ae8460a99617755f7b0f
MD5 0bb86156bd3ab187cdd965e6736edbcd
BLAKE2b-256 9439b75e709d3bae17acb0e1647d05ec50e743c316c594e2b230ecdb113ab61c

See more details on using hashes here.

Provenance

File details

Details for the file itk_spcn-0.1.5-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: itk_spcn-0.1.5-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for itk_spcn-0.1.5-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 252258b8b30d358de32d5d4e47b863408c99becdf4c01537d8063d94ae0f2ca5
MD5 f62899de0e67055ef8e1d984260e911e
BLAKE2b-256 a0e28d531ee2af87c9db256e18cf9974be05ed01f8ba6d3d85b83992939e8e70

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page