/// <summary> /// Filter histogram's low values. /// </summary> /// /// <param name="histogram">Histogram to filter.</param> /// private void FilterLowValues( Histogram histogram ) { int[] values = histogram.Values; int globalMax = 0; // find global maximum value for ( int k = 0; k < values.Length; k++ ) { if ( values[k] > globalMax ) { globalMax = values[k]; } } // filter values, which are below 10% of max int filterLevel = (int) ( (double) globalMax / 10 ); // do filtering for ( int k = 0; k < values.Length; k++ ) { if ( values[k] <= filterLevel ) { values[k] = 0; } } histogram.Update( ); }
/// <summary> /// Remove peaks from the histogram, which don't contain maximum value. /// </summary> /// /// <param name="histogram">Histogram to process.</param> /// private void FilterNoisyPeaks( Histogram histogram ) { int[] values = histogram.Values; int globalMax = 0; // find global maximum value for ( int k = 0; k < values.Length; k++ ) { if ( values[k] > globalMax ) { globalMax = values[k]; } } int i = 0; // process all peaks while ( i < values.Length ) { // find start of next peak while ( ( i < values.Length ) && ( values[i] == 0 ) ) { i++; } int localMax = 0; // find peak's maximum value while ( ( i < values.Length ) && ( values[i] != 0 ) ) { if ( values[i] > localMax ) { localMax = values[i]; } i++; } // remove this peak if it does not contain global maximum if ( localMax < globalMax ) { int j = i - 1; while ( ( j >= 0 ) && ( values[j] != 0 ) ) { values[j] = 0; j--; } } } histogram.Update( ); }
/// <summary> /// return a full depp copy /// </summary> /// <param name="from">Source</param> /// <returns>Copyed reference</returns> private Histogram copyHist(Histogram from) { int[] values = new int[from.Values.Length]; from.Values.CopyTo(values, 0); Histogram to = new Histogram(values); to.Update(); return to; }