Generate rays to form patches on the corresponding images. Args: num_patches_per_q: number of patches from each q patch_width_px: number of pixels in the patch in width patch_width_pitch_scale: (*b,
(
self,
num_patches_per_q: int,
patch_width_px: int,
patch_width_pitch_scale: T.Union[float, torch.Tensor] = 1., # (*b,)
patch_height_px: int = None, # (*b,)
patch_height_pitch_scale: T.Union[float, torch.Tensor] = None, # (*b,)
int_only: bool = True,
)
| 1795 | ) |
| 1796 | |
| 1797 | def generate_random_patch_rays( |
| 1798 | self, |
| 1799 | num_patches_per_q: int, |
| 1800 | patch_width_px: int, |
| 1801 | patch_width_pitch_scale: T.Union[float, torch.Tensor] = 1., # (*b,) |
| 1802 | patch_height_px: int = None, # (*b,) |
| 1803 | patch_height_pitch_scale: T.Union[float, torch.Tensor] = None, # (*b,) |
| 1804 | int_only: bool = True, |
| 1805 | ) -> T.Dict[str, T.Any]: |
| 1806 | """ |
| 1807 | Generate rays to form patches on the corresponding images. |
| 1808 | |
| 1809 | Args: |
| 1810 | num_patches_per_q: |
| 1811 | number of patches from each q |
| 1812 | patch_width_px: |
| 1813 | number of pixels in the patch in width |
| 1814 | patch_width_pitch_scale: |
| 1815 | (*b,) the pitch of the patch (new_pitch / old_pitch) |
| 1816 | patch_height_px: |
| 1817 | if None, the same as `patch_width_px` |
| 1818 | patch_height_pitch_scale: |
| 1819 | if None, the same as `patch_width_pitch_scale` |
| 1820 | int_only: |
| 1821 | whether the center is always at an integer index |
| 1822 | |
| 1823 | Returns: |
| 1824 | ray: |
| 1825 | (b, q, num_patches_per_q, hp, wp) |
| 1826 | uv: |
| 1827 | (b, q, num_patches_per_q, hp, wp, 2) |
| 1828 | """ |
| 1829 | b, q, _41, _42 = self.H_c2w.shape |
| 1830 | bq = b * q |
| 1831 | |
| 1832 | # sample uv |
| 1833 | uv = utils.sample_random_patch_uv( |
| 1834 | b_shape=[b, q, num_patches_per_q], |
| 1835 | width_px=self.width_px, |
| 1836 | height_px=self.height_px, |
| 1837 | patch_width_px=patch_width_px, |
| 1838 | patch_width_pitch_scale=patch_width_pitch_scale, |
| 1839 | patch_height_px=patch_height_px, |
| 1840 | patch_height_pitch_scale=patch_height_pitch_scale, |
| 1841 | int_only=int_only, |
| 1842 | device=self.H_c2w.device, |
| 1843 | ) # (b, q, num_patches_per_q, hp, wp, 2), [0, w], [0, h] |
| 1844 | |
| 1845 | # use the uv to create rays |
| 1846 | ray_origins_w, ray_directions_w = utils.generate_camera_rays_from_uv( |
| 1847 | cam_poses=self.H_c2w.reshape(bq, 4, 4), # (bq, 4, 4) |
| 1848 | intrinsics=self.intrinsic.reshape(bq, 3, 3), # (bq, 3, 3) |
| 1849 | uv=uv.flatten(start_dim=0, end_dim=1), # (bq, num_patches_per_q, hp, wp, 2) |
| 1850 | device=self.H_c2w.device, |
| 1851 | ) # (bq, num_patches_per_q, hp, wp, 3) |
| 1852 | |
| 1853 | _bq, *m_shape, _3 = ray_origins_w.shape |
| 1854 |
no test coverage detected