Professional Documents
Culture Documents
HOMEWORK – 1
Laplacian Blending:
We begin by dividing the two input images, the apple and the orange, into separate channels
using a mask. Next, we apply blending techniques to each channel individually. To enhance the
blending effect, we create a Gaussian pyramid for the mask and a Laplacian pyramid for the
images. These pyramids are then combined and downsized to generate the final blended
image. The fundamental idea is that in order to create pyramids and then seamlessly combine
two separate images into one, we must employ Gaussian (low pass) and Laplacian (high pass)
filters.
By utilizing the provided Apple, Orange, and Mask images and applying the algorithm, I have
obtained the blended image.
OUTPUT:
Also, I have tried on some images with two different colors where the results are pretty
inconsistent in most cases. As colors in the image are completely different in each other.
Code used for implementation:
#install and import the libraries
import numpy as np
import scipy.signal as sig
from scipy import misc
import matplotlib.pyplot as plt
from scipy import ndimage
import cv2
import imageio
from google.colab.patches import cv2_imshow
# Copy the pixels from the original image to alternate pixels in the new
image
image_upscale[::2, ::2] = image
# Reconstruct the pyramids as well as upsampling and adding up with each level
def reconstruct_image(pyramid):
# Reconstruct the image from the Laplacian pyramid
rows, cols = pyramid[0].shape
res = np.zeros((rows, cols + cols // 2), dtype=np.double)
reversed_pyramid = pyramid[::-1]
stack = reversed_pyramid[0]
for i in range(1, len(reversed_pyramid)):
# Upsample the previous level and add it to the current level
stack_upsampled = upsample_image(stack)
stack_upsampled_cropped =
stack_upsampled[:reversed_pyramid[i].shape[0], :reversed_pyramid[i].shape[1]]
stack = stack_upsampled_cropped + reversed_pyramid[i]
return stack
# Check dimensions
if img1_r.shape != img2_r.shape or img1_r.shape != mask_r.shape:
raise ValueError("Input image and mask dimensions do not match.")
# Perform pyramid blending on each color channel
R = reconstruct_image(pyramid_blending(img1_r, img2_r, mask))
G = reconstruct_image(pyramid_blending(img1_g, img2_g, mask))
B = reconstruct_image(pyramid_blending(img1_b, img2_b, mask))
References:
https://www.w3schools.com/python/
https://docs.opencv.org/4.x/dc/dff/tutorial_py_pyramids.html
http://persci.mit.edu/pub_pdfs/RCA84.pdf
http://graphics.cs.cmu.edu/courses/15463/2005_fall/www/Lectures/
Pyramids.pdf