Fix lossless decoding of point transformed and interleaved multi component scans - #25
Open
daker wants to merge 1 commit into
Open
Fix lossless decoding of point transformed and interleaved multi component scans#25daker wants to merge 1 commit into
daker wants to merge 1 commit into
Conversation
Author
|
@rii-mango hi, can you look at the proposed fix ? |
…onent scans ScanHeader parses Al out of the SOS header and nothing ever read it, so scans encoded with a point transform decoded wrong in two ways. T.81 H.1.2.1 seeds the prediction for the first sample of a scan with 2^(P - Pt - 1), not 2^(P - 1). Lossless prediction chains additively, so a wrong seed offsets every sample in the frame: a 16 bit scan with Al = 2 came out 24576 high. The encoder also right shifted every sample by Al before encoding (T.81 A.4.1), so the decoder has to shift them back. Without it the frame keeps 1/2^Al of its dynamic range. The shift runs once the whole frame is decoded rather than in setValue, because prediction reads previously decoded samples back out of outputData and those reads have to stay in the point transformed domain. Fixes cornerstonejs/cornerstone3D#757 Fixes cornerstonejs/cornerstone3D#1116
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.
ScanHeader parses Al out of the SOS header and nothing ever read it, so scans encoded with a point transform decoded wrong in two ways.
T.81 H.1.2.1 seeds the prediction for the first sample of a scan with 2^(P - Pt - 1), not 2^(P - 1). Lossless prediction chains additively, so a wrong seed offsets every sample in the frame: a 16 bit scan with Al = 2 came out 24576 high.
The encoder also right shifted every sample by Al before encoding (T.81 A.4.1), so the decoder has to shift them back. Without it the frame keeps 1/2^Al of its dynamic range.
The shift runs once the whole frame is decoded rather than in setValue, because prediction reads previously decoded samples back out of outputData and those reads have to stay in the point transformed domain.
Fixes cornerstonejs/cornerstone3D#757
Fixes cornerstonejs/cornerstone3D#1116