Skip to content

Commit

Permalink
Fix weird resized width and height if the difference of image ratio i…
Browse files Browse the repository at this point in the history
…s large (#18)

* remove job `github-release`

* fix giant factor if image ratio is too large

* keep `reg_w` and `reg_h` unchange if it's already multiply of strides
  • Loading branch information
Pandede authored Apr 10, 2024
1 parent 88bb23b commit 7427875
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions wpodnet/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ def _resize_to_fixed_ratio(self, image: Image.Image, dim_min: int, dim_max: int)
side = int(wh_ratio * dim_min)
bound_dim = min(side + side % self._stride, dim_max)

factor = bound_dim / min(h, w)
factor = bound_dim / max(h, w)
reg_w, reg_h = int(w * factor), int(h * factor)

# Ensure the both width and height are the multiply of `self._stride`
reg_w += self._stride - reg_w % self._stride
reg_h += self._stride - reg_h % self._stride
reg_w_mod = reg_w % self._stride
if reg_w_mod > 0:
reg_w += self._stride - reg_w_mod

reg_h_mod = reg_h % self._stride
if reg_h_mod > 0:
reg_h += self._stride - reg_h % self._stride

return image.resize((reg_w, reg_h))

Expand Down

0 comments on commit 7427875

Please sign in to comment.