Now my script looks like this:
Maybe if you have time, you can help me to optimize my script to avoid the use of temporal images that are not needed.
Code: Select all
toremove=$(convert input.png -threshold 50% -type bilevel \
-define connected-components:verbose=true \
-connected-components 4 \
null: |
awk '/x45/{
sub(/x/, "+", $2)
split($2,b,"+")
printf("%sx%s+%s+%s\n",b[1]+2,b[2],b[3]-1,b[4])
}')
#Here I copy input to use it in loop below
convert input.png out.png
#Now in this loop I colorize to black 4 regions and I use as input and as output the same out.png. Is there a better way to do this?
for region in $toremove; do
convert out.png -region $region -fill '#000000' -colorize 100 out.png
done
convert out.png \
-transparent '#39D6AE' \
-transparent '#9EB629' \
-transparent '#8DA718' \
-transparent '#A47721' \
-transparent '#BD8B2B' \
-transparent '#EEEEEE' \
-transparent '#B4CEF8' \
-alpha extract -negate \
-threshold 50% -type bilevel \
-define connected-components:verbose=true \
-define connected-components:area-threshold=2000 \
-connected-components 4 \
null: | awk 'NR>2{print $2}'
Code: Select all
423x310+530+634
422x310+70+634
423x160+530+424
422x160+70+424
423x155+530+193
423x145+70+203
264x40+680+109