
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/input_output/plot_read_dicom.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_input_output_plot_read_dicom.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_input_output_plot_read_dicom.py:


==================================
Read a Dataset and plot Pixel Data
==================================

This example illustrates how to open a DICOM file, print some dataset
information, and show it using matplotlib.

.. GENERATED FROM PYTHON SOURCE LINES 10-41



.. image-sg:: /auto_examples/input_output/images/sphx_glr_plot_read_dicom_001.png
   :alt: plot read dicom
   :srcset: /auto_examples/input_output/images/sphx_glr_plot_read_dicom_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    File path........: /build/pydicom-x4eeez/pydicom-2.4.3/pydicom/data/test_files/CT_small.dcm
    SOP Class........: 1.2.840.10008.5.1.4.1.1.2 (CT Image Storage)

    Patient's Name...: CompressedSamples, CT1
    Patient ID.......: 1CT1
    Modality.........: CT
    Study Date.......: 20040119
    Image size.......: 128 x 128
    Pixel Spacing....: [0.661468, 0.661468]
    Slice location...: -77.2040634155






|

.. code-block:: Python


    # authors : Guillaume Lemaitre <g.lemaitre58@gmail.com>
    # license : MIT

    import matplotlib.pyplot as plt
    from pydicom import dcmread
    from pydicom.data import get_testdata_file

    fpath = get_testdata_file('CT_small.dcm')
    ds = dcmread(fpath)

    # Normal mode:
    print()
    print(f"File path........: {fpath}")
    print(f"SOP Class........: {ds.SOPClassUID} ({ds.SOPClassUID.name})")
    print()

    pat_name = ds.PatientName
    print(f"Patient's Name...: {pat_name.family_comma_given()}")
    print(f"Patient ID.......: {ds.PatientID}")
    print(f"Modality.........: {ds.Modality}")
    print(f"Study Date.......: {ds.StudyDate}")
    print(f"Image size.......: {ds.Rows} x {ds.Columns}")
    print(f"Pixel Spacing....: {ds.PixelSpacing}")

    # use .get() if not sure the item exists, and want a default value if missing
    print(f"Slice location...: {ds.get('SliceLocation', '(missing)')}")

    # plot the image using matplotlib
    plt.imshow(ds.pixel_array, cmap=plt.cm.gray)
    plt.show()


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

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


.. _sphx_glr_download_auto_examples_input_output_plot_read_dicom.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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