def test_resize_save_aspect_ratio_frcnn_keep_aspect_ratio(self):
        input_image = np.ones((480, 640, 3))
        resize = Preprocessor.provide('resize', {
            'type': 'resize',
            'dst_width': 100,
            'dst_height': 150,
            'aspect_ratio_scale': 'frcnn_keep_aspect_ratio'
        })
        result = resize(DataRepresentation(input_image))

        assert result.data.shape == (100, 133, 3)
        assert result.metadata == {
                'geometric_operations': [
                    GeometricOperationMetadata(
                        type='resize',
                        parameters={
                            'scale_x': 0.2078125,
                            'scale_y': 0.20833333333333334,
                            'image_info': [100, 133, 1],
                            'original_width': 640,
                            'original_height': 480,
                            'preferable_width': 133,
                            'preferable_height': 150
                            }
                        )
                    ],
                'image_info': [100, 133, 1],
                'image_size': (480, 640, 3),
                'original_height': 480,
                'original_width': 640,
                'preferable_height': 150,
                'preferable_width': 133,
                'scale_x': 0.2078125,
                'scale_y': 0.20833333333333334
                }
    def test_crop_central_fraction_non_symmetric(self):
        crop = Crop({'central_fraction': 0.5, 'type': 'crop'})
        image = np.zeros((80, 40, 3))
        image_rep = crop(DataRepresentation(image))

        assert image_rep.data.shape == (40, 20, 3)
        assert image_rep.metadata == {'image_size': (80, 40, 3),
                'geometric_operations': [GeometricOperationMetadata(type='crop', parameters={})]}
    def test_crop_less_non_symmetric(self):
        crop = Crop({'dst_width': 42, 'dst_height': 151, 'type': 'crop'})
        image = np.zeros((30, 40, 3))
        image_rep = crop(DataRepresentation(image))

        assert image_rep.data.shape == (151, 42, 3)
        assert image_rep.metadata == {'image_size': (30, 40, 3),
                'geometric_operations': [GeometricOperationMetadata(type='crop', parameters={})]}
    def test_crop_to_size(self):
        crop = Crop({'size': 50, 'type': 'crop'})
        image = np.zeros((100, 100, 3))
        image_rep = crop(DataRepresentation(image))

        assert image_rep.data.shape == (50, 50, 3)
        assert image_rep.metadata == {'image_size': (100, 100, 3),
                'geometric_operations': [GeometricOperationMetadata(type='crop', parameters={})]}
 def test_crop_with_both_provided_size_and_dst_height_dst_width_warn(self):
     image = np.zeros((30, 40, 3))
     with pytest.warns(None) as warnings:
         crop = Crop({'dst_width': 100, 'dst_height': 100, 'size': 200, 'type': 'crop'})
         assert len(warnings) == 1
         result = crop.process(DataRepresentation(image))
         assert result.data.shape == (200, 200, 3)
         assert result.metadata == {'image_size': (30, 40, 3),
                 'geometric_operations': [GeometricOperationMetadata(type='crop', parameters={})]}