(self, width, height)
| 60 | return y |
| 61 | |
| 62 | def get_size(self, width, height): |
| 63 | # determine new height and width |
| 64 | scale_height = self.__height / height |
| 65 | scale_width = self.__width / width |
| 66 | |
| 67 | if self.__keep_aspect_ratio: |
| 68 | if self.__resize_method == "lower_bound": |
| 69 | # scale such that output size is lower bound |
| 70 | if scale_width > scale_height: |
| 71 | # fit width |
| 72 | scale_height = scale_width |
| 73 | else: |
| 74 | # fit height |
| 75 | scale_width = scale_height |
| 76 | elif self.__resize_method == "upper_bound": |
| 77 | # scale such that output size is upper bound |
| 78 | if scale_width < scale_height: |
| 79 | # fit width |
| 80 | scale_height = scale_width |
| 81 | else: |
| 82 | # fit height |
| 83 | scale_width = scale_height |
| 84 | elif self.__resize_method == "minimal": |
| 85 | # scale as least as possbile |
| 86 | if abs(1 - scale_width) < abs(1 - scale_height): |
| 87 | # fit width |
| 88 | scale_height = scale_width |
| 89 | else: |
| 90 | # fit height |
| 91 | scale_width = scale_height |
| 92 | else: |
| 93 | raise ValueError(f"resize_method {self.__resize_method} not implemented") |
| 94 | |
| 95 | if self.__resize_method == "lower_bound": |
| 96 | new_height = self.constrain_to_multiple_of(scale_height * height, min_val=self.__height) |
| 97 | new_width = self.constrain_to_multiple_of(scale_width * width, min_val=self.__width) |
| 98 | elif self.__resize_method == "upper_bound": |
| 99 | new_height = self.constrain_to_multiple_of(scale_height * height, max_val=self.__height) |
| 100 | new_width = self.constrain_to_multiple_of(scale_width * width, max_val=self.__width) |
| 101 | elif self.__resize_method == "minimal": |
| 102 | new_height = self.constrain_to_multiple_of(scale_height * height) |
| 103 | new_width = self.constrain_to_multiple_of(scale_width * width) |
| 104 | else: |
| 105 | raise ValueError(f"resize_method {self.__resize_method} not implemented") |
| 106 | |
| 107 | return (new_width, new_height) |
| 108 | |
| 109 | def __call__(self, sample): |
| 110 | width, height = self.get_size(sample["image"].shape[1], sample["image"].shape[0]) |
no test coverage detected