Skip to content

Generate Image With Solid Color

SUMMARY

Generate Image With Solid Color generates a solid color image with the same dimensions as a reference image.

Creates a uniform color image matching the reference dimensions, useful for masks, overlays, backgrounds, and testing. Supports named colors (e.g., "red", "blue") or custom color specifications.

Use this Skill when you want to create a solid color image matching reference dimensions.

The Skill

python
from telekinesis import pupil

solid_image = pupil.generate_image_with_solid_color(
    image=image,
    color="red",
)

API Reference

Example

Reference Image

Reference image

Reference image for dimensions

Solid Color Image

Output image

Solid color image matching reference size

The Code

python
from telekinesis import pupil
from datatypes import io
import pathlib
from loguru import logger

DATA_DIR = pathlib.Path("path/to/telekinesis-data")

# Load reference image
filepath = str(DATA_DIR / "images" / "gear.jpg")
image = io.load_image(filepath=filepath)
logger.success(f"Loaded image from {filepath}")

# Generate solid color image with same dimensions as reference
solid_image = pupil.generate_image_with_solid_color(
    image=image,
    color="red",
)

# Access results
solid_image_np = solid_image.to_numpy()
logger.success("Generated solid color image. Output shape: {}", solid_image_np.shape)

The Explanation of the Code

The code begins by importing the necessary modules: pupil for image processing operations, io for data handling, pathlib for path management, and loguru for logging.

python
from telekinesis import pupil
from datatypes import io
import pathlib
from loguru import logger

Next, a reference image is loaded from a .jpg file using the io.load_image function. The reference image provides the dimensions (height, width, channels) for the output solid color image.

python
DATA_DIR = pathlib.Path("path/to/telekinesis-data")

# Load reference image
filepath = str(DATA_DIR / "images" / "gear.jpg")
image = io.load_image(filepath=filepath)

The main operation uses the generate_image_with_solid_color Skill from the pupil module. This Skill generates a solid color image with the same dimensions as the reference image. The parameters can be tuned to control the fill color (named or BGR tuple) depending on the use case.

python
solid_image = pupil.generate_image_with_solid_color(
    image=image,
    color="red",
)

Finally, the solid color image is converted to a NumPy array using to_numpy() for further processing, visualization, or downstream tasks.

python
solid_image_np = solid_image.to_numpy()
logger.success(f"Output image shape: {solid_image_np.shape}")

This operation is particularly useful in robotics and vision pipelines for masks, overlays, backgrounds, and testing, where creating a solid color image matching reference dimensions is required.

Running the Example

Runnable examples are available in the Telekinesis examples repository. Follow the README in that repository to set up the environment. Once set up, you can run this specific example with:

bash
cd telekinesis-examples
python examples/pupil_examples.py --example generate_image_with_solid_color

How to Tune the Parameters

The generate_image_with_solid_color Skill has 1 parameter:

color (no default—required):

  • The fill color for the generated image
  • Options: Named colors ("red", "blue", "green", "white", "black") or BGR tuple (e.g., (0, 0, 255) for red in BGR)
  • Use named colors for readability; BGR tuples for custom colors
  • Use "black" or "white" for masks; colored overlays for visualization

TIP

Best practice: Use named colors for readability. For overlays, ensure the color format matches your pipeline (BGR vs RGB).

Where to Use the Skill in a Pipeline

Generate Image With Solid Color is commonly used in the following pipelines:

  • Mask creation - Create binary or colored masks
  • Overlay backgrounds - Solid color for compositing
  • Testing - Generate placeholder images for testing
  • Visualization - Highlight regions with colored overlays

Related skills to build such a pipeline:

  • overlay_images_using_weighted_overlay: Blend with solid color
  • bitwise_and_images: Apply mask from solid color

When Not to Use the Skill

Do not use Generate Image With Solid Color when:

  • You need a gradient or pattern (Use other image generation methods)
  • You have explicit dimensions (Use resize or create with known size)
  • You need transparency (Use RGBA with alpha channel)