added test test_stack_mean which was used to find bug in IJHyperstack.get_image

This commit is contained in:
Guillaume Raffy 2020-04-08 12:47:09 +02:00
parent c42972736f
commit 5a144f1907
1 changed files with 17 additions and 2 deletions

View File

@ -6,7 +6,7 @@
import unittest # unittest2 doesn't exist in fiji import unittest # unittest2 doesn't exist in fiji
import sys 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.imagej.ijimageengine import IJImageEngine, IJImage
from lipase.circsymdetector import create_circle_image from lipase.circsymdetector import create_circle_image
@ -41,7 +41,22 @@ class ImProcTester(unittest.TestCase):
print("measured_mean_value: %f" % measured_mean_value) print("measured_mean_value: %f" % measured_mean_value)
self.assertAlmostEqual(measured_mean_value, expected_mean_value, delta=0.01) 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(): def run_script():
print("executing run_script") print("executing run_script")