user1255409
user1255409

Reputation: 123

Change Color For Parts of an Image

I am trying find a solution that would allow me change color for parts of an image.

For example lets say a picture of a chair. A chair can have different frame or cushion colors. I intend to let users select a frame or cushion and update the image. We can only upload one chair image.

Any idea is much appreciated!

Upvotes: 3

Views: 1001

Answers (1)

Lukasz M
Lukasz M

Reputation: 5723

Detecting parts of the image to be modified

Detecting objects on images programatically is probably not the simplet thing to do ;). I suppose one of the good solutions to this problem was suggested by Collin O'Dell in his comment to the question. He suggested to use few images with manually separated parts of the image you want to recolor. Then, you can compose the final image from few different layers.

However, you can also keep the main image with all the objects and manually make some additional images, but only to keep masks of the objects (i.e. white pixels in places where the object is). You can then easily check which pixels should be recolored. This would allow you to paint directly on one image and avoid compositing.

Calculating the color

When you want to recolor the photograph, you probably want to be able to keep the shading effects etc. rather than covering all with the same solid color. In order to achieve this, you can use HSV color space instead of RGB. To use this method you should:

  • read pixel's color (in RGB)
  • recalculate it to HSV
  • change Hue value of the color to get the desired color shade
  • recaluclate modified color back to RGB
  • set the new color of the pixel

For more information about HSV color space you can look here: http://en.wikipedia.org/wiki/HSL_and_HSV.

Upvotes: 1

Related Questions