Denoiser_logo

Denoiser C++ library

v3.0.5

Table of contents

Overview

The Denoiser C++ library provides two noise cancellation backends behind a single interface: a software bilateral filter (a recursive, O(1)-per-pixel form of it, not the sliding-window one the article describes) and a software wrapper over the temporal noise reduction (TNR) of NVIDIA® Vision Programming Interface (VPI). The library is suitable for various types of cameras (daylight, SWIR, MWIR and LWIR) and provides a simple programming interface. Each instance of the Denoiser C++ class object performs frame-by-frame processing of a video data stream. The software backend processes each video frame independently. The VPI backend is temporal: it denoises the current frame against the previous one, so its output depends on the frames that came before it and a break in the stream should be signaled with the RESET command. The Denoiser library currently supports only the YUV24 and GRAY (software implementation only) pixel formats. The library depends on the VFilter library (provides the video filter interface), which depends on the Frame and ConfigReader libraries. The repository does not contain the source code of these libraries: see Build stand alone. The library software backend has no other external dependencies: one implementation serves every platform and returns the same output on all of them (the exception on aarch64 is described in Portability). The filter passes are parallelized with OpenMP, which is an optional build dependency - without it the library still compiles and the filter runs serially. The size of the thread team is selected by the CUSTOM_2 parameter and is capped at 4 threads, because the filter is memory-bound and stops scaling past that point. The library VPI backend depends on VPI 3.x or 4.x and runs the temporal noise reduction on the VIC or the CUDA backend of VPI, selected by the CUSTOM_1 parameter. It repacks the YUV24 frame into the format that backend takes - NV12 (4:2:0) for CUDA, YUYV (4:2:2) for VIC - and back, so the chroma of the output frame is subsampled. In addition, the test application depends on the SimpleUI library. The software backend is compatible with Linux and Windows. The VPI backend is Linux only, because VPI itself is distributed for Linux alone (x86_64 and Jetson). The library uses the C++17 standard.

Denoiser is general-purpose software: it is not tied to any sector or application, and the developer of a program decides what the program does with it.

Versions

Table 1 - Library versions.

Version Release date What’s new
1.0.0 19.03.2024 First version of the library.
1.0.1 21.05.2024 - VFilter interface class updated.
- Documentation updated.
1.0.2 23.07.2024 - CMake structure updated.
2.0.0 09.03.2025 - External dependencies have been removed.
- File structure has been changed.
- Bilateral noise reduction filter has been implemented.
2.0.1 27.03.2026 - Performance improved by 20-30% on average.
- Platform-specific filter core: fixed-point arithmetic on ARM, float on x86.
- Compiler optimizations scoped to library target only.
2.1.0 08.04.2026 - Added denoising via the Intel IPP bilateral filter.
3.0.0 02.09.2026 - Intel IPP dependency removed entirely: a single implementation for every platform.
- Performance improved.
- Added support of Jetson VPI.
3.0.1 29.09.2026 - Update VFilter to 1.1.5 version.
3.0.2 01.10.2026 - Removed OpenCV from the test application.
3.0.3 12.10.2026 - Submodules updated.
3.0.4 18.10.2026 - Git submodules removed: the libraries Frame, ConfigReader, VFilter and SimpleUI are expected next to the repository.
- processFrame(…) checks the pixel format, the size, the data pointer and the data size of the frame, executes one call at a time and measures the time with a monotonic clock. A frame whose size field is smaller than the size of its pixel data (a Frame created with a smaller size argument, or a frame whose data pointer was set by hand and size was left 0) is rejected.
- The VPI implementation rejects frames of an odd width or height and limits the level to the range 0 - 100.
- setParam(…) and initVFilter(…) reject NaN and values out of range; initVFilter(…) changes nothing if any value is rejected.
- Hardened build options, strict compiler warnings, standard C++ only.
- The test application has the –selftest mode with automatic checks.
3.0.5 25.10.2026 - The library links the thread library (CMake target Threads::Threads): programs built on a C library older than glibc 2.34 no longer need -pthread.

Library files

The library is supplied as source code only. The user is provided with a set of files in the form of a CMake project (repository). The repository structure is shown below:

