First, a one-liner:
ImageView.display(datafloat-1, scalei = ScaleSigned(1/0.5))
This will give you a green (negative)/magenta (positive) colormap rather than
your blue/red. If you can live with that, this is easy. (Note: you may need to
do Pkg.update(), because only in recent masters have I been exporting
ScaleSigned; there are also some other fixes for the demo below.)
Only slightly more difficult, but more flexible: as you say, use ImageCmap:
using Images, ImageView, Color
# build a sample image
datafloat = reshape(linspace(0.5, 1.5, 60000), 200, 300)
# convert the raw 0.5:1.5 data to a integer type, so we can index
dataint = iround(Uint8, 254*(datafloat - 0.5) + 1) # ranges from 1 to 255
# build our colormap
b = RGB(0,0,1)
w = RGB(1,1,1)
r = RGB(1,0,0)
cmaprgb = Array(RGB, 255)
f = linspace(0,1,128)
cmaprgb[1:128] = [(1-x)*b + x*w for x in f]
cmaprgb[129:end] = [(1-x)*w + x*r for x in f[2:end]]
img = ImageCmap(dataint, cmaprgb)
ImageView.display(img)
To simplify this process, I would be amenable to having a colormap() function
that constructs piecewise-linear colormaps. Also, if you need the utmost in
performance, you'd be best converting your cmaprgb array to Uint32 before
constructing the image, perhaps like this:
img = ImageCmap(dataint, uint32(cmaprgb))
More generally, the support for indexed/colormap images in Images is likely to
be somewhat rudimentary. I haven't used them a lot, and one of the barriers is
that I can't figure out how to get ImageMagick to return the raw Cmap for
standard image formats. I even have a question posted on the forum:
http://www.imagemagick.org/discourse-
server/viewtopic.php?f=1&t=22916&hilit=colormap
but the answers get us only partway. If you know how to solve that problem, it
would be most welcome.
Best,
--Tim