Source code for miop.image_helper.image_pair

# Copyright (c) 2025, Maxime Paschoud.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
# (http://opensource.org/licenses/BSD-3-Clause)
#
# __author__ = "Maxime Paschoud, ETHZ: CMBM"
#

from .image import Image
import numpy as np
from .geometry import get_rotation_matrix

[docs] class ImagePair: def __init__(self, img1: Image, img2: Image, tilt_axis): self.img1 = img1 self.img2 = img2 self.tilt_diff = img2.tilt - img1.tilt self.tilt_axis = tilt_axis if img1.tilt_rad != img2.tilt_rad: raise ValueError('one image has tilt in rad the other not') else: self.tilt_rad = img1.tilt_rad def __getitem__(self, index): if index == 0: return self.img1 elif index == 1: return self.img2 else: raise IndexError('Index for a pair should be 0 or 1')
[docs] def rotate(self, angle, rad=False): if self.tilt_axis is None: raise AttributeError('tilt_axis is None for this image pair.') self.img1.rotate(angle) self.img2.rotate(angle) self.tilt_axis = self.tilt_axis @ get_rotation_matrix([0.,0,1], angle, rad=rad).T
[docs] def rotate_by_transpose(self): self.img1.rotate_by_transpose() self.img2.rotate_by_transpose() self.tilt_axis = self.tilt_axis @ get_rotation_matrix([0.,0,1], 90, rad=False).T