【问题标题】:mapply on magick-image vectormapply on magick-image 矢量
【发布时间】:2019-09-10 22:42:57
【问题描述】:

我尝试使用 magick::image_rotate() 旋转图像以获得不同的旋转角度 mapplyimage_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.

【问题讨论】:

    标签: r imagemagick apply mapply


    【解决方案1】:

    我认为您需要将鸡蛋放入篮子(即"list" 对象)

    library(magick)
    egg <- sapply(easterEggs, image_read)
    eggRotation <- sapply(egg, function(x) runif(length(x), -90, 90))
    

    您的mapply 会正常工作。

    mapply(image_rotate, egg, eggRotation)
    

    【讨论】:

      【解决方案2】:

      尝试使用for 循环来旋转图像

      library(magick)
      
      egg_new <- egg
      for (i in seq_along(egg)) {
        egg_new[i] <- image_rotate(egg[i], eggRotation[i])
      }
      egg_new
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-09
        • 2012-10-16
        • 2014-05-20
        • 1970-01-01
        • 1970-01-01
        • 2015-01-08
        • 2012-01-03
        • 1970-01-01
        相关资源
        最近更新 更多