-
Notifications
You must be signed in to change notification settings - Fork 453
Feat: Axis-based Image Stretching #2443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arul-trenser
wants to merge
18
commits into
cornerstonejs:main
Choose a base branch
from
arul-trenser:feat-axis-based-image-stretching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cb13f4f
feature for axis based stretching
arul-trenser 34696fa
fix unit tests
arul-trenser ccaf796
Normalize pan to remove effect of stretch
arul-trenser b0e7319
fix: radii calc
arul-trenser eea06d9
removed aspectRatio property in CPUFallbackViewport
arul-trenser e98f687
Added example for axialBasedImageStretching
arul-trenser 6e4f744
fixed build issue
arul-trenser 240a378
Review comments updated
arul-trenser e5dcbf2
Added aspectRatio property to viewport
arul-trenser 2570a00
updated getCenterAndRadiusInCanvas to use world and canvas point
arul-trenser 6dd83f8
Added documentation for tools
arul-trenser 700ecbf
Merge remote-tracking branch 'origin/main' into feat-axis-based-image…
wayfarer3130 920e348
Add aspect ratio testing for resize and calibration
wayfarer3130 5ad78bc
fix review comments
arul-trenser b778c4b
fixed the resize issue for aspectRatio
arul-trenser 1d22a40
Modified the getProjectionScaleIndices to getProjectScaleMatrix
arul-trenser 8f832ab
Fixed unit test
arul-trenser e31cc95
Merge branch 'cornerstonejs:main' into feat-axis-based-image-stretching
arul-trenser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
62 changes: 62 additions & 0 deletions
62
packages/core/src/RenderingEngine/helpers/getProjectionScaleIndices.ts
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { vec3 } from 'gl-matrix'; | ||
|
|
||
| const EPSILON = 1e-6; | ||
|
|
||
| /** | ||
| * Determine which projection-matrix indices to multiply for canvas X and Y scaling. | ||
| * For each anatomical axis stretch work as follows | ||
| * axial => stretch in anterior-posterior | ||
| * sagittal => stretch in superior-inferior | ||
| * coronal => stretch in superior-inferior | ||
| * @param {Array<number>} viewUp - [ux, uy, uz] camera viewUp (patient-space) | ||
| * @param {Array<number>} viewPlaneNormal - [dx, dy, dz] camera viewPlaneNormal (patient-space) | ||
| * @returns {{ idxX: number, idxY: number}} | ||
| */ | ||
| export function getProjectionScaleIndices(viewUp, viewPlaneNormal) { | ||
| const up = vec3.normalize(vec3.create(), viewUp); | ||
| const vpn = vec3.normalize(vec3.create(), viewPlaneNormal); | ||
|
|
||
| // Image axes in patient space | ||
| // Right-hand coordinate system: imageX = up × vpn | ||
| const imageX = vec3.create(); | ||
| vec3.cross(imageX, up, vpn); | ||
| if (vec3.length(imageX) < EPSILON) { | ||
| // Fallback: if up and vpn are nearly parallel, create an orthogonal axis | ||
| const tmp = | ||
| Math.abs(up[0]) < 1 / Math.sqrt(2) // Use 45 degree to find the nearest isometric axis | ||
| ? vec3.fromValues(1, 0, 0) | ||
| : vec3.fromValues(0, 1, 0); | ||
| vec3.cross(imageX, tmp, up); | ||
| } | ||
| vec3.normalize(imageX, imageX); | ||
| const imageY = up; | ||
|
|
||
| // Determine anatomical orientation (axial/sagittal/coronal) | ||
| const absVpn = [Math.abs(vpn[0]), Math.abs(vpn[1]), Math.abs(vpn[2])]; | ||
| let orientation = 'axial'; | ||
| if (absVpn[0] === Math.max(...absVpn)) { | ||
| orientation = 'sagittal'; | ||
| } else if (absVpn[1] === Math.max(...absVpn)) { | ||
| orientation = 'coronal'; | ||
| } | ||
|
|
||
| // Determine which anatomical axis to stretch | ||
| const AY = vec3.fromValues(0, 1, 0); // A-P | ||
| const AZ = vec3.fromValues(0, 0, 1); // S-I | ||
| const target = orientation === 'axial' ? AY : AZ; | ||
|
|
||
| // Which image axis (X or Y) aligns better with target? | ||
| const scoreX = Math.abs(vec3.dot(imageX, target)); | ||
| const scoreY = Math.abs(vec3.dot(imageY, target)); | ||
|
|
||
| // Choose projection-matrix diagonal indices | ||
| // 0 - scale X (horizontal) | ||
| // 5 - scale Y (vertical) | ||
| let [idxX, idxY] = [0, 5]; | ||
| // If target aligns with horizontal, swap so vertical scaling follows rotation | ||
| if (scoreX > scoreY) { | ||
| [idxX, idxY] = [5, 0]; | ||
| } | ||
|
|
||
| return { idxX, idxY }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.