-
Notifications
You must be signed in to change notification settings - Fork 2
/
Li_LDR.m
executable file
·168 lines (128 loc) · 3.72 KB
/
Li_LDR.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
% Uses mid-level LDR image.
clc;
addpath(genpath('./scripts/'));
addpath(genpath('./GraphCut/'));
addpath(genpath('./HDRimaging/'));
set_cell{1,1}='SetA';
set_cell{2,1}='SetB';
set_cell{3,1}='SetC';
set_cell{4,1}='SetD';
set_cell{5,1}='SetE';
set_cell{6,1}='SetF';
set_cell{7,1}='SetG';
set_cell{8,1}='SetH';
set_cell{9,1}='SetI';
set_cell{10,1}='SetJ';
set_cell{11,1}='SetK';
set_cell{12,1}='SetL';
set_cell{13,1}='SetM';
set_cell{14,1}='SetN';
set_cell{15,1}='SetO';
set_cell{16,1}='SetP';
set_cell{17,1}='SetQ';
set_cell{18,1}='SetR';
set_cell{19,1}='SetS';
set_cell{20,1}='SetT';
set_cell{21,1}='SetU';
set_cell{22,1}='SetV';
set_cell{23,1}='SetW';
set_cell{24,1}='SetX';
set_cell{25,1}='SetY';
set_cell{26,1}='SetZ';
set_cell{27,1}='SetZA';
set_cell{28,1}='SetZB';
set_cell{29,1}='SetZC';
set_cell{30,1}='SetZD';
set_cell{31,1}='SetZE';
set_cell{32,1}='SetZF';
set_cell{33,1}='SetZG';
set_cell{34,1}='SetZH';
set_cell{35,1}='SetZI';
set_cell{36,1}='SetZJ';
set_cell{37,1}='SetZK';
set_cell{38,1}='SetZL';
set_cell{39,1}='SetZM';
set_cell{40,1}='SetZN';
set_cell{41,1}='SetZO';
set_cell{42,1}='SetZP';
set_cell{43,1}='SetZQ';
set_cell{44,1}='SetZR';
set_cell{45,1}='SetZS';
set_cell{46,1}='SetZT';
set_cell{47,1}='SetZU';
set_cell{48,1}='SetZV';
set_cell{49,1}='SetZW';
set_cell{50,1}='SetZX';
set_cell{51,1}='SetZY';
set_cell{52,1}='SetZZ';
set_numbers=1:52;
% Text file where data is to be written
fileID = fopen('./results/Li-LDR.txt','a');
fprintf(fileID,'HDRSet \t Precision \t Recall \t FScore \t Error \n');
Precision_arr=[];
Recall_arr=[];
FScore_arr=[];
Error_arr=[];
affected_arr=[];
CROP_DIM = 350 ;
for kot=set_numbers
disp (kot);
disp(set_cell{kot,1});
% Creating HDR
dirName=(['./HDRSEG/',set_cell{kot,1},'/cropped/']);
% Extracting the files
[filenames, exposures, numExposures] = readDir(dirName);
% 3 = Low; 2 = Mid; 1 = High
m_image = filenames(2);
I = imread(m_image{1}) ;
% Change the image size
rect = [(250-CROP_DIM/2) (250-CROP_DIM/2) CROP_DIM-1 CROP_DIM-1];
I_crop = I;
[satMap,~] = maskSaturatedLDR(I_crop,250);
satMap_crop = imcrop(satMap,rect);
percentagePixelsAffected = (length(find(satMap_crop(:)==1))/(length(satMap_crop(:))))*100;
affected_arr=cat(1,affected_arr,percentagePixelsAffected);
I2=rgb2gray(I_crop);
[rows,cols]=size(I2);
[BRImage] = BRImage_func(I_crop);
StBRArray=double(reshape(BRImage,1,(rows*cols)));
StandardDev=std(StBRArray);
Ts=0.03;
if StandardDev>Ts
% MCE
disp ('MCE Method');
ThresholdValue=MCE_func(BRImage);
else
% Fixed threshold
disp ('Fixed threshold Method');
ThresholdValue=0.25;
end
% Thresholding the input image
ThImage=zeros(rows,cols);
for i=1:rows
for j=1:cols
if BRImage(i,j)<ThresholdValue
ThImage(i,j)=1;
end
end
end
% Score calculation
ThreshImage=ThImage;
ThreshImage_crop = imcrop(ThreshImage,rect);
I_GT=double(imread(['./HDRSEG/',set_cell{kot,1},'/GT/GT.png']));
I_GT_crop = imcrop(I_GT,rect);
[Precision,Recall,FScore,Error,~,~] = error_withSat_s_c(ThreshImage_crop,I_GT_crop,satMap_crop)
fprintf(fileID,'%d \t %f \t %f \t %f \t %f \n',kot,Precision,Recall,FScore, Error);
Precision_arr=cat(1,Precision_arr,Precision);
Recall_arr=cat(1,Recall_arr,Recall);
FScore_arr=cat(1,FScore_arr,FScore);
Error_arr = cat(1,Error_arr,Error);
close all;
end
fclose(fileID);
disp ('Testing done');
Precision=nanmean(Precision_arr)
Recall=nanmean(Recall_arr)
FScore=nanmean(FScore_arr)
Error = nanmean(Error_arr)
pixelsAffected = nanmean(affected_arr)