Get coordinates Top, Left, size of some areas

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Posts: 42
Joined: 2018-10-10T23:36:52-07:00
Authentication code: 1152

Re: Get coordinates Top, Left, size of some areas

Post by cgkas »

I was able to remove the unwanted regions of big boxes filtering first all those regions that have 45 pixel height and changing those regions to black.

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)

#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

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

Thanks again

User avatar
Posts: 26057
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Get coordinates Top, Left, size of some areas

Post by fmw42 »

Looks pretty nice. Glad you resolved it.

Post Reply