Skip to content

Commit

Permalink
Added color LUT
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasteuwen committed Aug 13, 2024
1 parent 9e99882 commit 8cb01a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
31 changes: 30 additions & 1 deletion dlup/annotations_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,33 @@ def sort_polygons(self, key: callable, reverse: bool = False) -> None:
None
"""
self._layers.sort_polygons(key, reverse)
self._layers.sort_polygons(key, reverse)

def bounding_box(self) -> tuple[tuple[float, float], tuple[float, float]]:
"""Get the bounding box of the annotations combining points and polygons.
Returns
-------
tuple[tuple[float, float], tuple[float, float]]
The bounding box of the annotations.
"""
return self._layers.bounding_box

def color_lut(self) -> np.ndarray:
"""Get the color lookup table for the annotations.
Requires that the polygons have an index and color set.
Example
-------
>>> color_lut = annotations.color_lut
>>> colored_image = PIL.Image.fromarray(color_lut[mask])
Returns
-------
np.ndarray
The color lookup table.
"""
return self._layers.color_lut
5 changes: 4 additions & 1 deletion gen_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def convert_annotations_new(

print(LUT)

# other map
LUT2 = annotations2._layers.color_lut

np.asarray((56630.2124, 69640.6535)) * 0.02
region_size = (1393, 1133)

Expand All @@ -140,7 +143,7 @@ def convert_annotations_new(
PIL.Image.fromarray(LUT[mask]).resize((1133 // 2, 1393 // 2)).save("dlup_original.png")

mask_ = region2.to_mask(region_size, index_map, 0)
PIL.Image.fromarray(LUT[mask_]).resize((1133 // 2, 1393 // 2)).save("dlup_new_opencv.png")
PIL.Image.fromarray(LUT2[mask_]).resize((1133 // 2, 1393 // 2)).save("dlup_new_opencv.png")

mask3 = convert_annotations_new(region2.polygons, region_size=region_size, index_map=index_map)
PIL.Image.fromarray(LUT[mask3]).resize((1133 // 2, 1393 // 2)).save("dlup_new.png")
Expand Down

0 comments on commit 8cb01a6

Please sign in to comment.