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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_auto_examples_color_exposure_plot_rgb_to_gray.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_color_exposure_plot_rgb_to_gray.py:


================
RGB to grayscale
================

This example converts an image with RGB channels into an image with a single
grayscale channel.

The value of each grayscale pixel is calculated as the weighted sum of the
corresponding red, green and blue pixels as::

        Y = 0.2125 R + 0.7154 G + 0.0721 B

These weights are used by CRT phosphors as they better represent human
perception of red, green and blue than equal weights. [1]_

References
----------
.. [1] http://poynton.ca/PDFs/ColorFAQ.pdf

.. GENERATED FROM PYTHON SOURCE LINES 22-41



.. image-sg:: /auto_examples/color_exposure/images/sphx_glr_plot_rgb_to_gray_001.png
   :alt: Original, Grayscale
   :srcset: /auto_examples/color_exposure/images/sphx_glr_plot_rgb_to_gray_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt

    from skimage import data
    from skimage.color import rgb2gray

    original = data.astronaut()
    grayscale = rgb2gray(original)

    fig, axes = plt.subplots(1, 2, figsize=(8, 4))
    ax = axes.ravel()

    ax[0].imshow(original)
    ax[0].set_title("Original")
    ax[1].imshow(grayscale, cmap=plt.cm.gray)
    ax[1].set_title("Grayscale")

    fig.tight_layout()
    plt.show()


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

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


.. _sphx_glr_download_auto_examples_color_exposure_plot_rgb_to_gray.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_rgb_to_gray.zip <plot_rgb_to_gray.zip>`


.. only:: html

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

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