# Resolving Gas Bubbles Ascending in Liquid Metal from Low-SNR Neutron Radiography Images
## 3 Image Processing
### First Segment Estimates  
First segment estimates are obtained using an algorithm referred to in this article as the _global filter_, which is outlined in Algorithm 3. Segment estimation is performed in three stages--noise filtering and background removal, implicit edge detection and segment filling and cleanup. Noise filtering is done as follows. First, Perona-Malik (PM) filtering is performed on an input image whereby the following non-linear diffusion partial differential Equation (PDE) is solved over the image luminance map \(I\) over virtual time \(t\) with Neumann boundary conditions (BCs) [60]:  
\[\frac{\partial I}{\partial t}=\
abla\cdot(f(I,\alpha)\cdot\
abla I);\;\;f(I, \alpha)=\exp\left(-|\
abla_{\sigma}I|^{2}/\alpha^{2}\right) \tag{2}\]  
where \(I=I(\vec{r},t)\), \(f(I,\alpha)\) is the diffusion coefficient and \(\alpha\) is its control parameter, and \(I_{0}(\vec{r})=I(\vec{r},0)\) is the input image. \(f(I,\alpha)\) prescribes anisotropic diffusion by restricting luminance diffusion across sharp edges. The number of PM iterations, \(\alpha\) and the gradient Gaussian regularization width \(\sigma\) that controls the sensitivity of \(f(I,\alpha)\) to noise are chosen such that the PM process only acts on very small-scale noise structures--Equation (2) is edge-preserving--and it is mainly aimed at removing the remainder of the salt and pepper noise due to bright and dark outliers that survived pre-processing (Algorithm 2). Note that  
\[\
abla_{\sigma}I=\
abla(K_{\sigma}\oplus I) \tag{3}\]  
where \(K_{\sigma}\) is a Gaussian kernel with its standard deviation \(\sigma\). In the case of our images, we found that it is productive to set \(\alpha\) to the 0.5 quantile of \(|\
abla I|\) in \(I_{0}(\vec{r})\), and to set \(\sigma=1\) and the number of PM iterations to 5 [61; 62]. Next, the total variation (TV) filter is applied assuming Poisson noise (typical for low-SNR underexposed images as in this case) by solving the following PDE with Neumann BCs [63]:\[\frac{\partial I}{\partial t}=\underbrace{\
abla\bigg{(}\frac{\
abla I}{|\
abla I|} \bigg{)}}_{\text{Noise filtering}}+\underbrace{\frac{1}{BI}(I_{0}-I)}_{\text{Input}/ \text{output similarity}} \tag{4}\]  
where the regularization parameter \(\beta\) determines the balance between noise filtering (pixel value variation minimization) and input/output similarity preservation. Solving (4) over virtual time \(t\) asymptotically transforms the input image into a stationary (with respect to \(t\)) filtered image. The TV filter is set up such that it eliminates noise structures up to a fraction of the length scale of bubbles while avoiding overly distorting the luminance map. In our case, we find that setting \(\beta\in[0.8,1]\) and limiting the number of TV iterations to 100 [64] yields better results. ```
Input: Normalized pre-processed images (Algorithm 2) Noise filtering and background removal
1 Perona-Malik (PM) filter (2) Total variation (TV) filtering, Poisson model (4) Self-snakes curvature flow (SSCF) filter (5); memoize output Soft color tone map masking (SCTMM) (7); memoize output Implicit edge detection Compute the luminance using the gradient filter (Gaussian regularization + Bessel derivative kernel) 2-threshold hysteresis binarization (Optional) Morphological erosion Thinning transform Segment filling and cleanup
2 Filling transform Mean filtering (small radius) Otsu binarization Remove border components Output Image mask with first segment estimates Memoized SSCF-filtered image for later use in Algorithm 4 Memoized SCTMM-filtered image for later use in Algorithm 6
```  
**Algorithm 3**Global first segment estimator for pre-processed FOV images  
The third stage is the application of the self-snakes curvature flow (SSCF) filter.