# Bi-Directional Point Flow Estimation with Multi-Scale Attention for Deformable Lung CT Registration
## 3 The Proposed Approach
### Progressive Flow Refinement
#### 3.4.2 The Flow Estimator  
The cost volume features \(\mathbf{C}^{(l)}\) and source features \(\mathbf{F}^{(l)}_{\mathcal{P}}\) are concatenated to form the refinement input:  
\[\mathbf{Z}^{(l)}_{\mathcal{P}}=[\mathbf{C}^{(l)},\mathbf{F}^{(l)}_{\mathcal{P}} ]\in\mathbb{R}^{|\mathcal{P}^{(l)}|\times D_{l\text{-end}}}.\]  
To enhance the flow estimation accuracy, we introduce a contextual attention module composed of alternating self-attention and cross-attention layers. At this stage, the goal is to refine the localized residual flow patterns based on the learned contextual properties. Specifically, we first employ standard multi-head self-attention (MHSA) within the source point cloud to capture the internal structural context:  
\[(\mathbf{Z}^{(l)}_{\mathcal{P}})^{\prime}=\text{MHSA}\Big{(}\mathbf{Z}^{(l)} _{\mathcal{P}}\Big{)}, \tag{8}\]  
where MHSA is defined as  
\[\text{MHSA}(\mathbf{X}) =\text{Concat}[\text{head}_{1},\dots,\text{head}_{h}]\mathbf{W}^{ \text{O}}, \tag{9}\] \[\text{head}_{m} =\text{Softmax}\Bigg{(}\frac{(\mathbf{X}\mathbf{W}^{\text{O}}_{ m})(\mathbf{X}\mathbf{W}^{K}_{m})^{\top}}{\sqrt{d_{k}}}\Bigg{)}\mathbf{X} \mathbf{W}^{V}_{m}, \tag{10}\]  
with \(\mathbf{W}^{\text{O}}_{m},\mathbf{W}^{K}_{m},\mathbf{W}^{V}_{m},\mathbf{W}^{ \text{O}}\) as the learnable linear projection matrices and \(h\) as the number of attention heads.  
Subsequently, to explicitly incorporate the inter-cloud correspondence cues, we perform a cross-attention operation between these self-attended source features \((\mathbf{Z}^{(l)}_{\mathcal{P}})^{\prime}\) and the corresponding warped target features \(\mathbf{F}^{(l)}_{\mathcal{Q}}\in\mathbb{R}^{|\mathcal{Q}^{(l)}|\times D_{l \text{-end}}}\). This step aggregates relevant information from the warped target points to refine the source features:  
\[(\mathbf{\hat{Z}}^{(l)}_{\mathcal{P}})_{i} =\sum_{j=1}^{|\mathcal{Q}^{(l)}|}\beta_{i,j}\Big{(}(\mathbf{Z}^{( l)}_{\mathcal{Q}})_{j}\mathbf{W}^{V}\Big{)}, \tag{11}\] \[\beta_{i,j} =\text{Softmax}\Bigg{(}\frac{\Big{(}(\mathbf{Z}^{(l)}_{\mathcal{ P}})_{i}^{\prime}\mathbf{W}^{\text{Q}}\Big{)}\Big{(}(\mathbf{F}^{(l)}_{ \mathcal{Q}})_{j}\mathbf{W}^{K}\Big{)}^{\top}}{\sqrt{d_{k}}}\Bigg{)}, \tag{12}\]  
where \(\mathbf{W}^{\text{Q}},\mathbf{W}^{K},\mathbf{W}^{V}\in\mathbb{R}^{D_{l\text{-end }}\times D_{l\text{-end}}}\) are the query, key, and value projection matrices, respectively.  
By iteratively alternating the self-attention (intra-cloud) and cross-attention (inter-cloud) layers for \(N_{f}\) steps, we obtain refined embeddings \(\mathbf{\hat{Z}}^{(l)}_{\mathcal{P}}\) that jointly leverage the internal point cloud context and the external correspondence information.  
Finally, these enriched embeddings \(\mathbf{\hat{Z}}^{(l)}_{\mathcal{P}}\) are input into a residual flow prediction network (MLP) to estimate the residual displacements \(\Delta\mathbf{v}^{(l)}\):  
\[\Delta\mathbf{v}^{(l)}=\text{MLP}\big{(}(\mathbf{\hat{Z}}^{(l)}_{\mathcal{P} })\big{)}. \tag{13}\]  
The refined flow at level \(l\) is then computed by adding the residual displacement to the initial estimate:  
\[\mathbf{v}^{(l)}=\mathbf{\hat{v}}^{(l)}+\Delta\mathbf{v}^{(l)}, \tag{14}\]  
which is recursively applied at each decoder level until the finest resolution is reached, producing the final flow prediction \(\mathbf{v}^{(1)}\).  
Note that the same refinement procedure is applied in the reverse direction to obtain the backward flows \(\{\mathbf{u}^{(l)}\}_{l=1}^{L}\).