Enet4 / dicom-rs

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

[pixeldata] to_vec() and to_ndarray() broken for 16bit #243

Closed mike-kfed closed 2 years ago

mike-kfed commented 2 years ago

Hi, I just found that calling DecodedPixelData::to_vec() doesn't give me real u16 values when the resolution is 16bit. The reason is that a LUT is applied by default, and this LUT seems to be done for 8bit only even though there is a separate 16bit match-arm:

https://docs.rs/dicom-pixeldata/0.1.0/src/dicom_pixeldata/lib.rs.html#1174

since to_ndarray() calls to_vec() same problem applies. plus the docs of to_ndarray() do not mention that the LUT is applied by default.

my current workaround: use options to disable the LUT, pseudocode:

img.to_vec_with_options(&ConvertOptions {
    modality_lut: None, ..Default::default() });
Enet4 commented 2 years ago

Thank you for reporting. Indeed, I managed to reproduce these issues just now. Will try to build a patch soon.

It's also true that to_ndarray should document its default behavior, this was probably overlooked (although this is mentioned in a few other places).

mike-kfed commented 2 years ago

wow, thanks for the fast response! looking forward to the new release