def test_image_background(self): pipeline_parameters = { "camera_name": "simulation", "image_background": "white_background" } simulated_camera = CameraSimulation(CameraConfig("simulation")) image = simulated_camera.get_image() x_axis, y_axis = simulated_camera.get_x_y_axis() background_provider = MockBackgroundManager() x_size, y_size = simulated_camera.get_geometry() background_provider.save_background("white_background", numpy.zeros(shape=(y_size, x_size)), append_timestamp=False) pipeline_config = PipelineConfig("test_pipeline", pipeline_parameters) parameters = pipeline_config.get_configuration() image_background_array = background_provider.get_background(parameters.get("image_background")) result = process_image(image=image, timestamp=time.time(), x_axis=x_axis, y_axis=y_axis, parameters=parameters, image_background_array=image_background_array) self.assertTrue(numpy.array_equal(result["image"], image), "A zero background should not change the image.") max_value_in_image = result["max_value"] pipeline_parameters = { "camera_name": "simulation", "image_background": "max_background", "image_threshold": 0 } max_background = numpy.zeros(shape=(y_size, x_size), dtype="uint16") max_background.fill(max_value_in_image) background_provider.save_background("max_background", max_background, append_timestamp=False) pipeline_config = PipelineConfig("test_pipeline", pipeline_parameters) parameters = pipeline_config.get_configuration() image_background_array = background_provider.get_background(parameters.get("image_background")) expected_image = numpy.zeros(shape=(y_size, x_size)) result = process_image(image=image, timestamp=time.time(), x_axis=x_axis, y_axis=y_axis, parameters=parameters, image_background_array=image_background_array) self.assertTrue(numpy.array_equal(result["image"], expected_image), "The image should be all zeros - negative numbers are not allowed.")
def test_wrong_background_size(self): pipeline_parameters = { "camera_name": "simulation", "image_background": "white_background" } simulated_camera = CameraSimulation(CameraConfig("simulation")) image = simulated_camera.get_image() x_axis, y_axis = simulated_camera.get_x_y_axis() background_provider = MockBackgroundManager() # Invalid background size. background_provider.save_background("white_background", numpy.zeros(shape=(100, 100)), append_timestamp=False) parameters = PipelineConfig("test_pipeline", pipeline_parameters).get_configuration() image_background_array = background_provider.get_background("white_background") with self.assertRaisesRegex(RuntimeError, "Invalid background_image size "): process_image(image=image, timestamp=time.time(), x_axis=x_axis, y_axis=y_axis, parameters=parameters, image_background_array=image_background_array)