LabeledImageServer coordinate and downsample behaviour #26
+97
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Outline
Currently, LabeledImageServer has behaviour that is definitively broken with respect to coordinates, and some behaviour that is arguably unintuitive with respect to downsampling.
Coordinates
When querying a LabelledImageServer, we create a Pillow image and draw the geometries on it. This means that for any Region2D which does not begin at the origin, we are drawing geometries in a different coordinate space. To return a correct labelled image, we must first translate the geometries to remove the offset of the region request, such that (0,0) in the pillow image is the origin of the region request, rather than always being the origin of the full-sized labelled image as it currently is.
Relevant code:
qubalab/qubalab/images/labeled_server.py
Lines 94 to 125 in 2bc2027
Downsampling
The current behaviour is arguably unintuitive with respect to downsampling as demonstrated in the other 4 unit tests added. There is some discussion in #25 about whether this behaviour should change. In my view, if retaining the current behaviour, we should warn users (either in code or documentation but ideally both) that they may be receiving rasterised images, and that they should be supplying coordinates based on the downsampled image, rather than the full-sized image that the labeled image server is created from.
Code modifications
Currently, this PR just addresses the offset issue with coordinates.