Reputation: 17
Hope someone can help me on this or just to confirm if this is actually doable or not.
I've a PNG file that has horizontal lines. I'd like to split the image into smaller files based on these lines. How can I achieve this? Is this possible using imageMagick? Or from any other application for that matter that would allow it be automatic and batch processable.
I'm attaching the files as well so that it is more clear.
Thanks
Upvotes: 0
Views: 353
Reputation: 2018
Bash script:
#!/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
Upvotes: 1