image_col_numeric: Colorize an Image according to Gray Scale

Description Usage Arguments

View source: R/image_col_numeric.R

Description

A color image can be converted to one with different degrees of gray. Then, colors in a palette can be added according to the gray degrees. The function is a simple wrapper of scales::col_numeric. The pixels which are deliberately assigned "transparent" in the original magick image will always kept unchanged.

Usage

1
2
3
4
5
6
7
8
image_col_numeric(
  x,
  palette = c("purple", "yellow"),
  n = 256,
  alpha = FALSE,
  result = "magick",
  res = 144
)

Arguments

x

an image read into R by magick::image_read.

palette

two or more colors. The default is c("purple", "yellow") which means the deeper colors on the image will become purple and the lighter yellow.

n

the max num of colors that will be used. The default is 256. Note, the number of colors that really exist may be smaller than this number.

alpha

whether transparency is used. Transparency only exists when alpha = TRUE and your image is in the format (e. g., png) that supports transparency. The default is FALSE.

result

if it is "magick" (default), the result is a picture of the same type used by package magick. If it is "raster", the result is a matrix that can be used as a raster by ggplot2::annotation_raster.

res

resolution that is used by magick::image_graph. The default is 144.


plothelper documentation built on July 2, 2020, 4:03 a.m.