Created
February 28, 2015 13:39
-
-
Save esibirtseva/e53dd29963f715ae39bc to your computer and use it in GitHub Desktop.
naive blur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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