Why counting pixels does not work
The obvious way to find an image's colors is to count how often each exact value appears and take the most common. On anything photographic that fails badly.
A blue sky is not one blue. It is thousands of almost identical blues, each appearing a handful of times, so each one scores close to nothing. Meanwhile a flat background that really is a single value wins easily, and you get a palette of the least interesting part of the picture.
This groups similar colors together before counting, so those thousands of near-identical blues become the one blue a person would point at and name. That is why the result matches what you see rather than what the file technically contains.