gvtulder / elasticdeform

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

Can I get a full-size displacement of the image size? #14

Closed tuffr5 closed 5 months ago

tuffr5 commented 2 years ago

Thanks for the work. I got confused about the grid_size and points. Are there any relationships between those two? Like for 3x3 grid, we have 9 points at most? I don't know if I understand right. Besides, is there a way to get the displacement field of the same size of the image by using this package? I looked up the code, and find the displacement vector is relevant to the number of points. But set the number of points of the whole image size would be weird for the transformed image. Thanks.

gvtulder commented 2 years ago

The number of points is indeed linked to the grid size. If you set the points argument to 3 or (3, 3), you will get a 3x3 grid, i.e., a grid with 9 deformation points in total. The top-left deformation point is on the top-left of the image, the bottom-right deformation on the bottom-right of the image.

Each grid point gets its own, random deformation vector. Between the grid points, the deformation is interpolated from the neighboring grid points. Increasing the number of points in the grid makes the deformations more detailed and less smooth, because you get more random deformation vectors.

Usually, you will want to use a lower sigma if you increase the number of grid points: if the deformation vectors are larger than the distance between grid points, you get strange results.

If you make the deformation grid the same size as the image, you will get a different random deformation vector for every pixel. It won't be a smooth deformation.