switch_colors: Swap Colors in an Image

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Swap the palette of an image!

Usage

1
2
switch_colors(target_image, source_image, source_colors = 3,
  smoothness = 100, ...)

Arguments

target_image

Matrix The image you wish to transfer colors into. The output from readJPEG is of suitable format.

source_image

Matrix The image you wish to transfer colors from.

source_colors

Integer The number of colors you wish to extract from the source image.

smoothness

Integer The source colors are interpolated such that the image doesn't appear blocky. The value of smoothness determines how many values are interpoloated between the source_colors. That is, smoothness determines the length of the palette used. Higher values return smoother images.

...

Pass any of the arguments for image_palette

Value

The image, but with swapped colors!

Examples

1
2
3
4
5
#Trivial example of using only 5 dominant colors
# from an image to recolor itself
img1 <- jpeg::readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))
img2 <- jpeg::readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))
switch_colors(img1, img2, source_colors=5, smoothness=20)

joelcarlson/RImagePalette documentation built on Oct. 26, 2021, 3:34 a.m.