diff --git a/py360convert/e2p.py b/py360convert/e2p.py index 1557ae5..96c09bb 100644 --- a/py360convert/e2p.py +++ b/py360convert/e2p.py @@ -14,7 +14,7 @@ def e2p( e_img: NDArray[DType], - fov_deg: Union[float, int, tuple[float | int, float | int]], + fov_deg: Union[float, int, tuple[Union[float, int], Union[float, int]]], u_deg: float, v_deg: float, out_hw: tuple[int, int], @@ -65,7 +65,18 @@ def e2p( u = -float(np.deg2rad(u_deg)) v = float(np.deg2rad(v_deg)) in_rot = float(np.deg2rad(in_rot_deg)) - sampler = EquirecSampler.from_perspective(h_fov, v_fov, u, v, in_rot, h, w, order) + sampler = EquirecSampler.from_perspective( + h_fov, + v_fov, + u, + v, + in_rot, + h, + w, + out_hw[0], + out_hw[0], + order, + ) pers_img = np.stack([sampler(e_img[..., i]) for i in range(e_img.shape[2])], axis=-1) return pers_img[..., 0] if squeeze else pers_img diff --git a/py360convert/utils.py b/py360convert/utils.py index 05648ac..6163b09 100644 --- a/py360convert/utils.py +++ b/py360convert/utils.py @@ -431,7 +431,9 @@ def from_cubemap(cls, face_w: int, h: int, w: int, order: int): @classmethod @lru_cache(_CACHE_SIZE) - def from_perspective(cls, h_fov: float, v_fov: float, u, v, in_rot: float, h: int, w: int, order: int): + def from_perspective( + cls, h_fov: float, v_fov: float, u, v, in_rot: float, in_h: int, in_w: int, out_h, out_w, order: int + ): """Construct a EquirecSampler from perspective specs. Parameters @@ -446,16 +448,20 @@ def from_perspective(cls, h_fov: float, v_fov: float, u, v, in_rot: float, h: in Vertical viewing angle in radians in_rot: float Inplane rotation in radians. - h: int + in_h: int Height of input equirec image. - w: int + in_w: int Width of input equirec image. + out_h: int + Height of output perspective image. + out_w: int + Width of output perspective image. order: int The order of the spline interpolation. See ``scipy.ndimage.map_coordinates``. """ - xyz = xyzpers(h_fov, v_fov, u, v, (h, w), in_rot) + xyz = xyzpers(h_fov, v_fov, u, v, (out_h, out_w), in_rot) u, v = xyz2uv(xyz) - coor_x, coor_y = uv2coor(u, v, h, w) + coor_x, coor_y = uv2coor(u, v, in_h, in_w) return cls(coor_x, coor_y, order=order)