You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When running redaction on compressed pixel data, the returned pixel data is uncompressed. This is because when adding boxes via DicomImageRedactorEngine._add_redact_box, we use the loaded DICOM instance's .pixel_array values, which is uncompressed, unlike its .PixelData.
We are still able to redact correctly, but we are then unable to save the redacted instance as a .dcm file.
Side note: If an error occurs while trying to write out the pixel data post-redaction, then gdcm may need to be installed.
Whether the pixel data is compressed or not can be checked via the DICOM tag (0028, 2110). If the value is '01', then the pixel data is compressed.
ifredacted_instance[0x0028, 0x2110].value=='01':
compression_method=instance.file_meta.TransferSyntaxUIDprint(f'Pixel data is compressed with Transfer Syntax UID: {compression_method}')
Note that native support for compressing is not implemented in pydicom yet. The following line would be ideal but throws an error due to it not being available.
Expected behavior
With the above, we would ideally have the number of bytes pre- and post-redaction as equal. But when no compression is re-applied to previously compressed pixel data, then the number of bytes for post-redaction would be equal to what is expected with no compression.
If we run redacted_instance.save_as('FILE_NAME_HERE.dcm'), then we get the following error (which we want to avoid):
ValueError: Withtag (7fe0, 0010) gotexception: (7FE0,0010) PixelDatahasanundefinedlengthindicatingthatit's compressed, but the data isn'tencapsulatedasrequired. Seepydicom.encaps.encapsulate() formoreinformationTraceback (mostrecentcalllast):
File"/anaconda/envs/feasibility-study/lib/python3.8/site-packages/pydicom/tag.py", line28, intag_in_exceptionyieldFile"/anaconda/envs/feasibility-study/lib/python3.8/site-packages/pydicom/filewriter.py", line662, inwrite_datasetwrite_data_element(fp, dataset.get_item(tag), dataset_encoding)
File"/anaconda/envs/feasibility-study/lib/python3.8/site-packages/pydicom/filewriter.py", line579, inwrite_data_elementraiseValueError(
ValueError: (7FE0,0010) PixelDatahasanundefinedlengthindicatingthatit's compressed, but the data isn'tencapsulatedasrequired. Seepydicom.encaps.encapsulate() formoreinformation
Describe the bug
When running redaction on compressed pixel data, the returned pixel data is uncompressed. This is because when adding boxes via
DicomImageRedactorEngine._add_redact_box
, we use the loaded DICOM instance's.pixel_array
values, which is uncompressed, unlike its.PixelData
.We are still able to redact correctly, but we are then unable to save the redacted instance as a
.dcm
file.Whether the pixel data is compressed or not can be checked via the DICOM tag (0028, 2110). If the value is '01', then the pixel data is compressed.
To Reproduce
Steps to reproduce the behavior:
Note that native support for compressing is not implemented in pydicom yet. The following line would be ideal but throws an error due to it not being available.
Expected behavior
With the above, we would ideally have the number of bytes pre- and post-redaction as equal. But when no compression is re-applied to previously compressed pixel data, then the number of bytes for post-redaction would be equal to what is expected with no compression.
If we run
redacted_instance.save_as('FILE_NAME_HERE.dcm')
, then we get the following error (which we want to avoid):Additional context
Potentially helpful resources:
The text was updated successfully, but these errors were encountered: