我尝试使用magick::image_rotate()
旋转图像与mapply
不同的旋转角度和image_rotate
没有得到正确的输入
easterEggs <- c(
'https://cdn.pixabay.com/photo/2017/02/04/20/28/easter-2038263_960_720.png',
'https://cdn.pixabay.com/photo/2016/12/15/11/41/easter-1908690_960_720.png',
'https://cdn.pixabay.com/photo/2017/03/28/09/56/easter-egg-2181493_960_720.png',
'https://cdn.pixabay.com/photo/2019/01/29/13/49/egg-3962420_960_720.png',
'https://cdn.pixabay.com/photo/2018/02/25/09/44/easter-3180067_960_720.png'
)
egg <- image_read(easterEggs)
eggRotation <- runif(length(egg), -90, 90)
egg <- mapply(image_rotate, egg, eggRotation)
这导致错误
Error: The 'image' argument is not a magick image object.
我想你需要将鸡蛋放入一个篮子里(即一个"list"
物体)
library(magick)
egg <- sapply(easterEggs, image_read)
eggRotation <- sapply(egg, function(x) runif(length(x), -90, 90))
而你的mapply
将正常工作。
mapply(image_rotate, egg, eggRotation)
尝试使用for
循环旋转图像
library(magick)
egg_new <- egg
for (i in seq_along(egg)) {
egg_new[i] <- image_rotate(egg[i], eggRotation[i])
}
egg_new