Skip to content

Instantly share code, notes, and snippets.

@zhaar
Created December 20, 2016 23:58
Show Gist options
  • Save zhaar/19f0bf7b7d721a621028c1183fc8b38e to your computer and use it in GitHub Desktop.
Save zhaar/19f0bf7b7d721a621028c1183fc8b38e to your computer and use it in GitHub Desktop.
//Sane signature: Acc -> (Acc, [(Int, Int)]) the list of pair returned contains the index and the amount of votes associated
public static Function<HoughAccInterface, Pair<HoughAccInterface, List<Pair<Integer, Integer>>>> mapToClusters(int minVotes, int neighborhood) {
return hough -> {
//Sane: [(Int, Int)] -> (Int, Int) -> [(Int, Int)]
BiFunction<List<Pair<Integer, Integer>>, Pair<Integer, Integer>, List<Pair<Integer, Integer>>> accumulator = (acc, pair) -> {
int votes = pair._1();
int index = pair._2();
Pair<Integer, Integer> coord = hough.convertIndex(index);
if (votes > minVotes && isLocalMaxima(hough, coord._1(), coord._2(), neighborhood)) {
acc.add(new Pair<>(index, votes));
}
return acc;
};
List<Pair<Integer, Integer>> result = new ArrayList<>();
for (Pair<Integer, Integer> element : MyList.zipWithIndex(hough.getDataArray())) {
result = accumulator.apply(result, element);
}
return new Pair<>(hough, result);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment