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$

1 Answer 1

7
$\begingroup$

Update: Using EventHandler and TemperatureMap:

image = Import["https://i.sstatic.net/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["https://i.sstatic.net/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$
4
  • $\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$ Commented Dec 8, 2014 at 10:41
  • 1
    $\begingroup$ @MilenkoRubin-Zuzic, this sounds like a good candidate for a new question. $\endgroup$ Commented Dec 8, 2014 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$ Commented Dec 8, 2014 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$ Commented Dec 8, 2014 at 12:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.