Convert image from one color to another?

I would like to convert an RGB image to a different color. I know how to convert to grayscale using ColorConvert, but I can’t figure out how to change it to a custom RGB color.

I’m assuming it’s fairly straightforward, and I’m just missing something. Thanks in advance.

pic = Import@
“http://community.wolfram.com//c/portal/getImageAttachment?filename=\
multseg1-8combinedwithreflection250pixel.jpg&userId=167076”;

Maybe it can be done quicker, don’t know :slight_smile:

Colorize[
   ColorConvert[pic, "GrayScale"], 
   ColorFunction -> (Blend[{Red, White}, #] &)
]

Hi Bryan,

I am not sure whether I can answer that question. In your image there are many different shades of colours. If you save that image in the variable “img” you get:

DominantColors[img, 10]

ScreenShot2016-04-20at10.05.23.png

I can of course use one of the colours and substitute it by another RGB colour:

ColorReplace[img, DominantColors[img][[-1]] -> RGBColor[1, 0, 0]]

If you have a large range of colours and you want to change them to different RGB combinations, you obviously need some kind of rule to convert all colours.

Image[ImageData[img] /. {r_, g_, b_} /; {r, b, g} != {1, 1, 1} -> 0.75 Norm[{r, g, b}]*{0.99, 0.9, 0.7}]

It’s probably not what you want, but might point in a direction.

Cheers,

M.

@Kuba Podkalicki and @Marco Thiel gave excellent answers. I’d like to make a short note. When you would like to change the color you basically asking for a function mapping from existing RGB channels’ values to new ones. The most general function that does it is ImageApply. Look through numerous examples there. You can apply function directly to the channels vector {R,G,B} or different or mixed functions of separate channels. My favorite example is selective-coloring or color-splashing. Imagine you have an image:

I will import it back in WL and convert everything to grayscale but the most striking red:

img = Import["https://wolfr.am/c6vProOq"];
ImageApply[If[#[[1]] > #[[2]] + #[[3]], #, ConstantArray[Mean[#], 3]] &, img]

Of course you can act on all channels simultaneously too, - and going back to summer:

ImageApply[RotateRight, img] 

Another neat way is color transfer, see docs:

Very helpful, Thank you Kuba!

Marco this is a great solution for me. Much appreciated!

Wow Vitaliy, great stuff. I’m going to be using all of the above techniques to post some wicked images soon!