From 462983d5807ca2d26d929fbd386c49e5018d2c7f Mon Sep 17 00:00:00 2001 From: Rosie Wood Date: Tue, 12 Dec 2023 16:48:16 +0000 Subject: [PATCH] change how max_size is set in lieu of resize_to param --- mapreader/annotate/annotator.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mapreader/annotate/annotator.py b/mapreader/annotate/annotator.py index e24d4de8..88503581 100644 --- a/mapreader/annotate/annotator.py +++ b/mapreader/annotate/annotator.py @@ -22,7 +22,7 @@ warnings.filterwarnings("ignore", category=UserWarning) -MAX_SIZE = 100 +MAX_SIZE = 1000 _CENTER_LAYOUT = widgets.Layout( display="flex", flex_flow="column", align_items="center" @@ -92,7 +92,7 @@ class Annotator(pd.DataFrame): - ``buttons_per_row``: Number of buttons to display per row. Default: None. - ``ascending``: Whether to sort the DataFrame in ascending order. Default: True. - ``surrounding``: The number of surrounding images to show for context. Default: 1. - - ``max_size``: The size in pixels for the longest side to which constrain each patch image. Default: 100. + - ``max_size``: The size in pixels for the longest side to which constrain each patch image. Default: 1000. - ``resize_to``: The size in pixels for the longest side to which resize each patch image. Default: None. """ @@ -510,10 +510,6 @@ def get_context(self): def get_path(image_path, dim=True): # Resize the image im = Image.open(image_path) - if max(im.size) > self.max_size: - print(f"[DEBUG] Resizing {image_path} to {self.max_size}") - im = ImageOps.contain(im, (self.max_size, self.max_size)) - print(f"[DEBUG] --> {im.size}") # Dim the image if dim is True or dim == "True": @@ -591,6 +587,12 @@ def get_empty_square(): context_image = ImageOps.contain( context_image, (self.resize_to, self.resize_to) ) + # only constrain to max size if not resize_to + elif max(context_image.size) > self.max_size: + context_image = ImageOps.contain( + context_image, (self.max_size, self.max_size) + ) + return context_image def annotate( @@ -812,6 +814,9 @@ def get_patch_image(self, ix: int) -> Image: if self.resize_to is not None: image = ImageOps.contain(image, (self.resize_to, self.resize_to)) + # only constrain to max size if not resize_to + elif max(image.size) > self.max_size: + image = ImageOps.contain(image, (self.max_size, self.max_size)) return image