R/colormap.R

Defines functions colormap

Documented in colormap

colormap <- function(x, palette = heat.colors(256L)) {
  validImage(x)
  if (colorMode(x) != Grayscale) 
    stop("Color mapping can be applied only to grayscale images")
  
  tmp <- round(1 + x * (length(palette)-1L))
  tmp <- Image(array(palette[tmp], dim(tmp)))
  
  if ( is.Image(x) ) {
    res <- x
    imageData(res) <- tmp
    colorMode(res) <- Color
  }
  else {
    res <- tmp
  }
  
  res
}

Try the EBImage package in your browser

Any scripts or data that you put into this service are public.

EBImage documentation built on Nov. 8, 2020, 5:41 p.m.