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

Error while converting 32-bit pixel data to ndarray or image #325

Open
arturocs opened this issue Jan 27, 2023 · 2 comments
Open

Error while converting 32-bit pixel data to ndarray or image #325

arturocs opened this issue Jan 27, 2023 · 2 comments
Labels
A-lib Area: library C-pixeldata Crate: dicom-pixeldata enhancement

Comments

@arturocs
Copy link

When I try to convert the pixel data from a RT Dose dicom to an image or an ndarray I get the following error: Error(InvalidBitsAllocated { backtrace: Backtrace(())) })
I have followed the examples described here and as a test file I have used this dicom: https://github.com/dicompyler/dicompyler-core/blob/master/tests/testdata/example_data/rtdose.dcm
The error appears in version 0.1.5 of dicom_pixeldata whether or not I enable the gcmrs feature.

@Enet4 Enet4 added enhancement A-lib Area: library C-pixeldata Crate: dicom-pixeldata labels Jan 27, 2023
@Enet4
Copy link
Owner

Enet4 commented Jan 27, 2023

Thank you for reaching out!

The given RT dose image uses 32-bit pixel values, which is currently not supported by the DICOM-rs pixeldata crate. A known alternative to this is to fetch the pixel data manually from the object abstraction, but I would love to support this seamlessly though!
I will take this issue as a tracker for the functionality.

@Enet4 Enet4 changed the title Error while converting pixel data to ndarray or image Error while converting 32-bit pixel data to ndarray or image Jan 27, 2023
@arturocs
Copy link
Author

Thank you for your response. This function seems to work for my use case:

fn get_rtdose_pixel_data_as_ndarray(
    path: &str,
) -> Result<ndarray::Array3<u32>, Box<dyn std::error::Error>> {
    let obj = open_file(path)?;
    let pixel_data = obj.decode_pixel_data()?;
    let converted_data: Vec<_> = pixel_data
        .data()
        .chunks(4)
        .map(|i| u32::from_le_bytes([i[0], i[1], i[2], i[3]]))
        .collect();

    let ndarray = ndarray::Array3::from_shape_vec(
        [
            pixel_data.number_of_frames() as usize,
            pixel_data.rows() as usize,
            pixel_data.columns() as usize,
        ],
        converted_data,
    )?;
    Ok(ndarray)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lib Area: library C-pixeldata Crate: dicom-pixeldata enhancement
Projects
None yet
Development

No branches or pull requests

2 participants