CMakeLists.txt ------------ Main CMake file of the library.
src ----------------------- Folder with source code of the library.
    impl ------------------ Folder with filter implementation files.
        DenoiserImpl.h ---- Header file with filter implementation.
        DenoiserImpl.cpp -- C++ implementation file.
    vpiImpl --------------- Folder with VPI filter implementation.
        DenoiserImpl.h ---- Header file with VPI filter implementation.
        DenoiserImpl.cpp -- C++ implementation file.
    CMakeLists.txt -------- CMake file of the library.
    Denoiser.cpp ---------- C++ implementation file.
    Denoiser.h ------------ Header file with the Denoiser class declaration.
    DenoiserVersion.h ----- Header file with the library version.
    DenoiserVersion.h.in -- CMake service file to generate the version file.
static -------------------- Folder with the pictures of this description.
test ---------------------- Folder for test application.
    CMakeLists.txt -------- CMake file for test application.
    main.cpp -------------- Source code file of test application.

Denoiser class description

Exactly one backend is compiled into the library - the software one or the VPI one, selected at build time (see Build and connect to your project). There is no run-time switching between them, so the parameters and commands below are marked with the backend that owns them.

Denoiser class declaration

The Denoiser class is declared in the Denoiser.h file. Class declaration:

namespace rapidpixel
{
class Denoiser : public VFilter
{
public:

    /// Class constructor.
    Denoiser();

    /// Class destructor.
    ~Denoiser() override;

    /// Copy and move constructors and assignment operators are deleted.
    Denoiser(const Denoiser&) = delete;
    Denoiser(Denoiser&&) = delete;
    Denoiser& operator=(const Denoiser&) = delete;
    Denoiser& operator=(Denoiser&&) = delete;

    /// Get the version of the Denoiser class.
    static std::string getVersion();

    /// Initialize denoiser.
    bool initVFilter(VFilterParams& params) override;

    /// Set VFilter parameter.
    bool setParam(VFilterParam id, float value) override;

    /// Get the value of a specific VFilter parameter.
    float getParam(VFilterParam id) override;

    /// Get the structure containing all VFilter parameters.
    void getParams(VFilterParams& params) override;

    /// Execute a VFilter action command.
    bool executeCommand(VFilterCommand id) override;

    /// Process frame (noise cancellation) in place.
    bool processFrame(rapidpixel::Frame& frame) override;

    /// Set mask for filter. Masks are not supported by the class.
    bool setMask(rapidpixel::Frame) override;

    /// Decode and execute command.
    bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};
}

getVersion method

The getVersion() static method returns a string with the current class version. Method declaration:

static std::string getVersion();

The method can be used without a Denoiser class instance:

std::cout << "Denoiser version: " << rapidpixel::Denoiser::getVersion();

Console output:

Denoiser version: 3.0.5

initVFilter method

The initVFilter(…) method initializes the denoiser. Method declaration:

bool initVFilter(VFilterParams& params) override;
Parameter Value
params VFilterParams class object. The method uses the mode and level fields in any build, plus the fields of the compiled backend: custom2 in a software build, type and custom1 in a VPI build. The fields of the other backend are ignored.

Returns: TRUE if the params were accepted or FALSE if any of them was rejected: the integer part of level is outside 0 - 100 (or level is NaN), custom2 is NaN in a software build, type is outside 0 - 6 or the integer part of custom1 is not 0 or 1 in a VPI build. mode equal to 0 disables the denoiser, any other value enables it. If the method returns FALSE nothing is changed.

Note: the method only validates and stores the params. Both backends size their buffers from the frame, so the buffers - and, in a VPI build, the VPI stream, images and TNR payload - are created on the first processFrame(…) call. A failure to create them is reported by processFrame(…) returning FALSE, not by this method.

setParam method

The setParam(…) method sets a new parameter value. The library provides a thread-safe setParam(…) method call. This means that the setParam(…) method can be safely called from any thread. Method declaration:

bool setParam(VFilterParam id, float value) override;
Parameter Description
id Parameter ID according to the VFilterParam enum. The method supports MODE and LEVEL in any build, plus the parameters of the compiled backend: CUSTOM_2 in a software build, TYPE and CUSTOM_1 in a VPI build. Any other parameter is rejected and the method returns FALSE.
value Parameter value. Value depends on parameter ID. The ranges are listed in Table 3. A NaN value is always rejected.

Returns: TRUE if the parameter was set or FALSE if the parameter is not supported or the value is rejected (the parameter is not changed).

getParam method

The getParam(…) method returns a parameter value. The library provides a thread-safe getParam(…) method call. This means that the getParam(…) method can be safely called from any thread. Method declaration:

float getParam(VFilterParam id) override;
Parameter Description
id Parameter ID according to the VFilterParam enum. The method supports MODE, LEVEL and PROCESSING_TIME_MCSEC in any build, plus the parameters of the compiled backend: CUSTOM_2 in a software build, TYPE and CUSTOM_1 in a VPI build. For any other parameter the method will return -1.

Returns: the parameter value or -1 if the parameter does not exist (is not supported by a particular implementation).

getParams method

The getParams(…) method is designed to obtain all denoiser params. The library provides a thread-safe getParams(…) method call. This means that the getParams(…) method can be safely called from any thread. Method declaration:

void getParams(VFilterParams& params) override;
Parameter Description
params Reference to a VFilterParams object to store params. The method always fills in mode, level and processingTimeMcSec. A software build also fills in custom2; a VPI build also fills in type and custom1. Every field the compiled backend does not own is set to -1.

executeCommand method

The executeCommand(…) method executes a video filter (denoiser) action command. The library provides a thread-safe executeCommand(…) method call. This means that the executeCommand(…) method can be safely called from any thread. Method declaration:

bool executeCommand(VFilterCommand id) override;
Parameter Description
id Command ID according to the VFilterCommand enum. The method supports ON and OFF in any build, and RESET in a VPI build only - in a software build RESET returns FALSE.

Returns: TRUE if the command was executed or FALSE if not.

processFrame method

The processFrame(…) method is designed to process a frame (noise cancellation). If the mode is set to 0 (disabled), the method will skip the frame and return TRUE. The YUV24 format is supported by both the software and the VPI implementations; the GRAY format is supported by the software implementation only. Method declaration:

bool processFrame(rapidpixel::Frame& frame) override;
Parameter Description
frame Reference to Frame object. The frame is processed in place. Only the YUV24 and GRAY (software implementation only) formats are supported. The width and the height must be at least 16 pixels (in a VPI build also even numbers), the data pointer must not be nullptr and the data size (the size field) must be not less than width * height * 3 bytes for YUV24 or width * height bytes for GRAY. The width, the height and the other fields of the frame are not changed.

Returns: TRUE if the frame was processed (noise cancellation) or FALSE if the frame was rejected (an unsupported pixel format, a size or a data pointer that does not meet the requirements above), the memory for the buffers could not be allocated or VPI failed. If the filter is disabled, the method returns TRUE without checking or processing the video frame. The data of a rejected frame is not changed.

The library provides a thread-safe processFrame(…) method call: concurrent calls are executed one at a time. The method allocates internal buffers for the frame size and the pixel format of the first frame and allocates them again when they change; the software implementation uses 27 bytes of memory per pixel for YUV24 and 13 bytes per pixel for GRAY (56 MB for a 1920x1080 YUV24 frame).

setMask method

The setMask(…) method is designed to set a video filter mask. Masks are not supported by the Denoiser class. Method declaration:

bool setMask(rapidpixel::Frame mask) override;
Parameter Description
mask Filter mask in the form of a Frame object with the GRAY pixel format. Masks are not supported by the Denoiser class.

Returns: TRUE in any case.

encodeSetParamCommand method of VFilter class

The encodeSetParamCommand(…) static method encodes a command to change any VFilter parameter value. To control any video filter remotely, the developer has to design their own protocol and, according to it, encode the command and deliver it over the communication channel. To simplify this, the VFilter class contains static methods for encoding the control command. The VFilter class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeSetParamCommand(…) is designed to encode the SET_PARAM command. Method declaration:

static void encodeSetParamCommand(uint8_t* data, int& size, VFilterParam id, float value);
Parameter Description
data Pointer to data buffer for encoded command. Must have size >= 11.
size Size of encoded data. Will be 11 bytes.
id Parameter ID according to VFilterParam enum.
value Parameter value.

encodeSetParamCommand(…) is static and is used without a VFilter class instance. This method is used on the client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[11];
// Size of encoded data.
int size = 0;
// Parameter value.
float outValue = 20.0f;
// Encode command.
VFilter::encodeSetParamCommand(data, size, VFilterParam::LEVEL, outValue);

encodeCommand method of VFilter class

The encodeCommand(…) static method encodes a command for VFilter remote control. To control any video filter remotely, the developer has to design their own protocol and, according to it, encode the command and deliver it over the communication channel. To simplify this, the VFilter class contains static methods for encoding the control command. The VFilter class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeCommand(…) is designed to encode the COMMAND (action command). Method declaration:

static void encodeCommand(uint8_t* data, int& size, VFilterCommand id);
Parameter Description
data Pointer to data buffer for encoded command. Must have size >= 7.
size Size of encoded data. Will be 7 bytes.
id Command ID according to VFilterCommand enum.

encodeCommand(…) is static and is used without a VFilter class instance. This method is used on the client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[7];
// Size of encoded data.
int size = 0;
// Encode command.
VFilter::encodeCommand(data, size, VFilterCommand::RESET);

decodeCommand method of VFilter class

The decodeCommand(…) static method decodes a command on the video filter side. Method declaration:

static int decodeCommand(uint8_t* data, int size, VFilterParam& paramId, VFilterCommand& commandId, float& value);
Parameter Description
data Pointer to input command.
size Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND.
paramId VFilter parameter ID according to VFilterParam enum. After decoding a SET_PARAM command, the method will return the parameter ID.
commandId VFilter command ID according to VFilterCommand enum. After decoding a COMMAND, the method will return the command ID.
value VFilter parameter value (after decoding SET_PARAM command).

Returns: 0 if a COMMAND was decoded, 1 if a SET_PARAM command was decoded, or -1 in case of errors (nullptr, a size other than 7 or 11 bytes, a wrong version or data type, an ID outside the enum). The output arguments are changed only if the command is decoded.

decodeAndExecuteCommand method

The decodeAndExecuteCommand(…) method decodes and executes a command encoded by the encodeSetParamCommand(…) and encodeCommand(…) methods on the video filter side. The library provides a thread-safe decodeAndExecuteCommand(…) method call. This means that the decodeAndExecuteCommand(…) method can be safely called from any thread. Method declaration:

bool decodeAndExecuteCommand(uint8_t* data, int size) override;
Parameter Description
data Pointer to input command.
size Size of command. Must be 11 bytes for SET_PARAM or 7 bytes for COMMAND.

Returns: TRUE if the command was decoded (SET_PARAM or COMMAND) and executed (action command or set param command). FALSE if the data is not a valid command (nullptr, a size other than 7 or 11 bytes, a wrong version, an unknown command or parameter ID) or the command was rejected by executeCommand(…) or setParam(…). Nothing is changed if FALSE is returned.

Data structures

VFilterCommand enum

Enum declaration:

enum class VFilterCommand
{
    /// Reset video filter algorithm.
    RESET = 1,
    /// Enable filter.
    ON,
    /// Disable filter.
    OFF
};

Table 2 - Action commands description.

Command Description
RESET Resets denoiser: drops the temporal history and reinitializes it on the next frame. Supported only by VPI.
ON Enable the denoiser.
OFF Disable the denoiser.

VFilterParam enum

Enum declaration:

enum class VFilterParam
{
    /// Filter mode: 0 - off, 1 - on. Depends on implementation.
    MODE = 1,
    /// Enhancement level for particular filter, as a percentage from
    /// 0% to 100%. May have another meaning depends on implementation.
    LEVEL,
    /// Processing time in microseconds. Read only parameter.
    PROCESSING_TIME_MCSEC,
    /// Type of the filter. Depends on the implementation.
    TYPE,
    /// VFilter custom parameter. Custom parameters used when particular image
    /// filter has specific unusual parameter.
    CUSTOM_1,
    /// VFilter custom parameter. Custom parameters used when particular image
    /// filter has specific unusual parameter.
    CUSTOM_2,
    /// VFilter custom parameter. Custom parameters used when particular image
    /// filter has specific unusual parameter.
    CUSTOM_3
};

Table 3 - Params description.

Parameter Access Description
MODE read / write Denoiser mode: 0 - disabled, 1 - enabled. The value is truncated to an integer: any value whose integer part is not zero enables the denoiser. NaN and a value outside the range of int are rejected.
LEVEL read / write Denoiser level as a percentage. Valid values from 0.0 to 100.0: a value is accepted if its integer part is in this range, any other value and NaN are rejected. The level sets how far apart two pixels may be in brightness and in distance and still be averaged together: at 0 the filter only merges pixels within a few grey levels of each other, at 100 within about twenty. Higher levels remove more noise and soften more detail, so the useful setting follows the amount of noise in the source rather than being as high as possible.
PROCESSING_TIME_MCSEC read only Processing time in microseconds. Read only parameter. Used to check the performance of the denoiser.
TYPE read / write Scene preset of the VPI temporal noise reduction. VPI builds only: a software build rejects the parameter and reads back -1. Values:
0 - Default
1 - Outdoor low light
2 - Outdoor medium light
3 - Outdoor high light
4 - Indoor low light
5 - Indoor medium light
6 - Indoor high light. The integer part of the value is used; any other value and NaN are rejected.
CUSTOM_1 read / write VPI backend. VPI builds only: a software build rejects the parameter and reads back -1. Values: 0 - VIC, 1 - CUDA. The integer part of the value is used; any other value and NaN are rejected. Every accepted call drops the temporal history (the VPI objects are created again on the next frame), also if the backend does not change.
CUSTOM_2 read / write Size of the software filter thread team. Software builds only: a VPI build rejects the parameter and reads back -1. 0 or less selects automatic sizing: one thread per CPU core, minus one. Automatic or explicit, the value is clamped to 1 - 4; 1 runs the filter serially. NaN is rejected. The filter output does not depend on this parameter.
CUSTOM_3 read / write Not supported by the Denoiser class.

VFilterParams class description

VFilterParams class declaration

The VFilterParams class provides the video filter parameters structure. It also provides the ability to read params from JSON files and write them to JSON files (the JSON_READABLE macro), as well as methods to encode and decode params. The class only transports the values: they are not checked against any range. The Denoiser class checks them in initVFilter(…). The VFilterParams interface class is declared in the VFilter.h file. Class declaration:

class VFilterParams
{
public:
    /// Filter mode: 0 - off, 1 - on. Depends on implementation.
    int mode{ 1 };
    /// Enhancement level for particular filter, as a percentage from
    /// 0% to 100%. May have another meaning depends on implementation.
    float level{ 0.0f };
    /// Processing time in microseconds. Read only parameter.
    int processingTimeMcSec{ 0 };
    /// Type of the filter. Depends on the implementation.
    int type{ 0 };
    /// VFilter custom parameter. Custom parameters used when particular image
    /// filter has specific unusual parameter.
    float custom1{ 0.0f };
    /// VFilter custom parameter. Custom parameters used when particular image
    /// filter has specific unusual parameter.
    float custom2{ 0.0f };
    /// VFilter custom parameter. Custom parameters used when particular image
    /// filter has specific unusual parameter.
    float custom3{ 0.0f };

    /// Macro from ConfigReader to make params readable/writable from JSON.
    JSON_READABLE(VFilterParams, mode, level, type, custom1, custom2, custom3)

    // Encode (serialize) params.
    bool encode(uint8_t* data, int bufferSize, int& size,
                                             VFilterParamsMask* mask = nullptr);
    // Decode (deserialize) params.
    bool decode(uint8_t* data, int dataSize);
};

Table 4 - VFilterParams class field descriptions, related to the VFilterParam enum description.

Field type Description
mode int Denoiser mode: 0 - disabled, 1 - enabled.
level float Denoiser level as a percentage. Valid values from 0.0 to 100.0.
processingTimeMcSec int Processing time in microseconds. Read only parameter. Used to check the performance of the denoiser.
type int Scene preset of the VPI temporal noise reduction. VPI builds only: a software build reads back -1. Values:
0 - Default
1 - Outdoor low light
2 - Outdoor medium light
3 - Outdoor high light
4 - Indoor low light
5 - Indoor medium light
6 - Indoor high light
custom1 float VPI backend. VPI builds only: a software build reads back -1. Values: 0 - VIC, 1 - CUDA.
custom2 float Size of the software filter thread team. Software builds only: a VPI build reads back -1. 0 or less selects automatic sizing: one thread per CPU core, minus one. Automatic or explicit, the value is clamped to 1 - 4; 1 runs the filter serially. The filter output does not depend on this field.
custom3 float Not supported by the Denoiser class.

Note: The VFilterParams class fields listed in Table 4 have to reflect the params set and read by the setParam(…) and getParam(…) methods.

Serialize VFilter params

The VFilterParams class provides the encode(…) method to serialize VFilter params. Serialization of VFilterParams is needed when the image filter parameters have to be sent over a communication channel. The method provides an option to exclude particular parameters from serialization. To do this, the method inserts a binary mask (1 byte) in which each bit represents a particular parameter, and the decode(…) method recognizes it. Method declaration:

