Skip to content

Gamma Correction Operator#

Authors: Holoscan Team (NVIDIA)
Supported platforms: x86_64, aarch64
Language: C++, Python
Last modified: March 9, 2026
Latest version: 0.1.0
Minimum Holoscan SDK version: 3.5.0
Tested Holoscan SDK versions: 3.5.0
Contribution metric: Level 1 - Highly Reliable

The GammaCorrectionOp is a Holoscan operator that applies gamma correction to images using GPU-accelerated compute shaders. It provides efficient gamma correction processing for both single-channel and multi-channel images, with support for various data types and automatic normalization.

Overview#

The GammaCorrectionOp extends the SlangShaderOp to provide specialized gamma correction functionality. It automatically handles data type conversion, normalization for integer types, and multi-component processing while maintaining high performance through GPU acceleration.

Features#

  • Automatic Data Type Handling: Supports various data types (uint8, uint16, float32, etc.) with automatic normalization
  • Multi-Component Support: Processes images with 1-4 components (grayscale, RGB, RGBA)
  • Configurable Gamma Value: Adjustable gamma correction factor (default: 2.2)
  • GPU Acceleration: Leverages CUDA compute shaders for high-performance processing
  • Python and C++ APIs: Available in both Python and C++ interfaces

Requirements#

  • Holoscan SDK 3.4.0 or later
  • CUDA-compatible GPU
  • Supported platforms: x86_64, aarch64

Note: The IGX Thor iGPU platform is not supported. GammaCorrectionOp is built on SlangShaderOp, whose bundled Slang compiler emits PTX that the CUDA driver on the IGX Thor iGPU platform cannot load; the operator fails at setup with the provided PTX was compiled with an unsupported toolchain. (222). See the SlangShaderOp documentation.

Installation#

The GammaCorrectionOp is included as part of the HoloHub operators. It will be automatically built when you build the HoloHub project.

Usage#

Basic Usage#

The operator can be configured with data type and component count parameters:

from holoscan.operators import GammaCorrectionOp

# Basic gamma correction for uint8 grayscale image
op = GammaCorrectionOp(
    fragment=app,
    data_type="uint8_t",
    component_count=1,
    gamma=2.2,
    name="gamma_correction"
)

C++ Usage#

#include <gamma_correction/gamma_correction.hpp>

// Create the operator with uint8_t data type
auto gamma_op = make_operator<holoscan::ops::GammaCorrectionOp>("gamma_correction",
    Arg("data_type", "uint8_t"),
    Arg("component_count", 3),  // RGB
    Arg("gamma", 2.2f));

Parameters#

  • data_type (required): The data type of the input buffer
  • Supported types: int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, float, double
  • component_count (optional): Number of components in the input buffer
  • Default: 1 (grayscale)
  • Supported: 1-4 components
  • gamma (optional): Gamma correction factor
  • Default: 2.2
  • Range: Any positive float value

Supported Data Types#

Integer Types#

  • int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t: Automatically normalized to [0,1] range before processing
  • Gamma correction applied in normalized space
  • Results scaled back to original range

Floating Point Types#

  • float, double: Processed directly without normalization
  • Assumes input values are already in [0,1] range

Example: RGB Image Processing#

# Process RGB image with custom gamma
op = GammaCorrectionOp(
    fragment=app,
    data_type="uint8_t",
    component_count=3,
    gamma=1.8,
    name="rgb_gamma_correction"
)

Example: Float Image Processing#

# Process float image (assumes values in [0,1] range)
op = GammaCorrectionOp(
    fragment=app,
    data_type="float",
    component_count=1,
    gamma=2.2,
    name="float_gamma_correction"
)

Testing#

The GammaCorrectionOp includes comprehensive testing to ensure reliability and correctness:

Running Tests#

./holohub test gamma_correction

Contributing#

The GammaCorrectionOp is part of the HoloHub project. Contributions are welcome through the standard HoloHub contribution process.

License#

This operator is licensed under the Apache License 2.0, same as the HoloHub project.

API Reference#

holoscan::ops::GammaCorrectionOp#

Inherits from: holoscan::ops::SlangShaderOp

Gamma correction operator.

Methods#
Method Description
void setup(OperatorSpec &spec) override

GammaCorrectionOp#

The gamma_correction operator runs a gamma correction shader.

Constructor Parameters#
Parameter Type Required Description
fragment Fragment Required The fragment that the operator belongs to.
name str Optional The name of the operator (default: "gamma_correction")
data_type str Optional Data type of the input buffer (default: "uint8_t")
component_count int Optional Number of components in the input buffer (default: 1)
gamma float Optional Gamma correction factor (default: 2.2)
Methods#
  • initialize: Initialize the operator.
  • setup: Define the operator specification.