I am working on a drawing app, and I want to implement some texture brushes. If my user picks a texture (which is an image) and picks a color, I want to be able to change that image's color. For example this image:
Has the main color rgb(235,63,108) (this one shade I thought appears mostly), and the user wants to paint with cyan, rgb(0,255,255). How do I change the rest of the shades of pink into different shades of cyan based on that? I don't want the resulting picture to be a single-colored image. I tried to calculate a scale by dividing the rgb values between themselves, and multiply all pixels in the pink image with the scale. It doesn't work.
orig_col = np.array(self.hiddenArea.texture_cols[idx-1]) #(235,63,108), pink image
input_image = np.asarray(img.open("./resources/textures/brush"+str(idx)+".png", formats=None)) #pink image
image_array = input_image[:,:,:-1]
alpha = input_image[:,:,-1:]
print(image_array.shape)
myCol = self.hiddenArea.myPenColor #the cyan picked by user
my_blue = myCol.blue()
my_red = myCol.red()
my_green = myCol.green()
myCol = np.array([my_red, my_green, my_blue])
scale = myCol / orig_col
print(scale)
transformed = np.zeros(image_array.shape)
for i in range(len(image_array)):
for j in range(len(image_array[0])):
transformed[i][j][0] = image_array[i][j][0] * scale[0]
transformed[i][j][1] = image_array[i][j][1] * scale[1]
transformed[i][j][2] = image_array[i][j][2] * scale[2]
transformed = np.concatenate((transformed, alpha), axis=2)
print(transformed.shape)
print(transformed)
output_image = img.fromarray(transformed.astype(np.uint8))
output_image.save("output.png")