Skip to content

Commit 144e5de

Browse files
committed
Bug fix in deep image compare when pixels had different # of samples
The IBA::compare for deep images A and B would loop over pixels in the union of A's and B's ROIs (so far, so good), then for each pixel would loop from 0 to A's number of samples in that pixel. Oops! That means that if A had fewer samples than B (or if A had no samples but B had samples) in that pixel, it would not notice that the images were different.
1 parent 02df886 commit 144e5de

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/libOpenImageIO/imagebufalgo_compare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ compare_(const ImageBuf& A, const ImageBuf& B, float failthresh,
297297
if (deep) {
298298
for (int i = 0; i < batchsize && !a.done(); ++i, ++a, ++b) {
299299
bool warned = false, failed = false; // For this pixel
300+
auto nsamps = std::max(a.deep_samples(), b.deep_samples());
300301
for (int c = roi.chbegin; c < roi.chend; ++c)
301-
for (int s = 0, e = a.deep_samples(); s < e; ++s) {
302+
for (int s = 0, e = nsamps; s < e; ++s) {
302303
compare_value(a, c, a.deep_value(c, s),
303304
b.deep_value(c, s), result, maxval,
304305
batcherror, batch_sqrerror, failed,

testsuite/oiiotool-deep/ref/out.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
Computing diff of "src/deep-nosamples.exr" vs "src/deep-onesample.exr"
2+
Mean error = 42
3+
RMS error = 42
4+
Peak SNR = 0
5+
Max error = 42 @ (0, 0, Z)
6+
1 pixels (100%) over 1e-06
7+
0 pixels (0%) over 100
8+
WARNING
9+
Computing diff of "src/deep-onesample.exr" vs "src/deep-nosamples.exr"
10+
Mean error = 42
11+
RMS error = 42
12+
Peak SNR = 0
13+
Max error = 42 @ (0, 0, Z)
14+
1 pixels (100%) over 1e-06
15+
0 pixels (0%) over 100
16+
WARNING
117
Comparing "flat.exr" and "ref/flat.exr"
218
PASS
319
Comparing "ch.exr" and "ref/ch.exr"

testsuite/oiiotool-deep/run.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
# --resample
4141
command += oiiotool (exrdir+"/Balls.exr -resample 128x72 -o resampled-balls.exr")
4242

43+
44+
45+
# Regression test: it used to be that comparing deep image, it would loop
46+
# only over A's samples, so if A had no samples in a pixel but B had
47+
# samples, then the comparison would fail to see a difference. Be sure to
48+
# test both orderings.
49+
# Compare with both orderings
50+
command += oiiotool ("--fail 100 src/deep-nosamples.exr src/deep-onesample.exr --diff")
51+
command += oiiotool ("--fail 100 src/deep-onesample.exr src/deep-nosamples.exr --diff")
52+
# Recipe for creating the files:
53+
# spec = oiio.ImageSpec (1, 1, 1, oiio.TypeDesc.TypeFloat)
54+
# spec.channelnames = ("Z")
55+
# spec.deep = True
56+
# buf = oiio.ImageBuf (spec)
57+
# buf.write ("src/deep-nosamples.exr") # write a deep image with no samples
58+
# buf.set_deep_samples (0, 0, 0, 1)
59+
# buf.set_deep_value (0, 0, 0, 0, 0, 42.0)
60+
# buf.write ("src/deep-onesample.exr") # write another deep image with 1 sample
61+
62+
4363
# To add more tests, just append more lines like the above and also add
4464
# the new 'feature.tif' (or whatever you call it) to the outputs list,
4565
# below.
426 Bytes
Binary file not shown.
430 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)