Hi all,
I have a dicom file that I can read with pydicom without problem. Below is
some relevant information of this file.
(0002, 0010) Transfer Syntax UID UI: JPEG Baseline (Process 1)
(0028, 0002) Samples per Pixel US: 3
(0028, 0004) Photometric Interpretation CS: 'YBR_FULL_422'
(0028, 0006) Planar Configuration US: 0
(0028, 0008) Number of Frames IS: '852'
(0028, 0009) Frame Increment Pointer AT: (0018, 1063)
(0028, 0010) Rows US: 649
(0028, 0011) Columns US: 1170
(0028, 0100) Bits Allocated US: 8
(0028, 0101) Bits Stored US: 8
(0028, 0102) High Bit US: 7
(0028, 0103) Pixel Representation US: 0
(0028, 2110) Lossy Image Compression CS: '01'
(0028, 2112) Lossy Image Compression Ratio DS: '16.8'
(7fe0, 0010) Pixel Data OB: Array of 115504762 elements
I am trying to change some of the pixels and store it back to the DICOM file. So, I
have the following,
ds = pydicom.dcmread("path/to/dicom_file")
px_data = ds.pixel_array
n_frms = px_data.shape[0]
# my changes
px_data[0:n_frms, 0:50, :, :] = 0
px_data[0:n_frms, -90:-1, :, :] = 0
ds.PixelData = px_data.tobytes()
ds.save_as("path/to/new_dicom_file")
However, when saving, I get the following error:
ValueError: (7FE0,0010) Pixel Data has an undefined length indicating that it's compressed,
but the data isn't encapsulated as required. See pydicom.encaps.encapsulate() for more information.
As the error suggesting and based on my search on the web, I have to compress
the pixel data back to '1.2.840.10008.1.2.4.50'
format. But, so far, I have
failed to do so. I was wondering if anyone can give my some pointers.
Thanks,
Kourosh