1. Color manipulation#

ImageSdk provides several tools for color management, including saturation, white balance, red curve, green curve and blue curve. This example shows how to use these tools.

#include "P1Image.hpp"
#include <iostream>

using namespace P1::ImageSdk;

int main()
{
    try
    {
        // 1. Load IIQ image
        RawImage im("Sample.IIQ");

        // 2. Set convert parameters
        ConvertConfig config;

        // Increase color saturation
        config.SetSaturation(0.2);

        // Set custom white balance. 
        // These are multipliers to red, green, and blue color.
        config.SetWhiteBalanceGain(Color(1.2, 1.0, 1.3));

        // Set red curve
        // Input is a vector of P1::ImageSdk::Point2D
        config.SetRedCurve({
            {0, 0},
            {0.5, 0.6},
            {1, 1}
            });

        // 3. Convert
        BitmapImage bmp = im.Convert(config);

        // 4. Export to JPEG
        JpegWriter("out.jpeg", bmp, im, JpegConfig());
    

        return 0;
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what();
        return -1;
    }
}
using P1.ImageSdk;

// 1. Load IIQ
RawImage im = new("Sample.IIQ");

// 2. Set convert parameters
ConvertConfig config = new();


// Increase color saturation
config.SetSaturation(0.2f);

// Set custom white balance. 
// These are multipliers to red, green, and blue color.
config.SetWhiteBalanceGain(1.2f, 1.0f, 1.3f);

// Set red curve
config.SetRedCurve(new Point2D[]{
    new Point2D(0, 0),
    new Point2D(0.5, 0.6),
    new Point2D(1.0, 1.0)
});

// 3. Convert
IBitmapImage bmp = im.Convert(config);

// 4. Export to JPEG
im.WriteAsJpeg("out.jpeg", bmp, new JpegConfig());

Saturation enhances the image, making the colors vivid, rich, and bright. If set to a negative value, the colors become faded and pale.

WhiteBalanceGain gains red, green, and blue corresponding to the input parameters. Most software represents white balance using temperature and tint. There is no direct conversion from RGB gains to temperature and tint, so a lookup table is required for the translation.

Red, green and blue curve adjust the gain of each color channel independently and nonlinearly, also affecting color saturation. Refer to example 4. Curves for for more details on using curve.