Skip to content

Commit

Permalink
Parallel stream geometryToFilledRoi (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan authored Aug 21, 2024
1 parent 9ab48e8 commit afdfe08
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,27 @@ public List<PathObject> convertToObjects(Parameters<Mat, Mat> params, Mat output
roisToPathObjectsFunction = getTwoClassBiFunction(classes, rng);
}

List<PathObject> cells;
if (geomMaps.size() == 1) {
// One-channel detected, represent using detection objects
return geomMaps.get(0).values().stream()
.map(geom -> roisToPathObjectsFunction.apply(geometryToFilledROI(geom, plane), null))
cells = geomMaps.get(0).values().parallelStream()
.map(geom -> roisToPathObjectsFunction.
apply(geometryToFilledROI(geom, plane), null))
.collect(Collectors.toList());
} else {
// Two channels detected, represent using cell objects
// We assume that the labels are matched - and we can't have a nucleus without a cell
Map<Number, Geometry> childGeoms = geomMaps.get(0);
Map<Number, Geometry> parentGeoms = geomMaps.get(1);
List<PathObject> cells = new ArrayList<>();
for (var entry : parentGeoms.entrySet()) {
cells = parentGeoms.entrySet().parallelStream().map(entry -> {
var parent = geometryToFilledROI(entry.getValue(), plane);
var child = geometryToFilledROI(childGeoms.getOrDefault(entry.getKey(), null), plane);
var outputObject = roisToPathObjectsFunction.apply(parent, child);
cells.add(outputObject);
}
return cells;
return roisToPathObjectsFunction.apply(parent, child);

}).collect(Collectors.toList());
}
return cells;

}

private static ROI geometryToFilledROI(Geometry geom, ImagePlane plane) {
Expand Down

0 comments on commit afdfe08

Please sign in to comment.