Skip to content

Instantly share code, notes, and snippets.

@LionRoar
Last active November 19, 2017 22:28
Show Gist options
  • Save LionRoar/e6aa4effa7a89920be30a6eb888d80b3 to your computer and use it in GitHub Desktop.
Save LionRoar/e6aa4effa7a89920be30a6eb888d80b3 to your computer and use it in GitHub Desktop.
boxesForGaussianBlur
private int[] boxesForGaussian(double sigma, int n) {
double wIdeal = Math.Sqrt((12 * sigma * sigma / n) + 1);
double wl = Math.Floor(wIdeal);
if (wl % 2 == 0) wl--;
double wu = wl + 2;
double mIdeal = (12 * sigma * sigma– n * wl * wl– 4 * n * wl– 3 * n) / (-4 * wl– 4);
double m = Math.Round(mIdeal);
int[] sizes = new int[n];
for (int i = 0; i < n; i++) {
if (i < m) {
sizes[i] = (int) wl;
} else {
sizes[i] = (int) wu;
}
}
return sizes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment