gvtulder / elasticdeform

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

Displacement vector and axis related #7

Closed gganes3 closed 3 years ago

gganes3 commented 3 years ago

I have an image(200x200) and want to displace only in the x direction on the edges. I am using a displacement vector of (2,11,1). I want to displace only in the x direction. For that I am using axis = (1,0), that gives me an error. "assert displacement.ndim == len(axis[0]) + 1, 'Number of dimensions of displacement does not match input.' AssertionError: Number of dimensions of displacement does not match input."

gvtulder commented 3 years ago

If you want to displace in the x direction, you should give a displacement vector of shape (1, 11): the displacement vector has only one element for each point, and the displacement grid has only one dimension.

For example:

x = np.zeros((101, 101))
x[::10, :] = 1
x[:, ::10] = 1

# random displacement
x_deformed = elasticdeform.deform_random_grid(x, axis=1, sigma=2, points=11)
plt.subplot(1, 2, 1)
plt.imshow(x_deformed, cmap='gray')

# predefined displacement
displacement = np.random.uniform(-3, 3, (1, 11))
x_deformed = elasticdeform.deform_grid(x, axis=1, displacement=displacement)
plt.subplot(1, 2, 2)
plt.imshow(x_deformed, cmap='gray')

Is this what you are trying to do?