src/weightedBoxBlurGaussian.js
function boxesForGauss(sigma, n) {
    // Calculate how far out we need to go to capture the bulk of the distribution.
    var wIdeal = Math.sqrt(12*sigma*sigma/n + 1); // Ideal averaging filter width
    var wl = Math.floor(wIdeal); // Lower odd integer bound on the width
    if (wl % 2 === 0) wl--;
    var wu = wl+2; // Upper odd integer bound on the width

    var mIdeal = (12*sigma*sigma - n*wl*wl - 4*n*wl - 3*n)/(-4*wl - 4);
    var m = Math.round(mIdeal);
    // var sigmaActual = Math.sqrt( (m*wl*wl + (n-m)*wu*wu - n)/12 );

    var sizes = new Int16Array(n);
    for (var i = 0; i < n; i++) { sizes[i] = i < m ? wl : wu; }
    return sizes;
}
function boxesForGauss(sigma, n) {
    // Calculate how far out we need to go to capture the bulk of the distribution.
    var wIdeal = Math.sqrt(12*sigma*sigma/n + 1); // Ideal averaging filter width
    var wl = Math.floor(wIdeal); // Lower odd integer bound on the width
    if (wl % 2 === 0) wl--;
    var wu = wl+2; // Upper odd integer bound on the width

    var mIdeal = (12*sigma*sigma - n*wl*wl - 4*n*wl - 3*n)/(-4*wl - 4);
    var m = Math.round(mIdeal);
    // var sigmaActual = Math.sqrt( (m*wl*wl + (n-m)*wu*wu - n)/12 );

    var sizes = new Int16Array(n);
    for (var i = 0; i < n; i++) { sizes[i] = i < m ? wl : wu; }
    return sizes;
}
function boxesForGauss ( sigma , n ) { // Calculate how far out we need to go to capture the bulk of the distribution. var wIdeal = Math . sqrt ( 12 * sigma * sigma / n + 1 ) ; // Ideal averaging filter width var wl = Math . floor ( wIdeal ) ; // Lower odd integer bound on the width if ( wl % 2 === 0 ) wl -- ; var wu = wl + 2 ; // Upper odd integer bound on the width var mIdeal = ( 12 * sigma * sigma - n * wl * wl - 4 * n * wl - 3 * n ) / ( - 4 * wl - 4 ) ; var m = Math . round ( mIdeal ) ; // var sigmaActual = Math.sqrt( (m*wl*wl + (n-m)*wu*wu - n)/12 ); var sizes = new Int16Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { sizes [ i ] = i < m ? wl : wu ; } return sizes ; }
Calculate the size of boxes needed to approximate a Gaussian blur.

The appropriate box sizes depend on the number of box blur passes required.

@param Number sigma
The standard deviation (how much to blur).
@param Number n
The number of boxes (also the number of box blurs you want to perform
using those boxes).
Calculate the size of boxes needed to approximate a Gaussian blur .