|
| 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