Skip to content

Instantly share code, notes, and snippets.

@esibirtseva
Created February 28, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esibirtseva/e53dd29963f715ae39bc to your computer and use it in GitHub Desktop.
Save esibirtseva/e53dd29963f715ae39bc to your computer and use it in GitHub Desktop.
naive blur
public byte[] blurGauss_1(byte[] originalImage, int w, int h, double r)
{
byte[] blurImage = new byte[originalImage.Length];
int rs = (int)Math.Ceiling(r * 2.57);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
double val = 0, wsum = 0;
for (int iy = i - rs; iy < i + rs + 1; iy++ )
{
for (int ix = j - rs; ix < j + rs + 1; ix++)
{
int x = Math.Min(w-1, Math.Max(0, ix));
int y = Math.Min(h-1, Math.Max(0, iy));
int dsq = (ix - j) * (ix - j) + (iy - i) * (iy - i);
double wght = Math.Exp( -dsq / (2*r*r) ) / (Math.Sqrt(Math.PI*2)*r);
val += originalImage[y * w + x] * wght; wsum += wght;
}
}
blurImage[i * w + j] = (byte)Math.Round(val/wsum);
}
}
return blurImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment