Exemplo n.º 1
0
 def test_save_function_saves_image_in_a_default_destination(self):
     self.pm.get_args = Mock(
         return_value=Mock(output=None, log=None, config="test_config"))
     default_path = self.pm.get_out_file_path()
     self.assertFalse(isfile(default_path))
     self.pm.save_focused_image(Image(np.zeros((3, 3), dtype=np.uint8)))
     self.assertTrue(isfile(default_path))
Exemplo n.º 2
0
    def create_overlay_image(image1, image2, offset, rect_color=Color.black()):
        """ For the two images, A and B, where the position of B is offset from that of A, overlay
        image B onto image A at the appropriate position. The overlaid area will ve a blending of the
        two images. A rectangle will be drawn around the area.
        """
        # Make a copy of A, the background image
        background = image1.copy()

        # Get overlapping regions of images
        overlap_a, overlap_b = Overlayer.get_overlap_regions(
            image1, image2, offset)
        if overlap_a is None or overlap_b is None:
            return background

        # Blend the two overlapping regions
        perc_a, perc_b = 0.5, 0.5
        blended = cv2.addWeighted(overlap_a.raw(), perc_a, overlap_b.raw(),
                                  perc_b, 0)
        background.paste(Image(blended),
                         Point(max(offset.x, 0), max(offset.y, 0)))
        background = background.to_channels(3)

        # Define the rectangle that will be pasted to the background image
        w, h = image2.size()
        rect = Rectangle.from_corner(offset, w, h)
        background.draw_rectangle(rect, color=rect_color)

        return background
Exemplo n.º 3
0
    def get_focused_image(self):
        focusing_path = abspath(self.get_args().beamline_stack_path)
        if "." not in focusing_path:
            files = self._sort_files_according_to_names(focusing_path)
            # Run focusstack
            stacker = FocusStack(files, self.get_args().config)
            focused_image = stacker.composite()

            self.images_to_stack = stacker.get_fft_images_to_stack()
        else:
            focused_image = Image(cv2.imread(focusing_path))
        return focused_image
    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)
Exemplo n.º 5
0
 def draw_keypoints(image, keypoints):
     """ Draw the list of keypoints to the specified image and display it as a popup window. """
     marked_image = cv2.drawKeypoints(image.raw(), keypoints, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
     return Image(marked_image)
Exemplo n.º 6
0
 def inverse_transform_image(self, image, output_size):
     warped = cv2.warpPerspective(image.raw(), self._homography_inverse, output_size)
     warped = Image(warped)
     return warped
Exemplo n.º 7
0
 def crop_region_from_image(self):
     region = Rectangle.from_center(self.point, self.region_size,
                                    self.region_size)
     img = Image(self.img).crop(region)
     return img.raw()