bool encode(uint8_t* data, int bufferSize, int& size, VFilterParamsMask* mask = nullptr);
Parameter Value
data Pointer to data buffer. Buffer size must be >= 32 bytes.
bufferSize Data buffer size. Buffer size must be >= 32 bytes.
size Size of encoded data.
mask Parameters mask - pointer to VFilterParamsMask structure. VFilterParamsMask (declared in VFilter.h file) determines flags for each field (parameter) declared in VFilterParams class. If the user wants to exclude any parameters from serialization, they can pass a pointer to the mask. If the user wants to exclude a particular parameter from serialization, they should set the corresponding flag in the VFilterParamsMask structure.

Returns: TRUE if the params were encoded (serialized) or FALSE if not.

VFilterParamsMask structure declaration:

struct VFilterParamsMask
{
    bool mode{ true };
    bool level{ true };
    bool processingTimeMcSec{ true };
    bool type{ true };
    bool custom1{ true };
    bool custom2{ true };
    bool custom3{ true };
};

Example without parameters mask:

// Prepare parameters.
rapidpixel::VFilterParams params;
params.level = 80.0f;

// Encode (serialize) params.
int bufferSize = 128;
uint8_t buffer[128];
int size = 0;
params.encode(buffer, bufferSize, size);

Example with parameters mask:

// Prepare parameters.
rapidpixel::VFilterParams params;
params.level = 80.0;

// Prepare mask.
rapidpixel::VFilterParamsMask mask;
// Exclude level.
mask.level = false;

// Encode (serialize) params.
int bufferSize = 128;
uint8_t buffer[128];
int size = 0;
params.encode(buffer, bufferSize, size, &mask);

Deserialize VFilter params

The VFilterParams class provides the decode(…) method to deserialize params. Deserialization of VFilterParams is needed when params are received over a communication channel. The method automatically recognizes which parameters were serialized by the encode(…) method. Method declaration:

bool decode(uint8_t* data, int dataSize);
Parameter Value
data Pointer to data buffer with serialized params.
dataSize Size of the serialized data.

Returns: TRUE if the params were decoded (deserialized) or FALSE if not.

Example:

// Prepare parameters.
rapidpixel::VFilterParams params1;
params1.level = 80;

// Encode (serialize) params.
int bufferSize = 128;
uint8_t buffer[128];
int size = 0;
params1.encode(buffer, bufferSize, size);

// Decode (deserialize) params.
rapidpixel::VFilterParams params2;
params2.decode(buffer, size);

Read params from JSON file and write to JSON file

VFilter depends on the ConfigReader library, which provides methods to read params from a JSON file and to write params to a JSON file. Example of writing params to a JSON file and reading them back:

// Write params to file.
rapidpixel::ConfigReader inConfig;
rapidpixel::VFilterParams in;
in.level = 50.0f;
in.type = 1;
in.custom1 = 1.0f;
in.custom2 = 4.0f;
if (!inConfig.set(in, "vFilterParams") ||
    !inConfig.writeToFile("VFilterParams.json"))
{
    std::cout << "Can't write config file" << std::endl;
    return false;
}

// Read params from file.
rapidpixel::ConfigReader outConfig;
rapidpixel::VFilterParams out;
if (!outConfig.readFromFile("VFilterParams.json") ||
    !outConfig.get(out, "vFilterParams"))
{
    std::cout << "Can't read config file" << std::endl;
    return false;
}

readFromFile(…) returns FALSE if the file can not be opened or is not valid JSON. get(…) returns FALSE and leaves the object unchanged if the vFilterParams object does not exist or a field is missing or has a wrong type. VFilterParams.json will look as follows:

{
    "vFilterParams": {
        "mode": 1,
        "level": 50.0,
        "type": 1,
        "custom1": 1.0,
        "custom2": 4.0,
        "custom3": 0.0
    }
}

Portability

The library is plain C++17. It has no CPU specific code: no intrinsics, no inline assembly and no compiler options that select an instruction set. The software filter works on 8-bit pixels and 16-bit fixed point values, the lookup table of the filter is built with the standard function exp. The library does not access multi-byte values through pointers of another type, so the byte order of the CPU does not matter for the filter. The commands encoded by the VFilter class store integer and float values in the byte order of the host: both sides of a command channel must have the same byte order.

The software implementation was built and run on Windows (MSVC 2022, x86-64) and on Linux (x86-64: GCC 12 and 13, Clang 15 and 18; aarch64: GCC 13 and Clang 18). The output frames are bit-identical on Windows (MSVC) and on Linux x86-64 (GCC and Clang), in the Release and in the Debug configuration, with and without OpenMP and for any size of the thread team (CUSTOM_2). On aarch64 they are identical except for rare pixels that differ by one level: GCC and Clang fuse a multiplication and an addition into one instruction there (floating point contraction), which changes the last bit of a float result (in a test of 3000 random frames 7 bytes of one frame differed). A build with the compiler option -ffp-contract=off gives the same output as on x86-64. The VPI implementation is built on Linux only (x86-64 and aarch64), because VPI is distributed for Linux.

Build and connect to your project

Build stand alone

The repository does not contain sub-repositories. The libraries that Denoiser depends on (Frame, ConfigReader, VFilter, and SimpleUI for the test application) must be placed in the same folder as Denoiser: copy their folders, for example from the folder modules of the RapidPixel SDK. The folder structure must be:

<work folder>
    Denoiser
    Frame
    ConfigReader
    VFilter
    SimpleUI

Typical commands to build Denoiser with the software backend and its test application on Linux:

cd Denoiser
mkdir build
cd build
cmake .. -DDENOISER_USE_VPI=OFF
make

On Windows use cmake --build . --config Release instead of make. If Denoiser is the top-level CMake project, the main CMakeLists.txt file adds the folders ../Frame, ../ConfigReader and ../VFilter (in this order) before the library itself and the folder ../SimpleUI before the test application. If a folder does not exist CMake stops with an error.

The build looks for OpenMP and links it when present, which is what makes the CUSTOM_2 thread team effective. OpenMP is optional: without it the library compiles and the filter runs serially, and CUSTOM_2 is still accepted but has no effect. If OpenMP is found the library links OpenMP::OpenMP_CXX (and, in a VPI build, the vpi library): a program that links the library needs these libraries too (for example libgomp and pthread with GCC); CMake adds them to targets that link Denoiser.

Typical commands to build Denoiser with the VPI backend on Linux:

cd Denoiser
mkdir build
cd build
cmake .. -DDENOISER_USE_VPI=ON
make

If VPI is not found (or is older than 3.0) CMake prints a message and builds the software implementation.

CMake options

Table 5 - CMake options of the repository. In the options below ${PARENT} is the prefix defined by the top-level project (empty if Denoiser is the top-level project).

Option Default Description
${PARENT}_DENOISER ON Build the library.
${PARENT}_DENOISER_TEST ON (stand alone), OFF (included in other project) Build the test application. The test application needs the SimpleUI library: if Denoiser is included in another project, the project must add it.
${PARENT}_SUBMODULE_CACHE_OVERWRITE ON Forced rewriting of the options above in the CMake cache. The top-level project sets it to OFF when it includes Denoiser as a sub-repository.
DENOISER_USE_VPI OFF Build the VPI implementation if VPI 3.0 or newer is found, the software implementation otherwise.
VPI_PATH not set Root folder of the VPI installation (it contains lib/<architecture>/cmake/vpi). If not set, the folders /opt/nvidia/vpi* are searched from the newest one.
CMAKE_BUILD_TYPE Release (if not specified) Build type.

Connect to your project

If you want to connect Denoiser to your CMake project as source code, you can do the following. For example, if your repository has the following structure:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp

Create folder 3rdparty in your repository and copy the folders of the libraries Frame, ConfigReader, VFilter and Denoiser there (for example from the folder modules of the RapidPixel SDK). The new structure of your repository:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp
3rdparty
    Denoiser
    Frame
    ConfigReader
    VFilter

Denoiser does not add its dependencies when it is included in another project: your project must add them. Create a CMakeLists.txt file in the 3rdparty folder. It should add the libraries in the order of their dependencies (Frame, ConfigReader, VFilter, Denoiser):

cmake_minimum_required(VERSION 3.13)

################################################################################
## 3RD-PARTY
## dependencies for the project
################################################################################
project(3rdparty LANGUAGES CXX)

################################################################################
## SETTINGS
## basic 3rd-party settings before use
################################################################################
# To inherit the top-level architecture when the project is used as a submodule.
SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY)
# Disable self-overwriting of parameters inside included subdirectories.
SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE)

