LAB4 / src /anaglyph_converter.py
nnibras's picture
Upload 17 files
6aab31e verified
raw
history blame contribute delete
803 Bytes
import cv2
import numpy as np
def create_anaglyph(left_image, right_image):
# Ensure both images have the same dimensions
height, width = left_image.shape[:2]
right_image_resized = cv2.resize(right_image, (width, height))
# Extract the red channel from the left image and green-blue channels from the resized right image
left_red = left_image[:, :, 2] # Red channel from left image
right_green_blue = right_image_resized[
:, :, :2
] # Green and blue channels from right image
# Combine channels into a single anaglyph image
anaglyph = np.zeros_like(left_image)
anaglyph[:, :, 2] = left_red # Red channel from left image
anaglyph[:, :, :2] = right_green_blue # Green and blue channels from right image
return anaglyph