Last data update: 2014.03.03

R: Map a Greyscale Image to Color
colormapR Documentation

Map a Greyscale Image to Color

Description

Maps a greyscale image to color using a color palette.

Usage

colormap(x, palette = heat.colors(256L))

Arguments

x

an Image object of color mode Grayscale, or an array

palette

character vector containing the color palette

Details

The colormap function first linearly maps the pixel intensity values of x to the integer range 1:length(palette). It then uses these values as indices to the provided color palette to create a color version of the original image.

The default palette contains 256 colors, which is the typical number of different shades in a 8bit grayscale image.

Value

An Image object of color mode Color, containing the color-mapped version of x.

Author(s)

Andrzej Ole<c3><85><c2><9b>, andrzej.oles@embl.de, 2016

Examples

  x = readImage(system.file("images", "sample.png", package="EBImage"))

  ## posterize an image using the topo.colors palette
  y = colormap(x, topo.colors(8))

  display(y, method="raster")

  ## mimic MatLab's 'jet.colors' colormap
  jet.colors = colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
  y = colormap(x, jet.colors(256))

  display(y, method="raster")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(EBImage)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/EBImage/colormap.Rd_%03d_medium.png", width=480, height=480)
> ### Name: colormap
> ### Title: Map a Greyscale Image to Color
> ### Aliases: colormap
> 
> ### ** Examples
> 
>   x = readImage(system.file("images", "sample.png", package="EBImage"))
> 
>   ## posterize an image using the topo.colors palette
>   y = colormap(x, topo.colors(8))
> 
>   display(y, method="raster")
> 
>   ## mimic MatLab's 'jet.colors' colormap
>   jet.colors = colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
>   y = colormap(x, jet.colors(256))
> 
>   display(y, method="raster")
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>