Type: Package
Title: Create a Data Frame Representation of an Image
Version: 0.1.0
Description: Takes images, imported via 'imager', and converts them into a data frame that can be plotted to look like the imported image. This can be used for creating data that looks like a specific image. Additionally, images with color and alpha channels can be converted to grayscale in preparation for converting to the data frame format.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: magrittr, imager
RoxygenNote: 7.3.3
NeedsCompilation: no
Packaged: 2026-02-19 02:26:01 UTC; EthanBrown
Author: Falling Pineapples [aut] (Original author), Ethan C. Brown [cre] (Maintainer)
Maintainer: Ethan C. Brown <ethancbrown@gmail.com>
Repository: CRAN
Date/Publication: 2026-02-23 09:50:02 UTC

ort: Create a Data Frame Representation of an Image

Description

Takes images, imported via 'imager', and converts them into a data frame that can be plotted to look like the imported image. This can be used for creating data that looks like a specific image. Additionally, images with color and alpha channels can be converted to grayscale in preparation for converting to the data frame format.

Author(s)

Maintainer: Ethan C. Brown ethancbrown@gmail.com (Maintainer)

Authors:


Convert 'cimg' object to grayscale via XYZ

Description

Improves on the XYZ method of grayscale by handling alpha channel and retaining relative luminance of the image

Usage

ensure_grayscale(img, bg = 1)

Arguments

img

An cimg object containing an image (from 'imager')

bg

Background color in case of alpha (default is white)

Value

An cimg object, now in grayscale (just one color channel).

Examples

# Load image using imager
pineapple_img = load.image(system.file("FallingPineapple_16x16.png", package = "ort"))

# Create grayscale version
pineapple_gray = ensure_grayscale(pineapple_img)
plot(pineapple_gray)

# Example with alpha background

alph_img = load.image(system.file("alpha_gradient_test.png", package = "ort"))

# default assumes bg = 1 (white background)
alph_gray = ensure_grayscale(alph_img)
plot(alph_gray)

alph_gray_darker = ensure_grayscale(alph_img, bg = 0.75)
plot(alph_gray_darker)


Create a data frame representation of an image

Description

Takes a cimg object and attempts to create a data frame that, when plotted using the default plot in base R, looks like the original image.

Usage

ort(
  img,
  bg = 1,
  grid_size = function(x) {
     1/(250 * (1.0001 - x))
 },
  grid_offset = function(x) {
     sin(x * 100) * 10
 }
)

Arguments

img

An cimg object containing an image (from 'imager')

bg

Background color in case of alpha (default is white)

grid_size

Size of grid used for conversion

grid_offset

Offset of grid used for conversion

Value

A data frame with two columns, 'x' and 'y' that hopefully resembles the image when plotted

Examples

# Load image using imager
pineapple_img = load.image(system.file("FallingPineapple_16x16.png", package = "ort"))

# Convert to data frame plot
pineapple_ort = ort(pineapple_img)
plot(pineapple_ort)


# Example with alpha background
alph_img = load.image(system.file("alpha_gradient_test.png", package = "ort"))

# default assumes bg = 1 (white background)
alph_ort = ort(alph_img)
plot(alph_ort)

alph_ort_grey = ort(alph_img, bg = 0.5)
plot(alph_ort_grey)