img_2_data: Takes a PNG image and converts it into grayscale and returns...

View source: R/img_2_data.R

img_2_dataR Documentation

Takes a PNG image and converts it into grayscale and returns the individual channels along with the grayscale matrix.

Description

Inputs a PNG image and return the grayscale matrix along with the individual channels separated.
The input PNG images are normally classified into RGB, RGBA, G/grayscale or GA types.
The grayscale matrix could also be plotted.

Usage

img_2_data(source.png, x.lim, y.lim, pl = T, bgrnd = 1)
img_2_data(source.png, x.lim, y.lim)
img_2_data(source.png, x.lim, y.lim, bgrnd = 0.5)
img_2_data(source.png, x.lim, y.lim, pl = F)

Arguments

source.png

Path leading to the PNG file

x.lim

The x-limits of the image.
Must be a two element numeric vector.

y.lim

The y-limits of the image.
Must be a two element numeric vector.

pl

Boolean bit, set to TRUE by default.
Plots the grayscale matrix if set to TRUE.

bgrnd

Numeric scalar, set to 1 by default.
Value should lie between 0 and 1.
Determines the grayscale value of the background.
Values of 1 and 0 determine white and black backgrounds respectively.

Value

The returned value is always a two-element list.
The first element in the list is "gray.val" which is the grayscale matrix.
The second element of the list is "data".
"data" itself is a list which contains the matrixes pertaining to the different channels of the original PNG image, like red, green, blue and alpha in case of an RGBA image.

Author(s)

Chitran Ghosal

Examples


library(StatsChitran)
dat <- system.file("extdata", "asymmetry.png", package = "StatsChitran")
L <- img_2_data(source.png = dat, x.lim = c(0, 7), y.lim = c(0, 3), bgrnd = 0.1)

Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.