Enet4 / dicom-rs

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

toimage command line utility error - panics on LUT value processing #346

Closed MountainAndMorning closed 1 year ago

MountainAndMorning commented 1 year ago

I try to use the toimage command line utility with the attached dicom file but get the error below:

(base) liangwanyou@liangwanyoudeMacBook-Air toimage % cargo run /Users/liangwanyou/Desktop/d/1.2.840.113704.7.1.1.8340.1491789704.637.dcm
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `/Users/liangwanyou/Downloads/dicom-rs-master/target/debug/dicom-toimage /Users/liangwanyou/Desktop/d/1.2.840.113704.7.1.1.8340.1491789704.637.dcm`
thread '<unnamed>' panicked at 'assertion failed: (index as usize) < self.table.len()', pixeldata/src/lut.rs:300:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'assertion failed: (index as usize) < self.table.len()', pixeldata/src/lut.rs:300:9
thread '<unnamed>' panicked at 'assertion failed: (index as usize) < self.table.len()', pixeldata/src/lut.rs:300:9
thread '<unnamed>' panicked at 'assertion failed: (index as usize) < self.table.len()', pixeldata/src/lut.rs:300:9
thread '<unnamed>thread '' panicked at '<unnamed>assertion failed: (index as usize) < self.table.len()' panicked at '', assertion failed: (index as usize) < self.table.len()pixeldata/src/lut.rs', :pixeldata/src/lut.rs300::3009:
9
.
.
.
thread '<unnamed>' panicked at 'assertion failed: (index as usize) < self.table.len()', pixeldata/src/lut.rs:300:9
thread '<unnamed>' panicked at 'assertion failed: (index as usize) < self.table.len()', pixeldata/src/lut.rs:300:9
(base) liangwanyou@liangwanyoudeMacBook-Air toimage % 

1.2.840.113704.7.1.1.8340.1491789704.637.dcm.zip

Enet4 commented 1 year ago

Thank you very much for reporting this bug, @MountainAndMorning! This was caused by the file's Pixel Data filling in the pixel data values beyond the bits effectively reserved for imaging data (bits stored is 12 in the example, but the 4 high bits would occasionally be set to 1). This is technically allowed, according to the standard, but was not always considered here. I have just patched this in #347.

MountainAndMorning commented 1 year ago

Thanks for your help. I have another stupid question. How can I update dicom-rs to this patched version.

Enet4 commented 1 year ago

How can I update dicom-rs to this patched version.

You can temporarily specify the dependency as coming from the git branch containing the patch. I might work on publishing the patch later at some point.

[dependencies]
dicom_pixeldata = { git = "https://github.com/Enet4/dicom-rs.git", branch = "bug/346" }

A note of warning though, there are some breaking changes from past merged contributions.

MountainAndMorning commented 1 year ago

Great! Thank you very much.