-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadapt_display_hdrvqm.m
executable file
·83 lines (68 loc) · 2.74 KB
/
adapt_display_hdrvqm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function flag = adapt_display_hdrvqm(path_native,path_adapted,cfg_hdrvqm)
%%% Variables
Param.Display_Max_Value_HDR = 20;
Param.Display_Max_Value_EXR = 4500;
Param.Display_Max_Value = Param.Display_Max_Value_HDR;
Param.Perc_Max = 0.95;
Param.final_x = 1920;
Param.final_y = 1080;
%%% List the images
Images_List_HDR = dir([path_native '*.hdr']);
Images_List_EXR = dir([path_native '*.exr']);
Images_List = [Images_List_HDR;Images_List_EXR];
for index = 1:length(Images_List)
Image_Name{index} = Images_List(index).name;
end
switch cfg_hdrvqm.do_adapt
case ('none')
flag = 1;
case('linear')
%%% Find the max value of the current sequence
Max_Current_Video = 0;
% Min_Current_Video = 1000;
%fprintf('Find the max of the sequence\n');
h = waitbar(0,'Computing scaling factor...');
for index_image = 1:length(Image_Name)
%fprintf('Check the image %s\n',Image_Name{index_image});
if(strcmp(Image_Name{index_image}(end-3:end),'.hdr'))
current_image = hdrimread([path_native Image_Name{index_image}]);
else
current_image = exrread([path_native Image_Name{index_image}]);
end
current_image_resized = current_image;
current_image_resized(current_image_resized<0) = 0;
data_in_order = sort(current_image_resized(:));
current_max = mean(data_in_order(floor(length(data_in_order)*Param.Perc_Max):end));
if(current_max > Max_Current_Video)
Max_Current_Video = current_max;
end
waitbar(index_image/length(Image_Name),h)
end
close all force
h = waitbar(0,'Scaling the frames and writing in dest. folder...');
for index_image = 1:length(Image_Name)
%%% Read image
%fprintf('Load the image %s\n',Image_Name{index_image});
if(strcmp(Image_Name{index_image}(end-3:end),'.hdr'))
current_image = hdrimread([path_native Image_Name{index_image}]);
Param.Display_Max_Value = Param.Display_Max_Value_HDR;
else
current_image = exrread([path_native Image_Name{index_image}]);
Param.Display_Max_Value = Param.Display_Max_Value_EXR;
end
%%% Adjust the luminance to use the dynamic of the Sim2 display
current_image_resized = current_image;
current_image_resized(current_image_resized<0) = 0;
current_image_resized_adjusted = (current_image_resized*Param.Display_Max_Value/Max_Current_Video); %Max);
if(strcmp(Image_Name{index_image}(end-3:end),'.hdr'))
hdrimwrite(current_image_resized_adjusted,[path_adapted Image_Name{index_image}]);
else
exrwrite(current_image_resized_adjusted,[path_adapted Image_Name{index_image}]);
end
waitbar(index_image/length(Image_Name),h)
end
otherwise
error('Invalid selection of display processing')
end
close all force
end