diff --git a/src/main/java/qupath/lib/images/servers/omero/OmeroWebImageServer.java b/src/main/java/qupath/lib/images/servers/omero/OmeroWebImageServer.java index a04ff6e..cb854e1 100644 --- a/src/main/java/qupath/lib/images/servers/omero/OmeroWebImageServer.java +++ b/src/main/java/qupath/lib/images/servers/omero/OmeroWebImageServer.java @@ -281,8 +281,28 @@ else if (map.has("channels")) { int levels = map.getAsJsonPrimitive("levels").getAsInt(); if (levels > 1) { JsonObject zoom = map.getAsJsonObject("zoomLevelScaling"); + double aspectRatio = (double) sizeX / sizeY; + logger.debug("image aspect ratio = {}", aspectRatio); for (int i = 0; i < levels; i++) { - levelBuilder.addLevelByDownsample(1.0 / zoom.getAsJsonPrimitive(Integer.toString(i)).getAsDouble()); + double rawZoomFactor = zoom.getAsJsonPrimitive(Integer.toString(i)).getAsDouble(); + logger.debug("level = {}, rawZoomFactor = {}", i, rawZoomFactor); + + // level width and height calculation are best-effort, + // given that we cannot currently get the precise dimensions + // this needs to be fixed once web API is fixed + + // we expect the width calculation to be accurate, as zoomLevelScaling + // was calculated based upon the resolution widths alone + int levelWidth = (int) Math.floor(rawZoomFactor * sizeX); + + // now apply the image aspect ratio to find the height + // this assumes that the aspect ratio remains consistent across the whole pyramid + // subtract 1 to account for potential rounding issues + int levelHeight = (int) Math.floor(levelWidth / aspectRatio) - 1; + + logger.debug(" level width = {}, level height = {}", levelWidth, levelHeight); + + levelBuilder.addLevel(1 / rawZoomFactor, levelWidth, levelHeight); } } else { levelBuilder.addFullResolutionLevel();