################################################################################
## CONFIGURATION
## 3rd-party submodules configuration
################################################################################
SET(${PARENT}_SUBMODULE_FRAME                           ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_FRAME)
    SET(${PARENT}_FRAME                                 ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_FRAME_TEST                            OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_CONFIG_READER                   ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_CONFIG_READER)
    SET(${PARENT}_CONFIG_READER                         ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_EXAMPLES                OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_TESTS                   OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_VFILTER                         ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VFILTER)
    SET(${PARENT}_VFILTER                               ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_VFILTER_TEST                          OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_VFILTER_EXAMPLE                       OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_DENOISER                        ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_DENOISER)
    SET(${PARENT}_DENOISER                              ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_DENOISER_TEST                         OFF CACHE BOOL "" FORCE)
endif()

################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_FRAME)
    add_subdirectory(Frame)
endif()

if (${PARENT}_SUBMODULE_CONFIG_READER)
    add_subdirectory(ConfigReader)
endif()

if (${PARENT}_SUBMODULE_VFILTER)
    add_subdirectory(VFilter)
endif()

if (${PARENT}_SUBMODULE_DENOISER)
    add_subdirectory(Denoiser)
endif()

The 3rdparty/CMakeLists.txt file adds the folders to your project and excludes the test applications from the build (by default, the test applications and the examples are excluded from the build if a library is included as a sub-repository). The new structure of your repository:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp
3rdparty
    CMakeLists.txt
    Denoiser
    Frame
    ConfigReader
    VFilter

Next, you need to include the 3rdparty folder in the main CMakeLists.txt file of your repository. Add the following line at the end of your main CMakeLists.txt:

add_subdirectory(3rdparty)

Next, you have to link the Denoiser library in your src/CMakeLists.txt file:

target_link_libraries(${PROJECT_NAME} Denoiser)

If your project does not add the Frame, ConfigReader and VFilter libraries, the build stops with an error such as VFilter.h: No such file or directory.

Done!

Example

This section demonstrates how to use the Denoiser with a straightforward example.

#include <cstdint>
#include <iostream>
#include "Denoiser.h"

int main()
{
    std::cout << "Denoiser v" << rapidpixel::Denoiser::getVersion() << std::endl;

    // Init filter.
    rapidpixel::Denoiser denoiser;
    rapidpixel::VFilterParams params;
    params.mode = 1; // Enable the filter.
    params.level = 80.0f; // 80% filter strength.
    if (!denoiser.initVFilter(params))
    {
        std::cout << "Can't initialize the denoiser" << std::endl;
        return 1;
    }

    // Frame to process.
    rapidpixel::Frame frame(512, 512, rapidpixel::Fourcc::YUV24);

    for (int i = 0; i < 100; ++i)
    {
        // Prepare YUV24 frame...

        // Apply filter.
        if (!denoiser.processFrame(frame))
        {
            std::cout << "Frame " << i << " is not processed" << std::endl;
            return 1;
        }
    }

    return 0;
}

Test application

The Denoiser C++ library includes a test application located in the /test folder. This application is designed to help users evaluate the Denoiser’s capabilities. It provides options to adjust parameters such as LEVEL and MODE, and it displays the processing time in milliseconds. Since the application uses a synthetic image for testing, there’s no need to supply an actual image. The test application is independent of the operating system, meaning that it works the same way on both Linux and Windows. To start the test application on Windows, run the DenoiserTest.exe file. On Linux, use the commands below.

sudo chmod +x DenoiserTest
./DenoiserTest

After the start, the user will see a dialog for setting the resolution (from 16 to 8192 pixels) and the display mode (enable / disable the video display):

Denoiser v3.0.5

Set frame width: 1280
Set frame height: 720
Display frame ? (y/n): y

Once the application is successfully launched, it will display a noisy image in a window. Users can adjust the denoiser’s strength from the keyboard: key 2 decreases the strength and key 3 increases it. Key 1 toggles the denoiser on and off. In a VPI build keys 4 and 5 select the VIC and the CUDA backend and keys 6 and 7 select the previous and the next scene preset; in a software build keys 8 and 9 decrease and increase the size of the thread team. Esc closes the application. The application ends with an error message and the exit code 1 if the denoiser rejects the frame. The window will appear as follows:

denoiser_test_interface

The test application started with the –selftest argument runs automatic checks of the library instead of the dialog: it does not open a window, does not read the keyboard and does not write files. The checks are the parameters and the commands (valid, rejected and damaged), the validation of the frames, the output of the software filter (fixed values of the hash of the processed frames, the independence of the size of the thread team) and the calls from several threads. The application prints the title and the result of each check and returns the exit code 0 if all checks passed:

./DenoiserTest --selftest

Table of contents