diff --git a/tests/improc_tests.py b/tests/improc_tests.py index 7680db2..df31a47 100644 --- a/tests/improc_tests.py +++ b/tests/improc_tests.py @@ -6,7 +6,7 @@ import unittest # unittest2 doesn't exist in fiji import sys -from lipase.imageengine import IImageEngine, PixelType, Aabb, NullDebugger, FileBasedDebugger +from lipase.imageengine import IImageEngine, PixelType, Aabb, NullDebugger, FileBasedDebugger, StackImageFeeder from lipase.imagej.ijimageengine import IJImageEngine, IJImage from lipase.circsymdetector import create_circle_image @@ -41,7 +41,22 @@ class ImProcTester(unittest.TestCase): print("measured_mean_value: %f" % measured_mean_value) self.assertAlmostEqual(measured_mean_value, expected_mean_value, delta=0.01) - + def test_stack_mean(self): + ie = IImageEngine.get_instance() + num_channels = 4 + width = 16 + height = 16 + offset_value = 42.0 + stack = ie.create_hyperstack(width=width, height=height, num_channels=num_channels, num_slices=1, num_frames=1, pixel_type=PixelType.F32) + for channel_index in range(num_channels): + im = ie.create_image(width=width, height=height, pixel_type=PixelType.F32) + im.set_pixel(x=3, y=4, value=channel_index + offset_value) + stack.set_image(im, channel_index=channel_index) + mean_image = ie.compute_mean(StackImageFeeder(stack)) + measured_avg = mean_image.get_mean_value() + sum_of_numbers = num_channels*(num_channels-1)/2 # sum of numbers from 0 to n = n * (n-1) / 2 + expected_avg = (offset_value + float(sum_of_numbers)/num_channels)/(width*height) + self.assertAlmostEqual(measured_avg, expected_avg, delta=0.0001) def run_script(): print("executing run_script")