Colorizing a UInt8 matrix

julia> using ImageCore, IndirectArrays

julia> colormap = zeros(RGB{N0f8}, 0:255);

julia> colormap[[0,1,2,3,4,0xfd,0xfe,0xff]] = [colorant"red", colorant"white", colorant"light gray", colorant"aqua", colorant"blue", colorant"gold", colorant"black", colorant"red"]
8-element Array{RGB{N0f8},1} with eltype RGB{N0f8}:
 RGB{N0f8}(1.0,0.0,0.0)
 RGB{N0f8}(1.0,1.0,1.0)
 RGB{N0f8}(0.827,0.827,0.827)
 RGB{N0f8}(0.0,1.0,1.0)
 RGB{N0f8}(0.0,0.0,1.0)
 RGB{N0f8}(1.0,0.843,0.0)
 RGB{N0f8}(0.0,0.0,0.0)
 RGB{N0f8}(1.0,0.0,0.0)

julia> img = IndirectArray(mymatrix, colormap);

should do the trick.

4 Likes