Skip to content

Commit

Permalink
Consider layer transform metadata when applying transform
Browse files Browse the repository at this point in the history
  • Loading branch information
jni committed Nov 26, 2023
1 parent ee19c12 commit 711f126
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/affinder/apply_tf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from magicgui import magic_factory
from skimage import transform
from napari.utils.transforms import CompositeAffine
import numpy as np


Expand Down Expand Up @@ -62,8 +63,24 @@ def apply_affine(
'Only image transforms supported at this point.'
)

reference_meta = CompositeAffine(
scale=reference_layer.scale,
translate=reference_layer.translate,
rotate=reference_layer.rotate,
shear=reference_layer.shear,
)
moving_meta = CompositeAffine(
scale=moving_layer.scale,
translate=moving_layer.translate,
rotate=moving_layer.rotate,
shear=moving_layer.shear,
)
# Find the transformation relative to the reference image
affine = np.linalg.inv(reference_layer.affine) @ moving_layer.affine
affine = (
np.linalg.inv(reference_meta)
@ np.linalg.inv(reference_layer.affine) @ moving_layer.affine
@ moving_meta
)

# Apply the transformation
transformed = _apply_affine_image(
Expand Down

0 comments on commit 711f126

Please sign in to comment.