def _crop_images_in_ram(self, filenames_and_boxes):
     cropped_images = []
     for filename, box in filenames_and_boxes:
         cropped = load_and_crop_image(
             filename, box, output_shape=self.input_shape)
         bytes_io = io.BytesIO()
         cropped.save(bytes_io, format='png')
         cropped_images.append(bytes_io)
     return cropped_images
Пример #2
0
    def test_crop_box_is_used_with_resize_nearest(self):
        # we crop to a 1 px image, and check that all image values
        # are the same value
        filename = get_loadable_filenames()[0]
        box = (1, 1, 2, 2)
        image = util.load_and_crop_image(filename, box)

        correct_px_value = np.array(Image.open(filename))[box[0], box[1]]
        self.assertTrue(np.all(np.array(image) == correct_px_value))
Пример #3
0
    def read_image(self, filename, box):
        image_pil = load_and_crop_image(filename,
                                        box,
                                        output_shape=self.input_shape)
        image_np = np.array(image_pil).astype('float32')
        image_np /= 255.0
        image_np -= 0.5
        image_np /= 0.25

        image_torch = torch.from_numpy(image_np).repeat(3, 1,
                                                        1).to(self.device)
        return image_torch
Пример #4
0
 def _load_inputs_at_one_timepoint(self, f0_filename, box):
     bottom, middle, top = augment_focus(f0_filename)
     images = [
         np.array(
             load_and_crop_image(
                 name,
                 box,
                 output_shape=self.input_shape)
             )
         for name in [middle, top, bottom]]
     images = np.array(images).astype('float32') / 255.0
     images = (images - 0.5) / 0.25
     return images
Пример #5
0
 def test_output_image_is_correct_shape(self):
     filename = get_loadable_filenames()[0]
     box = (1, 1, 100, 100)
     shape = (150, 140)
     image = util.load_and_crop_image(filename, box, output_shape=shape)
     self.assertEqual(image.size, shape)
Пример #6
0
 def test_returns_pil_image(self):
     filename = get_loadable_filenames()[0]
     box = (1, 1, 2, 2)
     image = util.load_and_crop_image(filename, box)
     self.assertIsInstance(image, Image.Image)