This is a simple C++ program that converts an LDR image to an HDR image using the OpenCV library.

#include <opencv2/opencv.hpp>

using namespace cv;

void ldr2hdr(Mat& img, float gamma, float exposure)
{
    Mat ldr_img = img.clone();

    // gamma校正
    Mat gamma_img;
    pow(ldr_img / 255.f, gamma, gamma_img);
    gamma_img.convertTo(gamma_img, CV_32F);

    // 曝光调整
    Mat hdr_img;
    hdr_img = exposure * gamma_img;

    // 显示结果
    imshow('LDR Image', ldr_img);
    imshow('HDR Image', hdr_img);
}

int main()
{
    // 读取LDR图像
    Mat ldr_img = imread('input.jpg', IMREAD_GRAYSCALE);

    // 转换成浮点型
    ldr_img.convertTo(ldr_img, CV_32F);

    // 调用函数
    ldr2hdr(ldr_img, 2.2, 1.f);

    waitKey(0);

    return 0;
}

This program reads an LDR image named 'input.jpg', converts it to floating-point type, applies gamma correction and exposure adjustment, and displays the resulting HDR image. You can adjust the gamma value and exposure value to achieve your desired results.

C++ OpenCV LDR to HDR Image Conversion: Simple Code Example

原文地址: https://www.cveoy.top/t/topic/ntGV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录