【发布时间】:2018-03-25 14:50:43
【问题描述】:
我有大约 2700 张图片想要:
- 转换为 .png
- 使白色背景透明
为此,我使用 Homebrew 下载了 ImageMagick 并在相关目录中运行以下命令:
find . -type f -name "*.jpg" -print0 | while IFS= read -r -d $'\0' file; do convert -verbose "$file" -transparent white "$file.png"; done
这行得通,但是根据下图,图像周围仍有一些白色斑点。使用灰白色的瓶子,就更难了,因为它也使一些瓶子变得透明!
在 Photoshop 中,您可以调整“MagicWand”的“容差”以确保不会发生这种情况,但我不确定您如何使用 ImageMagick 来做到这一点,并且在 Google 上找不到任何东西。
Example of Image with white crust around outside
有人可以帮忙吗?有没有办法用 ImageMagick 做到这一点?有没有更好的方法来处理这 2700 张图像以去除白色背景?
谢谢 一个
【问题讨论】:
-
你可以尝试允许一些 "fuzz"...
convert bottle.png -fuzz 10% -transparent white result.png -
在实践中,您希望使用与 Gimp 的 Color-to-alpha 等效的方法,将边缘上的灰色像素转换为部分透明的像素。 magick 中没有这样的运算符,但存在一个很好的近似值,请参阅here
标签: image image-processing terminal imagemagick