登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
public class DataSmooth {
/** * * @Title: smoothValues * @Description: 进行数据平滑, 平滑为9宫格数据去除最高和最低之后取平均值。 * @param input * @return */ public static float[][] smoothValues(float[][] input) { float[][] values = new float[input.length][input[0].length]; for (int i = 0; i < input.length; i++) { for (int j = 0; j < input[0].length; j++) { if (input[j] == Constants.DEFAULT_EMPTY_DATA) { values[j] = Constants.DEFAULT_EMPTY_DATA; continue; }
float max = 999999; float min = -999999; float total = 0; int count = 0; for (int m = -1; m < 2; m++) { for (int n = -1; n < 2; n++) { if (isValid(input, i - m, j - n) && input[i - m][j - n] != Constants.DEFAULT_EMPTY_DATA) { total += input[i - m][j - n]; max = buildMax(input[i - m][j - n], max); min = buildMin(input[i - m][j - n], min); count++; } } }
if (count > 3) { total = total - max - min; values[j] = total / (count - 2); } else if (count > 0) { values[j] = total / count; } else { values[j] = Constants.DEFAULT_EMPTY_DATA; } } } return values; }
private static boolean isValid(float[][] input, int m, int n) { if (m < 0 || m > input.length - 1) { return false; }
if (n < 0 || n > input[0].length - 1) { return false; } return true; }
private static float buildMax(float input, float max) { if (input > max || max == 999999) { max = input; } return max; }
private static float buildMin(float input, float min) { if (input < min || min == -999999) { min = input; } return min; } }
|