如何使用peak_detection函数-Android Studio

时间:2018-09-09 20:08:48

标签: java android

我正在尝试使用this函数,但是遇到一些错误。我将使用此功能从Android相机的FastICA实现中实时检测有关RGB图像的峰值。我在FastICA的第一个参数Double[] Green = ArrayUtils.toObject(arrayGreen);中使用的输出正常。我在第二个参数中使用了double delta=10;,很好。我在使用第三个参数时遇到问题,因为我不了解我需要哪个是第三个参数。 我试图创建一个List<Integer> indices = new ArrayList<Integer>();,但是没有用。有人可以帮我吗? 预先感谢

我正在尝试的代码:

import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

public abstract class CustomUtils {


    /**
     * Detects peaks (calculates local minima and maxima) in the 
     * vector <code>values</code>. The resulting list contains
     * maxima at the first position and minima at the last one.
     * 
     * Maxima and minima maps contain the indice value for a
     * given position and the value from a corresponding vector.
     * 
     * A point is considered a maximum peak if it has the maximal
     * value, and was preceded (to the left) by a value lower by
     * <code>delta</code>.
     * 
     * @param values Vector of values for whom the peaks should be detected
     * @param delta The precedor of a maximum peak
     * @param indices Vector of indices that replace positions in resulting maps
     * @return List of maps (maxima and minima pairs) of detected peaks
     */
    public static <U> List<Map<U, Double>> peak_detection(List<Double> values, Double delta, List<U> indices)
    {
        assert(indices != null);
        assert(values.size() != indices.size());

        Map<U, Double> maxima = new HashMap<U, Double>();
        Map<U, Double> minima = new HashMap<U, Double>();
        List<Map<U, Double>> peaks = new ArrayList<Map<U, Double>>();
        peaks.add(maxima);
        peaks.add(minima);

        Double maximum = null;
        Double minimum = null;
        U maximumPos = null;
        U minimumPos = null;

        boolean lookForMax = true;

        Integer pos = 0;
        for (Double value : values) {
            if (value > maximum || maximum == null) {
                maximum = value;
                maximumPos = indices.get(pos);
            }

            if (value < minimum || minimum == null) {
                minimum = value;
                minimumPos = indices.get(pos);
            }

            if (lookForMax) {
                if (value < maximum - delta) {
                    maxima.put(maximumPos, value);
                    minimum = value;
                    minimumPos = indices.get(pos);
                    lookForMax = false;
                }
            } else {
                if (value > minimum + delta) {
                    minima.put(minimumPos, value);
                    maximum = value;
                    maximumPos = indices.get(pos);
                    lookForMax = true;
                }
            }

            pos++;
        }

        return peaks;
    }

    /**
     * Detects peaks (calculates local minima and maxima) in the 
     * vector <code>values</code>. The resulting list contains
     * maxima at the first position and minima at the last one.
     * 
     * Maxima and minima maps contain the position for a
     * given value and the value itself from a corresponding vector.
     * 
     * A point is considered a maximum peak if it has the maximal
     * value, and was preceded (to the left) by a value lower by
     * <code>delta</code>.
     * 
     * @param values Vector of values for whom the peaks should be detected
     * @param delta The precedor of a maximum peak
     * @return List of maps (maxima and minima pairs) of detected peaks
     */
    public static List<Map<Integer, Double>> peak_detection(List<Double> values, Double delta)
    {
        List<Integer> indices = new ArrayList<Integer>();
        for (int i=0; i<values.size(); i++) {
            indices.add(i);
        }

        return ANPRUtils.peak_detection(values, delta, indices);
    }

}

修改 在第一个函数中使用第二个函数,我遇到了这个错误: enter image description here

1 个答案:

答案 0 :(得分:1)

第三个参数有点奇怪-它是对应的最小值和最大值的名称列表。因此,假设数据中位置1处有1,然后将其与列表一起传递给第三个参数(“ A”,“ B”,“ C”)。返回值将是一个映射(“ B”->最大值)。

它的代码很奇怪,我不确定他们为什么这样做。看来做事很不方便。另外,我认为如果index.size()

请注意,函数的2值版本正在传入(1,2,3,4,... n)数组,其中n是数据中的值数。在这种情况下,返回值将是(位置索引->最大值/最小值)的映射。这似乎是您应该使用此方法的唯一方法。