Image Redactor - XA modality - ValueError: Too many dimensions: 3 > 2.
Describe the bug A clear and concise description of what the bug is.
Attempting to run image redaction on an XA modality image (X Ray Angiography) appears to be misinterpreting XA modality images as grayscale in some cases.
To Reproduce Steps to reproduce the behavior: You can obtain a test dicom file from [Aliza DICOM Conformance Tests] if you scroll down to "Enhanced XA Image Storage" and download the Siemens, non-uniform, rotation sample file.
When attempting to redact_and_return_bbox as described the presdio getting started guide using that file.
When attempting the above with the test file (and others that we've encountered in production) you will see an error similar to the following.
File ".../.venv/lib/python3.13/site-packages/presidio_image_redactor/dicom_image_redactor_engine.py", line 74, in redact_and_return_bbox
image_pil = Image.fromarray(image_np, mode="L")
File ".../.venv/lib/python3.13/site-packages/PIL/Image.py", line 3324, in fromarray
raise ValueError(msg)
ValueError: Too many dimensions: 3 > 2.
Expected behavior A clear and concise description of what you expected to happen. Image redaction should work as expected and described in the guide
Screenshots If applicable, add screenshots to help explain your problem. See above error example
Additional context Add any other context about the problem here.
Glad to offer more examples or more detail as needed.
Hi @joelbyler 👋
I’ve submitted a fix for issue https://github.com/microsoft/presidio/issues/1731 (handling XA modality multi-frame grayscale DICOMs). The changes add a _dicom_np_to_pil helper and improve handling in _get_most_common_pixel_value and _set_bbox_color to avoid the ValueError: Too many dimensions error. Could you please take a look when you get a chance? Thanks a lot!