This works by cropping away the outer 20% edge (gravity center indicates a crop of the outside edges). It then scales the image down to a single pixel and outputs that to the screen (if you replace the - at the end of the line with a filename you can write the output to a file). You can also experiment with resize/filter options, but scale is going to be quite a bit faster and for this application, I expect perfect.

Note that these values are Red/Green/Blue values, how you sort is another issue. You can pick the highest values and assume it is predominant, but that is probably not going to get the result you want, changing to either HSL or HSB is probably going to provide a more useful set of values for sorting: