4
$\begingroup$

I have a binarized image and would like to set pixel values which are 1 to a certain (any) color picked from ColorData["TemperatureMap"] and 0 to another color of "TemperatureMap".

How can I do that?

my image

Thanks in advance. Milenko

$\endgroup$
6
$\begingroup$

Update: Using EventHandler and TemperatureMap:

image = Import["http://i.stack.imgur.com/qmKND.png"];

DynamicModule[{col = Green}, 
 EventHandler[Column[{ColorData["TemperatureMap", "Image"], 
    Dynamic@Colorize[image, ColorRules -> {0 -> White, 1 -> col}, ImageSize -> 300]}], 
    {"MouseClicked" :> 
     (col = ColorData["TemperatureMap"][First[MousePosition["Graphics"]]])}, 
  PassEventsDown -> Automatic, PassEventsUp -> True]]

enter image description here

Update 2: Select background color using right-mouse-click:

DynamicModule[{col1 = Green, col2 = White}, 
 EventHandler[Column[{ColorData["TemperatureMap", "Image"], 
    Dynamic@Colorize[image, ColorRules -> {0 -> col2, 1 -> col1},ImageSize -> 300]}], 
 {{"MouseClicked", 1} :> 
  (col1 = ColorData["TemperatureMap"][First[MousePosition["Graphics"]]]),
  {"MouseClicked", 2} :> 
  (col2 = ColorData["TemperatureMap"][First[MousePosition["Graphics"]]])}, 
   PassEventsDown -> Automatic, PassEventsUp -> True]]

enter image description here

Update 3:

I want to pick up a special color from the color table "without GUI" and set all intensities of 1 with this color ...

col1 = ColorData["SunsetColors"][.7];
col2 = ColorData["SunsetColors"][.1]; 
Colorize[image,  ColorRules -> {0 -> col2, 1 -> col1}, ImageSize -> 300]

enter image description here


Original answer:

image = Import["http://i.stack.imgur.com/qmKND.png"];
Column[{ColorSetter[Dynamic[x]], 
      Dynamic@Colorize[MorphologicalComponents@image, ColorRules -> {0 -> White, _ :> x}]}]

enter image description here

Clicking on the ColorSetter button invokes color selection dialog:

enter image description here

After selecting a color, the colors in the image are updated:

enter image description here

$\endgroup$
  • $\begingroup$ This is great ;-) But how is it if I wish to select a special color from the color table with GUI interaction. For example each color should represent a certain depth information of the 2d image and I want to do that automatically. $\endgroup$ – mrz Dec 8 '14 at 10:41
  • 1
    $\begingroup$ @MilenkoRubin-Zuzic, this sounds like a good candidate for a new question. $\endgroup$ – kglr Dec 8 '14 at 11:10
  • $\begingroup$ Dear kguler, I meant: I want to pick up a special color from the color table "without GUI" and set all intensities of 1 with this color ... is that possible? $\endgroup$ – mrz Dec 8 '14 at 12:14
  • $\begingroup$ @Milenko, something like col1 = ColorData["TemperatureMap"][.2]; col2 = ColorData["TemperatureMap"][.6]; Colorize[image, ColorRules -> {0 -> col2, 1 -> col1}, ImageSize -> 300]? $\endgroup$ – kglr Dec 8 '14 at 12:42
  • $\begingroup$ Great ... thanks a lot $\endgroup$ – mrz Dec 8 '14 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.