public static double [ ] gaussianSmooth ( double [ ] values , int kernelRadius ) throws Exception { int size = values . length ; double [ ] newValues = new double [ values . length ] ; double [ ] kernelData2D = makeGaussianKernel ( kernelRadius ) ; for ( int i = 0 ; i < kernelRadius ; i ++ ) { newValues [ i ] = values [ i ] ; } for ( int r = kernelRadius ; r < size - kernelRadius ; r ++ ) { double kernelSum = 0.0 ; double outputValue = 0.0 ; int k = 0 ; for ( int kc = - kernelRadius ; kc <= kernelRadius ; kc ++ , k ++ ) { double value = values [ r + kc ] ; if ( ! isNovalue ( value ) ) { outputValue = outputValue + value * kernelData2D [ k ] ; kernelSum = kernelSum + kernelData2D [ k ] ; } } newValues [ r ] = outputValue / kernelSum ; } for ( int i = size - kernelRadius ; i < size ; i ++ ) { newValues [ i ] = values [ i ] ; } return newValues ; }
Smooth an array of values with a gaussian blur .