pydicom.pixel_data_handlers.numpy_handler

Use the numpy package to convert supported pixel data to a numpy.ndarray.

Supported transfer syntaxes

  • 1.2.840.10008.1.2 : Implicit VR Little Endian

  • 1.2.840.10008.1.2.1 : Explicit VR Little Endian

  • 1.2.840.10008.1.2.1.99 : Deflated Explicit VR Little Endian

  • 1.2.840.10008.1.2.2 : Explicit VR Big Endian

Supported data

The numpy handler supports the conversion of data in the (7FE0,0008) Float Pixel Data, (7FE0,0009) Double Float Pixel Data and (7FE0,0010) Pixel Data elements to a ndarray provided the related Image Pixel, Floating Point Image Pixel or Double Floating Point Image Pixel module elements have values given in the table below.

Element

Supported values

Tag

Keyword

Type

(0028,0002)

SamplesPerPixel

1

N

Required

(0028,0004)

PhotometricInterpretation

1

MONOCHROME1, MONOCHROME2, RGB, YBR_FULL, YBR_FULL_422

Required

(0028,0006)

PlanarConfiguration

1C

0, 1

Optional

(0028,0008)

NumberOfFrames

1C

N

Optional

(0028,0010)

Rows

1

N

Required

(0028,0011)

Columns

1

N

Required

(0028,0100)

BitsAllocated

1

1, 8, 16, 32, 64

Required

(0028,0101)

BitsStored

1

1, 8, 12, 16

Optional

(0028,0103)

PixelRepresentation

1C

0, 1

Optional

Functions

get_pixeldata(ds[, read_only])

Return a numpy.ndarray of the pixel data.

is_available()

Return True if the handler has its dependencies met.

needs_to_convert_to_RGB(ds)

Return True if the Pixel Data should to be converted from YCbCr to RGB.

should_change_PhotometricInterpretation_to_RGB(ds)

Return True if the Photometric Interpretation should be changed to RGB.

supports_transfer_syntax(transfer_syntax)

Return True if the handler supports the transfer_syntax.

pydicom.pixel_data_handlers.numpy_handler.get_pixeldata(ds: Dataset, read_only: bool = False) np.ndarray[source]

Return a numpy.ndarray of the pixel data.

Changed in version 1.4:

  • Added support for uncompressed pixel data with a Photometric Interpretation of YBR_FULL_422.

  • Added support for Float Pixel Data and Double Float Pixel Data

Parameters
  • ds (Dataset) – The Dataset containing an Image Pixel, Floating Point Image Pixel or Double Floating Point Image Pixel module and the Pixel Data, Float Pixel Data or Double Float Pixel Data to be converted. If (0028,0004) Photometric Interpretation is ‘YBR_FULL_422’ then the pixel data will be resampled to 3 channel data as per Part 3, Annex C.7.6.3.1.2 of the DICOM Standard.

  • read_only (bool, optional) – If False (default) then returns a writeable array that no longer uses the original memory. If True and the value of (0028,0100) Bits Allocated > 1 then returns a read-only array that uses the original memory buffer of the pixel data. If Bits Allocated = 1 then always returns a writeable array.

Returns

The contents of (7FE0,0010) Pixel Data, (7FE0,0008) Float Pixel Data or (7FE0,0009) Double Float Pixel Data as a 1D array.

Return type

np.ndarray

Raises
  • AttributeError – If ds is missing a required element.

  • NotImplementedError – If ds contains pixel data in an unsupported format.

  • ValueError – If the actual length of the pixel data doesn’t match the expected length.

pydicom.pixel_data_handlers.numpy_handler.is_available() bool[source]

Return True if the handler has its dependencies met.

pydicom.pixel_data_handlers.numpy_handler.needs_to_convert_to_RGB(ds: Dataset) bool[source]

Return True if the Pixel Data should to be converted from YCbCr to RGB.

This affects JPEG transfer syntaxes.

pydicom.pixel_data_handlers.numpy_handler.should_change_PhotometricInterpretation_to_RGB(ds: Dataset) bool[source]

Return True if the Photometric Interpretation should be changed to RGB.

This affects JPEG transfer syntaxes.

pydicom.pixel_data_handlers.numpy_handler.supports_transfer_syntax(transfer_syntax: pydicom.uid.UID) bool[source]

Return True if the handler supports the transfer_syntax.

Parameters

transfer_syntax (uid.UID) – The Transfer Syntax UID of the Pixel Data that is to be used with the handler.