pydicom.pixels.utils.set_pixel_data

pydicom.pixels.utils.set_pixel_data(ds: Dataset, arr: np.ndarray, photometric_interpretation: str, bits_stored: int, *, generate_instance_uid: bool = True) None[source]

Use an ndarray to set a dataset’s Pixel Data and related Image Pixel module elements.

Added in version 3.0.

The following Image Pixel module elements values will be added, updated or removed as necessary:

  • (0028,0002) Samples per Pixel using a value corresponding to photometric_interpretation.

  • (0028,0004) Photometric Interpretation from photometric_interpretation.

  • (0028,0006) Planar Configuration will be added and set to 0 if Samples per Pixel is > 1, otherwise it will be removed.

  • (0028,0008) Number of Frames from the array shape, however it will be removed if arr only contains a single frame.

  • (0028,0010) Rows and (0028,0011) Columns from the array shape.

  • (0028,0100) Bits Allocated from the array dtype.

  • (0028,0101) Bits Stored and (0028,0102) High Bit from bits_stored.

  • (0028,0103) Pixel Representation from the array dtype.

In addition:

  • The Transfer Syntax UID will be set to Explicit VR Little Endian if it doesn’t already exist or uses a compressed (encapsulated) transfer syntax.

  • If generate_instance_uid is True (default) then the SOP Instance UID will be added or updated.

Parameters:
  • ds (pydicom.dataset.Dataset) – The little endian encoded dataset to be modified.

  • arr (np.ndarray) –

    An array with dtype uint8, uint16, int8 or int16. The array must be shaped as one of the following:

    • (rows, columns) for a single frame of grayscale data.

    • (frames, rows, columns) for multi-frame grayscale data.

    • (rows, columns, samples) for a single frame of multi-sample data such as RGB.

    • (frames, rows, columns, samples) for multi-frame, multi-sample data.

  • photometric_interpretation (str) – The value to use for (0028,0004) Photometric Interpretation. Valid values are "MONOCHROME1", "MONOCHROME2", "PALETTE COLOR", "RGB", "YBR_FULL", "YBR_FULL_422".

  • bits_stored (int) – The value to use for (0028,0101) Bits Stored. Must be no greater than the number of bits used by the itemsize of arr.

  • generate_instance_uid (bool, optional) – If True (default) then add or update the (0008,0018) SOP Instance UID element with a value generated using generate_uid().