Ejemplo n.º 1
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)),
                    ])
Ejemplo n.º 2
0
def test_gaussian_noise_no_image_throws_value_error():
    trf = slt.Noise(p=1)
    # Setting up the data
    kpts_data = np.array([[0, 0], [0, 5], [1, 3], [2, 0]]).reshape((4, 2))
    kpts = slc.Keypoints(kpts_data, 6, 6)
    dc = slc.DataContainer((kpts, ), "P")

    with pytest.raises(ValueError):
        trf(dc)
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
def test_image_doesnt_change_when_gain_0_in_gaussian_noise_addition(img_3x3):
    dc = slc.DataContainer((img_3x3, ), "I")
    trf = slt.Noise(gain_range=(0, 0), p=1)
    dc_res = trf(dc)
    np.testing.assert_array_equal(img_3x3, dc_res.data[0])
Ejemplo n.º 5
0
def test_gaussian_noise_float_gain():
    trf = slt.Noise(gain_range=0.2, p=1)
    assert isinstance(trf.gain_range, tuple)
    assert len(trf.gain_range) == 2
    assert trf.gain_range[0] == 0 and trf.gain_range[1] == 0.2