0

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:

enter image description here

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")
Ann
  • 65
  • 1
  • 5
  • 1
    I don't understand fully what you tried here, but wouldn't it be the simplest solution to make a grayscale (with values between 0 and 1) version of the image and multiply it with the desired color? – some_name.py Jun 04 '21 at 12:28
  • You're a genius. It solved everything. Sorry I didn't explain what I meant with the texture brush and all. I am simulating a texture brush from the gif in this post https://stackoverflow.com/questions/49290951/creating-different-brush-patterns-in-c-sharp/49298313#49298313 it did work, except I couldn't change the color. – Ann Jun 04 '21 at 12:54
  • 1
    1. Convert from rgb to hsv. 2. Change Hue channel (cyclic padding add constant value). 3. Convert from hsv to rgb color space. – Alex Alex Jun 04 '21 at 13:14

0 Answers0