Skip to content

Conversation

MRADULTRIPATHI
Copy link
Contributor

@MRADULTRIPATHI MRADULTRIPATHI commented Sep 26, 2025

Change Description

Fixed handling of XA modality (X-Ray Angiography) DICOM images that were previously failing with
ValueError: Too many dimensions: 3 > 2 when passed to Image.fromarray.

  • Added _dicom_np_to_pil helper to robustly handle conversion of multi-frame grayscale and RGB images.
  • Updated _get_most_common_pixel_value to correctly handle multi-frame grayscale by taking the first frame.
  • Updated _set_bbox_color to use _dicom_np_to_pil for consistency across grayscale and RGB images.
  • Ensured redaction works as expected for XA modality and similar multi-frame images.
  • Verified fix with local tests (test_dicom_redactor.py) → all tests passed.

Issue reference

Fixes #1731

Checklist

  • I have reviewed the contribution guidelines
  • I have signed the CLA (if required)
  • My code includes unit tests (local test added to validate XA modality fix)
  • All unit tests and lint checks pass locally
  • My PR contains documentation updates / additions if required

@MRADULTRIPATHI
Copy link
Contributor Author

Hi @omri374 @joelbyler 👋

I’ve submitted a fix for issue #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!

@omri374
Copy link
Contributor

omri374 commented Sep 30, 2025

Hi @MRADULTRIPATHI thanks for the PR! Please add unit tests.

@MRADULTRIPATHI
Copy link
Contributor Author

Hi @omri374
Thanks for the feedback earlier. I've added the requested unit test for multi-frame grayscale DICOM handling.
All tests are passing locally

Please let me know if you’d like any further changes.

@joelbyler
Copy link

I'll test this out today, one thing that does come to mind, and its probably outside the scope of this change, but presidio dicom processing should really support multiframe image redaction. Its definately possible that if there is one frame with potential PHI included, there will likely be multiple frames with that same PHI included. perhaps it will always be in the same place in all or most frames, but possibly not. I'm thinking this is a separate issue though.

@MRADULTRIPATHI
Copy link
Contributor Author

Thanks @joelbyler
Agreed — multi-frame redaction across all frames would definitely be valuable, and I agree it should be tracked as a separate enhancement issue.
When you test it out, could you please share the results here as well? That would be really helpful.

@joelbyler
Copy link

I have run my tests locally using some test files and this does resolve the exception that I was seeing, and I can confirm that presidio is stlil not processing multliple frames for redaction, but that's not a regression at this point. I'll log a separate issue to provide image redaction support for multiframe dicom instances.

The files I have include synthetic PHI and computer generated pixeldata, glad to share those if its of interest.

@joelbyler
Copy link

Actually I'll share them here for reference, but also add them to the new issue.
multiframe_test_images.zip

@MRADULTRIPATHI
Copy link
Contributor Author

Hi @joelbyler

Thanks a lot for reviewing and confirming that the exception is resolved 🙏
Since this PR addresses the reported issue (#1731) and the separate multi-frame enhancement is now being tracked in #1737, I just wanted to check — is this PR ready to be merged, or would you like me to make any further changes? 🙂

@joelbyler
Copy link

Hi @joelbyler

Thanks a lot for reviewing and confirming that the exception is resolved 🙏

Since this PR addresses the reported issue (#1731) and the separate multi-frame enhancement is now being tracked in #1737, I just wanted to check — is this PR ready to be merged, or would you like me to make any further changes? 🙂

I'm not a maintainer on this project but I think these changes work for my use case

@MRADULTRIPATHI
Copy link
Contributor Author

Thanks a lot @joelbyler for confirming that the fix works for your use case 🙏

Hi @omri374 👋
Since this PR resolves the reported issue (#1731) and tests are passing locally, could you please review/approve it for merge when you get a chance? 🙂

@MRADULTRIPATHI
Copy link
Contributor Author

Hi @omri374 👋
Just following up on this PR — since it resolves issue #1731 and tests are passing locally, could you please take a look and let me know if it’s good to merge? 🙏

@omri374
Copy link
Contributor

omri374 commented Oct 2, 2025

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MRADULTRIPATHI
Copy link
Contributor Author

Hi @omri374 👋
I noticed that several CI jobs (linting + test_image_redactor) are failing after my changes.
Could you please guide me on what adjustments are needed to get all tests passing? 🙏
Happy to update the PR accordingly.

@MRADULTRIPATHI
Copy link
Contributor Author

@joelbyler can you help me with that??

@MRADULTRIPATHI MRADULTRIPATHI requested a review from a team as a code owner October 2, 2025 10:26
@MRADULTRIPATHI
Copy link
Contributor Author

Hi @microsoft/presidio-administrators 👋

This PR fixes the XA modality multi-frame grayscale DICOM redaction issue (#1731).
All linting/formatting issues have been resolved with ruff, and the tests are passing locally.

Since this PR now mainly waits for code owner review, could you please take a look and approve when you get a chance? 🙏
Thanks a lot!

@omri374
Copy link
Contributor

omri374 commented Oct 2, 2025

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MRADULTRIPATHI
Copy link
Contributor Author

Hi @omri374 👋
I noticed that several CI jobs (linting + test_image_redactor) are failing after my changes.
Could you please guide me on what adjustments are needed to get all tests passing? 🙏
Happy to update the PR accordingly.

@omri374
Copy link
Contributor

omri374 commented Oct 6, 2025

This PR now has 93 files. It seems to incorporate the anonymizer into the analyzer. Is there a reason for such big PR?

@omri374
Copy link
Contributor

omri374 commented Oct 19, 2025

Hi @MRADULTRIPATHI, are you interesting in continuing to work on this PR? is there anything we can assist with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Redactor - XA modality - ValueError: Too many dimensions: 3 > 2.

3 participants