homography module
Performs homography transformation on images.
This module provides a function for performing homography transformation on images. Homography is a technique used to map points from one image (source) to another image (destination) based on corresponding point locations. The homography is a linear mapping, so non-linear distortions in the image cannot be resolved by the homography alone.
The homography_transform function takes a source PIL image, corresponding source and destination point lists, and an original image size as input. It then:
Converts source and destination points to NumPy arrays.
Validates that both point lists have the same number of elements (and at least 4 points for homography calculation).
Converts the source PIL image to OpenCV format.
Calculates the homography matrix using cv2.findHomography.
Warps the source image to the destination perspective using cv2.warpPerspective.
Converts the resulting OpenCV image back to PIL format.
- image_registration.homography.homography_transform(src_image: Image, src_points: List[Tuple[float, float]], dest_points: List[Tuple[float, float]], original_image_size: Tuple[float, float] = (3300, 2250)) Image
Performs homography transformation on an image.
This function transforms an image (src_image) based on corresponding points between the source and destination images. It calculates the homography matrix and uses it to warp the source image to the perspective of the destination points.
- Parameters:
src_image (Image.Image) – A PIL image object representing the source image.
src_points (List[Tuple[int, int]]) – A list of tuples (x, y) representing points in the source image that correspond to points in the destination image.
dest_points (List[Tuple[int, int]]) – A list of tuples (x, y) representing points in the destination image that points in the source image correspond to (where the source image should be warped to).
original_image_size (Tuple[float, float]) – A tuple (width, height) representing the size of the control image. Defaults to (3300, 2250).
- Returns:
A PIL image object representing the transformed source image.
- Raises:
ValueError – If the length of src_points and dest_points don’t match (must have the same number of corresponding points), or if there are less than 4 points.