Ejemplo n.º 1
0
    def random_transform(self, x, y):

        translation,rotation,scale,transform_matrix_raw= dv.generate_random_transform(
            self.augmentation_params, x.shape[:-1]
        )
       
        transform_matrix = dv.transform_full_matrix_offset_center(
            transform_matrix_raw, x.shape[:-1]
        )
        x = dv.apply_affine_transform_channelwise(
            x,
            transform_matrix[:-1, :],
            channel_index=self.augmentation_params.img_channel_index,
            fill_mode=self.augmentation_params.fill_mode,
            cval=self.augmentation_params.cval,
        )

        # For y, mask data, fill mode constant, cval = 0
        y = dv.apply_affine_transform_channelwise(
            y,
            transform_matrix[:-1, :],
            channel_index=self.augmentation_params.img_channel_index,
            fill_mode=self.augmentation_params.fill_mode,
            cval=self.augmentation_params.cval,
        )
        
        return x, y,translation,rotation,scale,transform_matrix
Ejemplo n.º 2
0
def test_random_transform_3d():

    a = np.sin(np.linspace(0, np.pi * 5, 256))
    b = np.cos(np.linspace(0, np.pi * 5, 256))
    img = np.outer(a, b)[..., np.newaxis] * a

    x = dv.AugmentationParameters(
        image_dimension=3,
        translation_range=0.15,
        rotation_range=45,
        scale_range=0.15,
        flip=False,
        fill_mode="constant",
        cval=0.0,
    )

    txf = dv.generate_random_transform(x, img.shape)
    txf = dv.transform_full_matrix_offset_center(txf, img.shape)

    nb.viewers.OrthoSlicer3D(dv.apply_affine_transform(img,
                                                       txf[:-1, :])).show()
Ejemplo n.º 3
0
def test_random_transform_2d():

    img = face()

    x = dv.AugmentationParameters(
        image_dimension=2,
        translation_range=0.1,
        rotation_range=15,
        scale_range=0.1,
        flip=False,
        fill_mode="constant",
        cval=0.0,
    )

    txf = dv.generate_random_transform(x, img.shape)
    txf = dv.transform_full_matrix_offset_center(txf, img.shape[:-1])

    plt.imshow(
        dv.apply_affine_transform_channelwise(img,
                                              txf[:-1, :],
                                              channel_index=2))
    plt.show()