cambrian.renderer.render_utils

Rendering utilities.

Functions

resize(images, height, width)

Resize the image to the specified height and width.

resize_with_aspect_fill(images, height, width)

Resize the image while maintaining the aspect ratio and

generate_composite(images)

This is a debug method which renders the images as a composite image.

convert_depth_distances(model, depth)

Converts depth values from OpenGL to metric depth values using PyTorch.

convert_depth_to_rgb(depth[, znear, zfar])

Converts depth values to RGB values.

add_text(image, text[, position, size])

Add text to an image.

Module Contents

resize(images, height, width)[source]

Resize the image to the specified height and width.

resize_with_aspect_fill(images, height, width)[source]

Resize the image while maintaining the aspect ratio and filling the rest with black.

generate_composite(images)[source]

This is a debug method which renders the images as a composite image.

Will appear as a compound eye. For example, if we have a 3x3 grid of eyes:

TL T TR ML M MR BL B BR

Each eye has a red border around it.

Note

This assumes that the images have the same dimensions.

convert_depth_distances(model, depth)[source]

Converts depth values from OpenGL to metric depth values using PyTorch.

Parameters:
  • model (mj.MjModel) – The model.

  • depth (torch.Tensor) – The depth values to convert.

Returns:

torch.Tensor – The converted depth values.

Note

This function is based on [this code](https://github.com/google-deepmind/mujoco/blob/main/ python/mujoco/renderer.py). It is adapted to use PyTorch instead of NumPy.

convert_depth_to_rgb(depth, znear=None, zfar=None)[source]

Converts depth values to RGB values.

Parameters:
  • model (mj.MjModel) – The model.

  • depth (torch.Tensor) – The depth values.

Returns:

torch.Tensor – The RGB values.

add_text(image, text, position=(0, 0), size=None, **kwargs)[source]

Add text to an image.

Note

This is slow, so use it sparingly.

Parameters:
  • image (torch.Tensor) – The image to add text to.

  • text (str) – The text to add.

  • position (tuple[int, int]) – The position to add the text.

  • color (tuple[int, int, int], optional) – The color of the text. Defaults to (255, 255, 255).

Returns:

torch.Tensor – The image with the text added.