Ejemplo n.º 1
0
    def test_augment_tile_simple(self):
        '''
        im =
        [[ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 1.  1.  1.  1.  1.  1.  1.  3.  1.  1.  1.  1.  1.  1.  1.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]]

        '''
        def get_tile_func(pos=None, size=None, img=None):
            return img[get_tile_meshgrid(img.shape, pos, size)]

        val_ud = \
            np.array([[[[0., 0., 0., 0., 3., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 3., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 3., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 3., 0., 0., 0., 0.],
                        [2., 2., 2., 2., 5., 1., 1., 1., 1.],
                        [0., 0., 0., 0., 4., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 4., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 4., 0., 0., 0., 0.],
                        [0., 0., 0., 0., 4., 0., 0., 0., 0.]]]])

        im = np.zeros((1, 1, 15, 15))
        im[0, 0, 7, :7] = 1
        im[0, 0, 7, 8:] = 2
        im[0, 0, :7, 7] = 3
        im[0, 0, 8:, 7] = 4
        im[0, 0, 7, 7] = 5

        pos = np.array((0, 0, 3, 3))
        size = np.array((1, 1, 9, 9))

        tile_ud = ds._augment_tile(im.shape,
                                   pos,
                                   size,
                                   get_tile_func,
                                   augment_params={'flipud': True},
                                   **{'img': im})
        assert_array_equal(tile_ud, val_ud)
Ejemplo n.º 2
0
    def test_augment_tile_2(self):
        '''
        im =
        [[ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 1.  1.  1.  1.  1.  1.  1.  3.  1.  1.  1.  1.  1.  1.  1.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]]

        '''
        def get_tile_func(pos=None, size=None, img=None):
            return img[get_tile_meshgrid(img.shape, pos, size)]

        val = np.array([[[[3.]]]])

        im = np.zeros((1, 1, 15, 15))
        im[0, 0, 7, :] = 1
        im[0, 0, :, 7] = 2
        im[0, 0, 7, 7] = 3

        pos = np.array((0, 0, 7, 7))
        size = np.array((1, 1, 1, 1))

        tile_rot = ds._augment_tile(im.shape,
                                    pos,
                                    size,
                                    get_tile_func,
                                    augment_params={
                                        'rotation_angle': 45,
                                        'shear_angle': 0
                                    },
                                    **{'img': im})

        np.testing.assert_equal(val, tile_rot)
Ejemplo n.º 3
0
    def test__augment_tile(self):
        '''
        im =
        [[ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 1.  1.  1.  1.  1.  1.  1.  3.  1.  1.  1.  1.  1.  1.  1.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]
         [ 0.  0.  0.  0.  0.  0.  0.  2.  0.  0.  0.  0.  0.  0.  0.]]


         tile without augmentation
         tile =
          [[ 0.  0.  0.  0.  2.  0.  0.  0.  0.]
           [ 0.  0.  0.  0.  2.  0.  0.  0.  0.]
           [ 0.  0.  0.  0.  2.  0.  0.  0.  0.]
           [ 0.  0.  0.  0.  2.  0.  0.  0.  0.]
           [ 1.  1.  1.  1.  3.  1.  1.  1.  1.]
           [ 0.  0.  0.  0.  2.  0.  0.  0.  0.]
           [ 0.  0.  0.  0.  2.  0.  0.  0.  0.]
           [ 0.  0.  0.  0.  2.  0.  0.  0.  0.]
           [ 0.  0.  0.  0.  2.  0.  0.  0.  0.]]

        augmented tile afer 45 degree rotation
        tile_rot =
            [[ 1.  1.  0.  0.  0.  0.  0.  0.  2.]
             [ 0.  1.  1.  0.  0.  0.  0.  2.  2.]
             [ 0.  0.  1.  1.  0.  0.  2.  2.  0.]
             [ 0.  0.  0.  1.  1.  2.  2.  0.  0.]
             [ 0.  0.  0.  0.  3.  3.  0.  0.  0.]
             [ 0.  0.  0.  2.  2.  1.  1.  0.  0.]
             [ 0.  0.  2.  2.  0.  0.  1.  1.  0.]
             [ 0.  2.  2.  0.  0.  0.  0.  1.  1.]
             [ 2.  2.  0.  0.  0.  0.  0.  0.  1.]]

        '''
        def get_tile_func(pos=None, size=None, img=None):
            return img[get_tile_meshgrid(img.shape, pos, size)]

        val = np.array([[[[1., 1., 0., 0., 0., 0., 0., 0., 2.],
                          [0., 1., 1., 0., 0., 0., 0., 2., 2.],
                          [0., 0., 1., 1., 0., 0., 2., 2., 0.],
                          [0., 0., 0., 1., 1., 2., 2., 0., 0.],
                          [0., 0., 0., 0., 3., 3., 0., 0., 0.],
                          [0., 0., 0., 2., 2., 1., 1., 0., 0.],
                          [0., 0., 2., 2., 0., 0., 1., 1., 0.],
                          [0., 2., 2., 0., 0., 0., 0., 1., 1.],
                          [2., 2., 0., 0., 0., 0., 0., 0., 1.]]]])

        im = np.zeros((1, 1, 15, 15))
        im[0, 0, 7, :] = 1
        im[0, 0, :, 7] = 2
        im[0, 0, 7, 7] = 3

        pos = np.array((0, 0, 3, 3))
        size = np.array((1, 1, 9, 9))
        tile = get_tile_func(pos=pos, size=size, img=im)

        tile_rot = ds._augment_tile(im.shape,
                                    pos,
                                    size,
                                    get_tile_func,
                                    augment_params={
                                        'rotation_angle': 45,
                                        'shear_angle': 0
                                    },
                                    **{'img': im})

        print(im)
        print(tile)
        print(tile_rot)
        print(val)
        assert_array_equal(val, tile_rot)