-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wenzel Jakob
committed
May 15, 2013
1 parent
612f155
commit b8bbfe5
Showing
7 changed files
with
126 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
CMakeFiles | ||
Makefile | ||
CMakeCache.txt | ||
hdrmerge | ||
cmake_install.cmake | ||
rawspeed/librawspeed.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,100 @@ | ||
#include "hdrmerge.h" | ||
|
||
void merge(ExposureSeries &es) { | ||
int x = (int) (randf() * es.width); | ||
int y = (int) (randf() * es.height); | ||
float compute_weight(uint16_t value, uint16_t blacklevel, uint16_t saturation) { | ||
const float alpha = -1.0f / 10.0f; | ||
const float beta = 1.0f / std::exp(4.0f*alpha); | ||
|
||
cout << "x=" << x << ", y=" << y << endl; | ||
float scaled = (value - blacklevel) / (float) (saturation - blacklevel); | ||
|
||
cout << "["; | ||
for (int i=0; i<es.size(); ++i) { | ||
cout << es.eval(i, x, y); | ||
if (i+1 < es.size()) | ||
cout << ", "; | ||
} | ||
cout << "]" << endl; | ||
if (scaled <= 0 || scaled >= 1) | ||
return 0; | ||
|
||
return beta * std::exp(alpha * (1/scaled + 1/(1-scaled))); | ||
} | ||
|
||
float compute_weight(float scaled) { | ||
const float alpha = -1.0f / 10.0f; | ||
const float beta = 1.0f / std::exp(4.0f*alpha); | ||
|
||
if (scaled <= 0 || scaled >= 1) | ||
return 0; | ||
|
||
cout << "["; | ||
for (int i=0; i<es.size(); ++i) { | ||
cout << es.exposures[i].exposure; | ||
if (i+1 < es.size()) | ||
cout << ", "; | ||
return beta * std::exp(alpha * (1/scaled + 1/(1-scaled))); | ||
} | ||
|
||
void merge(ExposureSeries &es) { | ||
cout << "Merging " << es.size() << " exposures .." << endl; | ||
es.image = new float[es.width * es.height]; | ||
|
||
/* Precompute some tables for weights and normalized pixel values */ | ||
float weight_tbl[0xFFFF], value_tbl[0xFFFF]; | ||
for (int i=0; i<0xFFFF; ++i) { | ||
weight_tbl[i] = compute_weight((uint16_t) i, es.blacklevel, es.saturation); | ||
value_tbl[i] = (float) (i - es.blacklevel) / (float) (es.whitepoint - es.blacklevel); | ||
} | ||
cout << "]" << endl; | ||
|
||
|
||
// #pragma omp parallel for schedule(dynamic, 1) | ||
for (int y=0; y<es.height; ++y) { | ||
uint32_t offset = y * es.width; | ||
for (int x=0; x<es.width; ++x) { | ||
float value = 0, total_exposure = 0; | ||
offset = 11002202; | ||
|
||
cout << "Offset=" << offset << endl; | ||
for (int img=0; img<es.size(); ++img) { | ||
uint16_t pxvalue = es.exposures[img].image[offset]; | ||
float weight = weight_tbl[pxvalue]; | ||
value += value_tbl[pxvalue] * weight; | ||
total_exposure += es.exposures[img].exposure * weight; | ||
|
||
cout << img << ": " << pxvalue << " => weight=" << weight << ", value=" << value << endl; | ||
} | ||
|
||
if (total_exposure > 0) | ||
value /= total_exposure; | ||
|
||
cout << " ====>> reference = " << value << endl; | ||
float reference = value; | ||
value = total_exposure = 0; | ||
|
||
float blacklevel = es.blacklevel, scale = es.whitepoint - es.blacklevel; | ||
|
||
for (int img=0; img<es.size(); ++img) { | ||
float predicted = reference * es.exposures[img].exposure * scale + blacklevel; | ||
if (predicted <= 0 || predicted >= 65535.0f) | ||
continue; | ||
uint16_t predicted_pxvalue = (uint16_t) (predicted + 0.5f); | ||
uint16_t pxvalue = es.exposures[img].image[offset]; | ||
float weight = weight_tbl[predicted_pxvalue]; | ||
|
||
value += value_tbl[pxvalue] * weight; | ||
total_exposure += es.exposures[img].exposure * weight; | ||
// cout << img << ": " << value_tbl[pxvalue] << " (pred=" << reference * es.exposures[img].exposure << ") => weight=" << weight << ", value=" << value << endl; | ||
cout << pxvalue << ", " << predicted_pxvalue << "; "; | ||
} | ||
cout << endl; | ||
|
||
if (total_exposure > 0) | ||
value /= total_exposure; | ||
cout << " ====>> reference = " << value << endl; | ||
|
||
es.image[offset++] = value; | ||
exit(-1); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
ExposureSeries es; | ||
// es.add("test-%02i.cr2"); | ||
es.add("/mnt/raid0/layered2/meas-%05i-00000.cr2"); | ||
es.add("/mnt/raid0/layered2/meas2-%05i-00000.cr2"); | ||
es.check(); | ||
if (es.size() == 0) | ||
throw std::runtime_error("No input found / list of exposures to merge is empty!"); | ||
es.load(); | ||
merge(es); | ||
|
||
for (int i=0; i<10; ++i) { | ||
merge(es); | ||
} | ||
|
||
|
||
writeOpenEXR("test.exr", es.width, es.height, 1, es.exposures[2].image, es.metadata, false); | ||
writeOpenEXR("test.exr", es.width, es.height, 1, es.image, es.metadata, false); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters