Problem writing dicom file after decompression #1586
-
Hello, I have a multiframe dicom archive of CEUS and B-MODE images. After the update to version 2.x of pydicom lib, the images started to appear green. My problem now is that I can't write the processed RGB sequence to a new dicom file. I'm stuck because I'm not experienced enough to resolve the problem and the documentation doesn't help me a lot. Any further help would be welcomed. Kind regards. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
a code sample: #ceus_fixed is the loaded dicom dataset
result = pydicom.pixel_data_handlers.util.convert_color_space(ceus_fixed.pixel_array, initialInterpretation, targetInterpretation)
ceus_fixed.PixelData = result.tobytes()
ceus_fixed.fix_meta_info()
ceus_fixed.save_as(filepath, write_like_original=False) |
Beta Was this translation helpful? Give feedback.
-
Your data is in a compressed transfer syntax (JPEG Baseline), while ceus_fixed.PixelData = result.tobytes()
ceus_fixed.fix_meta_info()
ceus_fixed.file_meta.TransferSyntaxUID = ExplicitVRLittleEndian
ceus_fixed.save_as(filepath, write_like_original=False) |
Beta Was this translation helpful? Give feedback.
-
Thank you very much about your help. It works like a charm. |
Beta Was this translation helpful? Give feedback.
Your data is in a compressed transfer syntax (JPEG Baseline), while
pixel_array
is uncompressed data (it does the decompression on the fly). So, either you have to change the transfer syntax to match your data (e.g. use Little Endian Explicit), or you have indeed to compress and encapsulate the data first. It is probably easier to write the data uncompressed by changing theTransferSyntaxUID
, even if the file gets larger that way: