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={})]}
def test_crop__higher(): crop = Crop({'dst_width': 50, 'dst_height': 33, 'type': 'crop'}) image = np.zeros((100, 100, 3)) image_rep = crop(DataRepresentation(image)) assert image_rep.data.shape == (33, 50, 3) assert image_rep.metadata == {}
def test_crop__higher_non_symmetric(): crop = Crop({'dst_width': 50, 'dst_height': 12, 'type': 'crop'}) image = np.zeros((70, 50, 3)) image_rep = crop(DataRepresentation(image)) assert image_rep.data.shape == (12, 50, 3) assert image_rep.metadata == {}
def test_crop__less_non_symmetric(): 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 == {}
def test_crop_less(self): crop = Crop({'dst_width': 151, 'dst_height': 42, 'type': 'crop'}) image = np.zeros((30, 30, 3)) image_rep = crop(DataRepresentation(image)) assert image_rep.data.shape == (42, 151, 3) assert image_rep.metadata == {'image_size': (30, 30, 3)}
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)}
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_provided_dst_height_dst_width_and_central_fraction_raise_config_error( self): with pytest.raises(ConfigError): Crop({ 'type': 'crop', 'dst_height': 200, 'dst_width': 100, 'central_fraction': 0.875 })
def test_crop_provided_size_and_central_fraction_raise_config_error(self): with pytest.raises(ConfigError): Crop({'type': 'crop', 'size': 200, 'central_fraction': 0.875})
def test_crop_not_provided_size_dst_height_dst_width_central_fraction_raise_config_error( self): with pytest.raises(ConfigError): Crop({'type': 'crop'})
def test_crop_to_negative_destination_height_raise_config_error(self): with pytest.raises(ConfigError): Crop({'dst_width': 100, 'dst_height': -100, 'type': 'crop'})
def test_crop_to_negative_size_raise_config_error(self): with pytest.raises(ConfigError): Crop({'size': -151, 'type': 'crop'})
def test_crop__higher_non_symmetric(): crop = Crop({'dst_width': 50, 'dst_height': 12, 'type': 'crop'}) image = np.zeros((70, 50, 3)) image = crop(image) assert image.shape == (12, 50, 3)
def test_crop_with_negative_central_fraction_raise_config_error(self): with pytest.raises(ConfigError): Crop({'type': 'crop', 'central_fraction': -0.875})
def test_crop__less_non_symmetric(): crop = Crop({'dst_width': 42, 'dst_height': 151, 'type': 'crop'}) image = np.zeros((30, 40, 3)) image = crop(image) assert image.shape == (151, 42, 3)
def test_crop__less(): crop = Crop({'dst_width': 151, 'dst_height': 42, 'type': 'crop'}) image = np.zeros((30, 30, 3)) image = crop(image) assert image.shape == (42, 151, 3)
def test_crop_with_central_fraction_more_1_raise_config_error(self): with pytest.raises(ConfigError): Crop({'type': 'crop', 'central_fraction': 2})
def test_crop__higher(): crop = Crop({'dst_width': 50, 'dst_height': 33, 'type': 'crop'}) image = np.zeros((100, 100, 3)) image = crop(image) assert image.shape == (33, 50, 3)