希望有人可以帮助我,或者只是确认这是否确实可行。
我有一个带有水平线的PNG文件。我想根据这些行将图像分成较小的文件。我该如何实现?使用imageMagick可以吗?或从任何其他应用程序对此可以实现自动处理和批量处理。
我还要附加文件,以便更清晰。
谢谢
Bash脚本:
#!/bin/sh
w=$(identify -ping -format '%[width]' green_lines.png)
h=$(identify -ping -format '%[height]' green_lines.png)
convert green_lines.png -resize 1x"${h}"\! -resize "${w}"x"${h}"\! out_green.png
convert out_green.png -colorspace HSV -channel S -separate out_greenS.png
convert out_greenS.png -threshold 50% -negate out_greenS.png
convert out_greenS.png -define connected-components:verbose=true \
-define connected-components:area-threshold=500000 \
-connected-components 8 objects.png| awk '{print $2}'|tail -n +2 >coodr.txt
i=0
while read size
do
convert green_lines.png -crop "${size}" crop_"${i}".png
i=$((i+1))
done < coodr.txt