Download src/anaglyph_converter.py from nnibras/LAB4: direct link, hf CLI and curl.
- Browser
- Download file 803 Bytes
-
https://huggingface.co/spaces/nnibras/LAB4/resolve/main/src/anaglyph_converter.py
- Command line
-
hf download hf://spaces/nnibras/LAB4/src/anaglyph_converter.py
-
curl -L -o anaglyph_converter.py https://huggingface.co/spaces/nnibras/LAB4/resolve/main/src/anaglyph_converter.py
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 | |