YipengHu / label-reg

(This repo is no longer up-to-date. Any updates will be at https://github.com/DeepRegNet/DeepReg/) A demo of the re-factored label-driven registration code, based on "Weakly-supervised convolutional neural networks for multimodal image registration"
Apache License 2.0
117 stars 32 forks source link

Gradients of local displacement energy #18

Closed bashkanov closed 5 years ago

bashkanov commented 5 years ago

Dear @YipengHu,

thank you for sharing this code with us! I'm trying to understand your local_displacement_energy function. In your paper you refer to (Rueckert et al. 1999) where bending energy is clearly defined. Implementation of L1, L2 gradient norms are also pretty straightforward. But I still cannot get the intuition behind your gradient_dx/y/z functions.

It's clear to me why gradient_dx/y/z returns the vol shape less by 2 for x,y,z, axes, e.g. the input shape [batch, 90, 90, 90, 3] will result into shape [batch, 88, 88, 88, 3] for dx, dy, dz. If we want to preserve the original shape we should append zeroes accordingly as it states in this tf.doc image_gradients:

Both output tensors have the same shape as the input: [batch_size, h, w, d]. The gradient values are organized so that [I(x+1, y) - I(x, y)] is in location (x, y). That means that dy will always have zeros in the last row, and dx will always have zeros in the last column.

I’m eager to receive your response!

YipengHu commented 5 years ago

sorry @bashkanov i overlooked your ticket un till closed it just now :p Do you still have the questions or it is solved now?

bashkanov commented 5 years ago

The implementation part is clear to me now :+1:. Could you please elaborate on advantageous of calculating the image gradient with a step size of two (as you did) instead of taking it for neighboring pixels? Maybe there is a paper explaining it well?

sorry @bashkanov i overlooked your ticket un till closed it just now :p Do you still have the questions or it is solved now?

YipengHu commented 5 years ago

There is nothing fancy - this is standard gradient calculation using finite difference. You can use more than one pixels in each direction if not for computational efficiency. You can also convolve with derivatives of Gaussian using efficient FFT. The implemented is only one of the numerical solutions for computing gradient.

bashkanov commented 5 years ago

Thank you for answering my question to satisfy my curiosity!