RGB2gray {SpatialPack} | R Documentation |
Convert RGB image or colormap to grayscale image
Description
This function converts color image to gray image.
Usage
RGB2gray(img, method = "average", weights = NULL)
Arguments
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
|
Value
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.
Examples
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)
[Package SpatialPack version 0.4 Index]