gpt4 book ai didi

image-processing - 使用图像魔术从图像中删除背景(任何颜色)

转载 作者:行者123 更新时间:2023-12-02 16:04:20 26 4
gpt4 key购买 nike

嗨,我问这个问题是关于这个问题 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 .

感谢任何帮助

最佳答案

这对我来说适用于 Unix 语法的 ImageMagick 6。

输入:

enter image description here

convert eagle.png -alpha off -fuzz 10% -fill none -draw "matte 0,0 floodfill"  \
\( +clone -alpha extract -blur 0x2 -level 50x100% \) \
-alpha off -compose copy_opacity -composite \
eagle_transp.png

结果:

enter image description here

Windows 语法为:

convert eagle.png -alpha off -fuzz 10% -fill none -draw "matte 0,0 floodfill"^( +clone -alpha extract -blur 0x2 -level 50x100% ) ^-alpha off -compose copy_opacity -composite ^eagle_transp.png

如果在 .bat 脚本中,将 % 加倍到 %%

关于image-processing - 使用图像魔术从图像中删除背景(任何颜色),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69851329/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com