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.6, 3.7, 3.8, and 3.9. 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.2.0-cp311-cp311-win_amd64.whl (692.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

itk_spcn-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

itk_spcn-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

itk_spcn-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

itk_spcn-0.2.0-cp310-cp310-win_amd64.whl (692.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

itk_spcn-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

itk_spcn-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

itk_spcn-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

itk_spcn-0.2.0-cp39-cp39-win_amd64.whl (692.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

itk_spcn-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

itk_spcn-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

itk_spcn-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

itk_spcn-0.2.0-cp38-cp38-win_amd64.whl (718.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

itk_spcn-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

itk_spcn-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

itk_spcn-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

itk_spcn-0.2.0-cp37-cp37m-win_amd64.whl (717.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

itk_spcn-0.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.28+ x86-64

itk_spcn-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

itk_spcn-0.2.0-cp37-cp37m-macosx_10_9_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file itk_spcn-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: itk_spcn-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 692.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for itk_spcn-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1347a763ac2b1e99af081dd4dee9e765b0edcda00e106b41f784a76910eea4e5
MD5 0e8e0361721bd2e1171c4282d0bf2aab
BLAKE2b-256 e01160b98b90937700e40e908e256da2966d0b873930013f8fd66b0be321cf06

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9e61974759c5143a227a29f167d4038681d15d27d8e4652bdec0efcfcf1d5761
MD5 a610764c7c5bd42993c1fb201d6ec447
BLAKE2b-256 92e30a46e8aff6651c28856fa776b25f3f4417a2254632efd7a50cf331b0a060

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b85d395fd3e4a0281ce8c610f89fcd5a5781c08d5061c4f670eb44a5502e8f7
MD5 81a21312d5070793bb1776e2a20440bb
BLAKE2b-256 6ccc63bcc3076b919f35e168a856c5e20522586cec47527633f8f2d560d1b6af

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 88e4951533a7c3526375a02e72841df4dce91579665b4381f523fff8a95e4776
MD5 50724b8900a06f461d29caa54509496d
BLAKE2b-256 8433a29d414e4bb299a686d271f9a7f5befce669a8425bd27a29d06c431dbf5d

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: itk_spcn-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 692.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for itk_spcn-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 de2f51a4c89e029d4d807b4eb755d4846bec1e06ca9d627386113616c60b9613
MD5 c9e53b9c14f058f3fd2de06311ac3691
BLAKE2b-256 f6fc0bb7e49f1d5c3ad129bc482ebffa38a8d40e6fb7e13a94b9684b245740d8

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4a99d061a8577123a107266eaab416e543f8c9ecc8dc5c9e67131cb5c883ab14
MD5 ac69a9ce1f39f4c54c48108a3442b775
BLAKE2b-256 ac5f78c3a0c136ea19ae1ca7d395163b0771415589f5c20809986021e4d26c31

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 443d700ef78fdecf4107f9da7ecd368ec2f62afd9d4442e6e097432dc6547b6a
MD5 a33754688628df6d45edbf07b482aa1a
BLAKE2b-256 d24fc86d20be3431edf7c79ed29cf32347e1407bec1e67a3b201e068636ab69e

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9fcfc4571b7e851965c47a95f74dc43f5de025b926cb6e360dc9e2feb86b0a05
MD5 058f27b8743f2d57b378d43e43f783a7
BLAKE2b-256 e01b328890efe1fe8e6c95f7a6386ad75f696ddc006efd052b5a4af42ec28a7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: itk_spcn-0.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 692.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for itk_spcn-0.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 526895d0ef8c08ec4076344cec7927efba7915d2e079f8693754233af1bf4b98
MD5 38f92ef8da580164503593b22bd876fa
BLAKE2b-256 c0199111688b1acba06fbb6a85b9093352836011bfe46eb20ab764bddf4bb19b

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18e3c99db96cd2e75b768bf10d37b2931d0dd21a565a999356297568efb7b971
MD5 6e6e301a5ddccfff359aff083c1c01a3
BLAKE2b-256 4a5cb15f5c83cf828e111c73ea18a2298ebbbfa496aa644d48aa055b0ae037d5

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6256608b443485e068036147f372533c688c884e58c35f397040138e15257c23
MD5 03168042def6e40fa594d21d7adac050
BLAKE2b-256 6f509b3b1a34b70e398a7fc69cec30c05225cd4ec4a859e31c5d952dfc70b105

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8903f705e4703116c3ba27f14776fb053e75b245992fac9237879c3ae128fcc2
MD5 07a04bef046b672a1c69dd96c1fa108e
BLAKE2b-256 1efc50be9fc56322203e8032d74241159eeaba984915b5dcfc982cd05717f6c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: itk_spcn-0.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 718.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for itk_spcn-0.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c2f6c32e6e751fad8964afd2e115878f2d9b2a1b7e79f415707883fe2fcda3a6
MD5 6e9cfb6e591759af5ee3224da3cdcfb2
BLAKE2b-256 f0a36b5931d81b18c7a10820ecf8637947e199e8352a24269acc7007ff3a83bb

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 753ba5eba828c727ad81911fb5717b5eb3afd34163d64dabb671514c01e53bea
MD5 2d13cdfeabcf8574e5d203d711f40927
BLAKE2b-256 cccc97b20cc4da14ebb45fd0c7160b7102d7dee018352ac534744b37ac7e81e7

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef776077c2ce33027150d1ebc6be1860287ad585f49b28f1e4f81ee9c797d138
MD5 c1c1fa245585af3f52146c7a74b2da15
BLAKE2b-256 3b64dc849ee874600046dec2fd95d8febdd3dfa303dd5d10190498d22155eebe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1ee0631cd178906c963048c358c482e391ff39181f2f854f0ac072dc94ef9a4b
MD5 73171eb176e4011f499acaec0c0cdcdd
BLAKE2b-256 4c8306a93a412eaebb994d34ae4e5f88585587bc8575ee1f1d201ead6a7c137d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: itk_spcn-0.2.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 717.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for itk_spcn-0.2.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 8efde28ccd186846d397b4422ab4ee2e8da6210b57c188387aae14d4a9a1145f
MD5 35c43ed06c9f437db746e535798358d1
BLAKE2b-256 d474d333117661079e1d9bf11f1024051bc11793571281b9784b096d40a5b5b8

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 52067887188f2f2e401bed018bc3a2749b1599c45c78be80de16109722574d66
MD5 660ba9730ae616ab7a1afd5837bffd3d
BLAKE2b-256 2a08414066b7831de428a83c419cfcfd93b0cf05d6adc822b143dd5ab834f860

See more details on using hashes here.

File details

Details for the file itk_spcn-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 61eeea77ab96a2d86de680f8f1bf8d9ba8f111e75e1130c6214771b8eff7a2e3
MD5 89502208015adcb5a2e845c08ea97473
BLAKE2b-256 f2d48572cd5802aa6887ef2a5c6b3bac6350bd53d125078eefef7953220ff427

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for itk_spcn-0.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 25e1ec4fbcacf26b9933a7d67e56a999615b1b63307376131794e2b3b1e1e5da
MD5 02185d8682230e166f959a3f65762c50
BLAKE2b-256 e059a020e3339e1ab7add3204287834881ad403055e84306a286f390078831f6

See more details on using hashes here.

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