gvtulder / elasticdeform

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

elastic distortion to binary image #10

Closed TaekyungKi closed 3 years ago

TaekyungKi commented 3 years ago

Hi, thank for providing nice package. When i use the elastic distortion to binary image, i.e. label image which has value of 0 or 1, the binarization is broken. Thresholding also produces poor result. Is there any way to maintain the binarization ? Below is a toy example that I made. Thanks. example

gvtulder commented 3 years ago

Thanks! Which interpolation order are you using for the mask? By default, the function uses 3rd order spline interpolation, which works for floating point images but not for binary masks. You can specify the order when you call deform_grid or deform_random_grid. For binary masks, you should use 0 instead of 3.

Looking at your toy example, you probably want to use the same deformation for the image and the label. You can do that with a single call to deform_grid. You can specify a different interpolation order for each input:

[image_deform, label_deform] = elasticdeform.deform_random_grid([image, label], order=[3, 0])

There's something on this in the README, but I should probably add something about the interpolation order as well.

TaekyungKi commented 3 years ago

Oh, I used order 3 for interpolation. With your advice, I made the right one. Thank you! You save my time :) I will close this issue.