# How to replace color in an image without changing its texture/shades or brightness?

I want to replace color in an image from another color: For that sample image is below

I want to replace color such that it becomes

I know it can be easily done in Photoshop but I am looking for an algorithm which can replace a particular region color with another color but texture and shades should be preserved. These image are only for example.

I have tried changing hue and maintaining saturation and brightness but it fails when I try to change image to white/Black and nearby colors

<style>
img{
-webkit-filter: hue-rotate(120deg);
}
</style>

• Welcome to DSP.SE! Can you post some images that show examples of how it fails? That might give us some insight into what else to suggest. – Peter K. Apr 4 '16 at 13:37
• You can post your first code to get more answer. – Darleison Rodrigues Apr 4 '16 at 21:44
• @OlliNiemitalo : Thanks! I thought he needed rep to post ANY images. Didn't realize there's a limit of two. – Peter K. Apr 6 '16 at 12:04
• you can look here: google.com/… – Rosa Gronchi May 1 '16 at 18:37