# Multi-Focus Microscopy Image Fusion Based on Swin Transformer Architecture
## 3 Methodology
### Training Data Augmentation  
As reported in the previous literature, the multi-focus image dataset can be more easily generated from other types of image datasets, and more importantly, the ground-truth fusion images of the multi-focus images could be obtained simultaneously while generating training data [62]. In this paper, 525 texture images were selected from the Describable Textures Datasets [66], Salzburg Texture Image Database ([[https://www.wavelab.at/sources/STex/](https://www.wavelab.at/sources/STex/)]([https://www.wavelab.at/sources/STex/](https://www.wavelab.at/sources/STex/)) (accessed on 19 April 2023)) and Original Brodatz's Texture Database ([[http://multibandtexture.recherche.usherbrooke.ca/original_broatz.html](http://multibandtexture.recherche.usherbrooke.ca/original_broatz.html)]([http://multibandtexture.recherche.usherbrooke.ca/original_broatz.html](http://multibandtexture.recherche.usherbrooke.ca/original_broatz.html)) (accessed on 19 April 2023)). The texture images contain bubbly, fibrous, honeycomed, marble, pleated, veined, etc., images as well as images of objects such as gravel and hair. These textures are similar to the biomedical images observed under a microscope. Initially, the RGB images were resized to 224 \(\times\) 224 by cubic interpolation. Depth images for each texture dataset were generated by the Perlin noise algorithm with specified frequencies (2, 4, 8) and random curves (from 1 to 7). As a result, we generated 1575 training datasets. The resized pairs of RGB images (\(I_{s}\), Figure 3a) and depth images of the datasets (\(I_{d}\), Figure 3b) were applied to create the multi-focus image dataset as the following procedures:1. A completely blurry image (\(I_{b}\), Figure 3c) is generated by randomly blurring the source RGB image (\(I_{s}\)) with a Gaussian filter, which can be expressed as: \[I_{b}=G*I_{s}\] (8) Here, * denotes the convolution operation, and G denotes the Gaussian kernel, which is generated with a random kernel radius, \(kr\), from 1 to 15: \[G(x,y)=\frac{1}{\sqrt{2\pi\sigma}}e^{\frac{x^{2}+y^{2}}{2\sigma^{2}}}\] (9) where \(\sigma\) denotes the standard deviation of the Gaussian filter and can be expressed as: \[\sigma=0.3\times(kr-1)+0.8\] (10)
2. The mask map (\(I_{m}\), Figure 3d) was generated from depth images of datasets (\(I_{d}\)) based on a random threshold depth (\(d_{th}\)). \[I_{m}(x,y)=\left\{\begin{array}{ll}0,&I_{d}(x,y)\geq d_{th}\\ 1,&I_{d}(x,y)<d_{th}\end{array}\right.\] (11) \[d_{th}=\gamma\times(max(I_{d})-min(I_{d}))+min(I_{d})\] (12) Here, \(\gamma\) denotes the depth threshold ratio, which is randomly selected from the range 0.3 to 0.7.  
Figure 3: Example of generating multi-focus training dataset according to Section 3.2. (**a**,**b**) are the source image from texture datasets and depth image generated by Perlin noise algorithm, respectively. (**c**) denotes the randomly blurred image. (**d**) shows the mask map according to random threshold depth. (**e**,**f**) are the near-focus image and far-focus image, which are the input images for training models.  
The near-focus image \(I_{n}\) (Figure 3e) and the far-focus image \(I_{f}\) (Figure 3f) were generated based on source image (\(I_{s}\)), completely blurred image (\(I_{b}\)) and the mask map (\(I_{m}\)), which can be expressed as the following equation:  
\[\begin{cases}I_{n}=I_{s}\cdot I_{m}+I_{b}\cdot(1-I_{m})\\ I_{f}=I_{b}\cdot I_{m}+I_{s}\cdot(1-I_{m})\end{cases} \tag{13}\]  
Naturally, the source images (\(I_{s}\)) can serve as the ground truth for fused images.