(self, width, height)
| 103 | return y |
| 104 | |
| 105 | def get_size(self, width, height): |
| 106 | # determine new height and width |
| 107 | scale_height = self.__height / height |
| 108 | scale_width = self.__width / width |
| 109 | |
| 110 | if self.__keep_aspect_ratio: |
| 111 | if self.__resize_method == "lower_bound": |
| 112 | # scale such that output size is lower bound |
| 113 | if scale_width > scale_height: |
| 114 | # fit width |
| 115 | scale_height = scale_width |
| 116 | else: |
| 117 | # fit height |
| 118 | scale_width = scale_height |
| 119 | elif self.__resize_method == "upper_bound": |
| 120 | # scale such that output size is upper bound |
| 121 | if scale_width < scale_height: |
| 122 | # fit width |
| 123 | scale_height = scale_width |
| 124 | else: |
| 125 | # fit height |
| 126 | scale_width = scale_height |
| 127 | elif self.__resize_method == "minimal": |
| 128 | # scale as least as possbile |
| 129 | if abs(1 - scale_width) < abs(1 - scale_height): |
| 130 | # fit width |
| 131 | scale_height = scale_width |
| 132 | else: |
| 133 | # fit height |
| 134 | scale_width = scale_height |
| 135 | else: |
| 136 | raise ValueError( |
| 137 | f"resize_method {self.__resize_method} not implemented" |
| 138 | ) |
| 139 | |
| 140 | if self.__resize_method == "lower_bound": |
| 141 | new_height = self.constrain_to_multiple_of( |
| 142 | scale_height * height, min_val=self.__height |
| 143 | ) |
| 144 | new_width = self.constrain_to_multiple_of( |
| 145 | scale_width * width, min_val=self.__width |
| 146 | ) |
| 147 | elif self.__resize_method == "upper_bound": |
| 148 | new_height = self.constrain_to_multiple_of( |
| 149 | scale_height * height, max_val=self.__height |
| 150 | ) |
| 151 | new_width = self.constrain_to_multiple_of( |
| 152 | scale_width * width, max_val=self.__width |
| 153 | ) |
| 154 | elif self.__resize_method == "minimal": |
| 155 | new_height = self.constrain_to_multiple_of(scale_height * height) |
| 156 | new_width = self.constrain_to_multiple_of(scale_width * width) |
| 157 | else: |
| 158 | raise ValueError(f"resize_method {self.__resize_method} not implemented") |
| 159 | |
| 160 | return (new_width, new_height) |
| 161 | |
| 162 | def __call__(self, sample): |
no test coverage detected