Image processing ImageMagick使用透明背景提取非矩形区域

Image processing ImageMagick使用透明背景提取非矩形区域,image-processing,imagemagick,Image Processing,Imagemagick,根据下面问题的答案,我现在能够提取矩形区域 是否可以修改以下ImageMagick脚本: infile="image.png" inname=`convert -ping $infile -format "%t" info:` OLDIFS=$IFS IFS=$'\n' arr=(`convert $infile -blur 0x5 -auto-level -threshold 99% -type bilevel +write tmp.png \ -define connected-compon

根据下面问题的答案,我现在能够提取矩形区域

是否可以修改以下ImageMagick脚本:

infile="image.png"
inname=`convert -ping $infile -format "%t" info:`
OLDIFS=$IFS
IFS=$'\n'
arr=(`convert $infile -blur 0x5 -auto-level -threshold 99% -type bilevel +write tmp.png \
-define connected-components:verbose=true \
-connected-components 8 \
null: | tail -n +2 | sed 's/^[ ]*//'`)
num=${#arr[*]}
IFS=$OLDIFS
for ((i=0; i<num; i++)); do
#echo "${arr[$i]}"
color=`echo ${arr[$i]} | cut -d\  -f5`
bbox=`echo ${arr[$i]} | cut -d\  -f2`
echo "color=$color; bbox=$bbox"
if [ "$color" = "gray(0)" ]; then
convert $infile -crop $bbox +repage -fuzz 10% -trim +repage ${inname}_$i.png
fi
done
infle=“image.png”
inname=`convert-ping$infle-格式“%t”信息:`
OLDIFS=$IFS
IFS=$'\n'
arr=(`convert$infle-blur 0x5-auto-level-threshold 99%-类型二层+write tmp.png\
-定义连接的组件:verbose=true\
-连接部件8\
null:| tail-n+2 | sed's/^[]*/'`)
num=${#arr[*]}
IFS=$OLDIFS

对于((i=0;iYes),可以按如下方式修改ImageMagick脚本:

infile="image.png"
inname=`convert -ping $infile -format "%t" info:`
OLDIFS=$IFS
IFS=$'\n'
arr=(`convert $infile +repage -blur 0x7 -auto-level -negate -threshold 2% -negate -type bilevel +write tmp.png \
-define connected-components:verbose=true \
-connected-components 8 \
null: | tail -n +2 | sed 's/^[ ]*//'`)
num=${#arr[*]}
IFS=$OLDIFS
for ((i=0; i<num; i++)); do
echo "${arr[$i]}"
color=`echo ${arr[$i]} | cut -d\  -f5`
bbox=`echo ${arr[$i]} | cut -d\  -f2`
echo "color=$color; bbox=$bbox"
if [ "$color" = "gray(0)" ]; then
convert tmp.png -crop $bbox +repage -fuzz 10% -trim +repage -alpha copy -channel a -negate +channel ${inname}_$i.png
fi
done
infle=“image.png”
inname=`convert-ping$infle-格式“%t”信息:`
OLDIFS=$IFS
IFS=$'\n'
arr=(`convert$infle+repage-blur 0x7-auto-level-negate-threshold 2%-negate-type bilevel+write tmp.png\
-定义连接的组件:verbose=true\
-连接部件8\
null:| tail-n+2 | sed's/^[]*/'`)
num=${#arr[*]}
IFS=$OLDIFS

我非常感谢你一如既往的帮助!