如何改变R中的亮度

时间:2018-04-23 18:18:55

标签: r

有人知道R中的一个包允许我给几张照片提供相同的平均亮度吗?

我的照片一般都是低清晰度的。我已经看过包'magick'但是没有提到亮度是可以改变的东西。

虽然我对光的物理学很了解,但据我所知它的亮度和亮度不同,因此改变亮度还不够。

1 个答案:

答案 0 :(得分:3)

使用imager,您可以更改图像的颜色空间(从RGB到HSL / HSV / HSI / YUV / YCbCR)。在一个颜色空间中,您可以根据需要操作每个通道。

在这里,我将im从RGB转换为YUV(对应于一个亮度(Y)和两个色度(UV)通道)。然后,作为一个例子,我逐渐增加亮度:

library(imager)

im <- load.image(system.file('extdata/parrots.png',package='imager'))

im.yuv <- RGBtoYUV(im) # convert from RGB to YUV

par(mfrow=c(1,3))
plot(im) 
for (i in rep(0.2, 2)){
  im.yuv[,,1,1] <- im.yuv[,,1,1] + i  # the last dimension gives the channel; 1:Y 2:U 3:V
  im.cor <- YUVtoRGB(im.yuv) # convert back from YUV to RGB
  plot(im.cor)
}

enter image description here