def test_resize_img_to_arbitrary_size(img, mask, resize_to): # Setting up the data kpts_data = np.array([[0, 0], [0, 2], [2, 2], [2, 0]]).reshape( (4, 2)) # Top left corner kpts = slc.Keypoints(kpts_data.copy(), img.shape[0], img.shape[1]) dc = slc.DataContainer(( img, mask, kpts, ), "IMP") transf = slt.Resize(resize_to=resize_to) res = transf(dc).data if isinstance(resize_to, int): resize_to = (resize_to, resize_to) scale_x = resize_to[0] / img.shape[1] scale_y = resize_to[1] / img.shape[0] assert transf.resize_to == resize_to assert (res[0].shape[0] == resize_to[1]) and (res[0].shape[1] == resize_to[0]) assert (res[1].shape[0] == resize_to[1]) and (res[1].shape[1] == resize_to[0]) assert (res[2].height == resize_to[1]) and (res[2].width == resize_to[0]) kpts_data = kpts_data.astype(float) kpts_data[:, 0] *= scale_x kpts_data[:, 1] *= scale_y kpts_data = kpts_data.astype(int) assert np.array_equal(res[2].data, kpts_data)
def __init__(self): self.imgaug_transform = iaa.Scale(size=512, interpolation="linear") self.solt_stream = slc.Stream([slt.Resize(resize_to=(512, 512))]) self.augmentor_op = Operations.Resize(probability=1, width=512, height=512, resample_filter="BILINEAR")
def test_resize_img_to_arbitrary_size(img, mask, resize_to): # Setting up the data kpts_data = np.array([[0, 0], [0, 2], [2, 2], [2, 0]]).reshape( (4, 2)) # Top left corner kpts = slc.Keypoints(kpts_data.copy(), frame=(img.shape[:2])) dc = slc.DataContainer(( img, mask, kpts, ), "IMP") transf = slt.Resize(resize_to=resize_to) res = transf(dc).data if isinstance(resize_to, int): resize_to = (resize_to, resize_to) scales = tuple(resize_to[i] / img.shape[i] for i in range(img.ndim - 1)) assert transf.resize_to == resize_to np.testing.assert_array_equal(res[0].shape[:-1], resize_to) np.testing.assert_array_equal(res[1].shape, resize_to) np.testing.assert_array_equal(res[2].frame, resize_to) kpts_data = kpts_data.astype(float) kpts_data = (kpts_data * np.asarray(scales)[None, ]) kpts_data = kpts_data.astype(int) assert np.array_equal(res[2].data, kpts_data)
def test_different_interpolations_per_item_per_transform(img_6x6, transform_settings): dc = slc.DataContainer((img_6x6,), "I", transform_settings=transform_settings) dc_res = slt.Resize(resize_to=(10, 15), interpolation="bilinear")(dc) interp = ALLOWED_INTERPOLATIONS["bilinear"] if transform_settings is not None: interp = ALLOWED_INTERPOLATIONS[transform_settings[0]["interpolation"][0]] assert np.array_equal(cv2.resize(img_6x6, (10, 15), interpolation=interp).reshape(15, 10, 1), dc_res.data[0],)
def __init__(self): self.augmentor_pipeline = Pipeline() self.augmentor_pipeline.add_operation( Operations.Crop(probability=1, width=64, height=64, centre=False)) self.augmentor_pipeline.add_operation( Operations.Resize(probability=1, width=512, height=512, resample_filter="BILINEAR")) self.imgaug_transform = iaa.Sequential([ iaa.CropToFixedSize(width=64, height=64), iaa.Scale(size=512, interpolation="linear") ]) self.solt_stream = slc.Stream([ slt.Crop(crop_to=(64, 64), crop_mode="r"), slt.Resize(resize_to=(512, 512)) ])
def create_train_transforms(size): return solt.Stream([ slt.JPEGCompression(p=0.5,quality_range=(60,100)), slt.Noise(p=0.25), slt.Brightness(), slt.Contrast(), slt.Flip(), slt.Rotate90(), solt.SelectiveStream([ slt.GammaCorrection(gamma_range=0.5, p=1), slt.Noise(gain_range=0.1, p=1), slt.SaltAndPepper(), slt.Blur(), ], n=3), slt.Rotate(angle_range=(-10, 10), p=0.5), slt.Resize((size,size)), ])
def create_val_transforms(size): return solt.Stream([slt.Resize((size,size))])
def test_resize_does_not_change_labels(): trf = slt.Resize(resize_to=(5, 5)) dc = slc.DataContainer((1, ), "L") dc = trf(dc) assert dc.data[0] == 1
def test_wrong_resize_types(resize_to): with pytest.raises(TypeError): slt.Resize(resize_to=resize_to)