img_2_arr: Creates a complete array object for a 2D plot

View source: R/img_2_arr.R

img_2_arrR Documentation

Creates a complete array object for a 2D plot

Description

Takes an image along with x and y values and creates an R-array which is effectively a rank-3 Tensor or a 3 slice tensor T_{m,n,p}.

Usage

img_2_arr(source.png, x.lim, y.lim, pl = T, bgrnd = 1)
img_2_arr(source.png, x.lim, y.lim)

Arguments

source.png

Path 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.

Details

For returning only the grayscale matrix without any array format explaining the independent co-ordinates, please see img_2_data.
Since T_{m,n,2} is the X-matrix, hence every row of the matrix will be the same vector, i.e. T_{m,n,2} = T_{k,n,2}\,\,\forall m,n,k.
Since T_{m,n,3} is the Y-matrix, hence every column of the matrix will be the same vector, i.e. T_{m,n,3} = T_{m,k,3}\,\,\forall m,n,k.
See image below for clearer understanding.
array.png

Value

The returned value is a rank-3 tensor, T_{m, n, p}, in the form of an R-array.
In T_{m,n,p}, it should be noted that p \in \{1, 2, 3\}.
For p = 1, T_{m,n,1} is the grayscale matrix.
For p = 2, T_{m,n,2} is the X-matrix which returns the x-value at any point on the image.
For p = 3, T_{m,n,3} is the Y-matrix which returns the y-value at any point on the image.

Author(s)

Chitran Ghosal

Examples

dat <- system.file("extdata", "STM.png", package = "StatsChitran")
tens <- img_2_arr(source.png = dat, x.lim = c(0, 6.115*10^-9), y.lim = c(0, 6.115*10^-9))

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