Enet4 / dicom-rs

Rust implementation of the DICOM standard
https://dicom-rs.github.io
Apache License 2.0
403 stars 75 forks source link

Unusual Image Generation from RLE DICOM Files #457

Closed IsmailAlamKhan closed 2 months ago

IsmailAlamKhan commented 4 months ago

I'm encountering a problematic output when extracting a dynamic image using your package for some dicom files. I have attached the output image for you to understand the issue also provided the dicom file as well. I suspect the issue might be related to the Pixeldata tag on the dicom file.

    let obj  = open_dicom_file(&path_to_file)?;
    let image = &obj
        .decode_pixel_data()
        .map_err(|error| HsaiErrors::UnabledToDecodePixelData(error.to_string()))?;

    let dynamic_image = image
        .to_dynamic_image(0)
        .map_err(|_| HsaiErrors::UnableToConvertPixelDataToDynamicImage)?;

    let mut w = Cursor::new(Vec::new());

    dynamic_image
        .into_rgba8()
        .write_to(&mut w, ImageOutputFormat::Jpeg(100))
        .map_err(|_| HsaiErrors::UnableToConvertToJpeg)?;

test https://drive.google.com/file/d/15v9BVAJoYGCVaGDgMAzElN51sO_N8v14/view?usp=sharing

Enet4 commented 4 months ago

Thank you for reporting, @IsmailAlamKhan. This seems to be a bug in the RLE lossless decoder. Converting the file to native using other DICOM tools (such as DCMTK's dcmdrle) will give a coherent image.

CT000001 native

There is some test coverage for 8-bit RGB images, but it might need some work for the case of 16-bit monochrome images. Until then, if changing the transfer syntax is an option, 16-bit JPEG lossless is supported and might yield better compression ratios.

IsmailAlamKhan commented 4 months ago

Hey @Enet4 I am really sorry for the late response I thought I had closed this. We had fixed this issue by avoiding the compression for now. I am really sorry again for not responding before I wrote a msg and everything but forget to send it. And thanks a lot for your quick responses

Enet4 commented 4 months ago

No problem! But I hope you don't mind that I keep this issue open, since the bug in the RLE lossless decoder is still worth fixing.

IsmailAlamKhan commented 4 months ago

Oh sure you can keep it open, thanks.