def test_works_correctly_when_max_minus_half_smaller_than_number_of_images(self): max = 3 number_to_stuck = 12 self._config.number_to_stack.value = MagicMock(return_value=number_to_stuck) sd = SharpnessDetector(self._fft_images, self._config) rng = sd.find_range(max) self.assertEqual(len(rng), number_to_stuck) self.assertEqual(rng[0], 0) self.assertEqual(rng[number_to_stuck-1],number_to_stuck-1)
def test_works_correctly_when_to_stack_equals_number_of_images(self): max = 6 number_to_stuck = 20 self._config.number_to_stack.value = MagicMock(return_value=number_to_stuck) sd = SharpnessDetector(self._fft_images, self._config) rng = sd.find_range(max) self.assertEqual(len(rng), self._fft_images.__len__.return_value) self.assertEqual(rng[0], 0) self.assertEqual(rng[self._fft_images.__len__.return_value-1], self._fft_images.__len__.return_value-1)
def test_works_correctly_when_max_minus_half_equals_zero(self): max = 6 number_to_stuck = 12 self._config.number_to_stack.value = MagicMock(return_value=number_to_stuck) sd = SharpnessDetector(self._fft_images, self._config) rng = sd.find_range(max) half = number_to_stuck/2 self.assertEqual(len(rng), number_to_stuck) self.assertEqual(rng[0], max - half) self.assertEqual(rng[number_to_stuck-1], max+half-1)
def test_returns_correct_when_even_number_passed(self): max = 10 number_to_stuck = 12 self._config.number_to_stack.value = MagicMock(return_value = number_to_stuck) sd = SharpnessDetector(self._fft_images, self._config) rng = sd.find_range(max) self.assertEqual(len(rng), number_to_stuck) half = number_to_stuck/2 self.assertEqual(rng[0], max-half) self.assertEqual(rng[number_to_stuck-1], max+half-1)
def test_returns_one_less_for_number_to_stack_when_uneven(self): max = 10 number_to_stuck = 11 self._config.number_to_stack.value = MagicMock(return_value=number_to_stuck) sd = SharpnessDetector(self._fft_images, self._config) rng = sd.find_range(max) half = 6 self.assertEqual(len(rng), number_to_stuck+1) # one more self.assertEqual(rng[0], max-half) self.assertEqual(rng[number_to_stuck], max+half-1)
def test_image_stack_method_returns_list_of_images_within_a_range(self): fft_image = MagicMock() fft_image.getFFT.return_value = 10 fft_image.get_image_number.return_value = 0 fft_image.get_image.return_value = 100 self._config.number_to_stack.value.return_value = 1 self._fft_images = [fft_image] sd = SharpnessDetector(self._fft_images, self._config) images = sd.images_to_stack() self.assertEqual(images[0],100)
def composite(self): log = logging.getLogger(".".join([__name__, self.__class__.__name__])) log.addFilter(logconfig.ThreadContextFilter()) extra = self._config.all_to_json() log = logging.LoggerAdapter(log, extra) log.info("Focusstack Started, first image, " + self._image_file_list[0].name) log.debug(extra) start_t = time.time() t1 = time.time() man = ImageFFTManager(self._image_file_list) man.read_ftt_images() sd = SharpnessDetector(man.get_fft_images(), self._config) images = sd.images_to_stack() self.fft_images = sd.get_fft_images_to_stack() t2 = time.time() - t1 #add extra field to the log extra = {'FTT_time': t2} log = logging.LoggerAdapter(log, extra) log.info("FFT calculation finished") log.debug(extra) images = np.array(images, dtype=images[0].dtype) #TODO:Implement alignment algo #aligned_images, gray_images = self.align(images) #stacked_image = pyramid(aligned_images, self._config).get_pyramid_fusion() stacked_image = PyramidManager(images, self._config).get_pyramid_fusion() stacked_image = cv2.convertScaleAbs(stacked_image) backtorgb = cv2.cvtColor(stacked_image, cv2.COLOR_GRAY2RGB) calculation_time = time.time() - start_t extra = {'stack_time': calculation_time} log = logging.LoggerAdapter(log, extra) log.info("Stacking Finished") log.debug(extra) return Image(backtorgb)