views:

47

answers:

3

So say I have an image that I want to "pixelate". I want this sharp image represented by a grid of, say, 100 x 100 squares. So if the original photo is 500 px X 500 px, each square is 5 px X 5 px. So each square would have a color corresponding to the 5 px X 5 px group of pixels it swaps in for...

How do I figure out what this one color, which is best representative of the stuff it covers, is? Do I just take the R G and B numbers for each of the 25 pixels and average them? Or is there some obscure other way I should know about? What is conventionally used in "pixelation" functions, say like in photoshop?

A: 

Averaging the values of the pixels is the first thing I'd try.

An alternative method would be to scale the image down, then back up again. Scaling a small image to make it larger always gives it a distorted, pixelated appearance. I think you'll have much tighter control over the area of each pixelized region with the first method though.

Bill the Lizard
Beware: when scaling back up - you have to use 'nearest neighbor' algorithm, or else your pixelating will fail and you get something like 'blur' instead.
Daniel Mošmondor
A: 

when the source and target grids are so evenly divisible and aligned, most algorigthms give similar results. if the grids are fixed, go for simple averages.

in other cases, especially when resizing by a small percentage, the quality difference is quite evident. the simplest enhancement over simple average is weighting each pixel value considering how much of it's contained in the target pixel's area.

for more algorithms, check multivariate interpolation

Javier
+3  A: 
Porges