Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Multi-Frame DICOMs in Dicom Image Redactor #1512

Open
erencanuysal opened this issue Jan 16, 2025 · 1 comment
Open

Issue with Multi-Frame DICOMs in Dicom Image Redactor #1512

erencanuysal opened this issue Jan 16, 2025 · 1 comment

Comments

@erencanuysal
Copy link

erencanuysal commented Jan 16, 2025

Hello,

I’m encountering an issue when using the DICOM Image Redactor with multi-frame DICOM images (where the value in DICOM tag [0x0028, 0x0008] is more than one). The de-identification process works fine for DICOMs with a single frame (pixel_array.shape ≤ 3), but for multi-frame images (where pixel_array.shape > 3), the redaction seems to fail or not function as expected.

Specifically, the issue occurs in the _save_pixel_array_as_png() method of DicomImageRedactorEngine. The code attempts to flatten the pixel array for multi-frame images and save them as PNG files, leading to errors:

if is_greyscale:
    with open(f"{output_dir}/{output_file_name}.png", "wb") as png_file:
                w = png.Writer(shape[1], shape[0], greyscale=True)
                w.write(png_file, pixel_array
else:
    with open(f"{output_dir}/{output_file_name}.png", "wb") as png_file:
                w = png.Writer(shape[1], shape[0], greyscale=False)
                # Semi-flatten the pixel array to RGB representation in 2D
                pixel_array = np.reshape(pixel_array, (shape[0], shape[1] * 3))
                w.write(png_file, pixel_array)

For multi-frame images, such as with a pixel array shape of (135, 600, 800, 3), the code throws the following error:
ValueError: cannot reshape array of size 194400000 into shape (135,1800)

The root cause seems to be the redact_and_return_bbox() method not handling multi-frame DICOMs correctly, especially when working with pixel arrays that contain more than one frame.

To Reproduce

To reproduce the issue, simply use DicomImageRedactorEngine with a multi-frame DICOM image. The de-identification process fails for images with pixel arrays of shape (N, M, P, Q) where N > 1.

Expected Behavior

The DicomImageRedactorEngine should handle multi-frame DICOM images by processing each frame independently or appropriately handling the reshaping of the pixel array.

Question

Is there a solution to handle multi-frame DICOMs in the current implementation? Alternatively, I would be happy to contribute to resolving this issue.

Thank you!

@omri374
Copy link
Contributor

omri374 commented Jan 16, 2025

Thanks for raising this @erencanuysal. Any contribution would be appreciated, and we'd be happy to help with reviewing and guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants