pydicom.pixels.set_pixel_data¶
- pydicom.pixels.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.If a
bool
array is used then the pixel data will be bit-packed usingpack_bits()
.
Changed in version 3.1: Added the ability to use a
bool
ndarray for Bits Allocated1
with bit-packing.- Parameters:
ds (pydicom.dataset.Dataset) – The little endian encoded dataset to be modified.
arr (np.ndarray) –
An array with
dtype
bool, 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.
Additionally, the length of the encoded array must be no larger than the maximum allowed for uncompressed Pixel Data (4294967294 bytes).
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, or 1 in the case of an array of dtype bool.generate_instance_uid (bool, optional) – If
True
(default) then add or update the (0008,0018) SOP Instance UID element with a value generated usinggenerate_uid()
.