miop.rectification¶
Classes
Performs stereo image rectification based on affine fundamental matrices. |
- class miop.rectification.Rectification[source]¶
Bases:
DAGNodePerforms stereo image rectification based on affine fundamental matrices.
This class computes rectifying transformations (similarity or rigid), applies them to stereo image pairs, and returns rectified image pairs along with transformation matrices.
- rectification_transforms¶
List of transformation matrices for each image pair. Each dict contains ‘T1’, ‘T2’, and ‘Ht’.
- Type:
list of dict
- rectified_pairs¶
List of rectified image pairs, each as a 2-element NumPy array of images.
- Type:
list of np.ndarray
- eval(epipolar_sets, img_collection)[source]¶
Applies rectifying transformations to each stereo image pair in a dataset.
- Parameters:
epipolar_sets (list of dict) – Each dict contains at least a fundamental matrix under key ‘F’.
img_collection (object) – Object that holds image pairs in the pairs attribute. Each pair is a 2-tuple of image objects with .image fields.
- Returns:
A tuple of:
- rectification_transformslist of dict
Each dict contains matrices ‘T1’, ‘T2’, and ‘Ht’ (post-translation).
- rectified_pairslist of np.ndarray
Each element is an array of two rectified images.
- Return type:
tuple
- homogenize(m)[source]¶
Converts 2D point coordinates to homogeneous coordinates.
- Parameters:
m (np.ndarray) – 2D coordinates, shape (n, 2) or (2, n)
- Returns:
Homogeneous coordinates, shape (n, 3) or (3, n) to match input format.
- Return type:
np.ndarray
- rectifying_rigid_transformations(F, pts1, pts2)[source]¶
Computes rigid rectifying transformations from an affine F and matched points.
- Parameters:
F (np.ndarray) – 3x3 affine fundamental matrix.
pts1 (np.ndarray) – 3xn homogeneous point array from image 1.
pts2 (np.ndarray) – 3xn homogeneous point array from image 2.
- Returns:
- S1, S2np.ndarray
Rigid rectifying transformation matrices for the two images.
- Return type:
tuple
- Raises:
AssertionError – If F is not affine or not rank 2.
Exception – If rotation matrix signs cannot be resolved.
- rectifying_similarities(F)[source]¶
Computes rectifying similarity transforms from an affine fundamental matrix.
Based on Shimshoni’s geometric interpretation of weak-perspective motion.
- Parameters:
F (np.ndarray) – 3x3 affine fundamental matrix.
- Returns:
- S1, S2np.ndarray
Similarity transformations for image 1 and image 2.
- Return type:
tuple
- Raises:
AssertionError – If F is not affine or not rank 2 or not 3x3.
- transform_2D(pts, H)[source]¶
Applies a homography to 2D homogeneous points.
- Parameters:
pts (np.ndarray) – Homogeneous 2D points (3, n).
H (np.ndarray) – Homography matrix (3, 3).
- Returns:
Transformed 2D points (2, n).
- Return type:
np.ndarray
- transform_images(H1, H2, img1, img2)[source]¶
Applies given homographies to images and aligns them using a shared bounding box.
- Parameters:
H1 (np.ndarray) – 3x3 homography for image 1.
H2 (np.ndarray) – 3x3 homography for image 2.
img1 (np.ndarray) – Original image 1.
img2 (np.ndarray) – Original image 2.
- Returns:
- rectified_img1, rectified_img2np.ndarray
Warped images.
- Htnp.ndarray
Translation matrix used to shift both images into shared frame.
- Return type:
tuple
- transform_matches(pts1, pts2, H1, H2)[source]¶
Applies rectifying homographies to matched keypoints.
- Parameters:
pts1 (np.ndarray) – Matched keypoints from image 1, shape (n, 2).
pts2 (np.ndarray) – Matched keypoints from image 2, shape (n, 2).
H1 (np.ndarray) – Homography for image 1.
H2 (np.ndarray) – Homography for image 2.
- Returns:
- pts1r, pts2rnp.ndarray
Rectified keypoints in both images, shape (n, 3).
- Return type:
tuple