pytorch3d icon indicating copy to clipboard operation
pytorch3d copied to clipboard

How do I change the background colour when using the VolumeRenderer?

Open demiantill opened this issue 3 years ago • 6 comments

By default the background is black when using the VolumeRenderer. How can I change this e.g. to white? There doesn't appear to be any documentation on the VolumeRenderer beyond the tutorials which only cover limited use cases. Apologies if I'm missing something obvious.

demiantill avatar Jun 25 '21 22:06 demiantill

The volume renderer should return "features" (i.e. color) and opacity values. A first thing to try would thus be to leverage the returned opacity to blend the returned color with a custom background.

patricklabatut avatar Jul 05 '21 09:07 patricklabatut

The volume renderer should return "features" (i.e. color) and opacity values. A first thing to try would thus be to leverage the returned opacity to blend the returned color with a custom background.

OK so yes this works when I create the volume renderer using sample_mode='nearest' and do the blending by just adding white_background * (1 - opacity) to the rendered colors:

Screenshot 2021-07-06 at 19 30 56

That's just a 64 x 64 x 64 volume with all voxels having density = 0.2 and all voxels having the same (red) color.

It might help someone to note that if I blend them the way I initially thought would make the most sense, with rendered_colors * opacity + white_background * (1 - opacity) then I get a slightly dark outline which doesn't look right:

Screenshot 2021-07-06 at 19 35 21

If I go back to the former blending method but create the volume renderer using sample_mode='bilinear' then I get:

Screenshot 2021-07-06 at 19 38 26

I find it difficult to tell whether or not there's an unwanted slightly dark outline there. Perhaps that's working properly. There's also the issue that when using sample_mode='bilinear' it looks as though there is lighting being applied since the different faces of the cube have different colors which I don't understand, but that may end up being a subject for a different issue.

Cheers

demiantill avatar Jul 06 '21 18:07 demiantill

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 06 '21 05:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Aug 11 '21 05:08 github-actions[bot]

I also have this question.

lionlai1989 avatar Feb 09 '24 07:02 lionlai1989

This needs to be implemented in the raymarcher you are using. The provided one to use with VolumeRenderer is pytorch3d.renderer.EmissionAbsorptionRaymarcher which doesn't implement a background color.

Since this issue was created, pytorch3d.implicitron is available and has many more features for volume and implicit rendering. Its EmissionAbsorptionRaymarcher supports background color (code is in AccumulativeRaymarcherBase).

To implement: the logic could be copied to the basic EmissionAbsorptionRaymarcher, or to a local version, or an adapter could be made from implicitron's raymarcher to the basic raymarcher type, or you could use implicitron.

bottler avatar Feb 09 '24 09:02 bottler