RGB2gray | R Documentation |
This function converts color image to gray image.
RGB2gray(img, method = "average", weights = NULL)
img |
target image, specified as an |
method |
character, procedure for converting color to grayscale. Available methods
are |
weights |
weights for red (R), green (G), and blue (B) channels. Required if
|
Grayscale image, returned as an nrow
-by-ncol
numeric matrix with values
in the range [0,1]
.
RGB2gray
converts RGB values to grayscale values by forming a weighted sum
of the R, G, and B channels.
data(twelve)
par(pty = "s", mfrow = c(1,3))
plot(as.raster(twelve)) # in RGB
title(main = "original", font.main = 1)
x <- RGB2gray(twelve, method = "RMY")
plot(as.raster(x)) # in grayscale
title(main = "RMY", font.main = 1)
x <- RGB2gray(twelve, method = "ITU")
plot(as.raster(x)) # OMG! 12 is gone...
title(main = "ITU", font.main = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.