Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Grayscale-image/R/grayscale-image.r
Normal file
33
Task/Grayscale-image/R/grayscale-image.r
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Conversion from Grey to RGB uses the following code
|
||||
setAs("pixmapGrey", "pixmapRGB",
|
||||
function(from, to){
|
||||
z = new(to, as(from, "pixmap"))
|
||||
z@red = from@grey
|
||||
z@green = from@grey
|
||||
z@blue = from@grey
|
||||
z@channels = c("red", "green", "blue")
|
||||
z
|
||||
})
|
||||
|
||||
# Conversion from RGB to grey uses built-in coefficients of 0.3, 0.59, 0.11. To see this, type
|
||||
getMethods(addChannels)
|
||||
|
||||
# We can override this behaviour with
|
||||
setMethod("addChannels", "pixmapRGB",
|
||||
function(object, coef=NULL){
|
||||
if(is.null(coef)) coef = c(0.2126, 0.7152, 0.0722)
|
||||
z = new("pixmapGrey", object)
|
||||
z@grey = coef[1] * object@red + coef[2] * object@green +
|
||||
coef[3] * object@blue
|
||||
z@channels = "grey"
|
||||
z
|
||||
})
|
||||
|
||||
# Colour image
|
||||
plot(p1 <- pixmapRGB(c(c(1,0,0,0,0,1), c(0,1,0,0,1,0), c(0,0,1,1,0,0)), nrow=6, ncol=6))
|
||||
|
||||
#Convert to grey
|
||||
plot(p2 <- as(p1, "pixmapGrey"))
|
||||
|
||||
# Convert back to "colour"
|
||||
plot(p3 <- as(p2, "pixmapRGB"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue