I successfully changed a range of colors in an image to a single other color. I would like to make it more realistic by changing the colors to match the distribution of a swatch or, at the very least, a narrow band of random hues.
Some brown-looking grass
changed to very artificial green-looking grass
My code:
import cv2 as cv
import os
import numpy as np
import random
# Load the image and convert to HSV colourspace
image = cv.imread('brown_grass.jpg')
hsv=cv.cvtColor(image,cv.COLOR_BGR2HSV)
# Define lower and uppper limits of what we call "brown"
brown_lo=np.array([18,0,0])
brown_hi=np.array([28,255,255])
# Mask image to only select browns
mask=cv.inRange(hsv,brown_lo,brown_hi)
# Change image to green where we found brown
image[mask>0]=(74,183,125) # how do change it to a nice realistic texture swatch?
cv.imwrite('result.jpg',image)
(Thanks to I want to change the colors in image with python from specific color range to another color for the first part of the solution)