|
1 |
|
2 ############################################# |
|
3 # Utilities to work with colourmapped images |
|
4 ############################################# |
|
5 |
|
6 module ColourTools |
|
7 |
|
8 using ColorTypes: Gray |
|
9 |
|
10 # Our exports |
|
11 |
|
12 export grayimg, |
|
13 mapped_img, |
|
14 clip |
|
15 |
|
16 # Clip image values to allowed range |
|
17 clip = x -> min(max(x, 0.0), 1.0) |
|
18 |
|
19 # Tell that raw image data is grayscale |
|
20 grayimg = im -> Gray.(clip.(im)) |
|
21 |
|
22 # Apply a colourmap (vector of RGB objects) to raw image data |
|
23 function mapped_img(im, cmap) |
|
24 l = length(cmap) |
|
25 apply = t -> cmap[1+round(UInt8, clip(t) * (l-1))] |
|
26 return apply.(im) |
|
27 end |
|
28 |
|
29 end |
|
30 |