pytorch3d
pytorch3d copied to clipboard
How do I change the background colour when using the VolumeRenderer?
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.
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.
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:
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:
If I go back to the former blending method but create the volume renderer using sample_mode='bilinear' then I get:
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
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.
This issue was closed because it has been stalled for 5 days with no activity.
I also have this question.
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.