dahtah / imager

R package for image processing
GNU Lesser General Public License v3.0
187 stars 43 forks source link

How to save tif/tiff with LZW compression? #165

Open sihanwusean opened 1 year ago

sihanwusean commented 1 year ago

Hi, Do you know how to save a cimg class as tiff with LZW compression? Currently, the save.image() function can only output uncompressed tiff. I wonder if there's another way to get around it. Thank you!

sihanwusean commented 1 year ago

I figure it out now:

Basically, just turn the cimg into an object, then use the raster() in the raster package and writeRaster() for the output. I wish this feature can be built into the save.image() in the future though.

library(imager)
library(raster)
red = raster(cimg2im(red))
writeRaster(red, "red.tiff", options = "COMPRESS=LZW")