【发布时间】:2021-12-19 09:29:46
【问题描述】:
您好,我是根据这个问题问这个问题Fuzzy flood fill in ImageMagic php - making a transparent image
#!/bin/bash
# Get size of original
sz=$(convert -format "%wx%h" phone.png info:)
# Floodfill background area with transparency
convert phone.png -fuzz 5% -fill none -draw 'color 0,0 floodfill' ObjectOnTransparent.png
# Extract alpha channel
convert ObjectOnTransparent.png -alpha extract Alpha.png
# Extract edges of alpha channel - experiment with thickness
convert Alpha.png -edge 1 AlphaEdges.png
# Get difference from background for all pixels
convert phone.png \( +clone -fill white -colorize 100% \) -compose difference -composite Diff.png
# Multiply edges with difference, so only edge pixels will have a chance of getting through to final mask
convert AlphaEdges.png Diff.png -compose multiply -composite EdgexDiff.png
# Extend Alpha by differences at edges
convert Alpha.png EdgexDiff.png -compose add -composite ReEdgedAlpha.png
# Apply new alpha to original image
convert phone.png \( ReEdgedAlpha.png -colorspace gray \) -compose copyopacity -composite RemaskedPhone.png
# Splat RemaskedPhone over red background
convert -size $sz xc:red RemaskedPhone.png -composite Result.png
我运行了这些脚本,它在白色背景的图像上运行准确,并且产生了干净的边缘,但我想问是否有任何方法可以从像这张图片https://ibb.co/BNWnNBs 这样的图像中删除任何颜色背景我想从中删除像https://ibb.co/x7nD8Vb这样的图像角落的黑色。
感谢任何帮助
【问题讨论】:
标签: image-processing imagemagick