
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/color_exposure/plot_ihc_color_separation.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_color_exposure_plot_ihc_color_separation.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_color_exposure_plot_ihc_color_separation.py:


==============================================
Immunohistochemical staining colors separation
==============================================

Color deconvolution consists of the separation of features by their colors.

In this example we separate the immunohistochemical (IHC) staining from the
hematoxylin counterstaining. The separation is achieved with the method
described in [1]_, known as "color deconvolution".

The IHC staining expression of the FHL2 protein is here revealed with
Diaminobenzidine (DAB) which gives a brown color.


.. [1] A. C. Ruifrok and D. A. Johnston, "Quantification of histochemical
       staining by color deconvolution.," Analytical and quantitative
       cytology and histology / the International Academy of Cytology [and]
       American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.

.. GENERATED FROM PYTHON SOURCE LINES 22-59

.. code-block:: default

    import matplotlib.pyplot as plt

    from skimage import data
    from skimage.color import rgb2hed
    from matplotlib.colors import LinearSegmentedColormap

    # Create an artificial color close to the original one
    cmap_hema = LinearSegmentedColormap.from_list('mycmap', ['white', 'navy'])
    cmap_dab = LinearSegmentedColormap.from_list('mycmap', ['white',
                                                 'saddlebrown'])
    cmap_eosin = LinearSegmentedColormap.from_list('mycmap', ['darkviolet',
                                                   'white'])

    ihc_rgb = data.immunohistochemistry()
    ihc_hed = rgb2hed(ihc_rgb)

    fig, axes = plt.subplots(2, 2, figsize=(7, 6), sharex=True, sharey=True)
    ax = axes.ravel()

    ax[0].imshow(ihc_rgb)
    ax[0].set_title("Original image")

    ax[1].imshow(ihc_hed[:, :, 0], cmap=cmap_hema)
    ax[1].set_title("Hematoxylin")

    ax[2].imshow(ihc_hed[:, :, 1], cmap=cmap_eosin)
    ax[2].set_title("Eosin")

    ax[3].imshow(ihc_hed[:, :, 2], cmap=cmap_dab)
    ax[3].set_title("DAB")

    for a in ax.ravel():
        a.axis('off')

    fig.tight_layout()





.. image:: /auto_examples/color_exposure/images/sphx_glr_plot_ihc_color_separation_001.png
    :alt: Original image, Hematoxylin, Eosin, DAB
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 60-61

Now we can easily manipulate the hematoxylin and DAB "channels":

.. GENERATED FROM PYTHON SOURCE LINES 61-76

.. code-block:: default


    import numpy as np
    from skimage.exposure import rescale_intensity

    # Rescale hematoxylin and DAB signals and give them a fluorescence look
    h = rescale_intensity(ihc_hed[:, :, 0], out_range=(0, 1))
    d = rescale_intensity(ihc_hed[:, :, 2], out_range=(0, 1))
    zdh = np.dstack((np.zeros_like(h), d, h))

    fig = plt.figure()
    axis = plt.subplot(1, 1, 1, sharex=ax[0], sharey=ax[0])
    axis.imshow(zdh)
    axis.set_title("Stain separated image (rescaled)")
    axis.axis('off')
    plt.show()



.. image:: /auto_examples/color_exposure/images/sphx_glr_plot_ihc_color_separation_002.png
    :alt: Stain separated image (rescaled)
    :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.766 seconds)


.. _sphx_glr_download_auto_examples_color_exposure_plot_ihc_color_separation.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: plot_ihc_color_separation.py <plot_ihc_color_separation.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: plot_ihc_color_separation.ipynb <plot_ihc_color_separation.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
