【发布时间】:2018-08-24 07:14:52
【问题描述】:
我想将 2000x2000 像素 RGB 图像(具有三个分离通道的数组)中的颜色转换为一个通道,对应于十六进制颜色。我还想同时保留图像的尺寸,以便找到每个像素的确切十六进制颜色。然后目标是找到包含特定颜色的所有像素的位置。
让我们以这个可重现的例子为例:
# A 3x3 pixels image
img <- array(runif(3,0,1), dim = c(3L, 3L, 3L))
# The result I would expect (a unique matrix of hexadecimal values,
# corresponding to the conversion and the merging of the RGB values)
img_output <-matrix(c("#B1F5E1","#95E4EE","#A5EDD8","#517760",
"#A1E2C7","#00FFFF","#A9EFDB","#A9EFC4","#73CEE6"),nrow=3,ncol=3)
# In order then to find the position of specific color pixels in
# my image
which(img_output=="#95E4EE", arr.ind=TRUE)
目前,我已经有了将 RGB 颜色转换为十六进制的功能,但它返回了一个字符向量:
library(colorspace)
img_output <- hex(RGB(c(img[,,1]),c(img[,,2]),c(img[,,3])))
我该怎么做?
【问题讨论】: