Beispiel #1
0
def test_motion_blur_samples_transform(ks, img_6x6_rgb):
    blur = slt.Blur(p=1, blur_type="mo", k_size=ks)
    random.seed(42)
    dc = slc.DataContainer(img_6x6_rgb, "I")
    for i in range(100):
        blur.sample_transform(dc)
        if isinstance(ks, int):
            assert blur.state_dict["motion_kernel"].shape[0] == ks
        else:
            assert blur.state_dict["motion_kernel"].shape == ks
Beispiel #2
0
def test_blur_samples_correctly(blur_t, k_size, sigma, img_6x6_rgb):
    dc = slc.DataContainer(img_6x6_rgb, "I")
    trf = slt.Blur(blur_type=blur_t, k_size=k_size, gaussian_sigma=sigma)
    trf.sample_transform(dc)

    if isinstance(k_size, int):
        k_size = (k_size, )
    if sigma is None:
        sigma = 1

    assert trf.state_dict["k_size"] in k_size
    assert trf.state_dict["sigma"] == sigma
Beispiel #3
0
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)),
                    ])
Beispiel #4
0
def test_complex_transform_serialization():
    stream = slc.Stream([
        slt.Flip(axis=1, p=0.5),
        slc.SelectiveStream([
            slt.Rotate(angle_range=(-45, -45), p=1, padding="r"),
            slt.Rotate90(1, p=1),
            slt.Rotate(angle_range=(45, 45), p=1, padding="r"),
        ]),
        slt.Crop((350, 350)),
        slc.SelectiveStream([
            slt.GammaCorrection(gamma_range=0.5, p=1),
            slt.Noise(gain_range=0.1, p=1),
            slt.Blur()
        ],
                            n=3),
        slt.Projection(
            affine_transforms=slc.Stream([
                slt.Rotate(angle_range=(-45, 45), p=1),
                slt.Scale(range_x=(0.8, 1.5),
                          range_y=(0.8, 1.5),
                          p=1,
                          same=False),
            ]),
            v_range=(1e-4, 1e-3),
            p=1,
        ),
        slc.SelectiveStream(
            [
                slt.CutOut(40, p=1),
                slt.CutOut(30, p=1),
                slt.CutOut(20, p=1),
                slt.CutOut(40, p=1),
                slc.Stream(),
                slc.Stream(),
                slc.Stream(),
            ],
            n=3,
        ),
    ])

    assert slu.from_yaml(stream.to_yaml()).to_yaml() == slu.from_yaml(
        stream.to_yaml()).to_yaml()
Beispiel #5
0
def test_blur_arguments(blur_t, k_size, sigma, to_catch, img_6x6_rgb):
    dc = slc.DataContainer(img_6x6_rgb, "I")
    with pytest.raises(to_catch):
        b = slt.Blur(blur_type=blur_t, k_size=k_size, gaussian_sigma=sigma)
        b.sample_transform(dc)