Group Abstract Group Abstract

Message Boards Message Boards

Convert image from one color to another?

Posted 9 years ago

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.

enter image description here

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

POSTED BY: Bryan Lettner
6 Replies
POSTED BY: Vitaliy Kaurov
Posted 9 years ago

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

POSTED BY: Bryan Lettner

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]

enter image description here

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]]

enter image description here

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}]

enter image description here

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

Cheers,

M.

POSTED BY: Marco Thiel
pic = Import@
  "http://community.wolfram.com//c/portal/getImageAttachment?filename=\
multseg1-8combinedwithreflection250pixel.jpg&userId=167076";

Maybe it can be done quicker, don't know :)

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

enter image description here

POSTED BY: Kuba Podkalicki
Posted 9 years ago

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

POSTED BY: Bryan Lettner
Posted 9 years ago

Very helpful, Thank you Kuba!

POSTED BY: Bryan Lettner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard