r magick高亮显示图片

时间:2019-03-28 15:29:57

标签: r imagemagick

我想通过在图片上添加白色填充来突出显示图片的某些部分,这与此https://tex.stackexchange.com/questions/78378/highlighting-part-of-an-image中的操作类似。

我正在使用magick和下面的代码。

library(magick)
frink <- image_read("https://jeroen.github.io/images/frink.png") %>%
  image_colorize( opacity = 80 , color = "white") %>% 
  image_draw(.)
rect(40, 20, 150, 150, border = "red", lty = "dashed", lwd = 5)
rect(80, 170, 150, 300, border = "blue", lty = "solid", lwd = 5)

结果就是这个

enter image description here

如何删除方块内的白色填充物?

1 个答案:

答案 0 :(得分:1)

如果我认为Mark Setchell的注释正确,那么使用Imagemagick命令行,您可以执行以下操作。抱歉,我不认识RMagick。

输入:

enter image description here

我要做的是:

1. Read the input image.
2. Copy the input image and add 80% to make it whiter
3. Copy the image and fill it with white, then draw a black rectangle where you want to keep the original color. This will be a mask image
4. Use the mask image to composite the original and the white image together
5. Add a blue border
6. Save the result


convert lena.png \
\( -clone 0 -evaluate add 80% \) \
\( -clone 0 -fill white -colorize 100 \
-fill black -draw "rectangle 100,100 150,150" -alpha off \) \
-compose over -composite \
-fill none -stroke blue -strokewidth 5 \
-draw "rectangle 100,100 150,150" \
result.jpg


enter image description here

将80%调整为您想要使输入更白的任何值。

也许50%更令人愉悦。

enter image description here