Skip to content

Commit 0e377c6

Browse files
shapovalovfacebook-github-bot
authored andcommitted
Monte-Carlo rasterisation; arbitrary dimensionality of AlphaCompositor blending
Summary: Fixes required for MC rasterisation to work. 1) Wrong number of channels for background was used (derived from points dimensions, not features dimensions; 2) split of the results on the wrong dimension was done; 3) CORE CHANGE: blending in alpha compositor was assuming RGBA input. Reviewed By: davnov134 Differential Revision: D34933673 fbshipit-source-id: a5cc9f201ea21e114639ab9e291a10888d495206
1 parent e64f25c commit 0e377c6

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pytorch3d/renderer/points/compositor.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ def _add_background_color_to_images(pix_idxs, images, background_color):
9292

9393
background_color = background_color.to(images)
9494

95-
# add alpha channel
96-
if background_color.shape[0] == 3 and images.shape[1] == 4:
97-
# special case to allow giving RGB background for RGBA
95+
# add alpha channel if needed
96+
if background_color.shape[0] + 1 == images.shape[1]:
9897
alpha = images.new_ones(1)
9998
background_color = torch.cat([background_color, alpha])
10099

@@ -107,7 +106,7 @@ def _add_background_color_to_images(pix_idxs, images, background_color):
107106
num_background_pixels = background_mask.sum()
108107

109108
# permute so that features are the last dimension for masked_scatter to work
110-
masked_images = images.permute(0, 2, 3, 1)[..., :4].masked_scatter(
109+
masked_images = images.permute(0, 2, 3, 1).masked_scatter(
111110
background_mask[..., None],
112111
background_color[None, :].expand(num_background_pixels, -1),
113112
)

0 commit comments

Comments
 (0)