Skip to content

Commit

Permalink
Fix parsing of pixel size for nan case (#110)
Browse files Browse the repository at this point in the history
Previously the double cast of NaN would fail silently, now we go down the "invalid pixel size of {} for {}" route.
Also remove "pixel calibration" from log message as toString of pixel calibration already contains "Pixel Calibration"
  • Loading branch information
alanocallaghan authored Nov 15, 2024
1 parent 7611373 commit 9540dd2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/qupath/ext/instanseg/core/InstanSegModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public double getPreferredDownsample(PixelCalibration cal) {
if (requested > 0 && current > 0) {
return getPreferredDownsample(current, requested);
} else {
logger.warn("Invalid pixel size of {} for pixel calibration {}", requested, cal);
logger.warn("Invalid pixel size of {} for {}", requested, cal);
return 1.0;
}
}
Expand All @@ -193,6 +193,7 @@ public double getPreferredDownsample(PixelCalibration cal) {
* @return The exact downsample, unless it's close to an integer, in which case the integer.
*/
static double getPreferredDownsample(double currentPixelSize, double requestedPixelSize) {
System.out.println(requestedPixelSize);
double downsample = requestedPixelSize / currentPixelSize;
double downsampleRounded = Math.round(downsample);
if (GeneralTools.almostTheSame(downsample, Math.round(downsample), 0.01)) {
Expand Down Expand Up @@ -358,9 +359,11 @@ private Optional<Map<String, Double>> getPixelSize() {
var config = model.getConfig().getOrDefault("qupath", null);
if (config instanceof Map configMap) {
var axes = (List) configMap.get("axes");
String x = (String) ((Map) (axes.get(0))).get("step");
String y = (String) ((Map) (axes.get(1))).get("step");
return Optional.of(Map.of(
"x", (Double) ((Map) (axes.get(0))).get("step"),
"y", (Double) ((Map) (axes.get(1))).get("step")
"x", Double.valueOf(x),
"y", Double.valueOf(y)
));
}
return Optional.of(Map.of("x", 1.0, "y", 1.0));
Expand Down

0 comments on commit 9540dd2

Please sign in to comment.