LockBits new Rectangle 0, 0, b. Distinct ; Optionally: Eliminate similar colors until you have your preferred palette size. You may need to consider some heuristics rather than blindly picking the top so-many counts, because you probably want to pick hues that are somewhat separated on the color spectrum. If you have made a selection to select just part of the image, click the Selected Pixels only tick box. For block 8 index 1,1 I would determine the pixels from the smoothed image and add all of the color values together and take the average.
Once you have the reduced palette, you recolor the picture using the nearest neighbor color that is in the palette. I really don't understand how to average or add colors together. These are experiental and I'm still tweaking the numbers. This problem had been solved when you posted this answer, several decades prior, actually. After picking several prominent hues, subdivide pixels of those hues into another histogram measuring saturation, and pick out prominent clusters, and so on.
The answers involving the code show you how to get the full palette. Blurring will smooth out these sharp color changes for a more predictable result. I'm going to describe the best approach at a very high level. This can be useful if you want your layout to have the opposite look of a particular image. It would follow, then, that fetching distinct colors will likely not help you accomplish your goal. Provide details and share your research! Rough Example The code below makes some attempt to help identify prominent hues.
In addition to generating a color palette for the image, a color palette of complimentary colors is also generated. Would you like to know what color is in your picture? Facebook is a registered trademark of Facebook, Inc. Sorry for being so negative about your solution, I'm just really surprised that this gets so many upvotes. Instead of white for the clouds and blue for the sky, you get lots of light blues and grays. I have no idea where to even begin.