I have this image:
And I would like to change the group of pixels(greem colour) between or in contact with red and yellow pixels, by red color, this way:
Sorry, I don't have any one code, because I don't know how to start this, and I did not find an approach to do this. I think a similar logic related to PIL
, like this:
import numpy as np
from PIL import Image
im = Image.open('image.png')
data = np.array(im)
r1, g1, b1 = 255, 255, 255 # Original value
r2, g2, b2 = 0, 0, 0 # Value that we want to replace it with
red, green, blue = data[:,:,0], data[:,:,1], data[:,:,2]
mask = (red == r1) & (green == g1) & (blue == b1)
data[:,:,:3][mask] = [r2, g2, b2]
im = Image.fromarray(data)
But with a condition.
CodePudding user response:
We may start the solution by using
The above solution is not the most general solution.
There is also an option to find all the green contours, create a mask of the contours perimeter, and analyze the colors of the perimeter of each contour (and fill contours with mixed perimeter colors with red color).