8
8
from torchvision .transforms import functional_tensor as _FT , functional_pil as _FP
9
9
from torchvision .transforms .functional import pil_modes_mapping , _get_inverse_affine_matrix
10
10
11
- from ._meta_conversion import convert_bounding_box_format
11
+ from ._meta import convert_bounding_box_format , get_dimensions_image_tensor , get_dimensions_image_pil
12
12
13
13
14
14
horizontal_flip_image_tensor = _FT .hflip
@@ -39,7 +39,7 @@ def resize_image_tensor(
39
39
antialias : Optional [bool ] = None ,
40
40
) -> torch .Tensor :
41
41
new_height , new_width = size
42
- num_channels , old_height , old_width = _FT . get_dimensions (image )
42
+ num_channels , old_height , old_width = get_dimensions_image_tensor (image )
43
43
batch_shape = image .shape [:- 3 ]
44
44
return _FT .resize (
45
45
image .reshape ((- 1 , num_channels , old_height , old_width )),
@@ -141,7 +141,7 @@ def affine_image_tensor(
141
141
142
142
center_f = [0.0 , 0.0 ]
143
143
if center is not None :
144
- _ , height , width = _FT . get_dimensions (img )
144
+ _ , height , width = get_dimensions_image_tensor (img )
145
145
# Center values should be in pixel coordinates but translated such that (0, 0) corresponds to image center.
146
146
center_f = [1.0 * (c - s * 0.5 ) for c , s in zip (center , (width , height ))]
147
147
@@ -167,7 +167,7 @@ def affine_image_pil(
167
167
# it is visually better to estimate the center without 0.5 offset
168
168
# otherwise image rotated by 90 degrees is shifted vs output image of torch.rot90 or F_t.affine
169
169
if center is None :
170
- _ , height , width = _FP . get_dimensions (img )
170
+ _ , height , width = get_dimensions_image_pil (img )
171
171
center = [width * 0.5 , height * 0.5 ]
172
172
matrix = _get_inverse_affine_matrix (center , angle , translate , scale , shear )
173
173
@@ -184,7 +184,7 @@ def rotate_image_tensor(
184
184
) -> torch .Tensor :
185
185
center_f = [0.0 , 0.0 ]
186
186
if center is not None :
187
- _ , height , width = _FT . get_dimensions (img )
187
+ _ , height , width = get_dimensions_image_tensor (img )
188
188
# Center values should be in pixel coordinates but translated such that (0, 0) corresponds to image center.
189
189
center_f = [1.0 * (c - s * 0.5 ) for c , s in zip (center , (width , height ))]
190
190
@@ -260,13 +260,13 @@ def _center_crop_compute_crop_anchor(
260
260
261
261
def center_crop_image_tensor (img : torch .Tensor , output_size : List [int ]) -> torch .Tensor :
262
262
crop_height , crop_width = _center_crop_parse_output_size (output_size )
263
- _ , image_height , image_width = _FT . get_dimensions (img )
263
+ _ , image_height , image_width = get_dimensions_image_tensor (img )
264
264
265
265
if crop_height > image_height or crop_width > image_width :
266
266
padding_ltrb = _center_crop_compute_padding (crop_height , crop_width , image_height , image_width )
267
267
img = pad_image_tensor (img , padding_ltrb , fill = 0 )
268
268
269
- _ , image_height , image_width = _FT . get_dimensions (img )
269
+ _ , image_height , image_width = get_dimensions_image_tensor (img )
270
270
if crop_width == image_width and crop_height == image_height :
271
271
return img
272
272
@@ -276,13 +276,13 @@ def center_crop_image_tensor(img: torch.Tensor, output_size: List[int]) -> torch
276
276
277
277
def center_crop_image_pil (img : PIL .Image .Image , output_size : List [int ]) -> PIL .Image .Image :
278
278
crop_height , crop_width = _center_crop_parse_output_size (output_size )
279
- _ , image_height , image_width = _FP . get_dimensions (img )
279
+ _ , image_height , image_width = get_dimensions_image_pil (img )
280
280
281
281
if crop_height > image_height or crop_width > image_width :
282
282
padding_ltrb = _center_crop_compute_padding (crop_height , crop_width , image_height , image_width )
283
283
img = pad_image_pil (img , padding_ltrb , fill = 0 )
284
284
285
- _ , image_height , image_width = _FP . get_dimensions (img )
285
+ _ , image_height , image_width = get_dimensions_image_pil (img )
286
286
if crop_width == image_width and crop_height == image_height :
287
287
return img
288
288
0 commit comments