Test if image has ALL the given colors?
Posted: 2013-09-18T19:56:48-07:00
Okay I have been running a program that remotely controls an application, grabs screen shots, and looks for specific (exact) colors in that screen shot.
ASIDE: the colors represent biomes in a randomised world generator.
This is the code I am currently using (ignoring the image source and other irrelevent stuff)
If the resulting single pixel image is not black then we have found a image that contains at least one of the four colors. The 'sed' command returns a non-blank string if this is the case.
Now the above is straight forward. but what I now need is a similar test for an image that contains ALL of these colors, not just any one of them. Logically a test for an image containing a 'AND' of the colors, not just a 'OR'.
I am a little stumped by the problem. perhaps I am just having a brain block as I am usually pretty good at solving it.
ASIDE: the colors represent biomes in a randomised world generator.
This is the code I am currently using (ignoring the image source and other irrelevent stuff)
Code: Select all
color1='magenta'
color2='#B4DCDC'
color3='#FF6D3D'
color4='#E5DA87'
search=`convert image.png \
-fill black -opaque "white" \
-fill white -opaque "$color1" \
-fill white -opaque "$color2" \
-fill white -opaque "$color3" \
-fill white -opaque "$color4" \
-fill black +opaque "white" \
-scale 1x1 \
-depth 16 txt:- |
sed '1d; /black/d'`
if [ "X$search" != "X" ]; then
echo "===================Found One================"
# ....
fi
Now the above is straight forward. but what I now need is a similar test for an image that contains ALL of these colors, not just any one of them. Logically a test for an image containing a 'AND' of the colors, not just a 'OR'.
I am a little stumped by the problem. perhaps I am just having a brain block as I am usually pretty good at solving it.