fix(dicom): match the volume buffer to the decoded pixel values - #934
Merged
Conversation
✅ Deploy Preview for volview-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
The volume buffer's element type was derived from the first instance's stored range put through its rescale, floored and ceiled to integers. ITK applies the rescale while decoding and picks the output type from it: an integral slope and intercept keep an integer type, anything fractional produces float64. A fractional rescale whose endpoints landed on integers got an integer buffer, and every fraction was dropped on write. An integral range past 32 bits threw at allocation. A later instance decoding outside the first instance's type wrote through TypedArray.set with no error, wrapping every value the type cannot hold. Allocate for the union of every instance's declared range, choosing Float64Array whenever the slope or intercept is fractional or the range is not a safe 32-bit integer range, and the narrowest integer type otherwise. Ordinary CT and MR allocation is unchanged. An instance whose tags give no finite range is left out of the union and judged on its decoded values. Check each chunk after it decodes and before it is written. Its actual range must fit the buffer's element type, and float output bound for an integer buffer must be whole numbers. Both rejections name the file, the values it decoded to, and the buffer it has to fit. Only decoder output that disagrees with the tags can fail these checks. Reproduced with a public DSC perfusion series whose slope is 112067.85375182 over 16-bit unsigned storage.
PaulHax
force-pushed
the
dicom-volume-buffer
branch
from
September 4, 2026 22:18
12b54f7 to
9dfd670
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
VolView allocates one typed array for the whole DICOM volume. The old allocator chose that array from the first file's metadata, but ITK decodes pixels after applying each file's rescale. The declared storage type and the decoded values can differ.
That caused three failures:
Loading flow
Choosing the volume buffer
The allocator now uses the union of the ranges declared by every usable file.
Float64Array.Float64Array.Checking decoded pixels
Before copying a decoded chunk, VolView checks the actual values returned by ITK.
Tradeoffs
Tests
Coverage includes fractional and negative rescale, mixed bit depths, ranges beyond 32 bits, missing metadata, decoded values that disagree with metadata, the public DSC slope case, and a browser test using generated DICOM files.