Advertisement
Guest User

Color Detection in Bash…

a guest
Nov 15th, 2017
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Color Detection in Bash…
  2.  
  3. I stumbled upon this article about Color Detection in Scans…
  4. http://virantha.com/2014/03/30/images-color-and-blank-detection/
  5.  
  6. It's written in Python… I thought it my be quite handsome to have the same idea as bash script… and as usual I build a 1-liner.
  7.  
  8. Needed: Imagemagicks 'convert', sed, awk & cat – you always need a cat ;)
  9.  
  10. cat Name_a_picture.png | convert - -colors 8 -depth 8 -format %c histogram:info:- | sed -e 's/\((\|)\)/_/g' -e 's/ //g' -e 's/_/ /g' | awk '{print $1" "$2}' | sort -t : -k 1 -g -r | awk '{print $2}' | sed -e 's/,/ /g' | awk -F' ' 'function abs(x){return ((x < 0.0) ? -x : x)} {if (((abs($3-$2)+abs($3-$1)+abs($2-$1))/3) > 20) print "Color found."}'
  11.  
  12. …grumpy…
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement