Skip to content

Commit 96ddeda

Browse files
committedFeb 12, 2017
OpenCV creación de imágenes HDR
Creación de imágenes HDR con OpenCV y aplicación de Mapeo Tonal para obtener una imagen LDR.
1 parent cfb68e8 commit 96ddeda

21 files changed

+354
-0
lines changed
 

‎opencv-hdr/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.4)
2+
3+
project( Tutorial_OpenCV_HDR )
4+
5+
find_package( OpenCV 3.0.0 REQUIRED )
6+
7+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
8+
file(COPY exposures DESTINATION data)
9+
10+
add_executable( ${PROJECT_NAME} source.cpp)
11+
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )

‎opencv-hdr/exposures/list.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
memorial00.png 0.03125
2+
memorial01.png 0.0625
3+
memorial02.png 0.125
4+
memorial03.png 0.25
5+
memorial04.png 0.5
6+
memorial05.png 1
7+
memorial06.png 2
8+
memorial07.png 4
9+
memorial08.png 8
10+
memorial09.png 16
11+
memorial10.png 32
12+
memorial11.png 64
13+
memorial12.png 128
14+
memorial13.png 256
15+
memorial14.png 512
16+
memorial15.png 1024

‎opencv-hdr/exposures/memorial00.png

619 KB
Loading

‎opencv-hdr/exposures/memorial01.png

663 KB
Loading

‎opencv-hdr/exposures/memorial02.png

660 KB
Loading

‎opencv-hdr/exposures/memorial03.png

633 KB
Loading

‎opencv-hdr/exposures/memorial04.png

611 KB
Loading

‎opencv-hdr/exposures/memorial05.png

537 KB
Loading

‎opencv-hdr/exposures/memorial06.png

479 KB
Loading

‎opencv-hdr/exposures/memorial07.png

424 KB
Loading

‎opencv-hdr/exposures/memorial08.png

381 KB
Loading

‎opencv-hdr/exposures/memorial09.png

342 KB
Loading

‎opencv-hdr/exposures/memorial10.png

312 KB
Loading

‎opencv-hdr/exposures/memorial11.png

311 KB
Loading

‎opencv-hdr/exposures/memorial12.png

306 KB
Loading

‎opencv-hdr/exposures/memorial13.png

290 KB
Loading

‎opencv-hdr/exposures/memorial14.png

293 KB
Loading

‎opencv-hdr/exposures/memorial15.png

286 KB
Loading

‎opencv-hdr/exposures/readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Images by Paul Debevec
2+
http://www.pauldebevec.com/Research/HDR/

‎opencv-hdr/exposures/response.csv

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
9.9913286e-006; 2.4236835e-005; 3.9994137e-007
2+
1.1925539e-005; 2.9175266e-005; 7.2169547e-007
3+
1.4234167e-005; 3.5119036e-005; 1.3023017e-006
4+
1.6990005e-005; 4.2273783e-005; 2.3500165e-006
5+
2.0279218e-005; 5.0886887e-005; 4.2408833e-006
6+
2.4205099e-005; 6.1254876e-005; 7.652673e-006
7+
2.8891574e-005; 7.373171e-005; 1.3809575e-005
8+
3.4484929e-005; 8.8751774e-005; 2.4920517e-005
9+
4.116134e-005; 0.000106836; 4.4969966e-005
10+
4.913066e-005; 0.00012860021; 8.1150611e-005
11+
5.8643494e-005; 0.00015479898; 0.00014644253
12+
6.999691e-005; 0.00018633543; 0.00026426406
13+
8.354913e-005; 0.00022429255; 0.00047687421
14+
9.9724472e-005; 0.00026998454; 0.00086054811
15+
0.00011903355; 0.00032499025; 0.001497223
16+
0.00014207728; 0.00039119407; 0.0032238537
17+
0.00016958543; 0.00047088918; 0.0068687052
18+
0.00026635907; 0.00057208241; 0.01298642
19+
0.00068084634; 0.00078411098; 0.02096951
20+
0.0021898078; 0.0013579689; 0.029799931
21+
0.0060876836; 0.0034766553; 0.037982803
22+
0.012188704; 0.0098313969; 0.044623155
23+
0.019381572; 0.022857832; 0.04994081
24+
0.026102243; 0.040900759; 0.053975735
25+
0.031212151; 0.057897139; 0.056405284
26+
0.035172567; 0.071038961; 0.057697482
27+
0.038957849; 0.078668691; 0.058579911
28+
0.042469174; 0.081798084; 0.059707697
29+
0.045985129; 0.083096661; 0.061045852
30+
0.049889911; 0.084040791; 0.062604435
31+
0.054434128; 0.086006746; 0.064022601
32+
0.059628017; 0.088912345; 0.065038152
33+
0.065554708; 0.093969978; 0.066094339
34+
0.070699766; 0.10087334; 0.067394927
35+
0.075364105; 0.1092255; 0.069467463
36+
0.079596102; 0.11908042; 0.072204329
37+
0.083443239; 0.13001455; 0.075088762
38+
0.086503379; 0.14028794; 0.07816086
39+
0.088823065; 0.14963987; 0.0817618
40+
0.091458172; 0.15715683; 0.086675413
41+
0.094501376; 0.1623891; 0.092589013
42+
0.097134598; 0.16534188; 0.099591233
43+
0.099586129; 0.1679147; 0.10749805
44+
0.10185703; 0.17125806; 0.11600714
45+
0.10438181; 0.17597049; 0.12514366
46+
0.10744093; 0.18148969; 0.1337149
47+
0.11125616; 0.18945038; 0.14152265
48+
0.11604005; 0.20072773; 0.14808039
49+
0.12170326; 0.21555845; 0.15299451
50+
0.12809271; 0.23381919; 0.15718059
51+
0.13476521; 0.254437; 0.16146819
52+
0.14159222; 0.27452907; 0.16553761
53+
0.14841424; 0.29258692; 0.16949625
54+
0.15471385; 0.3070789; 0.17380963
55+
0.16003047; 0.31420258; 0.17884901
56+
0.16477887; 0.31552976; 0.18465891
57+
0.16931167; 0.3118991; 0.19136043
58+
0.17341983; 0.30436093; 0.19856755
59+
0.17728512; 0.29494864; 0.20577778
60+
0.18154515; 0.28588876; 0.21220571
61+
0.18664724; 0.27816865; 0.21822441
62+
0.19229634; 0.27175796; 0.22394404
63+
0.19824135; 0.2663303; 0.22921002
64+
0.2041911; 0.26236475; 0.23451768
65+
0.20996097; 0.25984395; 0.24044029
66+
0.21601056; 0.25904408; 0.24759097
67+
0.22291714; 0.26027361; 0.25590575
68+
0.23130628; 0.26368624; 0.26528409
69+
0.24074949; 0.26967406; 0.2744216
70+
0.25079298; 0.27739134; 0.28298622
71+
0.26129454; 0.2860643; 0.29056588
72+
0.27210599; 0.29597396; 0.29664648
73+
0.28243971; 0.30744672; 0.30159831
74+
0.29147351; 0.3207399; 0.30550534
75+
0.29906559; 0.3339403; 0.30818614
76+
0.30509186; 0.34655997; 0.30947343
77+
0.31002164; 0.35843495; 0.30984345
78+
0.31471661; 0.36962065; 0.31013519
79+
0.31959948; 0.38018823; 0.31161192
80+
0.32529372; 0.39029211; 0.31597647
81+
0.33226511; 0.40003452; 0.32258257
82+
0.3403759; 0.40907177; 0.33122337
83+
0.349489; 0.41763854; 0.34159046
84+
0.35952392; 0.42592329; 0.35348898
85+
0.37040061; 0.43413231; 0.36674932
86+
0.38199392; 0.44249433; 0.38113692
87+
0.3939347; 0.45179623; 0.39665207
88+
0.40580627; 0.46259034; 0.41329506
89+
0.41765487; 0.47536421; 0.43013224
90+
0.42950493; 0.48945805; 0.44592372
91+
0.44138184; 0.50413293; 0.45882881
92+
0.45352197; 0.51859689; 0.46967641
93+
0.46589905; 0.53197801; 0.47920594
94+
0.4783982; 0.544186; 0.48873377
95+
0.49091184; 0.55523062; 0.49877656
96+
0.50327688; 0.56559324; 0.50987637
97+
0.51529467; 0.57573372; 0.52062386
98+
0.52681386; 0.58627373; 0.53010958
99+
0.53763264; 0.59723228; 0.53855902
100+
0.54699099; 0.60851473; 0.54639161
101+
0.55540437; 0.6197288; 0.55386436
102+
0.56360042; 0.63075167; 0.56121278
103+
0.5723362; 0.64097178; 0.56909269
104+
0.58236271; 0.64982271; 0.57812947
105+
0.59413236; 0.65744478; 0.58849686
106+
0.6073041; 0.66493136; 0.59911156
107+
0.62147474; 0.67307079; 0.60993063
108+
0.63638443; 0.68267119; 0.62064523
109+
0.65176171; 0.69293618; 0.63118637
110+
0.66770059; 0.70342726; 0.64150083
111+
0.68432587; 0.71393144; 0.65151322
112+
0.70177519; 0.72422701; 0.66115344
113+
0.72015655; 0.73411244; 0.67036527
114+
0.73962659; 0.74335539; 0.67886585
115+
0.75982279; 0.75170702; 0.68690473
116+
0.78035831; 0.76142794; 0.69464266
117+
0.80084038; 0.77483463; 0.70222121
118+
0.82084703; 0.79118592; 0.7101205
119+
0.839975; 0.80961627; 0.71994179
120+
0.85786271; 0.82931268; 0.73339379
121+
0.87412214; 0.84939575; 0.75260991
122+
0.8892889; 0.868922; 0.77640855
123+
0.90383244; 0.88815367; 0.80381316
124+
0.9182685; 0.90738946; 0.83371073
125+
0.93308127; 0.92669237; 0.86525053
126+
0.94860053; 0.94612491; 0.89752066
127+
0.96475244; 0.96575582; 0.93025255
128+
0.98145217; 0.98550087; 0.96274126
129+
0.99860603; 1.0060949; 0.99405634
130+
1.0161384; 1.0261074; 1.0228131
131+
1.0339549; 1.0453422; 1.0496169
132+
1.0519547; 1.0635725; 1.0742604
133+
1.0703163; 1.0805377; 1.0964041
134+
1.0892165; 1.0960625; 1.1158583
135+
1.1088436; 1.1103494; 1.1323045
136+
1.1286206; 1.1236085; 1.145463
137+
1.1491616; 1.1361049; 1.1552131
138+
1.1711268; 1.1487024; 1.1615497
139+
1.1945977; 1.1622846; 1.1646422
140+
1.218582; 1.1768064; 1.1648315
141+
1.2430724; 1.1922448; 1.1645665
142+
1.2680446; 1.2085837; 1.1663285
143+
1.2934674; 1.2260224; 1.1699555
144+
1.3193187; 1.2448113; 1.1753913
145+
1.3455693; 1.2626257; 1.1831408
146+
1.3722063; 1.2790579; 1.1939249
147+
1.3991799; 1.2925897; 1.2086184
148+
1.4264627; 1.3036833; 1.2276043
149+
1.4540219; 1.3129274; 1.2487261
150+
1.4818317; 1.3208206; 1.2710675
151+
1.5098374; 1.327595; 1.293633
152+
1.5380114; 1.333542; 1.314491
153+
1.566313; 1.3388915; 1.333127
154+
1.5946969; 1.3439003; 1.3489835
155+
1.6231157; 1.3488177; 1.3616651
156+
1.6522359; 1.3538951; 1.3713053
157+
1.6816937; 1.359374; 1.3780791
158+
1.7111499; 1.3654904; 1.3845967
159+
1.7402135; 1.3724906; 1.3934025
160+
1.768482; 1.3806238; 1.4048418
161+
1.7962079; 1.3901138; 1.4198877
162+
1.8236461; 1.4017309; 1.439696
163+
1.8510005; 1.4174237; 1.4654926
164+
1.8785691; 1.4390672; 1.4953684
165+
1.9062947; 1.4688425; 1.5274891
166+
1.9341581; 1.5038412; 1.5620629
167+
1.9621236; 1.5408998; 1.5992228
168+
1.9901478; 1.5797547; 1.6392071
169+
2.0181818; 1.6201134; 1.6798421
170+
2.0462127; 1.6616611; 1.7188451
171+
2.0741763; 1.7040519; 1.7537067
172+
2.1030586; 1.7479676; 1.7830769
173+
2.1342936; 1.7935996; 1.8070787
174+
2.1694415; 1.8411915; 1.8259538
175+
2.2101707; 1.8886664; 1.8413572
176+
2.2580678; 1.9348837; 1.8550737
177+
2.3140199; 1.9788822; 1.8688371
178+
2.3790815; 2.0195994; 1.8851267
179+
2.4541366; 2.0560946; 1.9062871
180+
2.5405233; 2.0872638; 1.9323473
181+
2.6366429; 2.11198; 1.9633822
182+
2.7405005; 2.1316218; 1.9982532
183+
2.8500042; 2.1474531; 2.0359147
184+
2.9626627; 2.1607804; 2.0753171
185+
3.0757074; 2.1736951; 2.1157353
186+
3.1858821; 2.1861637; 2.1564054
187+
3.2895253; 2.1983471; 2.1964977
188+
3.3830886; 2.2104034; 2.2351975
189+
3.4623823; 2.2225049; 2.2716548
190+
3.5231643; 2.2348216; 2.3051777
191+
3.5674424; 2.2480111; 2.335144
192+
3.5970533; 2.2627511; 2.3611958
193+
3.6141043; 2.2797306; 2.3829494
194+
3.6211514; 2.3005326; 2.4002106
195+
3.6205578; 2.3281479; 2.4126313
196+
3.6147132; 2.3657403; 2.4199345
197+
3.6061006; 2.4108756; 2.4271879
198+
3.5970531; 2.4612732; 2.4328902
199+
3.589911; 2.5132818; 2.4396446
200+
3.5868025; 2.5630326; 2.4499555
201+
3.5872359; 2.6063156; 2.4653387
202+
3.5907016; 2.6371846; 2.4850256
203+
3.5966294; 2.6603441; 2.5081179
204+
3.6043668; 2.6777611; 2.5325418
205+
3.613236; 2.6914861; 2.5561678
206+
3.6225328; 2.7036824; 2.5802944
207+
3.6315649; 2.7164392; 2.6062336
208+
3.6397135; 2.7319281; 2.6353457
209+
3.6463161; 2.7521806; 2.6689532
210+
3.6507142; 2.7794316; 2.7054877
211+
3.6522264; 2.8160179; 2.7432706
212+
3.6515446; 2.8641613; 2.7805786
213+
3.6491809; 2.9266038; 2.8165269
214+
3.6457596; 2.9959128; 2.8501496
215+
3.6418676; 3.0707374; 2.8816233
216+
3.6380084; 3.1496816; 2.9124076
217+
3.6347945; 3.2312739; 2.9440465
218+
3.6327286; 3.3153543; 2.9780848
219+
3.632345; 3.4019151; 3.0165203
220+
3.6341732; 3.4908454; 3.0614984
221+
3.638721; 3.58199; 3.1150503
222+
3.6464689; 3.6752813; 3.1826136
223+
3.6577027; 3.7705483; 3.2603936
224+
3.6725714; 3.8676968; 3.3441794
225+
3.6913502; 3.9665241; 3.429599
226+
3.7142625; 4.0668344; 3.5127351
227+
3.7415745; 4.1684489; 3.5924125
228+
3.7735393; 4.2711701; 3.6672175
229+
3.8105009; 4.3747692; 3.7356856
230+
3.8527117; 4.4790072; 3.7968595
231+
3.9005468; 4.5835958; 3.8496428
232+
3.9544387; 4.6882434; 3.8928525
233+
4.0146904; 4.7927446; 3.9248433
234+
4.0817723; 4.8967395; 3.9513063
235+
4.156261; 4.9959707; 3.9776495
236+
4.2385316; 5.0862246; 4.0083594
237+
4.3292894; 5.1628013; 4.0453262
238+
4.4292712; 5.208868; 4.090549
239+
4.5391016; 5.2085571; 4.1504045
240+
4.6590405; 5.1931009; 4.2231388
241+
4.7892585; 5.1713238; 4.3068471
242+
4.9298091; 5.1520205; 4.3986373
243+
5.080884; 5.1435499; 4.495626
244+
5.2427516; 5.1544037; 4.5946674
245+
5.4155412; 5.1925159; 4.6923766
246+
5.5994644; 5.2670083; 4.7851367
247+
5.7947478; 5.3840528; 4.8690419
248+
6.0014763; 5.550056; 4.9403625
249+
6.2198949; 5.7741976; 5.0185084
250+
6.4501748; 6.0682302; 5.1226621
251+
6.6923175; 6.4454927; 5.2754979
252+
6.946454; 6.9251842; 5.5180821
253+
7.2126765; 7.532608; 5.8734803
254+
7.491024; 8.2988958; 6.3710842
255+
7.7813053; 9.2470798; 7.0532293
256+
8.083519; 10.405034; 7.9306288

