Skip to main content

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.

Release files for itk-spcn 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for itk-spcn 0.2.0
File
itk_spcn-0.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
itk_spcn-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
itk_spcn-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
itk_spcn-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
itk_spcn-0.2.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
itk_spcn-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
itk_spcn-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
itk_spcn-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details
itk_spcn-0.2.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
itk_spcn-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64 Details
itk_spcn-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
itk_spcn-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
itk_spcn-0.2.0-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
itk_spcn-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.28+ x86-64 Details
itk_spcn-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
itk_spcn-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
itk_spcn-0.2.0-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
itk_spcn-0.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.28+ x86-64 Details
itk_spcn-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
itk_spcn-0.2.0-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details

Total release size: 32.4 MB

Release files / itk_spcn-0.2.0-cp311-cp311-win_amd64.whl

Download URL itk_spcn-0.2.0-cp311-cp311-win_amd64.whl
Size 692.4 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
1347a763ac2b1e99af081dd4dee9e765b0edcda00e106b41f784a76910eea4e5
BLAKE2b-256 checksum
How to use checksums
e01160b98b90937700e40e908e256da2966d0b873930013f8fd66b0be321cf06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL itk_spcn-0.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9e61974759c5143a227a29f167d4038681d15d27d8e4652bdec0efcfcf1d5761
BLAKE2b-256 checksum
How to use checksums
92e30a46e8aff6651c28856fa776b25f3f4417a2254632efd7a50cf331b0a060
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL itk_spcn-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6b85d395fd3e4a0281ce8c610f89fcd5a5781c08d5061c4f670eb44a5502e8f7
BLAKE2b-256 checksum
How to use checksums
6ccc63bcc3076b919f35e168a856c5e20522586cec47527633f8f2d560d1b6af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl

Download URL itk_spcn-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Size 2.3 MB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
88e4951533a7c3526375a02e72841df4dce91579665b4381f523fff8a95e4776
BLAKE2b-256 checksum
How to use checksums
8433a29d414e4bb299a686d271f9a7f5befce669a8425bd27a29d06c431dbf5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp310-cp310-win_amd64.whl

Download URL itk_spcn-0.2.0-cp310-cp310-win_amd64.whl
Size 692.4 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
de2f51a4c89e029d4d807b4eb755d4846bec1e06ca9d627386113616c60b9613
BLAKE2b-256 checksum
How to use checksums
f6fc0bb7e49f1d5c3ad129bc482ebffa38a8d40e6fb7e13a94b9684b245740d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL itk_spcn-0.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4a99d061a8577123a107266eaab416e543f8c9ecc8dc5c9e67131cb5c883ab14
BLAKE2b-256 checksum
How to use checksums
ac5f78c3a0c136ea19ae1ca7d395163b0771415589f5c20809986021e4d26c31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL itk_spcn-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
443d700ef78fdecf4107f9da7ecd368ec2f62afd9d4442e6e097432dc6547b6a
BLAKE2b-256 checksum
How to use checksums
d24fc86d20be3431edf7c79ed29cf32347e1407bec1e67a3b201e068636ab69e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl

Download URL itk_spcn-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Size 2.3 MB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
9fcfc4571b7e851965c47a95f74dc43f5de025b926cb6e360dc9e2feb86b0a05
BLAKE2b-256 checksum
How to use checksums
e01b328890efe1fe8e6c95f7a6386ad75f696ddc006efd052b5a4af42ec28a7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp39-cp39-win_amd64.whl

Download URL itk_spcn-0.2.0-cp39-cp39-win_amd64.whl
Size 692.9 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
526895d0ef8c08ec4076344cec7927efba7915d2e079f8693754233af1bf4b98
BLAKE2b-256 checksum
How to use checksums
c0199111688b1acba06fbb6a85b9093352836011bfe46eb20ab764bddf4bb19b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL itk_spcn-0.2.0-cp39-cp39-manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
18e3c99db96cd2e75b768bf10d37b2931d0dd21a565a999356297568efb7b971
BLAKE2b-256 checksum
How to use checksums
4a5cb15f5c83cf828e111c73ea18a2298ebbbfa496aa644d48aa055b0ae037d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL itk_spcn-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6256608b443485e068036147f372533c688c884e58c35f397040138e15257c23
BLAKE2b-256 checksum
How to use checksums
6f509b3b1a34b70e398a7fc69cec30c05225cd4ec4a859e31c5d952dfc70b105
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl

Download URL itk_spcn-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl
Size 2.3 MB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
8903f705e4703116c3ba27f14776fb053e75b245992fac9237879c3ae128fcc2
BLAKE2b-256 checksum
How to use checksums
1efc50be9fc56322203e8032d74241159eeaba984915b5dcfc982cd05717f6c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp38-cp38-win_amd64.whl

Download URL itk_spcn-0.2.0-cp38-cp38-win_amd64.whl
Size 718.1 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
c2f6c32e6e751fad8964afd2e115878f2d9b2a1b7e79f415707883fe2fcda3a6
BLAKE2b-256 checksum
How to use checksums
f0a36b5931d81b18c7a10820ecf8637947e199e8352a24269acc7007ff3a83bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl

Download URL itk_spcn-0.2.0-cp38-cp38-manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.8 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
753ba5eba828c727ad81911fb5717b5eb3afd34163d64dabb671514c01e53bea
BLAKE2b-256 checksum
How to use checksums
cccc97b20cc4da14ebb45fd0c7160b7102d7dee018352ac534744b37ac7e81e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL itk_spcn-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ef776077c2ce33027150d1ebc6be1860287ad585f49b28f1e4f81ee9c797d138
BLAKE2b-256 checksum
How to use checksums
3b64dc849ee874600046dec2fd95d8febdd3dfa303dd5d10190498d22155eebe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl

Download URL itk_spcn-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Size 2.3 MB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
1ee0631cd178906c963048c358c482e391ff39181f2f854f0ac072dc94ef9a4b
BLAKE2b-256 checksum
How to use checksums
4c8306a93a412eaebb994d34ae4e5f88585587bc8575ee1f1d201ead6a7c137d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp37-cp37m-win_amd64.whl

Download URL itk_spcn-0.2.0-cp37-cp37m-win_amd64.whl
Size 717.2 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
8efde28ccd186846d397b4422ab4ee2e8da6210b57c188387aae14d4a9a1145f
BLAKE2b-256 checksum
How to use checksums
d474d333117661079e1d9bf11f1024051bc11793571281b9784b096d40a5b5b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl

Download URL itk_spcn-0.2.0-cp37-cp37m-manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
52067887188f2f2e401bed018bc3a2749b1599c45c78be80de16109722574d66
BLAKE2b-256 checksum
How to use checksums
2a08414066b7831de428a83c419cfcfd93b0cf05d6adc822b143dd5ab834f860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL itk_spcn-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
61eeea77ab96a2d86de680f8f1bf8d9ba8f111e75e1130c6214771b8eff7a2e3
BLAKE2b-256 checksum
How to use checksums
f2d48572cd5802aa6887ef2a5c6b3bac6350bd53d125078eefef7953220ff427
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / itk_spcn-0.2.0-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL itk_spcn-0.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
Size 2.3 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
25e1ec4fbcacf26b9933a7d67e56a999615b1b63307376131794e2b3b1e1e5da
BLAKE2b-256 checksum
How to use checksums
e059a020e3339e1ab7add3204287834881ad403055e84306a286f390078831f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.2.0 This release

20 release files

0.1.7

12 release files

0.1.6

12 release files

0.1.4

11 release files

0.1.3

11 release files

0.1.0

12 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page