GA_2_gray: Converts GA values to grayscales

View source: R/GA_2_gray.R

GA_2_grayR Documentation

Converts GA values to grayscales

Description

Converts GA values in R numeric formats to grayscale values of the same format

Usage

GA_2_gray(gray.ch, alp.ch)
GA_2_gray(gray.ch, alp.ch, bg = 1)
GA_2_gray(gray.ch, alp.ch, bg = 0)

Arguments

gray.ch

The gray channel of the data that you want to convert.
This can be either a vector, a matrix or an array.

alp.ch

This argument denotes the transparency of the GA data.
The alpha channel of the data that you want to convert.
This can be either a vector, a matrix or an array.

bg

This argument has to be a single number between 0 and 1.
Denotes the background for implementing the transparency.
bg = 0 denotes black, while bg = 1 denotes white.
bg = 1 by default, hence default background is white.

Details

gray.ch and alp.ch, can be have structures of matrix, vectors(NOT lists) and arrays.
gray.ch and alp.ch all need to have the same structures and dimensions.
Dataframes will not be handled.

Value

The return value will have the same structure and dimension of gray.ch and alp.ch.
It will defintely be a numeric as non-numeric values are not entertained as inputs.
The gray values are defined as shown below......
gray_val <- alp.ch*gray_val + (1 - alp.ch)*bg

Author(s)

Chitran Ghosal

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or standard data sets, see data().
#write a program to test RGBA_2_Gray
library(StatsChitran)
#define the GA array
arr <- array(data = runif(n = 2*10^4, min = 0, max = 1), dim = c(100, 100, 2))

#define the X and the Y values
X <- seq(1, 100)
Y <- seq(1, 100)

#call the GA_2_gray values with different backgrounds
M1 <- GA_2_gray(gray.ch = arr[,,1], alp.ch = arr[,,2]) #white background
M2 <- GA_2_gray(gray.ch = arr[,,1], alp.ch = arr[,,2], bg = 0) #black background

#plot the results
subplot(c(2, 1))
plot2D.mat(X, Y, Z = M1)
plot2D.mat(X, Y, Z = M2)
subplot(c(1, 1))


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