Approach
As halirutan suggested in Apply ColorFunction to an Image, we can create a custom, compiled color function and apply it using the trick
Image[colorFunction @ ImageData @ img]
On my computer with my custom avocado color function, this is more than eight times faster than Colorize, taking only 0.035 seconds.
How to create a fast custom color function
In order to create a faster avocado color function, we first need to find out what colors that color function is based on. Mr. Wizard explains that in his answer to Is it possible to insert new colour schemes into ColorData?.
Position[DataPaclets`ColorDataDump`colorSchemes, "AvocadoColors", Infinity]
(* Out: {{141, 1, 1}} *)
So the colors are given by
List @@@ DataPaclets`ColorDataDump`colorSchemes[[141, 5]]
(* Out: {{0., 0., 0.}, {0., 0.442859, 0.0749256}, {0.289326, 0.685107,
0.108759}, {0.683989, 0.830896, 0.145815}, {1., 0.984375, 0.230411}} *)
So we've got five different colors. Just like halirutan, I will do a linear interpolation between these colors which is what Blend does, which is what Colorize uses (thanks J. M. for debugging help to make it work perfectly). I'm also using the Parallelization and Listable settings like halirutan to make the function fast. I also added CompilationTarget -> "C" which improves the speed even more.
avocadoColors = Compile[value, Module[{c1, c2, c3, c4, c5},
c1 = {0., 0., 0.};
c2 = {0., 0.442859, 0.0749256};
c3 = {0.289326, 0.685107, 0.108759};
c4 = {0.683989, 0.830896, 0.145815};
c5 = {1., 0.984375, 0.230411};
Which[
value < 0.25, c1 + (c2 - c1) (value/0.25),
value < 0.5, c2 + (c3 - c2) ((value - 0.25)/0.25),
value < 0.75, c3 + (c4 - c3) ((value - 0.5)/0.25),
True, c4 + (c5 - c4) ((value - 0.75)/0.25)
]
],
Parallelization -> True,
RuntimeAttributes -> {Listable},
CompilationTarget -> "C"
]
You can now test this using
Image[avocadoColors @ ImageData @ img]
ImageFileApplyto be a useful function, especially when processing a large number of images. – chuy May 20 '15 at 23:55Graphics[Raster[ImageData[A, DataReversed -> True], ColorFunction -> "AvocadoColors"]]– chuy May 20 '15 at 23:59