pydicom.pixel_data_handlers.pylibjpeg_handler

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

New in version 2.1.

Supported data

The pylibjpeg handler supports the conversion of data in the (7FE0,0010) Pixel Data elements to a ndarray provided the related Image Pixel module elements have values given in the table below.

Element

Supported values

Tag

Keyword

Type

(0028,0002)

SamplesPerPixel

1

1, 3

Required

(0028,0004)

PhotometricInterpretation

1

MONOCHROME1, MONOCHROME2, RGB, YBR_FULL, YBR_FULL_422, YBR_ICT, YBR_RCT

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

8, 16

Required

(0028,0101)

BitsStored

1

Up to 16

Required

(0028,0103)

PixelRepresentation

1

0, 1

Required

Changed in version 2.2: Added support for RLE Lossless via the pylibjpeg-rle plugin.

Functions

as_array(ds)

Return the entire Pixel Data as an ndarray.

generate_frames(ds[, reshape])

Yield a Pixel Data frame from ds as an ndarray.

get_pixeldata(ds)

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(tsyntax)

Return True if the handler supports the tsyntax.

pydicom.pixel_data_handlers.pylibjpeg_handler.as_array(ds: Dataset) np.ndarray[source]

Return the entire Pixel Data as an ndarray.

New in version 2.1.

Parameters

ds (pydicom.dataset.Dataset) – The Dataset containing an Image Pixel module and the Pixel Data to be converted.

Returns

The contents of (7FE0,0010) Pixel Data as an ndarray with shape (rows, columns), (rows, columns, components), (frames, rows, columns), or (frames, rows, columns, components) depending on the dataset.

Return type

numpy.ndarray

pydicom.pixel_data_handlers.pylibjpeg_handler.generate_frames(ds: Dataset, reshape: bool = True) Iterable[np.ndarray][source]

Yield a Pixel Data frame from ds as an ndarray.

New in version 2.1.

Parameters
  • ds (pydicom.dataset.Dataset) – The Dataset containing an Image Pixel module and the Pixel Data to be converted.

  • reshape (bool, optional) – If True (default), then the returned ndarray will be reshaped to the correct dimensions. If False then no reshaping will be performed.

Yields

numpy.ndarray – A single frame of (7FE0,0010) Pixel Data as an ndarray with an appropriate dtype for the data.

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

  • RuntimeError – If the plugin required to decode the pixel data is not installed.

pydicom.pixel_data_handlers.pylibjpeg_handler.get_pixeldata(ds: Dataset) np.ndarray[source]

Return a numpy.ndarray of the pixel data.

New in version 2.1.

Parameters

ds (pydicom.dataset.Dataset) – The Dataset containing an Image Pixel module and the Pixel Data to be converted.

Returns

The contents of (7FE0,0010) Pixel Data as a 1D array.

Return type

numpy.ndarray

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

Return True if the handler has its dependencies met.

pydicom.pixel_data_handlers.pylibjpeg_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.pylibjpeg_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.pylibjpeg_handler.supports_transfer_syntax(tsyntax: UID) bool[source]

Return True if the handler supports the tsyntax.

Parameters

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