MCPcopy Index your code
hub / github.com/apple/ml-pointersect / silhouette_carving

Method silhouette_carving

pointersect/inference/structures.py:942–1022  ·  view source on GitHub ↗

Use the hit_map and the camera in the rgbd_image to invalid points. It marks the valid_mask to be False for point that should be carved without actually remove them. Args: hit_map: hit_map: (b, q, h, w) camera:

(
            self,
            hit_map: torch.Tensor,
            camera: 'Camera',
            dilate: bool = True,
    )

Source from the content-addressed store, hash-verified

940 )
941
942 def silhouette_carving(
943 self,
944 hit_map: torch.Tensor,
945 camera: 'Camera',
946 dilate: bool = True,
947 ) -> 'PointCloud':
948 """
949 Use the hit_map and the camera in the rgbd_image to invalid points.
950 It marks the valid_mask to be False for point that should be carved
951 without actually remove them.
952
953 Args:
954 hit_map:
955 hit_map: (b, q, h, w)
956 camera:
957 (b, q), h, w
958 clone:
959 whether to create a new point cloud (new memory)
960
961
962 Returns:
963 a new point cloud (b, n')
964 """
965
966 ori_include_inf = self.included_point_at_inf
967 self.remove_point_at_inf()
968 self.realize_valid_mask()
969
970 b, n, _3 = self.xyz_w.shape
971 _b, q, h, w = hit_map.shape
972 bq = b * q
973 assert b == 1
974
975 # project onto the sensor
976 uv_cs = utils.pinhole_projection(
977 xyz_w=self.xyz_w, # (b, n)
978 intrinsics=camera.intrinsic, # (b, q)
979 H_c2w=camera.H_c2w, # (b, q)
980 dim_b=1,
981 ) # (b, q, n, 2), [0, w] [0, h]
982
983 # convert to [0, 1]
984 uv_cs[..., 0] = uv_cs[..., 0] / camera.width_px
985 uv_cs[..., 1] = uv_cs[..., 1] / camera.height_px
986
987 uv_cs = uv_cs.reshape(bq, n, 2)
988 hit_map = hit_map.reshape(bq, h, w, 1) # (bq, h, w, 1)
989
990 # dilation the hit map so the boundary is more robust
991 if dilate:
992 hit_map = kornia.morphology.dilation(
993 tensor=hit_map.permute(0, 3, 1, 2).float(), # (bq, 1, h, w)
994 kernel=torch.ones(3, 3, dtype=torch.float, device=hit_map.device),
995 ).permute(0, 2, 3, 1) # (bq, h, w, 1)
996 else:
997 hit_map = hit_map.float()
998
999 miss_map = 1 - hit_map # (bq, h, w, 1)

Callers

nothing calls this directly

Calls 4

remove_point_at_infMethod · 0.95
realize_valid_maskMethod · 0.95
insert_point_at_infMethod · 0.95
reshapeMethod · 0.45

Tested by

no test coverage detected