# Resolving Gas Bubbles Ascending in Liquid Metal from Low-SNR Neutron Radiography Images
## 3 Image Processing
### First Segment Estimates
Here the following PDE is solved with Neumann BCs [65]:  
\[\frac{\partial I}{\partial t}=|\
abla I|\cdot\
abla\bigg{(}g(I,\gamma)\cdot \frac{\
abla I}{|\
abla I|}\bigg{)};\;\;g(I,\gamma)=\exp\Big{(}-|\
abla I|^{2}/ \gamma^{2}\Big{)} \tag{5}\]  
where \(g(I,\gamma)\) is the curvature diffusion coefficient and \(\gamma\) is its control parameter. Unlike the PM filter (2), SSCF diffuses local luminance curvature, not luminance itself. It is also edge-preserving. The number of SSCF iterations and \(\gamma\) are set such that the SSCF filter eliminates any remaining sharply localized luminance maxima about the bubbles since there the luminance curvature is the greatest; at the same time, filtering must preserve bubble region contrast with respect to background. For our images we find that in some cases one may set \(\gamma\rightarrow\infty\), which simplifies (5) to  
\[\frac{\partial I}{\partial t}=|\
abla I|\cdot\
abla\bigg{(}\frac{\
abla I}{| \
abla I|}\bigg{)} \tag{6}\]  
which is the mean curvature flow PDE. However, other cases require anistropic curvature diffusion and then we set \(\gamma\) to the 0.5 quantile of \(|\
abla I|\) in \(I_{0}(\vec{r})\) as with the PM filtering. The number of performed SSCF iterations is set to 7 [66]. The next stage is the soft color tone map (CTM) masking (SCTMM) which is a nonlinear filter designed to clean up the image background by removing large-scale artefacts left over after denoising and to further separate background from bubbles while avoiding excessive erosion of the bubble regions. The large-scale structures in the background were actually one of the sources of the edge detection instability in the previous approach, especially for low-CNR images (\(\text{CNR}=|S_{\text{b}}-S_{0}|/\sigma_{\text{n}}\); \(S_{0}\)--background signal intensity) with higher bubble number density where bubble detection was often outright impossible due formed edge artefacts that could not be reliably removed. Given a normalized original image \(x\), the SCTMM background correction generates a new image \(y\):  
\[y=x*\underbrace{\left(x-\underbrace{(1-\text{CTM}(x,c))}_{\text{Soft thresholding}}\right)}_{\text{Soft background mask}} \tag{7}\]  
where \(\text{CTM}(x,c)\) is the CTM operation and \(c\) is the luminance compression factor. The CTM operation maps the colors (in this case the gray-scale values) of the image using gamma compression with a global compression factor \(c\)[67]. The idea behind SCTMM (7) is as follows. A pure \(x*x\) product would have the effect of non-uniformly increasing the distances between the nearest luminance values (input \(x\) is normalized) and luminance maxima and minima values would be much more distant from the mid-range luminance values, which are affected the most. If one masks or lowers the values of certain pixels within one of the images \(x^{\prime}\), then \(x*x^{\prime}\) would act as a \"_soft_\", i.e., weighed, mask (as opposed to a \"hard\" binary mask) that would shift the pixels with reduced values in \(x^{\prime}\) further towards the lower end of the luminance range, ideally making them background. Soft masking is preferred here because masking using binarization and then replacing the removed background using luminance interpolation or other methods will generally produce artificial and potentially very pronounced edges and/or reduce the contrast of actual edges. Here it is required that \(x^{\prime}\) is such that background and post-filtering artefacts are removed, and bubble contrast is enhanced while bubble features are eroded as little as possible. It was decided to opt for additive masking of the form \(x^{\prime}(x)=x-mask\). An inverted \(\text{CTM}(x,c)\) was chosen as _mask_ because, if the right \(c\) value is set, \(1-\text{CTM}(x,c)\) will have high luminance for background and denoising artefacts since \(\text{CTM}(x,c)\) reduces the difference in their luminance values. This way \(x^{\prime}=x-(1-\text{CTM}(x,c))\) has, conversely, greatly reduced luminance for artefacts and background.