There is no ImageView involved in what I said. But you would need GMT and Ghostscript installed and that imshow is from GMT. To have it displayed on IJulia you would need something like
These are all great suggestions. Just for the record, one other alternative is to use IndirectArrays, which can be used to lazily construct a colormap array. In this case you’d need to convert your Float64 array to an Int array, which you could do in a lazy way with MappedArrays. For example:
using MappedArrays, IndirectArrays
function color_me(A, cmap)
n = length(cmap)
f = s->clamp(round(Int, (n-1)*s)+1, 1, n) # safely convert 0-1 to 1:n
Ai = mappedarray(f, A) # like f.(A) but does not allocate significant memory
IndirectArray(Ai, cmap) # colormap array
end
(For this to work you have to be running the very latest IndirectArrays.)
In most cases you may find PerceptualColourmap’s applycolormap easier, since it’s already written. Cases there might be reasons to consider IndirectArrays:
big data (e.g., >1TB image): the version here allocates essentially no memory and takes essentially no time (you pay only when you access the values, and then only for those values you need)
in applications where you’d like to pass the colorized array to a function but also have access to the original values (which you can get with parent(imgc.index)). An example might be a GUI “tooltip hover” application.
Again, these probably don’t matter in most cases. Not only is applycolormap already available, but @peterkovesi’s color maps are so well designed that you should just be using those anyway .
Sorry to resurrect this old thread but Prof. Edelman’s recent Julia video about Structure (Structure | Week3 | 18.S191 MIT Fall 2020) led me here.
A function show_image() is used in a Pluto notebook to display matrices as images in color, instead of using heatmap(). Could not find this function anywhere, until finding @tim.holy’s color_me() in post above.
In case it might be useful to others, please find herein a working example (at least on Win10 Julia 1.5.3 VS_Code):
using Plots, MappedArrays, IndirectArrays, PerceptualColourMaps
outer(v,w) = [x * y for x ∈ v, y ∈ w] # Prof. Edelman's: https://youtu.be/ConoBmjlivs
show_image(m) = plot(color_me(m,cmap("R3"))) # color_me() by @tim.holy
m = outer(rand(8),rand(12))
show_image(m)
After 6 months I also resurect this thread, because I’d like to use a colorscheme defined in ColorSchemes.jl, instead of a cmap from PerceptualColourMaps. I didn’t succeed with a colorscheme. How to access a colorscheme and pass it as an argument for color_me? Thanks!!
Here is another version of the function that scales the colormap linearly between the extrema of A:
function color_me_scaleminmax(A, cmap)
n = length(cmap)
scale = takemap(scaleminmax, A)
f = s->clamp(round(Int, (n-1)*scale(s))+1, 1, n) # safely convert 0-1 to 1:n
Ai = mappedarray(f, A) # like f.(A) but does not allocate significant memory
IndirectArray(Ai, cmap) # colormap array
end
precompile(color_me_scaleminmax, (Matrix{Float64}, Vector{RGB{Float64}}))
Why use both IndirectArray and mappedarray here? Wouldn’t the code below work as well?
function color_me(A, clr_map)
n = length(clr_map)
f(s) = clr_map[clamp(round(Int, (n-1)*s)+1, 1, n)]
Am = mappedarray(f, A)
return of_eltype(eltype(clr_map), Am)
end
I guess it’s connected with this discussion, that is, MappedArrays are powerful.