Repository navigation
fix(orientation): allocate matrix transform output with the input type (port of #602) - #661
Merged
Merged
Conversation
…e (port of #602) flipMatrix2D.h, flipMatrix2D.v and rotateMatrix902D always allocated a Uint8Array, so 16-bit input lost its high byte ([300, 513] -> [44, 1]). Allocate the output with the constructor of the input data. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🎉 This PR is included in version 1.0.0-beta.18 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
This PR is the 1.0 port of #602 from 0.x.
Summary
The 2D matrix transforms of
src/utilities/orientation/now keep the type of the input data. Before this fix, a 16-bit labelmap lost its high byte:[300, 513]became[44, 1](cornerstone3D#2961).Cause
flipMatrix2D.h,flipMatrix2D.vandrotateMatrix902Dalways allocated the output withnew Uint8Array(rows * cols). The functions then wrote each input value into thatUint8Array, and JavaScript kept only the low 8 bits of each value.Changes
src/utilities/orientation/flipMatrix2D.js:handvallocate the output withnew matrix.data.constructor(rows * cols).src/utilities/orientation/rotateMatrix902D.js: the function allocates the output withnew matrix.data.constructor(rows * cols).test/orientationMatrix2D.test.js(new): 4 tests, the same tests as fix(orientation): allocate matrix transform output with the input typed array type #602. Three tests check thath,vandrotateMatrix902DkeepUint16Arraydata and values. One control test checks thatUint8Arrayinput still gives aUint8Arrayresult.Callers
utilities.orientation.flipMatrix2Dandutilities.orientation.rotateMatrix902D. An external caller, for example Cornerstone3D, can give 16-bit data. The fix is for that caller.alignPixelDataWithSourceDatainsrc/adapters/Cornerstone/Segmentation_3X.jsandsrc/adapters/Cornerstone/Segmentation_4X.js. Each in-repo caller gives an ndarray on aUint8Arrayview of the SEG pixel data. Thus the in-repo callers get aUint8Arrayresult, as before. No in-repo caller gives 16-bit data, and no behavior changes for these callers.Uint8Arrayresult for non-Uint8Arrayinput.Verified
npx jest --runInBand test/orientationMatrix2D.test.jsgaveTests: 3 failed, 1 passed, 4 total. Each failure wasExpected: [Function Uint16Array],Received: [Function Uint8Array].npx jest --runInBand test/orientationMatrix2D.test.js test/adapters.test.js test/compat-052.test.jsgaveTest Suites: 3 passed, 3 total.pnpm run buildpassed. After the build,test/bundle-size.test.jspassed (7 of 7 tests). The PR did not change the bundle-size limits.eslintandprettier --checkpassed on the changed files.Not ported and why
src/utilities/orientation/. No package inpackages/*has a copy of the functions or calls the functions.🤖 Generated with Claude Code