@@ -262,7 +262,10 @@ def get_ndc_camera_transform(self, **kwargs) -> Transform3d:
262
262
# We don't flip xy because we assume that world points are in
263
263
# PyTorch3D coordinates, and thus conversion from screen to ndc
264
264
# is a mere scaling from image to [-1, 1] scale.
265
- return get_screen_to_ndc_transform (self , with_xyflip = False , ** kwargs )
265
+ image_size = kwargs .get ("image_size" , self .get_image_size ())
266
+ return get_screen_to_ndc_transform (
267
+ self , with_xyflip = False , image_size = image_size
268
+ )
266
269
267
270
def transform_points_ndc (
268
271
self , points , eps : Optional [float ] = None , ** kwargs
@@ -318,8 +321,9 @@ def transform_points_screen(
318
321
new_points: transformed points with the same shape as the input.
319
322
"""
320
323
points_ndc = self .transform_points_ndc (points , eps = eps , ** kwargs )
324
+ image_size = kwargs .get ("image_size" , self .get_image_size ())
321
325
return get_ndc_to_screen_transform (
322
- self , with_xyflip = True , ** kwargs
326
+ self , with_xyflip = True , image_size = image_size
323
327
).transform_points (points_ndc , eps = eps )
324
328
325
329
def clone (self ):
@@ -923,7 +927,7 @@ def __init__(
923
927
K: (optional) A calibration matrix of shape (N, 4, 4)
924
928
If provided, don't need focal_length, principal_point
925
929
image_size: (height, width) of image size.
926
- A tensor of shape (N, 2). Required for screen cameras.
930
+ A tensor of shape (N, 2) or a list/tuple . Required for screen cameras.
927
931
device: torch.device or string
928
932
"""
929
933
# The initializer formats all inputs to torch tensors and broadcasts
@@ -1044,8 +1048,9 @@ def get_ndc_camera_transform(self, **kwargs) -> Transform3d:
1044
1048
pr_point_fix_transform = Transform3d (
1045
1049
matrix = pr_point_fix .transpose (1 , 2 ).contiguous (), device = self .device
1046
1050
)
1051
+ image_size = kwargs .get ("image_size" , self .get_image_size ())
1047
1052
screen_to_ndc_transform = get_screen_to_ndc_transform (
1048
- self , with_xyflip = False , ** kwargs
1053
+ self , with_xyflip = False , image_size = image_size
1049
1054
)
1050
1055
ndc_transform = pr_point_fix_transform .compose (screen_to_ndc_transform )
1051
1056
@@ -1105,7 +1110,7 @@ def __init__(
1105
1110
K : Optional [torch .Tensor ] = None ,
1106
1111
device : Device = "cpu" ,
1107
1112
in_ndc : bool = True ,
1108
- image_size : Optional [torch .Tensor ] = None ,
1113
+ image_size : Optional [Union [ List , Tuple , torch .Tensor ] ] = None ,
1109
1114
) -> None :
1110
1115
"""
1111
1116
@@ -1123,7 +1128,7 @@ def __init__(
1123
1128
K: (optional) A calibration matrix of shape (N, 4, 4)
1124
1129
If provided, don't need focal_length, principal_point, image_size
1125
1130
image_size: (height, width) of image size.
1126
- A tensor of shape (N, 2). Required for screen cameras.
1131
+ A tensor of shape (N, 2) or list/tuple . Required for screen cameras.
1127
1132
device: torch.device or string
1128
1133
"""
1129
1134
# The initializer formats all inputs to torch tensors and broadcasts
@@ -1241,8 +1246,9 @@ def get_ndc_camera_transform(self, **kwargs) -> Transform3d:
1241
1246
pr_point_fix_transform = Transform3d (
1242
1247
matrix = pr_point_fix .transpose (1 , 2 ).contiguous (), device = self .device
1243
1248
)
1249
+ image_size = kwargs .get ("image_size" , self .get_image_size ())
1244
1250
screen_to_ndc_transform = get_screen_to_ndc_transform (
1245
- self , with_xyflip = False , ** kwargs
1251
+ self , with_xyflip = False , image_size = image_size
1246
1252
)
1247
1253
ndc_transform = pr_point_fix_transform .compose (screen_to_ndc_transform )
1248
1254
@@ -1537,7 +1543,9 @@ def look_at_view_transform(
1537
1543
1538
1544
1539
1545
def get_ndc_to_screen_transform (
1540
- cameras , with_xyflip : bool = False , ** kwargs
1546
+ cameras ,
1547
+ with_xyflip : bool = False ,
1548
+ image_size : Optional [Union [List , Tuple , torch .Tensor ]] = None ,
1541
1549
) -> Transform3d :
1542
1550
"""
1543
1551
PyTorch3D NDC to screen conversion.
@@ -1563,7 +1571,6 @@ def get_ndc_to_screen_transform(
1563
1571
1564
1572
"""
1565
1573
# We require the image size, which is necessary for the transform
1566
- image_size = kwargs .get ("image_size" , cameras .get_image_size ())
1567
1574
if image_size is None :
1568
1575
msg = "For NDC to screen conversion, image_size=(height, width) needs to be specified."
1569
1576
raise ValueError (msg )
@@ -1605,7 +1612,9 @@ def get_ndc_to_screen_transform(
1605
1612
1606
1613
1607
1614
def get_screen_to_ndc_transform (
1608
- cameras , with_xyflip : bool = False , ** kwargs
1615
+ cameras ,
1616
+ with_xyflip : bool = False ,
1617
+ image_size : Optional [Union [List , Tuple , torch .Tensor ]] = None ,
1609
1618
) -> Transform3d :
1610
1619
"""
1611
1620
Screen to PyTorch3D NDC conversion.
@@ -1631,6 +1640,8 @@ def get_screen_to_ndc_transform(
1631
1640
1632
1641
"""
1633
1642
transform = get_ndc_to_screen_transform (
1634
- cameras , with_xyflip = with_xyflip , ** kwargs
1643
+ cameras ,
1644
+ with_xyflip = with_xyflip ,
1645
+ image_size = image_size ,
1635
1646
).inverse ()
1636
1647
return transform
0 commit comments