#include "fie.h" #include "oal_aloc.h" //linear crf + hood INT do_hdr_linear_hood() { // 画像のパス const CHAR* file_names[] = { "input_img_files/00.bmp", "input_img_files/01.bmp", "input_img_files/02.bmp" }; //露光量例 const DOUBLE exposure_ratios[] = {1.0,2.0,3.0}; INT status = F_ERR_UNKNOWN; INT img_num = -1; INT ratios_num = -1; FHANDLE imgstack = NULL; FHANDLE hdst = NULL; FHANDLE hdst_uc8 = NULL; FHANDLE hdr_object=NULL; FHANDLE himg_temp = NULL; INT width, height; INT dst_type; INT dst_ch; INT width_temp, height_temp; INT ch_temp, type_temp; INT i; img_num = sizeof(file_names) / sizeof(file_names[0]); ratios_num = sizeof(exposure_ratios) / sizeof(exposure_ratios[0]); if (img_num < 2) { status = F_ERR_INVALID_IMAGE; goto EXIT; } if (img_num != ratios_num) { status = F_ERR_INVALID_PARAM; goto EXIT; } //最初の一枚目の画像読み込み(これを基準にする) { status = fnFIE_load_img_file(file_names[0], &himg_temp, F_COLOR_IMG_TYPE_UC8); if (status != F_ERR_NONE) { goto EXIT; } status = fnFIE_img_get_params(himg_temp, &ch_temp, &type_temp, NULL, &width_temp, &height_temp); if (status != F_ERR_NONE) { goto EXIT; } fnFIE_free_object(himg_temp); himg_temp = NULL; } //入力画像スタック作成 { imgstack = fnFIE_imgstack_alloc(F_IMGSTACK_ROOT_MODE, TRUE); if (imgstack == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } for (i = 0; i < img_num; i++) { status = fnFIE_load_img_file(file_names[i], &himg_temp, F_COLOR_IMG_TYPE_UC8); if (status != F_ERR_NONE) { goto EXIT; } status = fnFIE_imgstack_push_back(imgstack, himg_temp); if (status != F_ERR_NONE) { goto EXIT; } fnFIE_free_object(himg_temp); himg_temp = NULL; } } //出力画像準備 { width = width_temp; height = height_temp; dst_ch = ch_temp; dst_type = F_IMG_DOUBLE; hdst = fnFIE_img_root_alloc(dst_type, dst_ch, width, height); if (hdst == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } } //出力画像(トーンマッピング後のUC8画像)準備 { width = width_temp; height = height_temp; dst_ch = ch_temp; dst_type = F_IMG_UC8; hdst_uc8 = fnFIE_img_root_alloc(dst_type, dst_ch, width, height); if (hdst_uc8 == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } } //linear_crf + hood { //execute(linear_crf):線形の場合はhdr_object==NULLでよい。 status = fnFIE_hdr_execute(hdr_object, imgstack, hdst, exposure_ratios); if (status != F_ERR_NONE) { goto EXIT; } //tonemapping(hood) status = fnFIE_hdr_tonemap_hood(hdst,hdst_uc8,-1); if (status != F_ERR_NONE) { goto EXIT; } //executeではtonemapping必要 //結果画像保存 status = fnFIE_save_png("hdst_linear_hood.png", hdst_uc8, -1); if (status != F_ERR_NONE) { goto EXIT; } } EXIT: fnFIE_free_object(imgstack); fnFIE_free_object(hdr_object); fnFIE_free_object(hdst); fnFIE_free_object(hdst_uc8); fnFIE_free_object(himg_temp); return status; } //robertson + hood INT do_hdr_robertson_hood() { // 画像のパス const CHAR* file_names[] = { "input_img_files/00.bmp", "input_img_files/01.bmp", "input_img_files/02.bmp" }; //露光量例 const DOUBLE exposure_ratios[] = { 1.0,2.0,3.0 }; INT status = F_ERR_UNKNOWN; INT img_num = -1; INT ratios_num = -1; FHANDLE imgstack = NULL; FHANDLE hdst = NULL; FHANDLE hdst_uc8 = NULL; FHANDLE hdr_object = NULL; FHANDLE himg_temp = NULL; INT width, height; INT dst_type; INT dst_ch; INT width_temp, height_temp; INT ch_temp, type_temp; INT iter_num; DOUBLE thresh; INT i; img_num = sizeof(file_names) / sizeof(file_names[0]); ratios_num = sizeof(exposure_ratios) / sizeof(exposure_ratios[0]); if (img_num < 2) { status = F_ERR_INVALID_IMAGE; goto EXIT; } if (img_num != ratios_num) { status = F_ERR_INVALID_PARAM; goto EXIT; } //最初の一枚目の画像読み込み(これを基準にする) { status = fnFIE_load_img_file(file_names[0], &himg_temp, F_COLOR_IMG_TYPE_UC8); if (status != F_ERR_NONE) { goto EXIT; } status = fnFIE_img_get_params(himg_temp, &ch_temp, &type_temp, NULL, &width_temp, &height_temp); if (status != F_ERR_NONE) { goto EXIT; } fnFIE_free_object(himg_temp); himg_temp = NULL; } //入力画像スタック作成 { imgstack = fnFIE_imgstack_alloc(F_IMGSTACK_ROOT_MODE, TRUE); if (imgstack == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } for (i = 0; i < img_num; i++) { status = fnFIE_load_img_file(file_names[i], &himg_temp, F_COLOR_IMG_TYPE_UC8); if (status != F_ERR_NONE) { goto EXIT; } status = fnFIE_imgstack_push_back(imgstack, himg_temp); if (status != F_ERR_NONE) { goto EXIT; } fnFIE_free_object(himg_temp); himg_temp = NULL; } } //出力画像準備 { width = width_temp; height = height_temp; dst_ch = ch_temp; dst_type = F_IMG_DOUBLE; hdst = fnFIE_img_root_alloc(dst_type, dst_ch, width, height); if (hdst == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } } //出力画像(トーンマッピング後のUC8画像)準備 { width = width_temp; height = height_temp; dst_ch = ch_temp; dst_type = F_IMG_UC8; hdst_uc8 = fnFIE_img_root_alloc(dst_type, dst_ch, width, height); if (hdst_uc8 == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } } //robertson + hood { iter_num = 30; thresh = 0.01; //hdrオブジェクト作成 hdr_object = fnFIE_hdr_calibrate_robertson(imgstack,exposure_ratios,iter_num,thresh,&status); if (status != F_ERR_NONE) { goto EXIT; } //execute(robertson) status = fnFIE_hdr_execute(hdr_object, imgstack, hdst, exposure_ratios); if (status != F_ERR_NONE) { goto EXIT; } //tonemapping(hood) status = fnFIE_hdr_tonemap_hood(hdst, hdst_uc8, -1); if (status != F_ERR_NONE) { goto EXIT; } //executeではtonemapping必要 //結果画像保存 status = fnFIE_save_png("hdst_robertson_hood.png", hdst_uc8, -1); if (status != F_ERR_NONE) { goto EXIT; } } EXIT: fnFIE_free_object(imgstack); fnFIE_free_object(hdr_object); fnFIE_free_object(hdst); fnFIE_free_object(hdst_uc8); fnFIE_free_object(himg_temp); return status; } //Mertens INT do_hdr_mertens() { // 画像のパス const CHAR* file_names[] = { "input_img_files/00.bmp", "input_img_files/01.bmp", "input_img_files/02.bmp" }; INT status = F_ERR_UNKNOWN; INT img_num = -1; FHANDLE imgstack = NULL; FHANDLE hdst = NULL; FHANDLE himg_temp = NULL; INT width, height; INT dst_type; INT dst_ch; INT width_temp, height_temp; INT ch_temp, type_temp; INT py_level; INT i; img_num = sizeof(file_names) / sizeof(file_names[0]); if (img_num < 2) { status = F_ERR_INVALID_IMAGE; goto EXIT; } //最初の一枚目の画像読み込み(これを基準にする) { status = fnFIE_load_img_file(file_names[0], &himg_temp, F_COLOR_IMG_TYPE_UC8); if (status != F_ERR_NONE) { goto EXIT; } status = fnFIE_img_get_params(himg_temp, &ch_temp, &type_temp, NULL, &width_temp, &height_temp); if (status != F_ERR_NONE) { goto EXIT; } fnFIE_free_object(himg_temp); himg_temp = NULL; } //入力画像スタック作成 { imgstack = fnFIE_imgstack_alloc(F_IMGSTACK_ROOT_MODE, TRUE); if (imgstack == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } for (i = 0; i < img_num; i++) { status = fnFIE_load_img_file(file_names[i], &himg_temp, F_COLOR_IMG_TYPE_UC8); if (status != F_ERR_NONE) { goto EXIT; } status = fnFIE_imgstack_push_back(imgstack, himg_temp); if (status != F_ERR_NONE) { goto EXIT; } fnFIE_free_object(himg_temp); himg_temp = NULL; } } //出力画像準備 { width = width_temp; height = height_temp; dst_ch = ch_temp; dst_type = F_IMG_UC8; hdst = fnFIE_img_root_alloc(dst_type, dst_ch, width, height); if (hdst == NULL) { status = F_ERR_NOMEMORY; goto EXIT; } } //Mertens法実行 { py_level = -1;//デフォルト status = fnFIE_hdr_mertens(imgstack, hdst, py_level); if (status != F_ERR_NONE) { goto EXIT; } //Mertensではtonemapping不要 //結果画像保存 status = fnFIE_save_png("hdst_mertens.png", hdst, -1); if (status != F_ERR_NONE) { goto EXIT; } } EXIT: fnFIE_free_object(imgstack); fnFIE_free_object(hdst); fnFIE_free_object(himg_temp); return status; } INT main() { INT status = F_ERR_UNKNOWN; // FIEライブラリのセットアップ fnFIE_setup(); // HDR:linear_crf + hood status = do_hdr_linear_hood(); // HDR:robertson + hood //status = do_hdr_robertson_hood(); // HDR:mertens //status = do_hdr_mertens(); // ライブラリの終了処理 fnFIE_teardown(); return status; }
入力画像1枚目 |
入力画像2枚目 |
入力画像3枚目
|
出力画像(Mertens法) |
出力画像(liner_crf,tonemappingはhood) |
出力画像(Robertson,tonemappingはhood)
|