blending¶
-
class
pytorch3d.renderer.blending.
BlendParams
[source]¶ Bases:
tuple
Data class to store blending params with defaults
- Members:
- sigma (float): Controls the width of the sigmoid function used to
- calculate the 2D distance based probability. Determines the sharpness of the edges of the shape. Higher => faces have less defined edges.
- gamma (float): Controls the scaling of the exponential function used
- to set the opacity of the color. Higher => faces are more transparent.
- background_color: RGB values for the background color as a tuple or
- as a tensor of three floats.
-
sigma
¶ Alias for field number 0
-
gamma
¶ Alias for field number 1
-
background_color
¶ Alias for field number 2
-
pytorch3d.renderer.blending.
hard_rgb_blend
(colors: torch.Tensor, fragments, blend_params: pytorch3d.renderer.blending.BlendParams) → torch.Tensor[source]¶ - Naive blending of top K faces to return an RGBA image
- RGB - choose color of the closest point i.e. K=0
- A - 1.0
Parameters: - colors – (N, H, W, K, 3) RGB color for each of the top K faces per pixel.
- fragments –
the outputs of rasterization. From this we use - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices
of the faces (in the packed representation) which overlap each pixel in the image. This is used to determine the output shape. - blend_params – BlendParams instance that contains a background_color
- specifying the color for the background (field) –
Returns: RGBA pixel_colors – (N, H, W, 4)
-
pytorch3d.renderer.blending.
sigmoid_alpha_blend
(colors, fragments, blend_params: pytorch3d.renderer.blending.BlendParams) → torch.Tensor[source]¶ - Silhouette blending to return an RGBA image
- RGB - choose color of the closest point.
- A - blend based on the 2D distance based probability map [1].
Parameters: - colors – (N, H, W, K, 3) RGB color for each of the top K faces per pixel.
- fragments –
the outputs of rasterization. From this we use - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices
of the faces (in the packed representation) which overlap each pixel in the image.- dists: FloatTensor of shape (N, H, W, K) specifying the 2D euclidean distance from the center of each pixel to each of the top K overlapping faces.
Returns: RGBA pixel_colors – (N, H, W, 4)
- [1] Liu et al, ‘Soft Rasterizer: A Differentiable Renderer for Image-based
- 3D Reasoning’, ICCV 2019
-
pytorch3d.renderer.blending.
softmax_rgb_blend
(colors: torch.Tensor, fragments, blend_params: pytorch3d.renderer.blending.BlendParams, znear: Union[float, torch.Tensor] = 1.0, zfar: Union[float, torch.Tensor] = 100) → torch.Tensor[source]¶ RGB and alpha channel blending to return an RGBA image based on the method proposed in [1]
- RGB - blend the colors based on the 2D distance based probability map and relative z distances.
- A - blend based on the 2D distance based probability map.
Parameters: - colors – (N, H, W, K, 3) RGB color for each of the top K faces per pixel.
- fragments –
namedtuple with outputs of rasterization. We use properties - pix_to_face: LongTensor of shape (N, H, W, K) specifying the indices
of the faces (in the packed representation) which overlap each pixel in the image.- dists: FloatTensor of shape (N, H, W, K) specifying the 2D euclidean distance from the center of each pixel to each of the top K overlapping faces.
- zbuf: FloatTensor of shape (N, H, W, K) specifying the interpolated depth from each pixel to to each of the top K overlapping faces.
- blend_params –
instance of BlendParams dataclass containing properties - sigma: float, parameter which controls the width of the sigmoid
function used to calculate the 2D distance based probability. Sigma controls the sharpness of the edges of the shape.- gamma: float, parameter which controls the scaling of the exponential function used to control the opacity of the color.
- background_color: (3) element list/tuple/torch.Tensor specifying the RGB values for the background color.
- znear – float, near clipping plane in the z direction
- zfar – float, far clipping plane in the z direction
Returns: RGBA pixel_colors – (N, H, W, 4)
[0] Shichen Liu et al, ‘Soft Rasterizer: A Differentiable Renderer for Image-based 3D Reasoning’