I have an image that must be processed with the package magick. So the output belongs to class magick-image. I need to transform it to a class rasterBrick for further processing.
How can I transform an object magick-image to rasterBrick? I need to avoid saving and loading an intermediate temp file.
library(magick)
library(raster)
# load sample image
i <- image_read("https://i.picsum.photos/id/10/2500/1667.jpg?hmac=J04WWC_ebchx3WwzbM-Z4_KC_LeLBWr5LZMaAkWkF68")
# does not work
r <- raster::raster(i)
# workaround that I must avoid
image_write(i,"temp_image.jpg")
t <- brick("temp_image.jpg")
t
You can do this:
You may want to stick with
terra, but if you want to go back to aRasterBrick, you can add