RGBA_2_gray | R Documentation |
Converts RGB or RGBA values in R numeric formats to grayscale values of the same format
RGBA_2_gray(red.ch, green.ch, blue.ch, alp.ch, bg = 1, alp = T)
RGBA_2_gray(red.ch, green.ch, blue.ch, alp = F)
RGBA_2_gray(red.ch, green.ch, blue.ch)
red.ch |
The red channel of the data that you want to convert. |
green.ch |
The green channel of the data that you want to convert. |
blue.ch |
The blue channel of the data that you want to convert. |
alp.ch |
This argument is only needed when alp = T. |
bg |
This argument is only needed when alp = T. |
alp |
This argument denotes whether an alpha value is needed for the conversion. |
red.ch, green.ch, blue.ch and alp.ch (if needed), can be have structures of matrix, vectors(NOT lists) and arrays.
red.ch, green.ch, blue.ch and alp.ch (if needed) all need to have the same structures and dimensions.
Dataframes will not be handled.
The return value will have the same structure and dimension of red.ch, green.ch and blue.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 <- 0.2989*red.ch + 0.5870*green.ch + 0.1140*blue.ch
gray_val <- alp.ch*gray_val + (1 - alp.ch)*bg
Chitran Ghosal
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or standard data sets, see data().
#write a program to test RGBA_2_Gray
library(StatsChitran)
r.ch <- matrix(data = runif(n = 10^4, min = 0, max = 2), nrow = 100, byrow = T)
g.ch <- matrix(data = runif(n = 10^4, min = 0, max = 2), nrow = 100, byrow = T)
b.ch <- matrix(data = runif(n = 10^4, min = 0, max = 2), nrow = 100, byrow = T)
a.ch <- matrix(data = runif(n = 10^4, min = 0, max = 2), nrow = 100, byrow = T)
gray_mat1 <- RGBA_2_gray(red.ch = r.ch, green.ch = g.ch, blue.ch = b.ch, alp.ch = a.ch, bg=0, alp = T)
gray_mat2 <- RGBA_2_gray(red.ch = r.ch, green.ch = g.ch, blue.ch = b.ch, alp = F )
subplot(c(2, 1))
plot2D.mat(X = seq(1, 100), Y = seq(1, 100), Z = gray_mat1)
plot2D.mat(X = seq(1, 100), Y = seq(1, 100), Z = gray_mat2)
subplot(c(1, 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.