detectPeaks method

List<List<int>> detectPeaks (List<Float64List> matrix, int startRow, int endRow, int startCol, int endCol, double noise, double threshold, String peakSign, int maxPeaks)

Detects 2D peaks in matrix. Method: Detects row an col peaks separately. A 2D peak is found if a row and a column both have a peak at their crossing point. Detection is performed in the submatrix defined by ixstartRows, ixendRows, ixstartCols, ixendCols (end exclusive). noise is used for differentiating peaks from noise, i.e. small variations of the array values, e.g. in case the values represent measurements.The noise is data dependent and must be estimated from the data. All peaks less or equal than threshold will not be added to the list. peakSign is one of PeakPicker1D's PICK_POS, PICK_NEG, PICK_POSNEG. If maxPeaks > 0, the returned list will only contain the maxPeaks biggest peaks (or smallest for negative peaks) of all detected ones. Possibly in this case the returned list has not the length maxPeaks*2, but it is smaller, even 0. Returns the peak coordinates as a list of row,col pairs: row, col, row, col, ... The resulting array's length is the number of peaks found.

Implementation

List<List<int>> detectPeaks(
    List<Float64List> matrix,
    int startRow,
    int endRow,
    int startCol,
    int endCol,
    double noise,
    double threshold,
    String peakSign,
    int maxPeaks) {
  detectRowPeaks(matrix, startRow, endRow, startCol, endCol, noise, threshold,
      peakSign, maxPeaks);
  detectColPeaks(matrix, startRow, endRow, startCol, endCol, noise, threshold,
      peakSign, maxPeaks);

  List<List<int>> peaklist = [];
  // check if a column has a peak at the same position as a row.
  // if yes, at the 2D peak to the list.
  rowPeaks.forEach((int row, List<int> cols) {
    cols.forEach((int col) {
      if (colPeaks.containsKey(col) && colPeaks[col].contains(row)) {
        peaklist.add([row, col]);
      }
    });
  });
  return peaklist;
}