I have a grayscale image that contains two objects. The grayscale pixel values can be divided into three intervals where two of them represent objects and the third represents the background. The background is almost uniform, with pixel values close to 0.5. The other two intervals are [.2,.4] and [.55,.73].
I developed a function to colorize this image. It works fine, but I'm looking for ways to make it run faster. Any suggestions?
colorizeFunction[image_, α_, β_, γ_, θ_] :=
Module[{data, newdata, red, green, blue, datared, datagreen,
datablue, newdatared, newdatagreen, newdatablue}, (
{red, green, blue} = ColorSeparate[image];
datared = ImageData[red];
datagreen = ImageData[green];
datablue = ImageData[blue];
newdatared = datared /. x_ /; α <= x <= β -> 1;
newdatagreen = datagreen /. x_ /; α <= x <= β -> 0;
newdatablue = datablue /. x_ /; α <= x <= β -> 0;
newdatared = newdatared /. x_ /; γ <= x <= θ -> 0;
newdatagreen = newdatagreen /. x_ /; γ <= x <= θ -> 1;
newdatablue = newdatablue /. x_ /; γ <= x <= θ -> 0;
ColorCombine[{Image[newdatared], Image[newdatagreen],
Image[newdatablue]}, "RGB"]
)]