Skip to content

Commit e59e603

Browse files
committed
Remove MSE computation for UINT samples
Improve the handling of non-finite samples Signed-off-by: Pierre-Anthony Lemieux <pal@palemieux.com>
1 parent cae54f0 commit e59e603

5 files changed

Lines changed: 16 additions & 65 deletions

File tree

src/bin/exrmetrics/exrmetrics.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,7 @@ exrmetrics (
12211221
i != outHeaders[p].channels ().end ();
12221222
++i, ++channelIndex)
12231223
{
1224-
if (i.channel ().type != HALF && i.channel ().type != FLOAT &&
1225-
i.channel ().type != UINT)
1224+
if (i.channel ().type != HALF && i.channel ().type != FLOAT)
12261225
continue;
12271226

12281227
uint64_t pixelsInChannel =
@@ -1270,16 +1269,6 @@ exrmetrics (
12701269
sumSq,
12711270
count);
12721271
}
1273-
else
1274-
{
1275-
metrics.stats[p].mseKind = MSE_LOG_INT;
1276-
accumMSE (
1277-
reinterpret_cast<const unsigned int*> (origData),
1278-
reinterpret_cast<const unsigned int*> (rereadData),
1279-
pixelsInChannel,
1280-
sumSq,
1281-
count);
1282-
}
12831272
}
12841273

12851274
metrics.stats[p].mseCount = count;

src/bin/exrmetrics/exrmetrics.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ enum MSEKind
4949
MSE_NONE,
5050
MSE_LOG_HALF,
5151
MSE_LOG_FLOAT,
52-
MSE_LOG_INT
5352
};
5453

5554
struct partStats

src/bin/exrmetrics/main.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ usageMessage (ostream& stream, const char* program_name, bool verbose = false)
9292
" --csv print output in csv mode. If passes>1, show median timing\n"
9393
" default is JSON mode\n"
9494
" --passes num write and re-read file num times (default 1)\n"
95-
" --mse compute MSE per part, comparing original vs. re-read after compression.\n"
96-
" Parts must have uniform channel types. Half and float channels use\n"
97-
" signed log-space MSE (reported as \"log_mse\"), skipping non-finite\n"
98-
" original samples; non-finite re-read samples produce NaN. Uint\n"
99-
" channels use linear MSE (reported as \"mse\").\n"
95+
" --mse compute LogMSE per part, comparing original vs. re-read after compression.\n"
96+
" Parts must have uniform half or float channel types. Samples that are non-finite\n"
97+
" in the original are skipped. Samples that are finite in the original and not finite\n"
98+
" in the re-read result in Nan."
10099
"\n"
101100
" -h, --help print this message\n"
102101
" -v output progress messages\n"
@@ -406,11 +405,7 @@ jsonStats (
406405
if (computeMSE)
407406
{
408407
out << ",\n";
409-
const char* mseKey =
410-
run.metrics.stats[part].mseKind != MSE_LOG_INT
411-
? "log_mse"
412-
: "mse";
413-
out << " \"" << mseKey
408+
out << " \"" << "log_mse"
414409
<< "\": " << run.metrics.stats[part].mse;
415410
}
416411
if (timing)
@@ -497,9 +492,6 @@ csvStats (ostream& out, list<runData>& data, bool outputSizeData, int timing, bo
497492
{
498493
if (p > 0) { out << '|'; }
499494
switch (run.metrics.stats[p].mseKind) {
500-
case MSE_LOG_INT:
501-
out << "mse:" << run.metrics.stats[p].mse;
502-
break;
503495
case MSE_LOG_HALF:
504496
case MSE_LOG_FLOAT:
505497
out << "log_mse:" << run.metrics.stats[p].mse;

src/bin/exrmetrics/mseutils.cpp

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ accumMSE<half> (
2222
{
2323
double a = static_cast<double> (orig[px]);
2424
double b = static_cast<double> (reread[px]);
25+
if (!std::isfinite (a)) { continue; }
2526
if (!std::isfinite (b)) { count = 0; sumSq = 0.0; return; }
26-
if (std::isfinite (a))
27-
{
28-
double diff = (a < 0 ? -1.0 : 1.0) * (std::log (std::abs (a) + HALF_DENORM_MIN) - LN_HALF_DENORM_MIN) -
29-
(b < 0 ? -1.0 : 1.0) * (std::log (std::abs (b) + HALF_DENORM_MIN) - LN_HALF_DENORM_MIN);
30-
sumSq += diff * diff;
31-
++count;
32-
}
33-
}
27+
28+
double diff = (a < 0 ? -1.0 : 1.0) * (std::log (std::abs (a) + HALF_DENORM_MIN) - LN_HALF_DENORM_MIN) -
29+
(b < 0 ? -1.0 : 1.0) * (std::log (std::abs (b) + HALF_DENORM_MIN) - LN_HALF_DENORM_MIN);
30+
sumSq += diff * diff;
31+
++count;
32+
}
3433
}
3534

3635
template <>
@@ -48,30 +47,10 @@ accumMSE<float> (
4847
{
4948
double a = static_cast<double> (orig[px]);
5049
double b = static_cast<double> (reread[px]);
50+
if (!std::isfinite (a)) { continue; }
5151
if (!std::isfinite (b)) { count = 0; sumSq = 0.0; return; }
52-
if (std::isfinite (a))
53-
{
54-
double diff = (a < 0 ? -1.0 : 1.0) * (std::log (std::abs (a) + eps) - ln_eps) -
55-
(b < 0 ? -1.0 : 1.0) * (std::log (std::abs (b) + eps) - ln_eps);
56-
sumSq += diff * diff;
57-
++count;
58-
}
59-
}
60-
}
61-
62-
template <>
63-
void
64-
accumMSE<unsigned int> (
65-
const unsigned int* orig,
66-
const unsigned int* reread,
67-
uint64_t pixelsInChannel,
68-
double& sumSq,
69-
uint64_t& count)
70-
{
71-
for (uint64_t px = 0; px < pixelsInChannel; ++px)
72-
{
73-
double diff =
74-
static_cast<double> (orig[px]) - static_cast<double> (reread[px]);
52+
double diff = (a < 0 ? -1.0 : 1.0) * (std::log (std::abs (a) + eps) - ln_eps) -
53+
(b < 0 ? -1.0 : 1.0) * (std::log (std::abs (b) + eps) - ln_eps);
7554
sumSq += diff * diff;
7655
++count;
7756
}

src/bin/exrmetrics/mseutils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,4 @@ void accumMSE<float> (
3131
double& sumSq,
3232
uint64_t& count);
3333

34-
template <>
35-
void accumMSE<unsigned int> (
36-
const unsigned int* orig,
37-
const unsigned int* reread,
38-
uint64_t pixelsInChannel,
39-
double& sumSq,
40-
uint64_t& count);
41-
4234
#endif

0 commit comments

Comments
 (0)