AForge.Math.Histogram.Update C# (CSharp) Method

Update() public method

Update statistical value of the histogram.
The method recalculates statistical values of the histogram, like mean, standard deviation, etc., in the case if histogram's values were changed directly. The method should be called only in the case if histogram's values were retrieved through Values property and updated after that.
public Update ( ) : void
return void
        public void Update( )
        {
            int i, n = values.Length;

            max = 0;
            min = n;
            total = 0;

            // calculate min and max
            for ( i = 0; i < n; i++ )
            {
                if ( values[i] != 0 )
                {
                    // max
                    if ( i > max )
                        max = i;
                    // min
                    if ( i < min )
                        min = i;

                    total += values[i];
                }
            }

            mean   = Statistics.Mean( values );
            stdDev = Statistics.StdDev( values, mean );
            median = Statistics.Median( values );
        }
    }

Usage Example

        /// <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( );
        }
All Usage Examples Of AForge.Math.Histogram::Update