airlab-unibas / airlab

Image registration laboratory for 2D and 3D image data
Apache License 2.0
408 stars 92 forks source link

some questions about kernel transform #35

Closed cs123951 closed 3 years ago

cs123951 commented 3 years ago

Hi,

Thank you so much for sharing such brilliant code! 
But I am confused about the implementation of kernel transform. The exact code is shown as below.

`
def _compute_flow_3d(self):

    # compute dense displacement
    displacement = F.conv_transpose3d(self.trans_parameters, self._kernel,
                                      padding=self._padding, stride=self._stride, groups=3)

    # crop displacement
    return th.squeeze(displacement[:, :, self._stride[0] + self._crop_start[0]:-self._stride[0] - self._crop_end[0],
                              self._stride[1] + self._crop_start[1]:-self._stride[1] - self._crop_end[1],
                              self._stride[2] + self._crop_start[2]:-self._stride[2] - self._crop_end[2]
                              ].transpose_(1,4).transpose_(1,3).transpose_(1,2))

` I found on the Internet that transposed convolution doesn’t reverse the standard convolution by values, rather by dimensions only. And I have also read other bspline implementations like https://github.com/C4IR/FAIR.m/blob/master/kernel/transformations/splineTransformation2D.m. They get spline coefficients and then compute the displacement. I am wondering if your implementation has some theories behind. Thank you very much if you could answer my questions!

RobinSandkuehler commented 3 years ago

Hi,

we used the transposed convolution in this way:

https://i.stack.imgur.com/f2RiP.gif

The stride is the distance between the control points (blue). We then use a kernel to interpolate the values between those control points to obtain a dense transformation by using the transposed convolution. I hope this could answer your question.

cs123951 commented 3 years ago

@RobinSandkuehler Thanks for your quick reply. I know the transposed convolution. "We then use a kernel to interpolate the values between those control points to obtain a dense transformation by using the transposed convolution." ——we know that the displacement A is convolved with the kernel to get the control points C. And the control points C are changed into a displacement B using the transposed convolution. The issue is that displacement A does not equal to displacement B.

RobinSandkuehler commented 3 years ago

Hi,

the control points are the parameter that are optimized and not generated by a convolution with a displacement. The transposed convolution is used to generate the dense transformation field out of the control points. So we have only one direction C->B.

cs123951 commented 3 years ago

@RobinSandkuehler Thank you again for your kind answers. I understand.