diff --git a/aero_vloc/geo_referencers/linear_referencer.py b/aero_vloc/geo_referencers/linear_referencer.py index 68befb6..b3389ff 100644 --- a/aero_vloc/geo_referencers/linear_referencer.py +++ b/aero_vloc/geo_referencers/linear_referencer.py @@ -22,8 +22,7 @@ class LinearReferencer(GeoReferencer): def get_lat_lon( self, map_tile: MapTile, pixel: Tuple[int, int], resize: int = None ) -> Tuple[float, float]: - map_image = map_tile.image - height, width = map_image.shape[:2] + height, width = map_tile.shape if resize is not None: height, width = get_new_size(height, width, resize) diff --git a/aero_vloc/maps/base_map.py b/aero_vloc/maps/base_map.py index 123528a..4665643 100644 --- a/aero_vloc/maps/base_map.py +++ b/aero_vloc/maps/base_map.py @@ -56,7 +56,7 @@ def __init__(self, path_to_metadata: Path): tiles.append(map_tile) self.tiles = tiles height, width = self.shape - tile_height, tile_width = self.tile_shape + tile_height, tile_width = self.tiles[0].shape self.pixel_shape = height * tile_height, width * tile_width @property @@ -74,15 +74,6 @@ def shape(self) -> tuple[int, int]: height = int(len(self.tiles) / width) return height, width - @property - def tile_shape(self) -> tuple[int, int]: - """ - :return: Height and width of tiles in the map - """ - tile_img = self.tiles[0].image - tile_height, tile_width = tile_img.shape[:2] - return tile_height, tile_width - @property def tiles_2d(self) -> np.ndarray: """ diff --git a/aero_vloc/maps/map.py b/aero_vloc/maps/map.py index 24ac0f1..15274c1 100644 --- a/aero_vloc/maps/map.py +++ b/aero_vloc/maps/map.py @@ -49,9 +49,10 @@ def __init__( super().__init__(path_to_metadata) self.geo_referencer = geo_referencer - old_tile_h, old_tile_w = self.tile_shape + old_tile_h, old_tile_w = self.tiles[0].shape map_pixel_height, map_pixel_width = self.pixel_shape new_tile_h, new_tile_w = int(old_tile_h // zoom), int(old_tile_w // zoom) + tiles_2d = self.tiles_2d # Generating of the new tiles tiles = [] @@ -76,7 +77,7 @@ def __init__( new_bottom_right_x // old_tile_w, new_bottom_right_y // old_tile_h, ) - involved_tiles = self.tiles_2d[ + involved_tiles = tiles_2d[ top_left_index_y : bottom_right_index_y + 1, top_left_index_x : bottom_right_index_x + 1, ] diff --git a/aero_vloc/primitives/map_tile.py b/aero_vloc/primitives/map_tile.py index b2dcce9..d1bc9cf 100644 --- a/aero_vloc/primitives/map_tile.py +++ b/aero_vloc/primitives/map_tile.py @@ -14,6 +14,7 @@ import cv2 import numpy as np +from functools import cached_property from pathlib import Path @@ -69,3 +70,11 @@ def image(self) -> np.ndarray: top_left_y : bottom_right_y + 1, top_left_x : bottom_right_x + 1 ] return result + + @cached_property + def shape(self) -> tuple[int, int]: + """ + :return: Height and width of the tile + """ + height, width = self.image.shape[:2] + return height, width