Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcting type hints for get_slice_bboxes(). #930

Merged
merged 6 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -561,7 +561,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 @@ -600,10 +602,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 @@ -622,7 +624,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