【发布时间】:2018-02-04 03:54:18
【问题描述】:
基于对以下问题Programmatically divide scanned images into separate images 的回答,我现在能够提取矩形区域。
是否可以修改以下 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
能够提取与 tmp.png 中的黑色区域完全匹配的非矩形区域:
例如,为提取的图像的其余与黑色区域无关的矩形区域添加透明背景。
【问题讨论】:
标签: image-processing imagemagick