Skip to content

Commit

Permalink
Merge branch 'main' into feature/fix-types-slice_image
Browse files Browse the repository at this point in the history
  • Loading branch information
fcakyon authored Nov 6, 2023
2 parents bf8039d + 10beacb commit 25c451d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sahi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.11.15"
__version__ = "0.11.16"

from sahi.annotation import BoundingBox, Category, Mask
from sahi.auto_model import AutoDetectionModel
Expand Down
20 changes: 11 additions & 9 deletions sahi/slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import time
from pathlib import Path
from typing import Dict, List, Optional, Sequence, Union
from typing import Dict, List, Optional, Sequence, Tuple, Union

import numpy as np
from PIL import Image
Expand All @@ -31,8 +31,8 @@
def get_slice_bboxes(
image_height: int,
image_width: int,
slice_height: int = None,
slice_width: int = None,
slice_height: Optional[int] = None,
slice_width: Optional[int] = None,
auto_slice_resolution: bool = True,
overlap_height_ratio: float = 0.2,
overlap_width_ratio: float = 0.2,
Expand All @@ -44,8 +44,8 @@ def get_slice_bboxes(
Args:
image_height (int): Height of the original image.
image_width (int): Width of the original image.
slice_height (int): Height of each slice. Default 512.
slice_width (int): Width of each slice. Default 512.
slice_height (int, optional): Height of each slice. Default None.
slice_width (int, optional): Width of each slice. Default None.
overlap_height_ratio(float): Fractional overlap in height of each
slice (e.g. an overlap of 0.2 for a slice of size 100 yields an
overlap of 20 pixels). Default 0.2.
Expand Down Expand Up @@ -557,7 +557,9 @@ def calc_aspect_ratio_orientation(width: int, height: int) -> str:
return "square"


def calc_slice_and_overlap_params(resolution: str, height: int, width: int, orientation: str) -> List:
def calc_slice_and_overlap_params(
resolution: str, height: int, width: int, orientation: str
) -> Tuple[int, int, int, int]:
"""
This function calculate according to image resolution slice and overlap params.
Args:
Expand Down Expand Up @@ -596,10 +598,10 @@ def calc_slice_and_overlap_params(resolution: str, height: int, width: int, orie
x_overlap = int(slice_width * overlap_width_ratio)
y_overlap = int(slice_height * overlap_height_ratio)

return x_overlap, y_overlap, slice_width, slice_height # noqa
return x_overlap, y_overlap, slice_width, slice_height


def get_resolution_selector(res: str, height: int, width: int):
def get_resolution_selector(res: str, height: int, width: int) -> Tuple[int, int, int, int]:
"""
Args:
Expand All @@ -618,7 +620,7 @@ def get_resolution_selector(res: str, height: int, width: int):
return x_overlap, y_overlap, slice_width, slice_height


def get_auto_slice_params(height: int, width: int):
def get_auto_slice_params(height: int, width: int) -> Tuple[int, int, int, int]:
"""
According to Image HxW calculate overlap sliding window and buffer params
factor is the power value of 2 closest to the image resolution.
Expand Down

0 comments on commit 25c451d

Please sign in to comment.