From 97c21d5e62d00d32875f17727bbff4fb31a1059a Mon Sep 17 00:00:00 2001 From: CiscoTheWolf Date: Sun, 21 May 2023 23:28:03 +0200 Subject: [PATCH] comming for merge --- imageFader.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ rpi/roy-test.py | 2 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 imageFader.py diff --git a/imageFader.py b/imageFader.py new file mode 100644 index 0000000..07a9b1d --- /dev/null +++ b/imageFader.py @@ -0,0 +1,83 @@ +import numpy as np +import cv2 +from PIL import Image + +def image_interpolation(image1, image2, alpha): + # Ensure both images have the same size + assert image1.shape == image2.shape, "Input images must have the same shape" + + # Normalize the alpha value + alpha = max(0, min(1, alpha)) + + # Perform interpolation + interpolated_image = np.uint8((1 - alpha) * image1 + alpha * image2) + + return interpolated_image + +def pure_pil_alpha_to_color_v2(image, color=(0, 0, 0)): + image.load() # needed for split() + background = Image.new('RGB', image.size, color) + background.paste(image, mask=image.split()[3]) # 3 is the alpha channel + return background + +image = Image.open("ciscoTheProot/faces/prootface1.bmp") +image.thumbnail((128, 32), Image.ANTIALIAS) +RGBImage = pure_pil_alpha_to_color_v2(image) +image1 = np.array(RGBImage, dtype=np.uint8) + +image = Image.open("ciscoTheProot/faces/prootface2.bmp") +image.thumbnail((128, 32), Image.ANTIALIAS) +RGBImage = pure_pil_alpha_to_color_v2(image) +image2 = np.array(RGBImage, dtype=np.uint8) + +image = Image.open("ciscoTheProot/faces/prootface3.bmp") +image.thumbnail((128, 32), Image.ANTIALIAS) +RGBImage = pure_pil_alpha_to_color_v2(image) +image3 = np.array(RGBImage, dtype=np.uint8) + + +# Assuming you have image1 and image2 as input images + +# Interpolate with alpha = 0.5 +alpha = 0 +interpolated_image = image_interpolation(image2, image3, alpha) + +# Display the interpolated image +im_bgr = cv2.cvtColor(interpolated_image, cv2.COLOR_RGB2BGR) +cv2.imshow("Interpolated Image", im_bgr) +cv2.waitKey(0) + + +alpha = 0.2 +interpolated_image = image_interpolation(image2, image3, alpha) +im_bgr = cv2.cvtColor(interpolated_image, cv2.COLOR_RGB2BGR) +cv2.imshow("Interpolated Image", im_bgr) +cv2.waitKey(0) + + +alpha = 0.4 +interpolated_image = image_interpolation(image2, image3, alpha) +im_bgr = cv2.cvtColor(interpolated_image, cv2.COLOR_RGB2BGR) +cv2.imshow("Interpolated Image", im_bgr) +cv2.waitKey(0) + +alpha = 0.6 +interpolated_image = image_interpolation(image2, image3, alpha) +im_bgr = cv2.cvtColor(interpolated_image, cv2.COLOR_RGB2BGR) +cv2.imshow("Interpolated Image", im_bgr) +cv2.waitKey(0) + +alpha = 0.8 +interpolated_image = image_interpolation(image2, image3, alpha) +im_bgr = cv2.cvtColor(interpolated_image, cv2.COLOR_RGB2BGR) +cv2.imshow("Interpolated Image", im_bgr) +cv2.waitKey(0) + + +alpha = 1 +interpolated_image = image_interpolation(image2, image3, alpha) +im_bgr = cv2.cvtColor(interpolated_image, cv2.COLOR_RGB2BGR) +cv2.imshow("Interpolated Image", im_bgr) +cv2.waitKey(0) + +cv2.destroyAllWindows() \ No newline at end of file diff --git a/rpi/roy-test.py b/rpi/roy-test.py index f52af6a..eb18ff9 100644 --- a/rpi/roy-test.py +++ b/rpi/roy-test.py @@ -22,7 +22,7 @@ def pure_pil_alpha_to_color_v2(image, color=(0, 0, 0)): return background image = Image.open("../prootface.bmp") -image.thumbnail((128, 62), Image.ANTIALIAS) +image.thumbnail((128, 32), Image.ANTIALIAS) RGBImage = pure_pil_alpha_to_color_v2(image)