I would like to take an original image and fade it towards the color white. I should be able to control the amount of which the image is faded using a variable. How can I achieve this?
Example:
Original Image:
Faded Image:
You can assume that the faded image in the example is faded 75% towards the color white
What I have tried: Based on Mark Meyer solution on How to fade color, I tried to convert my image in NumPy array and tried to change the value of each pixel (fading each pixel). However, it didn't go well.
This is what I get as an output image:
Code:
import numpy as np
from PIL import Image
from matplotlib.image import imread
# Converting image to numpy array
data = imread("image.png")
# numpy array of white pixel
white = np.array([255, 255, 255])
vector = white-data
# percentage of 0.0 will return the same color and 1.0 will return white
percent = 0.5
# fading image
value = data + vector * percent
# saving faded image
img = Image.fromarray(value, 'RGB')
img.save('my.png')