4

I have read an RGB image using the following code

library(raster)
#Load an image
logo <- stack(system.file("external/rlogo.grd", package="raster"))
plot(logo)

Now, I want to convert the RGB image to CIELAB image. How to do it using raster R package? I know CRImage Bioconductor package has a function to implement this (convertRGBToLAB). But I want to implement it using raster R package.

UseR10085
  • 7,120
  • 3
  • 24
  • 54

1 Answers1

2

You could use the convertColor() function:

library(raster)
logo <- stack(system.file("external/rlogo.grd", package="raster"))
plot(logo)

new_vals <- values(logo) / 255
new_vals <- convertColor(new_vals, from = "sRGB", to = "Lab")
values(logo) <- new_vals
plot(logo)

Jot eN
  • 6,120
  • 4
  • 40
  • 59