如何使用R中的magick包在图像边缘周围添加羽毛?

时间:2019-05-22 16:29:57

标签: r imagemagick

我有一个要使用magick包读入R的gif文件,并且我想模糊或向每帧图像边缘添加羽化效果。我从文档(例如https://www.imagemagick.org/Usage/morphology/#distance_featherhttps://www.imagemagick.org/Usage/transform/#vignette)中可以在ImageMagick中看到它,但无法弄清楚如何将此信息转换为R。我需要哪些magick函数和参数用来实现这一目标?

我知道我需要分别处理gif的每一帧,例如:

img <- image_read("myGif.gif")

featheredGif <- _____ # ????insert a function to feather edges, applied to img[1]

for(i in 2:length(img)){
  featheredFrame <- _____ # ???? insert function to feather edges, applied to img[i]
  featheredGif <- c(featheredGif, featheredFrame)
}

我希望结果看起来像这个https://www.imagemagick.org/Usage/thumbnails/soft_edge.png或这个https://www.imagemagick.org/Usage/morphology/rose_feathered.png,尽管它应用于gif中的每个帧。

1 个答案:

答案 0 :(得分:0)

抱歉,但是我不知道RMagick或R。但是这里有ImageMagick CLI命令,用于绘制椭圆形羽化和圆形矩形羽化。

输入:

enter image description here

椭圆形:

<div class="converter">
  <div class="ccontent">Scroll me: 400px</div>
</div>


enter image description here

矩形:

Read the image
Clone it and use -vignette to draw an ellipse and extract the alpha channel, blur it, then apply -level
Then put the result into the alpha channel of the input image

convert thumbnail.gif \
\( -clone 0 -background none -virtual-pixel none -vignette 0x0+0+0 \
-alpha extract -blur 0x10 -level 50x100% \) \
-alpha off -compose copyopacity -composite \
result.png


enter image description here

因此您需要-vignette,-composite,-draw,-blur和-level的RMagick等效项。