# HSVで画像処理 library(imager) cutoff <- function(x) { x[x > 1] <- 1 x[x < 0] <- 0 return(x) } # 元の画像 im.rgb <- load.example("parrots") # RGBからHSVへ変換 im.hsv <- RGBtoHSV(im.rgb) # HSVの変換パラメータ h.shift <- 0 s.scale <- 1 v.scale <- 1 # 色相 H im.hsv[, , 1, 1] <- (im.hsv[, , 1, 1] + h.shift) %% 360 # 彩度 S im.hsv[, , 1, 2] <- cutoff(im.hsv[, , 1, 2] * s.scale) # 明るさ V im.hsv[, , 1, 3] <- cutoff(im.hsv[, , 1, 3] * v.scale) # HSVからRGBに変換 im.new <- HSVtoRGB(im.hsv) layout(t(1 : 2)) plot(im.rgb, rescale= FALSE, main = "元の画像") plot(im.new, rescale= FALSE, main = "新しい画像") layout(1)