Exemple #1
0
        /// <summary>
        /// Assumes the passed matrix is a spectrogram. i.e. rows=frames, cols=freq bins.
        /// WARNING: This method should NOT be used for short recordings (i.e LT approx 10-15 seconds long)
        /// because it obtains a background noise profile from the passed percentile of lowest energy frames.
        ///
        /// Same method as above except take square root of the cell energy divided by the noise.
        /// Taking the square root has the effect of reducing image contrast.
        /// </summary>
        public static double[,] NoiseReduction_byDivisionAndSqrRoot(double[,] matrix, int percentileThreshold)
        {
            double[] profile = NoiseProfile.GetNoiseProfile_fromLowestPercentileFrames(matrix, percentileThreshold);
            profile = DataTools.filterMovingAverage(profile, 3);

            // to prevent division by zero.
            double epsilon = 0.0001;

            int rowCount = matrix.GetLength(0);
            int colCount = matrix.GetLength(1);

            double[,] outM = new double[rowCount, colCount]; //to contain noise reduced matrix

            // for all cols i.e. freq bins
            for (int col = 0; col < colCount; col++)
            {
                double denominator = profile[col];
                if (denominator < epsilon)
                {
                    denominator = epsilon;
                }

                // for all rows
                for (int y = 0; y < rowCount; y++)
                {
                    outM[y, col] = Math.Sqrt(matrix[y, col] / denominator);
                } //end for all rows
            }     //end for all cols

            return(outM);
        }
        /// <summary>
        /// Assumes the passed matrix is a spectrogram. i.e. rows=frames, cols=freq bins.
        /// WARNING: This method should NOT be used for short recordings (i.e LT approx 10-15 seconds long)
        /// Obtains a background noise profile from the passed percentile of lowest energy frames,
        /// Then subtracts the noise profile value from every cell.
        /// This method was adapted from a paper by Briggs.
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="percentileThreshold"></param>
        /// <returns></returns>
        public static double[,] NoiseReduction_byLowestPercentileSubtraction(double[,] matrix, int percentileThreshold)
        {
            double[] profile = NoiseProfile.GetNoiseProfile_fromLowestPercentileFrames(matrix, percentileThreshold);
            profile = DataTools.filterMovingAverage(profile, 3);

            int rowCount = matrix.GetLength(0);
            int colCount = matrix.GetLength(1);

            double[,] outM = new double[rowCount, colCount]; //to contain noise reduced matrix

            for (int col = 0; col < colCount; col++)         //for all cols i.e. freq bins
            {
                for (int y = 0; y < rowCount; y++)           //for all rows
                {
                    outM[y, col] = matrix[y, col] - profile[col];
                } //end for all rows
            }     //end for all cols

            return(outM);
        }