Why this mask layer does not mask image.
import matplotlib.image as mpimg
import numpy
path = 'inp.jpg'
arr = numpy.array(Image.open(path))
img = mpimg.imread(path)
black_pixels_mask = np.all(img == [0, 0, 0], axis=-1)
img[black_pixels_mask] = [255,255,255]
The result img should be the masked one.and the code should replace black to white. Just as a sample colour.
CodePudding user response:
Try this code
arr[numpy.all(arr == [0, 0, 0], axis=-1)]=[255,255,255]
data = Image.fromarray(arr)
data.save(path)