Here you can find the source of meanFilter(float[] weights, int context)
Parameter | Description |
---|---|
weights | the array |
context | the context to be used for smoothing (from -context/2 to context/2) |
public static float[] meanFilter(float[] weights, int context)
//package com.java2s; /*/* w ww. j a va 2 s. c o m*/ * Copyright (C) 2010-2014 Andreas Maier * CONRAD is developed as an Open Source project under the GNU General Public License (GPL). */ public class Main { /** * Performs mean filtering of the array. * @param weights the array * @param context the context to be used for smoothing (from -context/2 to context/2) * @return the smoothed array */ public static float[] meanFilter(float[] weights, int context) { float meanFiltered[] = new float[weights.length]; float mean = 0; for (int i = 0; i < weights.length; i++) { if (i > context / 2) { mean -= weights[i - (context / 2)]; } if (i < (weights.length - 1) - (context / 2)) { mean += weights[i + (context / 2)]; } if (i < context / 2) { meanFiltered[i] = computeMean(weights, 0, i); } else if ((i + context / 2) >= weights.length) { meanFiltered[i] = computeMean(weights, i, weights.length - 1); } else { meanFiltered[i] = computeMean(weights, i - context / 2, i + context / 2); } } return meanFiltered; } /** * computes the mean of the array "values" on the interval [start, end]. * @param values the array * @param start the start index * @param end the end index * @return the mean value */ public static float computeMean(float[] values, int start, int end) { float revan = 0; for (int i = start; i <= end; i++) { revan += values[i]; } revan /= end - start + 1; return revan; } /** * Computes the mean value of a given array * @param array the array * @return the mean value as float */ public static float computeMean(float[] array) { float mean = 0; for (int i = 0; i < array.length; i++) { mean += array[i]; } return mean / array.length; } }