I\'m trying to figure out how to sample all of the pixels in an image and generate a palette of colors from it, something like this or this. I have no idea where to even beg
The answers involving the code show you how to get the full palette. If you want to get the average colors like in the websites you posted, this is how I would do it.
Source Image:

First, I would average the colors by applying a lowpass filter (something like a Gaussian Blur)

That way you are limiting the total palette. From there I would divide the screen into N blocks (N being the total number of pixels you want in your palette)

From there, target each block and iterate over each pixel, and get the average pixel for that block and add it to your palette index. The result is something like this:

That way your palette is limited and you get the average colors from the different regions. You can do all of that in code, and if you'd like some help with that, let me know and I'll post some. This is just the High Level "what I would do".