R未正确显示HSV颜色

R未正确显示HSV颜色,r,colors,R,Colors,我正在使用RGB和HSV格式的颜色[0-255]和[0-1],因此我希望在两个方向上正确转换它们 假设我有一组RGB颜色值: x_order<-structure(list(X1 = c(247, 202, 201), X2 = c(247, 120, 107), X3 = c(145, 168, 208), X4 = c(3, 79, 132), X5 = c(251, 227, 55), X6 = c(152, 221, 222), X7 = c(152, 150,

我正在使用RGB和HSV格式的颜色
[0-255]
[0-1]
,因此我希望在两个方向上正确转换它们

假设我有一组RGB颜色值:

x_order<-structure(list(X1 = c(247, 202, 201), X2 = c(247, 120, 107), 
    X3 = c(145, 168, 208), X4 = c(3, 79, 132), X5 = c(251, 227, 
    55), X6 = c(152, 221, 222), X7 = c(152, 150, 164), X8 = c(220, 
    68, 58), X9 = c(177, 143, 106), X10 = c(113, 204, 81)), .Names = c("X1", 
"X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10"), row.names = c(NA, 
-3L), class = "data.frame")
因此,我检查转换:

 library(grDevices)

 plot(1, type="n", xlab="", ylab="", xlim=c(0, 25), ylim=c(0, 1))

 for (i in 1:10){
   points(i*2,0.8,pch=19,col=rgb(x_order[1,i],x_order[2,i],
                               x_order[3,i],maxColorValue = 255), cex=5)

   points(i*2,0.4,pch=19,col=hsv(rgb2hsv(x_order[,i],
                               maxColorValue = 255)), cex=5)       
 }
hsvColors <- rgb2hsv(x_order)

plot(1, type="n", xlab="", ylab="", xlim=c(0, 25), ylim=c(0, 1))

for (i in 1:10){
    points(i*2, 0.8, pch=19, 
           col=rgb(x_order[1,i],x_order[2,i], x_order[3,i], maxColorValue = 255),
           cex=5)

    points(i*2, 0.4, pch=19, 
          col = hsv(hsvColors[1, i], hsvColors[2, i], hsvColors[3, i]), 
          cex=5)       
}
结果是:

如何将RGB值正确转换为HSV并显示输出

还有一件事是,我确信rgb2hsv的工作是正确的,因为我有文章中设置的颜色的色调值

UPD:


您正在将一个值向量传递给
hsv
,它不会以您期望的方式接受该向量。您可以分别传入参数
h
s
v
,并获得正确的转换:

 library(grDevices)

 plot(1, type="n", xlab="", ylab="", xlim=c(0, 25), ylim=c(0, 1))

 for (i in 1:10){
   points(i*2,0.8,pch=19,col=rgb(x_order[1,i],x_order[2,i],
                               x_order[3,i],maxColorValue = 255), cex=5)

   points(i*2,0.4,pch=19,col=hsv(rgb2hsv(x_order[,i],
                               maxColorValue = 255)), cex=5)       
 }
hsvColors <- rgb2hsv(x_order)

plot(1, type="n", xlab="", ylab="", xlim=c(0, 25), ylim=c(0, 1))

for (i in 1:10){
    points(i*2, 0.8, pch=19, 
           col=rgb(x_order[1,i],x_order[2,i], x_order[3,i], maxColorValue = 255),
           cex=5)

    points(i*2, 0.4, pch=19, 
          col = hsv(hsvColors[1, i], hsvColors[2, i], hsvColors[3, i]), 
          cex=5)       
}

hsvColors您正在将一个值向量传递给
hsv
,它不会以您期望的方式接受该向量。您可以分别传入参数
h
s
v
,并获得正确的转换:

 library(grDevices)

 plot(1, type="n", xlab="", ylab="", xlim=c(0, 25), ylim=c(0, 1))

 for (i in 1:10){
   points(i*2,0.8,pch=19,col=rgb(x_order[1,i],x_order[2,i],
                               x_order[3,i],maxColorValue = 255), cex=5)

   points(i*2,0.4,pch=19,col=hsv(rgb2hsv(x_order[,i],
                               maxColorValue = 255)), cex=5)       
 }
hsvColors <- rgb2hsv(x_order)

plot(1, type="n", xlab="", ylab="", xlim=c(0, 25), ylim=c(0, 1))

for (i in 1:10){
    points(i*2, 0.8, pch=19, 
           col=rgb(x_order[1,i],x_order[2,i], x_order[3,i], maxColorValue = 255),
           cex=5)

    points(i*2, 0.4, pch=19, 
          col = hsv(hsvColors[1, i], hsvColors[2, i], hsvColors[3, i]), 
          cex=5)       
}

hsvColors非常感谢您!我有点错过了,非常感谢!不知怎的,我错过了