code: def hard_rgb_blend(
      colors: torch.Tensor, fragments, blend_params: BlendParams
  ) -> torch.Tensor:
      """
      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
  
      Args:
          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
          field specifying the color for the background
      Returns:
          RGBA pixel_colors: (N, H, W, 4)
      """
      background_color = _get_background_color(
          blend_params, fragments.pix_to_face.device
      )
  
      # Mask for the background.
      is_background = fragments.pix_to_face[..., 0] < 0  # (N, H, W)
  
      # Find out how much background_color needs to be expanded to be used for masked_scatter.
      num_background_pixels = is_background.sum()
  
      # Set background color.
      pixel_colors = colors[..., 0, :].masked_scatter(
          is_background[..., None],
          background_color[None, :].expand(num_background_pixels, -1),
      )  # (N, H, W, 3)
  
      # Concat with the alpha channel.
      alpha = (~is_background).type_as(pixel_colors)[..., None]
  
      return torch.cat([pixel_colors, alpha], dim=-1)
  
file_path: pytorch3d/pytorch3d/renderer/blending.py
imports: from typing import NamedTuple, Sequence, Union
  import torch
  from pytorch3d import _C
  from pytorch3d.common.datatypes import Device
label_desc: Use image node_id 2 for calling a global function with example usage: hard_rgb_blend(colors, fragments, blend_params) and returns: torch