基于水平线的切片图像

slice image based on horizontal lines

希望有人可以帮助我解决这个问题,或者只是确认这是否真的可行。

我有一个包含水平线的 PNG 文件。我想根据这些行将图像拆分成更小的文件。 我怎样才能做到这一点?这可能使用 imageMagick 吗?或者来自任何其他允许自动和批处理的应用程序。

我也附上文件,这样更清楚。

谢谢

原文件:

切片第 1 部分:

切片第 2 部分:

切片第 3 部分:

切片第 4 部分:

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 }'|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