Bird
Raised Fist0
Computer Visionml~20 mins

Homography and image alignment in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Homography Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does a homography matrix represent in image alignment?

In the context of aligning two images taken from different viewpoints, what does the homography matrix represent?

AA matrix that encodes the 3D depth information of the scene.
BA transformation that maps points from one image plane to another, assuming the scene is planar or the camera rotates around its optical center.
CA matrix that describes the color adjustment needed to match brightness between two images.
DA filter that removes noise from images before alignment.
Attempts:
2 left
💡 Hint

Think about how points in one flat image relate to points in another flat image when the camera moves.

Predict Output
intermediate
2:00remaining
Output of homography application on a point

Given the homography matrix H = [[1, 0, 2], [0, 1, 3], [0, 0, 1]] and a point p = [4, 5], what is the transformed point p' after applying the homography?

Computer Vision
import numpy as np
H = np.array([[1, 0, 2], [0, 1, 3], [0, 0, 1]])
p = np.array([4, 5, 1])
p_prime = H @ p
p_prime_cartesian = p_prime[:2] / p_prime[2]
print(p_prime_cartesian.tolist())
A[6.0, 8.0]
B[4.0, 5.0]
C[2.0, 3.0]
D[8.0, 10.0]
Attempts:
2 left
💡 Hint

Remember to convert from homogeneous coordinates back to Cartesian coordinates by dividing by the last element.

Hyperparameter
advanced
2:00remaining
Choosing the number of point correspondences for homography estimation

When estimating a homography matrix using point correspondences between two images, what is the minimum number of point pairs required, and why?

A4 pairs, because a homography has 8 degrees of freedom and each point provides two equations.
B3 pairs, because each point provides three equations for the homography.
C8 pairs, because the homography matrix has 8 elements to solve for.
D2 pairs, because each pair gives enough constraints for the transformation.
Attempts:
2 left
💡 Hint

Consider how many unknowns the homography matrix has and how many equations each point correspondence provides.

Metrics
advanced
2:00remaining
Evaluating homography quality with reprojection error

Which metric best measures the quality of a computed homography matrix when aligning two images?

AMean squared error of pixel intensities between the two images.
BNumber of matched keypoints detected.
CStructural similarity index (SSIM) between the images.
DAverage reprojection error between transformed points and their true correspondences.
Attempts:
2 left
💡 Hint

Think about how well the homography maps points from one image to the other.

🔧 Debug
expert
3:00remaining
Why does this homography estimation fail with RANSAC?

Consider this Python snippet using OpenCV to estimate a homography with RANSAC:

import cv2
import numpy as np
pts_src = np.array([[10, 20], [30, 40], [50, 60], [70, 80]])
pts_dst = np.array([[12, 22], [32, 42], [52, 62], [72, 82]])
h, mask = cv2.findHomography(pts_src, pts_dst, cv2.RANSAC, 5.0)
print(h)

The output is None. What is the most likely reason?

AThe points are perfectly aligned, so RANSAC returns None.
BThe threshold value 5.0 is too small for RANSAC to accept any inliers.
CThere are too few point correspondences; RANSAC requires more points to find a valid homography.
DThe input points are not in homogeneous coordinates, causing failure.
Attempts:
2 left
💡 Hint

Recall the minimum number of points needed for homography estimation and how RANSAC works.

Practice

(1/5)
1. What is the main purpose of computing a homography matrix in image alignment?
easy
A. To increase the brightness of an image
B. To detect edges in an image
C. To segment objects in an image
D. To find a transformation that maps points from one image to another

Solution

  1. Step 1: Understand homography concept

    Homography is a matrix that relates points between two images taken from different views.
  2. Step 2: Identify its use in image alignment

    It helps to map points from one image to corresponding points in another to align them.
  3. Final Answer:

    To find a transformation that maps points from one image to another -> Option D
  4. Quick Check:

    Homography = Point mapping [OK]
Hint: Homography maps points between images [OK]
Common Mistakes:
  • Confusing homography with edge detection
  • Thinking homography changes image brightness
  • Mixing homography with image segmentation
2. Which OpenCV function is used to compute the homography matrix from matched points?
easy
A. cv2.warpPerspective()
B. cv2.findHomography()
C. cv2.matchTemplate()
D. cv2.resize()

