| Title: | 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. |
| Authors: | Falling Pineapples [aut] (Original author), Ethan C. Brown [cre] (Maintainer) |
| Maintainer: | Ethan C. Brown <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-25 08:32:37 UTC |
| Source: | https://github.com/cran/ort |
Improves on the XYZ method of grayscale by handling
alpha channel and retaining relative luminance of the image
ensure_grayscale(img, bg = 1)ensure_grayscale(img, bg = 1)
img |
An |
bg |
Background color in case of alpha (default is white) |
An cimg object, now in grayscale (just one
color channel).
# 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)# 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)
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.
ort( img, bg = 1, grid_size = function(x) { 1/(250 * (1.0001 - x)) }, grid_offset = function(x) { sin(x * 100) * 10 } )ort( img, bg = 1, grid_size = function(x) { 1/(250 * (1.0001 - x)) }, grid_offset = function(x) { sin(x * 100) * 10 } )
img |
An |
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 |
A data frame with two columns, 'x' and 'y' that hopefully resembles the image when plotted
# 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)# 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)