Skip to content

Commit 0f03544

Browse files
committed
Average of N integer images was overflowing data type
Fix #86
1 parent 6ed8f31 commit 0f03544

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See DataLab [roadmap page](https://datalab-platform.com/en/contributing/roadmap.
1313
* This issue is related to [Issue #84](https://github.com/DataLab-Platform/DataLab/issues/84)
1414
* Adding the test data paths multiple times to `cdl.utils.tests.TST_PATH` was causing the test data to be loaded multiple times, which lead to some tests failing (a simple workaround was added to V0.16.2: this issue is now fixed)
1515
* Thanks again to [@rolandmas](https://github.com/rolandmas) for reporting the issue in the context of the Debian packaging
16+
* Fixed [Issue #86](https://github.com/DataLab-Platform/DataLab/issues/86) - Average of N integer images overflows data type
1617

1718
## DataLab Version 0.16.2 ##
1819

cdl/core/gui/processor/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,10 @@ def compute_n1(
584584
dst_gid = None
585585

586586
for src_gid, dst_obj in dst_objs.items():
587-
if is_integer_dtype(src_dtypes[src_gid]):
588-
dst_obj.set_data_type(dtype=src_dtypes[src_gid])
589587
if func_objs is not None:
590588
func_objs(dst_obj, src_objs[src_gid])
589+
if is_integer_dtype(src_dtypes[src_gid]):
590+
dst_obj.set_data_type(dtype=src_dtypes[src_gid])
591591
short_ids = [obj.short_id for obj in src_objs[src_gid]]
592592
dst_obj.title = f'{name}({", ".join(short_ids)})'
593593
group_id = dst_gid if dst_gid is not None else src_gid
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file.
2+
3+
"""
4+
Average application test
5+
========================
6+
7+
The purpose of this test is to check that we can average a set of images without
8+
overflowing the data type.
9+
10+
This test was written following a regression where the average of 10 images of
11+
size 256x256 with a Gaussian distribution of values was overflowing the data type
12+
uint8.
13+
"""
14+
15+
# pylint: disable=invalid-name # Allows short reference names like x, y, ...
16+
# pylint: disable=duplicate-code
17+
# guitest: show
18+
19+
import numpy as np
20+
21+
import cdl.obj
22+
import cdl.tests.data as ctd
23+
from cdl.tests import cdltest_app_context
24+
from cdl.utils.tests import check_array_result
25+
26+
27+
def test_image_average():
28+
"""Average application test."""
29+
with cdltest_app_context() as win:
30+
panel = win.imagepanel
31+
N, size = 10, 256
32+
dtype = cdl.obj.ImageDatatypes.UINT8
33+
p = cdl.obj.NewImageParam.create(height=size, width=size, dtype=dtype)
34+
data = ctd.create_2d_gaussian(size, np.dtype(dtype.value))
35+
for _idx in range(N):
36+
obj = cdl.obj.create_image_from_param(p)
37+
obj.data = data
38+
panel.add_object(obj)
39+
panel.objview.select_groups([0])
40+
panel.processor.compute_average()
41+
res_data = panel.objview.get_sel_objects(include_groups=True)[0].data
42+
check_array_result("Average", res_data, data)
43+
44+
45+
if __name__ == "__main__":
46+
test_image_average()

0 commit comments

Comments
 (0)