Pixelate image with average cell color I wrote a function that will pixelate an image using the average color of each 4x4 cell.

The function will "split" the image into 4x4 cells, and find the average color of each pixel in the 4x4 cell, and set the 4x4 cell to the average color.

I'd like some help optimizing my function so it can pixelate an image as fast as possible. In its current state the pixelation process is quite slow.

private static Image PixelateImage(Image image)
{
    var bitmap = new Bitmap(image.Width, image.Height);
    using (var graphics = Graphics.FromImage(bitmap))
    {
        graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),
            new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
    }

    // Loop through the image in 4x4 cells.
    for (var yy = 0; yy &lt; image.Height &amp;&amp; yy &lt; image.Height; yy += 4)
    {
        for (var xx = 0; xx &lt; image.Width &amp;&amp; xx &lt; image.Width; xx += 4)
        {
            var cellColors = new List&lt;Color&gt;();

            // Store each color from the 4x4 cell into cellColors.
            for (var y = yy; y &lt; yy + 4 &amp;&amp; y &lt; image.Height; y++)
            {
                for (var x = xx; x &lt; xx + 4 &amp;&amp; x &lt; image.Width; x++)
                {
                    cellColors.Add(bitmap.GetPixel(x, y));
                }
            }

            // Get the average red, green, and blue values.
            var averageRed = cellColors.Aggregate(0, (current, color) =&gt; current + color.R) / cellColors.Count;
            var averageGreen = cellColors.Aggregate(0, (current, color) =&gt; current + color.G) / cellColors.Count;
            var averageBlue = cellColors.Aggregate(0, (current, color) =&gt; current + color.B) / cellColors.Count;

            var averageColor = Color.FromArgb(averageRed, averageGreen, averageBlue);

            // Go BACK over the 4x4 cell and set each pixel to the average color.
            for (var y = yy; y &lt; yy + 4 &amp;&amp; y &lt; image.Height; y++)
            {
                for (var x = xx; x &lt; xx + 4 &amp;&amp; x &lt; image.Width; x++)
                {
                    bitmap.SetPixel(x, y, averageColor);
                }
            }
        }
    }
    return bitmap;
}
Jerry Coffin suggested that I should simply scale the image down to a smaller size, and then back up to the original size. (Thanks!)

Using Emgu CV, I was able to shorten my function to a single return statement.

private Image&lt;Bgr, byte&gt; PixelateImage(Image&lt;Bgr, byte&gt; image)
{
    return image.Resize((int)(image.Width * .25), (int)(image.Height * .25), Inter.Area)
        .Resize(image.Width, image.Height, Inter.Nearest);
}