‎opencv-hdr/source.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <opencv2/photo.hpp>
2+
#include <opencv2/imgcodecs.hpp>
3+
#include <opencv2/highgui.hpp>
4+
#include <vector>
5+
#include <iostream>
6+
#include <fstream>
7+
8+
using namespace cv;
9+
using namespace std;
10+
11+
void loadExposureSeq(String, vector<Mat>&, vector<float>&);
12+
13+
int main(int, char**argv)
14+
{
15+
vector<Mat> images;
16+
vector<float> times;
17+
18+
loadExposureSeq("data/exposures", images, times);
19+
20+
//--------------- Image HDR -----------------------//
21+
22+
Mat response;
23+
Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
24+
calibrate->process(images, response, times);
25+
26+
Mat hdr;
27+
Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
28+
merge_debevec->process(images, hdr, times, response);
29+
30+
imwrite("memorial-hdr.hdr", hdr);
31+
32+
//--------------- Tone Mapping -----------------------//
33+
34+
Mat ldr;
35+
Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);
36+
tonemap->process(hdr, ldr);
37+
38+
imwrite("memorial-ldr.png", ldr * 255);
39+
40+
//--------------- Exposure fusion -----------------------//
41+
42+
Mat fusion;
43+
Ptr<MergeMertens> merge_mertens = createMergeMertens();
44+
merge_mertens->process(images, fusion);
45+
46+
imshow("fusion", fusion);
47+
imwrite("fusion-ldr.png", fusion * 255);
48+
49+
cout << "HDR creado correctamente." << endl;
50+
cout << "Presione una tecla para continuar..." << endl;
51+
52+
waitKey();
53+
54+
return 0;
55+
}
56+
57+
void loadExposureSeq(String path, vector<Mat>& images, vector<float>& times)
58+
{
59+
path = path + std::string("/");
60+
ifstream list_file((path + "list.txt").c_str());
61+
string name;
62+
float val;
63+
while (list_file >> name >> val) {
64+
Mat img = imread(path + name);
65+
images.push_back(img);
66+
times.push_back(1 / val);
67+
}
68+
list_file.close();
69+
}

0 commit comments

Comments
 (0)
Please sign in to comment.