gvtulder / elasticdeform

Differentiable elastic deformations for N-dimensional images (Python, SciPy, NumPy, TensorFlow, PyTorch).
Other
186 stars 25 forks source link

If I want to transform a RGB image in pytorch way, how to use etorch.deform_grid to deal with it? #12

Closed Brandy0k closed 3 years ago

gvtulder commented 3 years ago

If your image has three channels, you should apply the deformation only on the x and y dimension. So suppose that your image x has shape (channels, height, width), you would do the deformation with

# generate a 2D displacement grid of 3 x 3, with two displacement coordinates per grid point
displacement = numpy.random.randn(2, 3, 3) * 5
# apply the deformation to the last two dimensions of x
x_deformed = etorch.deform_grid(x, displacement, axis=(1, 2))
Brandy0k commented 3 years ago

thank u very much