Solution

  1. Step 1: Identify function for homography calculation

    cv2.findHomography() computes the homography matrix from matched point sets.
  2. Step 2: Differentiate from other functions

    cv2.warpPerspective applies the homography, matchTemplate finds template matches, resize changes image size.
  3. Final Answer:

    cv2.findHomography() -> Option B
  4. Quick Check:

    Compute homography = findHomography [OK]
Hint: Find homography matrix with cv2.findHomography() [OK]
Common Mistakes:
  • Using warpPerspective to compute homography
  • Confusing template matching with homography calculation
  • Trying to resize image to get homography
3. Given the following code snippet, what will be the shape of aligned_img after applying homography?
import cv2
import numpy as np
img1 = cv2.imread('img1.jpg')
img2 = cv2.imread('img2.jpg')
pts1 = np.array([[10,10],[100,10],[100,100],[10,100]])
pts2 = np.array([[12,14],[102,12],[98,110],[14,108]])
H, _ = cv2.findHomography(pts1, pts2)
aligned_img = cv2.warpPerspective(img1, H, (img2.shape[1], img2.shape[0]))
medium
A. Same height and width as img1
B. Shape is (4, 2) because of points
C. Same height and width as img2
D. Shape depends on H matrix size

Solution

  1. Step 1: Understand warpPerspective parameters

    The third parameter in warpPerspective sets output image size as (width, height).
  2. Step 2: Check given size argument

    It uses (img2.shape[1], img2.shape[0]) which is width and height of img2.
  3. Final Answer:

    Same height and width as img2 -> Option C
  4. Quick Check:

    Output size = img2.shape [OK]
Hint: warpPerspective size param sets output image shape [OK]
Common Mistakes:
  • Assuming output shape matches img1
  • Thinking homography matrix size affects output shape
  • Confusing point arrays with image shape
4. You wrote this code to align two images but get a distorted output. What is the likely error?
H, status = cv2.findHomography(pts1, pts2)
aligned = cv2.warpPerspective(img1, pts1, (img2.shape[1], img2.shape[0]))
medium
A. Using pts1 instead of H in warpPerspective
B. Swapping pts1 and pts2 in findHomography
C. Not converting points to float32
D. Missing cv2.imshow to display image

Solution

  1. Step 1: Check warpPerspective arguments

    warpPerspective expects the homography matrix as the second argument, not point arrays.
  2. Step 2: Identify incorrect argument usage

    Code passes pts1 (points) instead of H (homography matrix), causing distortion.
  3. Final Answer:

    Using pts1 instead of H in warpPerspective -> Option A
  4. Quick Check:

    warpPerspective needs homography matrix [OK]
Hint: Pass homography matrix, not points, to warpPerspective [OK]
Common Mistakes:
  • Passing points instead of homography matrix
  • Swapping source and destination points in findHomography
  • Ignoring data type requirements for points
5. You want to stitch two images taken from different angles into a panorama. Which sequence of steps correctly uses homography for alignment?
hard
A. Detect keypoints -> Match points -> Compute homography -> Warp one image -> Blend images
B. Resize images -> Compute homography -> Detect edges -> Warp images -> Blend images
C. Match points -> Resize images -> Compute homography -> Warp images -> Detect keypoints
D. Warp images -> Detect keypoints -> Compute homography -> Match points -> Blend images

Solution

  1. Step 1: Detect and match keypoints

    First, find keypoints in both images and match them to get corresponding points.
  2. Step 2: Compute homography and warp image

    Use matched points to compute homography, then warp one image to align with the other.
  3. Step 3: Blend images to create panorama

    Finally, blend the aligned images smoothly to form a panorama.
  4. Final Answer:

    Detect keypoints -> Match points -> Compute homography -> Warp one image -> Blend images -> Option A
  5. Quick Check:

    Correct panorama steps = Detect keypoints -> Match points -> Compute homography -> Warp one image -> Blend images [OK]
Hint: Detect -> Match -> Compute -> Warp -> Blend for panorama [OK]
Common Mistakes:
  • Resizing images before matching points
  • Warping images before computing homography
  • Detecting keypoints after warping images