[R] bizarre color space conversion problem

Sarah Goslee @@r@h@go@|ee @end|ng |rom gm@||@com
Thu Jul 18 16:35:57 CEST 2019


I am getting unexpected results when converting from RGB to Lab. This
is clearly some kind of configuration problem, but I cannot find it. I
have three linux workstations, both fully updated (except all are
running R 3.6.0 instead of 3.6.1, because that's the latest Fedora 30
binary). I'm running R --vanilla from the command line. On one
workstation, it functions correctly; on the other two the conversion
malfunctions as below.

I found it when my scico color palettes were wildly wrong, but it
isn't a scico package problem.
https://twitter.com/numberwright/status/1151601407436439554

After spending far too much time poking at it, I'm still curious as to
what might be going on. It's got to be my computer rather than R, but
I do want to figure out what, in case it has consequences for other
calculations.

Here's my sample code:

red.in <- rep("red", 20)

red.rgb   <- t(col2rgb(red.in, alpha = 0)/255)
red.lab   <- convertColor(red.rgb, from = "sRGB", to = "Lab")
convertColor(red.lab, from = "Lab", to = "sRGB")

#-#-#

Output on computer A, as expected:

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 30 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.6.0
>
> red.in <- rep("red", 20)
>
> red.rgb   <- t(col2rgb(red.in, alpha = 0)/255)
> red.lab   <- convertColor(red.rgb, from = "sRGB", to = "Lab")
> convertColor(red.lab, from = "Lab", to = "sRGB")
      [,1] [,2] [,3]
 [1,]    1    0    0
 [2,]    1    0    0
 [3,]    1    0    0
 [4,]    1    0    0
 [5,]    1    0    0
 [6,]    1    0    0
 [7,]    1    0    0
 [8,]    1    0    0
 [9,]    1    0    0
[10,]    1    0    0
[11,]    1    0    0
[12,]    1    0    0
[13,]    1    0    0
[14,]    1    0    0
[15,]    1    0    0
[16,]    1    0    0
[17,]    1    0    0
[18,]    1    0    0
[19,]    1    0    0
[20,]    1    0    0

#-#-#

Output on computer B (and also computer C!)

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 30 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.6.0
>
> red.in <- rep("red", 20)
>
> red.rgb   <- t(col2rgb(red.in, alpha = 0)/255)
> red.lab   <- convertColor(red.rgb, from = "sRGB", to = "Lab")
> convertColor(red.lab, from = "Lab", to = "sRGB")
      [,1]   [,2] [,3]
 [1,]    1 0.0000    1
 [2,]    1 0.0000    1
 [3,]    1 0.0000    1
 [4,]    1 0.0000    1
 [5,]    0 0.5472    0
 [6,]    0 0.5472    0
 [7,]    0 0.5472    0
 [8,]    0 0.5472    0
 [9,]    1 0.0000    1
[10,]    1 0.0000    1
[11,]    1 0.0000    1
[12,]    1 0.0000    1
[13,]    0 0.5472    0
[14,]    0 0.5472    0
[15,]    0 0.5472    0
[16,]    0 0.5472    0
[17,]    1 0.0000    0
[18,]    1 0.0000    0
[19,]    1 0.0000    0
[20,]    1 0.0000    0

#-#-#

I've gotten as far as locating the problem in this line from
grDevices::convertColor()

    xyz <- from$toXYZ(color, from.ref.white)


Packages are up to date on all computers, although this doesn't
involve any contributed packages.

Thoughts?

-- 
Sarah Goslee (she/her)
http://www.numberwright.com



More information about the R-help mailing list