Skip to content

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
vnmsklnk committed Jan 7, 2024
1 parent 8715feb commit d142031
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
3 changes: 1 addition & 2 deletions aero_vloc/geo_referencers/linear_referencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 1 addition & 10 deletions aero_vloc/maps/base_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
"""
Expand Down
5 changes: 3 additions & 2 deletions aero_vloc/maps/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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,
]
Expand Down
9 changes: 9 additions & 0 deletions aero_vloc/primitives/map_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cv2
import numpy as np

from functools import cached_property
from pathlib import Path


Expand Down Expand Up @@ -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

0 comments on commit d142031

Please sign in to comment.