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?
Thanks in advance. Milenko
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]]
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]]
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]
Original answer:
image = Import["https://i.sstatic.net/qmKND.png"];
Column[{ColorSetter[Dynamic[x]],
Dynamic@Colorize[MorphologicalComponents@image, ColorRules -> {0 -> White, _ :> x}]}]
Clicking on the ColorSetter
button invokes color selection dialog:
After selecting a color, the colors in the image are updated:
col1 = ColorData["TemperatureMap"][.2]; col2 = ColorData["TemperatureMap"][.6]; Colorize[image, ColorRules -> {0 -> col2, 1 -> col1}, ImageSize -> 300]
?
$\endgroup$