main
Matthew 6 months ago
parent 2767bab6ea
commit 38e4ef464c

@ -197,14 +197,17 @@ class finish
return m; return m;
} }
void load_rawPathList(std::string burstPath){ void load_rawPathList(std::string burstPath)
{
DIR *pDir; // pointer to root DIR *pDir; // pointer to root
struct dirent *ptr; struct dirent *ptr;
if (!(pDir = opendir(burstPath.c_str()))) { if (!(pDir = opendir(burstPath.c_str())))
{
std::cout << "root dir not found!" << std::endl; std::cout << "root dir not found!" << std::endl;
return; return;
} }
while ((ptr = readdir(pDir)) != nullptr) { while ((ptr = readdir(pDir)) != nullptr)
{
// ptr will move to the next file automatically // ptr will move to the next file automatically
std::string sub_file = burstPath + "/" + ptr->d_name; // current filepath that ptr points to std::string sub_file = burstPath + "/" + ptr->d_name; // current filepath that ptr points to
if (ptr->d_type != 8 && ptr->d_type != 4) { // not normal file or dir if (ptr->d_type != 8 && ptr->d_type != 4) { // not normal file or dir

@ -33,14 +33,16 @@ namespace hdrplus
(*it)[2] *= (255.0 / USHRT_MAX); (*it)[2] *= (255.0 / USHRT_MAX);
} }
ans.convertTo(ans, CV_8UC3); ans.convertTo(ans, CV_8UC3);
}else if(ans.type()==CV_16UC1){ }
else if (ans.type() == CV_16UC1) {
uint16_t* ptr = (uint16_t*)ans.data; uint16_t* ptr = (uint16_t*)ans.data;
int end = ans.rows*ans.cols; int end = ans.rows*ans.cols;
for (int i = 0; i < end; i++) { for (int i = 0; i < end; i++) {
*(ptr + i) *= (255.0 / USHRT_MAX); *(ptr + i) *= (255.0 / USHRT_MAX);
} }
ans.convertTo(ans, CV_8UC1); ans.convertTo(ans, CV_8UC1);
}else{ }
else {
std::cout << "Unsupported Data Type" << std::endl; std::cout << "Unsupported Data Type" << std::endl;
} }
return ans; return ans;
@ -58,7 +60,8 @@ namespace hdrplus
(*it)[2] *= (65535.0 / 255.0); (*it)[2] *= (65535.0 / 255.0);
} }
}else if(ans.type()==CV_8UC1){ }
else if (ans.type() == CV_8UC1) {
ans.convertTo(ans, CV_16UC1); ans.convertTo(ans, CV_16UC1);
uint16_t* ptr = (uint16_t*)ans.data; uint16_t* ptr = (uint16_t*)ans.data;
int end = ans.rows*ans.cols; int end = ans.rows*ans.cols;
@ -66,7 +69,8 @@ namespace hdrplus
*(ptr + i) *= (65535.0 / 255.0); *(ptr + i) *= (65535.0 / 255.0);
} }
}else{ }
else {
std::cout << "Unsupported Data Type" << std::endl; std::cout << "Unsupported Data Type" << std::endl;
} }
return ans; return ans;
@ -92,13 +96,15 @@ namespace hdrplus
// check the val against the threshold // check the val against the threshold
if (x <= threshold) { if (x <= threshold) {
x = gainMin * x; x = gainMin * x;
}else{ }
else {
x = gainMax * pow(x, exponent) - gainMax + 1; x = gainMax * pow(x, exponent) - gainMax + 1;
} }
// clip // clip
if (x < 0) { if (x < 0) {
x = 0; x = 0;
}else{ }
else {
if (x > 1) { if (x > 1) {
x = 1; x = 1;
} }
@ -115,13 +121,15 @@ namespace hdrplus
// check the val against the threshold // check the val against the threshold
if (x <= threshold) { if (x <= threshold) {
x = x / gainMin; x = x / gainMin;
}else{ }
else {
x = pow((x + gainMax - 1) / gainMax, exponent); x = pow((x + gainMax - 1) / gainMax, exponent);
} }
// clip // clip
if (x < 0) { if (x < 0) {
x = 0; x = 0;
}else{ }
else {
if (x > 1) { if (x > 1) {
x = 1; x = 1;
} }
@ -140,14 +148,16 @@ namespace hdrplus
(*it)[1] = uGammaCompress_1pix((*it)[1], threshold, gainMin, gainMax, exponent); (*it)[1] = uGammaCompress_1pix((*it)[1], threshold, gainMin, gainMax, exponent);
(*it)[2] = uGammaCompress_1pix((*it)[2], threshold, gainMin, gainMax, exponent); (*it)[2] = uGammaCompress_1pix((*it)[2], threshold, gainMin, gainMax, exponent);
} }
}else if(m.type()==CV_16UC1){ }
else if (m.type() == CV_16UC1) {
uint16_t* ptr = (uint16_t*)m.data; uint16_t* ptr = (uint16_t*)m.data;
int end = m.rows*m.cols; int end = m.rows*m.cols;
for (int i = 0; i < end; i++) { for (int i = 0; i < end; i++) {
*(ptr + i) = uGammaCompress_1pix(*(ptr + i), threshold, gainMin, gainMax, exponent); *(ptr + i) = uGammaCompress_1pix(*(ptr + i), threshold, gainMin, gainMax, exponent);
} }
}else{ }
else {
std::cout << "Unsupported Data Type" << std::endl; std::cout << "Unsupported Data Type" << std::endl;
} }
return m; return m;
@ -162,14 +172,16 @@ namespace hdrplus
(*it)[1] = uGammaDecompress_1pix((*it)[1], threshold, gainMin, gainMax, exponent); (*it)[1] = uGammaDecompress_1pix((*it)[1], threshold, gainMin, gainMax, exponent);
(*it)[2] = uGammaDecompress_1pix((*it)[2], threshold, gainMin, gainMax, exponent); (*it)[2] = uGammaDecompress_1pix((*it)[2], threshold, gainMin, gainMax, exponent);
} }
}else if(m.type()==CV_16UC1){ }
else if (m.type() == CV_16UC1) {
uint16_t* ptr = (uint16_t*)m.data; uint16_t* ptr = (uint16_t*)m.data;
int end = m.rows*m.cols; int end = m.rows*m.cols;
for (int i = 0; i < end; i++) { for (int i = 0; i < end; i++) {
*(ptr + i) = uGammaDecompress_1pix(*(ptr + i), threshold, gainMin, gainMax, exponent); *(ptr + i) = uGammaDecompress_1pix(*(ptr + i), threshold, gainMin, gainMax, exponent);
} }
}else{ }
else {
std::cout << "Unsupported Data Type" << std::endl; std::cout << "Unsupported Data Type" << std::endl;
} }
@ -179,7 +191,8 @@ namespace hdrplus
cv::Mat gammasRGB(cv::Mat img, bool mode) { cv::Mat gammasRGB(cv::Mat img, bool mode) {
if (mode) {// compress if (mode) {// compress
return uGammaCompress_(img, 0.0031308, 12.92, 1.055, 1. / 2.4); return uGammaCompress_(img, 0.0031308, 12.92, 1.055, 1. / 2.4);
}else{ // decompress }
else { // decompress
return uGammaDecompress_(img, 0.04045, 12.92, 1.055, 2.4); return uGammaDecompress_(img, 0.04045, 12.92, 1.055, 2.4);
} }
} }
@ -235,9 +248,11 @@ namespace hdrplus
double tmp = *(ptr + i)*gain; double tmp = *(ptr + i)*gain;
if (tmp < 0) { if (tmp < 0) {
*(ptr + i) = 0; *(ptr + i) = 0;
}else if(tmp>USHRT_MAX){ }
else if (tmp > USHRT_MAX) {
*(ptr + i) = USHRT_MAX; *(ptr + i) = USHRT_MAX;
}else{ }
else {
*(ptr + i) = (uint16_t)tmp; *(ptr + i) = (uint16_t)tmp;
} }
} }
@ -262,7 +277,8 @@ namespace hdrplus
if (img.channels() != 3) { if (img.channels() != 3) {
std::cout << "unsupport img type in meanGain_()" << std::endl; std::cout << "unsupport img type in meanGain_()" << std::endl;
return cv::Mat(); return cv::Mat();
}else{ // RGB img }
else { // RGB img
int H = img.rows; int H = img.rows;
int W = img.cols; int W = img.cols;
cv::Mat processedImg = cv::Mat(H, W, CV_16UC1); cv::Mat processedImg = cv::Mat(H, W, CV_16UC1);
@ -318,9 +334,11 @@ namespace hdrplus
double tmp = (*it)[c] * s; double tmp = (*it)[c] * s;
if (tmp < 0) { if (tmp < 0) {
(*it)[c] = 0; (*it)[c] = 0;
}else if(tmp>USHRT_MAX){ }
else if (tmp > USHRT_MAX) {
(*it)[c] = USHRT_MAX; (*it)[c] = USHRT_MAX;
}else{ }
else {
(*it)[c] = tmp; (*it)[c] = tmp;
} }
} }
@ -363,7 +381,8 @@ namespace hdrplus
} }
} }
}else{ }
else {
if (options.ltmGain > 0) { if (options.ltmGain > 0) {
gain = options.ltmGain; gain = options.ltmGain;
} }
@ -403,7 +422,8 @@ namespace hdrplus
x = x - gain * sin(2 * M_PI*x); x = x - gain * sin(2 * M_PI*x);
if (x < 0) { if (x < 0) {
x = 0; x = 0;
}else if(x>1){ }
else if (x > 1) {
x = 1; x = 1;
} }
uint16_t result = x * USHRT_MAX; uint16_t result = x * USHRT_MAX;
@ -417,7 +437,8 @@ namespace hdrplus
for (int idx = 0; idx < end; idx++) { for (int idx = 0; idx < end; idx++) {
*(ptr + idx) = enhanceContrast_1pix(*(ptr + idx), options.gtmContrast); *(ptr + idx) = enhanceContrast_1pix(*(ptr + idx), options.gtmContrast);
} }
}else{ }
else {
std::cout << "GTM ignored, expected a contrast enhancement ratio between 0 and 1" << std::endl; std::cout << "GTM ignored, expected a contrast enhancement ratio between 0 and 1" << std::endl;
} }
return image; return image;
@ -434,11 +455,13 @@ namespace hdrplus
for (int i = 0; i < end_x; i++) { for (int i = 0; i < end_x; i++) {
if (*(ptr_x + i) < *(ptr_y + i)) { if (*(ptr_x + i) < *(ptr_y + i)) {
*(ptr_r + i) = *(ptr_y + i) - *(ptr_x + i); *(ptr_r + i) = *(ptr_y + i) - *(ptr_x + i);
}else{ }
else {
*(ptr_r + i) = *(ptr_x + i) - *(ptr_y + i); *(ptr_r + i) = *(ptr_x + i) - *(ptr_y + i);
} }
} }
}else{ }
else {
std::cout << "Mat size not match. distL1_ failed!" << std::endl; std::cout << "Mat size not match. distL1_ failed!" << std::endl;
} }
return result; return result;

Loading…
Cancel
Save