[DAR-5370][External] Axially-agnostic pixdim
scaling on import for medical files that require it
#991
+257
−73
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.
Problem
Annotations outside the platform are represented in "pixel space". This is a measurement independent of real-world distance where 1 pixel maps to 1 pixel. Most annotations in-platform are also represented in pixel space, except those created on post-
MED_2D_VIEWER
medical files. Why?These files are represented on a stretched workview canvas in "mm space". This means instead of measuring annotation coordinates in terms of pixel values, they are represented in millimetres
Given a
pixdim
mapping, you can transform coordinates between pixel space and mm space.pixdim
is an n-dimensional array that represents how many millimetres are represented by a single pixel for each axis. For example,pixdim = [0.5, 0.25, 1]
means:x
axis represents0.5
mm of physical distancey
axis represents0.25
mm of physical distancez
axis represents1
mm of physical distanceThen:
x
andy
coordinate by thepixdim
value aligned with the appropriate axisx
andy
coordinate by thepixdim
value aligned with the appropriate axisWhy is this a problem? Importing and exporting. Given that when importing and exporting non-
NifTI
annotations, we do not perform any scaling under any circumstance, consider the following 2 scenarios:pixdim
values other than1
, the coordinates of the exported annotations will not match the pixel space of the originally uploaded filepixdim
values other than1
, they will not be aligned with the canvas's mm space expectationsProblem 1 is being addressed in DAR-5339 and will be released to backend at the same time this ticket is. It will apply a mm space to pixel space transformation for all non-
NifTI
mm space annotations upon exportProblem 2 is addressed by this PR
Solution
This PR introduces scaling of non-
NifTI
annotations upon import as follows:NifTI
scaling method if importingNifTI
annotations. These are medical files that have been uploaded with theMED_2D_VIEWER
feature flag disabled (notmonai
handler)MED_2D_VIEWER
feature flag enabled (monai
handler)pixdim
values associated with the axis of acquisition of the target remote fileNifTI
annotations are not considered because theNifTI
importer already performspixdim
scaling, so we don't want to apply it twiceNote that 2a is a re-write of a previously existing feature. We did this re-write to reduce the load it was exerting on our list
/items
API. Previously, it would list every file in the dataset and then filter. Now, it polls/items
only for the files that are targeted by the importChangelog
Introduced automatic transformation from pixel space to mm space when importing annotations to medical files that require it. i.e. those that have been processed with
MED_2D_VIEWER