Skip to content

Commit

Permalink
Resolve coordinate offset problem
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Nov 1, 2024
1 parent 974c482 commit 35d5d21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions qubalab/images/labeled_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _read_block(self, level: int, region: Region2D) -> np.ndarray:
draw_geometry(
image.size,
drawing_context,
self._geometries[i],
shapely.affinity.translate(self._geometries[i], -region.x, -region.y),
1
)
full_image[label, :, :] = np.asarray(image, dtype=self.metadata.dtype)
Expand All @@ -119,7 +119,7 @@ def _read_block(self, level: int, region: Region2D) -> np.ndarray:
draw_geometry(
image.size,
drawing_context,
self._geometries[i],
shapely.affinity.translate(self._geometries[i], -region.x, -region.y),
self._feature_index_to_label[i]
)
return np.expand_dims(np.asarray(image, dtype=self.metadata.dtype), axis=0)
9 changes: 4 additions & 5 deletions tests/images/test_labeled_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,16 @@ def test_multi_channel_labeled_image_with_region_request():
downsample = 1
features = [ImageFeature(geojson.LineString([(7, 5), (9, 5)]))]
expected_image = np.array(
[[[[False, False, False, False, False],
[[[False, False, False, False, False],
[False, False, False, False, False],
[False, False, False, False, False]]],
[[[False, False, False, False, False],
[False, False, False, False, False]],
[[False, False, False, False, False],
[False, False, False, False, False],
[False, False, True, True, True]]]]
[False, False, True, True, True]]]
)
labeled_server = LabeledImageServer(sample_metadata, features, multichannel=True, downsample=downsample)
region = Region2D(5, 3, labeled_server.metadata.width-5, labeled_server.metadata.height-3)
image = labeled_server.read_region(1, region)

np.testing.assert_array_equal(image, expected_image)

def test_multi_channel_labeled_image_with_starting_downsample():
Expand Down

0 comments on commit 35d5d21

Please sign in to comment.