Learn R Programming

threeBrain (version 1.0.1)

voxel_colormap: Color maps for volume or surface data

Description

Color maps for volume or surface data

Usage

create_colormap(
  gtype = c("surface", "volume"),
  dtype = c("continuous", "discrete"),
  key,
  color,
  value,
  alpha = FALSE,
  con = NULL,
  auto_rescale = FALSE,
  ...
)

save_colormap(cmap, con)

freeserfer_colormap(con)

load_colormap(con)

Value

A list of color map information

Arguments

gtype

geometry type, choices are "surface", "volume"

dtype

data type, "continuous" or "discrete"

key

non-negative integer vector corresponding to color values; its length must exceed 1; see 'Details'

color

characters, corresponding to color strings for each key

value

actual value for each key

alpha

whether to respect transparency

con

a file path to write results to or to read from. The file path can be passed as voxel_colormap into threejs_brain.

auto_rescale

automatically scale the color according to image values; only valid for continuous color maps

...

used by continuous color maps, passed to colorRampPalette

cmap

color map object

Details

Internal 'JavaScript' shader implementation uses integer color keys to connect color palettes and corresponding values. The keys must be non-negative.

Zero key is a special color key reserved by system. Please avoid using it for valid values.

Examples

Run this code

# Creates a symmetric continuous colormap with 3 keys
# The color range is -10 to 10
# The colors are 'blue','white','red' for these keys

pal <- create_colormap(
  gtype = "volume", dtype = "continuous",
  key = c(1,2,3), value = c(-10,0,10),
  color = c('blue','white','red'))

print( pal )

# ---------------- Get colormap key from a value ------------

# returns key index starting from
pal$get_key( -10 )

# nearest value
pal$get_key( 2 )

# set threshold, key is now 0 (no color)
pal$get_key( 2, max_delta = 1 )


# ---------------- Save and load ----------------
f <- tempfile( fileext = '.json' )
save_colormap( pal, f )
cat(readLines(f), sep = '\n')

load_colormap(f)

Run the code above in your browser using DataLab