ManiSkill icon indicating copy to clipboard operation
ManiSkill copied to clipboard

Segmentation mask of soft bodies

Open pauljansonnie opened this issue 2 years ago • 3 comments

Hi,

I would like to get the segmentation mask of soft bodies in Pinch-v0. I am unable to find any example doing this and since soft bodies do not have any mesh-level or object/link id, it does not seem straight-forward. The fact that goals in Pinch-v0 are provided as point-clouds of the dough (or as images with segmented soft body) makes me believe that this should be feasible. Is it possible to get a segmentation mask of soft bodies? How? If not, how were the goals in Pinch-v0 actually recorded?

Thanks a lot

pauljansonnie avatar Nov 15 '23 10:11 pauljansonnie

You can get the soft body segmentation through the actor id.

obs, _ = env.reset()
env.get_actors() # [Actor(name="ground", id="14"), Actor(name="", id="15")]
soft_body_seg = (obs['image']['hand_camera']['Segmentation'][..., 1] == 15)

xuanlinli17 avatar Nov 15 '23 18:11 xuanlinli17

This does not segment the soft-body but just removes the robot from the scene. I actually looped over all segmentation masks already and none of them corresponds to the soft-body.

For instance, based on your code snippet, let us apply the mask to the RGB image and save the masked image:

import matplotlib.pyplot as plt
obs, _ = env.reset()
env.get_actors() # [Actor(name="ground", id="14"), Actor(name="", id="15")]
camera_name = "hand_camera" # or "base_camera"
img_color = (obs['image'][camera_name]["Color"][:, :, :3] * 255).astype(np.uint8)
soft_body_seg = (obs['image'][camera_name]['Segmentation'][..., 1] == 15)
img_masked = img_color * soft_body_seg.reshape(*soft_body_seg.shape, 1)
plt.imsave("img_masked.png", img_masked)

We get the following images: img_masked img_masked

pauljansonnie avatar Nov 16 '23 07:11 pauljansonnie

Oh my bad, the soft body segmentation isn't officially supported.

However I believe that @hzaskywalker has implemented one, probably he can provide you with a code snippet.

xuanlinli17 avatar Nov 16 '23 22:11 xuanlinli17