protected override float PerPixelOperation(Matrix input, int row, int column) { float signalMean; float signalVariance; float trimmedMean; //calculate signal mean 1 and signal variance 1 SignalMeanInfo signalMeanInfo = new SignalMeanInfo(); DoWindowPass(input, row, column, CalculateSignalMean, signalMeanInfo); signalMean = signalMeanInfo.sum / signalMeanInfo.count; SignalVarianceInfo signalVarianceInfo = new SignalVarianceInfo(); signalVarianceInfo.signalMean = signalMean; DoWindowPass(input, row, column, CalculateSignalVariance, signalVarianceInfo); signalVariance = signalVarianceInfo.sum / (signalVarianceInfo.count - 1); //calculate z and eta and trimmed mean ZtmInfo ztmInfo = new ZtmInfo(WindowSize); ztmInfo.mean = signalMean; ztmInfo.stdev = (float)Math.Sqrt(signalVariance); DoWindowPass(input, row, column, CalcTrimmedMean, ztmInfo); trimmedMean = ztmInfo.sum / ztmInfo.eta; return(trimmedMean); }
protected virtual void CalcTrimmedMean(float value, int row, int column, int rowWithinWindow, int columnWithinWindow, ZtmInfo info) { float z = Math.Abs((value - info.mean) / info.stdev); info.z[rowWithinWindow, columnWithinWindow] = z; if (z <= _zeta) { info.eta++; info.sum += value; } }