Can we expand an image?
We know that we can use seam carving to reduce the width of an image without deteriorating the interesting regions. So, naturally, we need to ask ourselves if we can expand an image without deteriorating the interesting regions. As it turns out, we can do it using the same logic. When we compute the seams, we just need to add a column instead of deleting one.
If we expand the image of the ducks naively, it will look something like this:
If we do it in a smarter way—that is, by using seam carving—it will look something like this:
As you can see, the width of the image has increased and the ducks don't look stretched. The following is the code to do it:
import sys import cv2 import numpy as np # Add a vertical seam to the image def add_vertical_seam(img, seam, num_iter): seam = seam + num_iter rows, cols = img.shape[:2] zero_col_mat = np.zeros((rows,1,3), dtype=np.uint8) img_extended = np.hstack((img, zero_col_mat)) for row in range(rows)...