|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <opencv2/opencv.hpp> // all opencv header
|
|
|
|
|
#include "hdrplus/finish.h"
|
|
|
|
|
#include "hdrplus/utility.h"
|
|
|
|
@ -554,23 +555,29 @@ namespace hdrplus
|
|
|
|
|
myfile.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void finish::process(const hdrplus::burst& burst_images){
|
|
|
|
|
void finish::process(const hdrplus::burst& burst_images, cv::Mat& finalOutputImage){
|
|
|
|
|
// copy mergedBayer to rawReference
|
|
|
|
|
std::cout<<"finish pipeline start ..."<<std::endl;
|
|
|
|
|
|
|
|
|
|
// save merged Image value
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
writeCSV("merged.csv",burst_images.merged_bayer_image);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
this->refIdx = burst_images.reference_image_idx;
|
|
|
|
|
// this->burstPath = burstPath;
|
|
|
|
|
// std::cout<<"processMerged:"<<std::endl;
|
|
|
|
|
// show20_20(mergedB);
|
|
|
|
|
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
// this->mergedBayer = processMergedMat(mergedB,CV_16UC1);//loadFromCSV("merged.csv", CV_16UC1);
|
|
|
|
|
// std::cout<<"processMerged:"<<std::endl;
|
|
|
|
|
// show20_20(this->mergedBayer);
|
|
|
|
|
this->mergedBayer = loadFromCSV("merged.csv", CV_16UC1);
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
this->mergedBayer = processMergedMat(burst_images.merged_bayer_image, CV_16UC1);
|
|
|
|
|
// std::cout<<"processMerged:"<<std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
// std::cout<<"csv:"<<std::endl;
|
|
|
|
|
// show20_20(this->mergedBayer);
|
|
|
|
|
// load_rawPathList(burstPath);
|
|
|
|
@ -585,6 +592,7 @@ namespace hdrplus
|
|
|
|
|
std::cout<<"size ref: "<<processedRefImage.rows<<"*"<<processedRefImage.cols<<std::endl;
|
|
|
|
|
|
|
|
|
|
// write reference image
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeReferenceImage"]){
|
|
|
|
|
std::cout<<"writing reference img ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(processedRefImage.clone());
|
|
|
|
@ -593,8 +601,10 @@ namespace hdrplus
|
|
|
|
|
cv::imwrite("processedRef.jpg", outputImg);
|
|
|
|
|
// cv::waitKey(0);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// write gamma reference
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeGammaReference"]){
|
|
|
|
|
std::cout<<"writing Gamma reference img ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = gammasRGB(processedRefImage.clone(),true);
|
|
|
|
@ -602,6 +612,7 @@ namespace hdrplus
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
cv::imwrite("processedRefGamma.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// get the bayer_image of the merged image
|
|
|
|
|
// bayer_image* mergedImg = new bayer_image(rawPathList[refIdx]);
|
|
|
|
@ -611,14 +622,17 @@ namespace hdrplus
|
|
|
|
|
cv::Mat processedMerge = postprocess(mergedImg->libraw_processor,params.rawpyArgs);
|
|
|
|
|
|
|
|
|
|
// write merged image
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeMergedImage"]){
|
|
|
|
|
std::cout<<"writing Merged img ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(processedMerge.clone());
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
cv::imwrite("mergedImg.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// write gamma merged image
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeMergedImage"]){
|
|
|
|
|
std::cout<<"writing Gamma Merged img ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = gammasRGB(processedMerge.clone(),true);
|
|
|
|
@ -626,6 +640,7 @@ namespace hdrplus
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
cv::imwrite("mergedImgGamma.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// step 5. HDR tone mapping
|
|
|
|
|
// processedImage, gain, shortExposure, longExposure, fusedExposure = localToneMap(burstPath, processedImage, options)
|
|
|
|
@ -635,27 +650,40 @@ namespace hdrplus
|
|
|
|
|
|
|
|
|
|
localToneMap(processedMerge, params.options,shortExposure,longExposure,fusedExposure,gain);
|
|
|
|
|
std::cout<<"gain="<< gain<<std::endl;
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeShortExposure"]){
|
|
|
|
|
std::cout<<"writing ShortExposure img ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(shortExposure);
|
|
|
|
|
cv::imwrite("shortg.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeLongExposure"]){
|
|
|
|
|
std::cout<<"writing LongExposure img ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(longExposure);
|
|
|
|
|
cv::imwrite("longg.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeFusedExposure"]){
|
|
|
|
|
std::cout<<"writing FusedExposure img ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(fusedExposure);
|
|
|
|
|
cv::imwrite("fusedg.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeLTMImage"]){
|
|
|
|
|
std::cout<<"writing LTMImage ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(processedMerge.clone());
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
cv::imwrite("ltmGain.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeLTMGamma"]){
|
|
|
|
|
std::cout<<"writing LTMImage Gamma ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = gammasRGB(processedMerge.clone(),true);
|
|
|
|
@ -663,6 +691,7 @@ namespace hdrplus
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
cv::imwrite("ltmGain_gamma.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// step 6 GTM: contrast enhancement / global tone mapping
|
|
|
|
@ -675,22 +704,31 @@ namespace hdrplus
|
|
|
|
|
processedMerge = gammasRGB(processedMerge.clone(),true);
|
|
|
|
|
std::cout<<"-- Apply Gamma"<<std::endl;
|
|
|
|
|
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeGTMImage"]) {
|
|
|
|
|
std::cout<<"writing GTMImage ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(processedMerge.clone());
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
|
|
|
|
|
cv::imwrite("GTM_gamma.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Step 7: sharpen
|
|
|
|
|
cv::Mat processedImage = sharpenTriple(processedMerge.clone(), params.tuning, params.options);
|
|
|
|
|
finalOutputImage = sharpenTriple(processedMerge.clone(), params.tuning, params.options);
|
|
|
|
|
cv::Mat& processedImage = finalOutputImage;
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeFinalImage"]){
|
|
|
|
|
std::cout<<"writing FinalImage ..."<<std::endl;
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(processedImage.clone());
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
|
|
|
|
|
cv::imwrite("FinalImage.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// write final ref
|
|
|
|
|
#ifndef HDRPLUS_NO_DETAILED_OUTPUT
|
|
|
|
|
if(params.flags["writeReferenceFinal"]){
|
|
|
|
|
std::cout<<"writing Final Ref Image ..."<<std::endl;
|
|
|
|
|
if(params.options.ltmGain){
|
|
|
|
@ -706,8 +744,10 @@ namespace hdrplus
|
|
|
|
|
processedRefImage = sharpenTriple(processedRefImage.clone(), params.tuning, params.options);
|
|
|
|
|
cv::Mat outputImg = convert16bit2_8bit_(processedRefImage.clone());
|
|
|
|
|
cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
|
|
|
|
|
cv::imwrite("FinalReference.jpg", outputImg);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
// End of finishing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|