# CS5330 Lab 4 # This file includes functions for creating an anaglyph image from PIL import Image from segmentation import extract_person from insert import insert_person_in_pair from insert import Background from insert import Disparity # Create an anaglyph image def create_anaglyph(left_image, right_image): # Ensure both images are in 'RGB' mode left_image = left_image.convert('RGB') right_image = right_image.convert('RGB') # Separate the color channels for both images left_red, left_green, left_blue = left_image.split() right_red, right_green, right_blue = right_image.split() # Create a new image with the red channel from the left image, # and green and blue channels from the right image anaglyph_image = Image.merge("RGB", (left_red, right_green, right_blue)) return anaglyph_image # ==========Test case========== # person_image = extract_person(Image.open('test_img/mona_lisa.jpg')) # left, right = insert_person_in_pair( # background=Background.NATURE, # person=person_image, # disparity=Disparity.MED # ) # anaglyph_image = create_anaglyph(left, right) # anaglyph_image.show()