Fred's dominantcolor script for imagemagick might work for you:
https://www.fmwconcepts.com/imagemagick/dominantcolor/index....