'image task in python with PIL

The program should load images from graphic files InputFile1 and InputFile2, for all pixels of the first image for which the corresponding pixels of the second image are black, replace in the first image all pixels to gray pixels with the same brightness

The brightness of a pixel is the sum of the components all three pixel components.

initial code:

import numpy as np
from PIL import Image

image1 = Image.open("./InputFile1.jpg")
image2 = Image.open("./InputFile2.jpg")
image_array1 = np.array(image1)
image_array2 = np.array(image2)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source