v9.1.1
Menu

Panorama Canvas Size

mediumPROPanoramasStitchingCV: Image Alignment and Stitching

Implement a function to calculate the required canvas size for a panorama given multiple images with their respective dimensions and positions. The goal is to determine the minimum canvas size that can accommodate all images without any overlap or truncation.

To achieve this, we need to understand the concept of image alignment and how images are positioned within a panorama. Each image has a width ww, height hh, and a horizontal offset xoffx_{off}, which represents the x-coordinate of the left edge of the image in the panorama's coordinate system. The total width of the canvas is determined by the rightmost edge of any image, which can be calculated as xoff+wx_{off} + w. The total height of the canvas is simply the maximum height among all images, denoted as max(h)max(h).

Here are the steps to calculate the canvas size:

  1. Initialize variables to store the maximum rightmost edge and maximum height.
  2. Iterate through each image and calculate its rightmost edge.
  3. Update the maximum rightmost edge and maximum height if necessary.
max_right=max(xoff+w)max\_right = max(x_{off} + w) max_height=max(h)max\_height = max(h)

This technique is widely used in image stitching applications to create seamless panoramas.

Example

Input
images = [(100, 50, 0), (100, 50, 80), (100, 50, 160)]
Output
(260, 50)
Reasoning

Analyzing each image:

Image 1: width=100, height=50, x_offset=0

  • Right edge: 0 + 100 = 100

Image 2: width=100, height=50, x_offset=80

  • Right edge: 80 + 100 = 180
  • Overlaps with Image 1 by 20 pixels

Image 3: width=100, height=50, x_offset=160

  • Right edge: 160 + 100 = 260
  • Overlaps with Image 2 by 20 pixels

Canvas dimensions:

  • Width = max right edge = 260
  • Height = max height = 50

Result: (260, 50)

Constraints

  • images: list of (width, height, x_offset) tuples
  • All x_offsets are non-negative
  • Return (total_width, max_height) tuple

Learn this in

More from CV: Image Alignment and Stitching

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.