# HG changeset patch # User Tuomo Valkonen # Date 1638601704 -7200 # Node ID 198108ecdab77132690ad9110e011a79871dfd7e # Parent 471f9f64ff2d40a415e99874685adf6b98e8a9e9 Oops, the ColourTools.jl file was missing. diff -r 471f9f64ff2d -r 198108ecdab7 src/ColourTools.jl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ColourTools.jl Sat Dec 04 09:08:24 2021 +0200 @@ -0,0 +1,30 @@ + +############################################# +# Utilities to work with colourmapped images +############################################# + +module ColourTools + +using ColorTypes: Gray + +# Our exports + +export grayimg, + mapped_img, + clip + +# Clip image values to allowed range +clip = x -> min(max(x, 0.0), 1.0) + +# Tell that raw image data is grayscale +grayimg = im -> Gray.(clip.(im)) + +# Apply a colourmap (vector of RGB objects) to raw image data +function mapped_img(im, cmap) + l = length(cmap) + apply = t -> cmap[1+round(UInt8, clip(t) * (l-1))] + return apply.(im) +end + +end +