# SA-GAN: Stain Aclimation Generative Adversarial Network for Histopathology Image Analysis
## 3 Methodology  
Model Formulation: We designed the architecture of our SA-GAN color transfer network by using convolution neural networks. In proposed SA-GAN, the style transfer task is performed with generator network \(G\) that competes against two discriminators, \(D_{1}\) and \(D_{2}\). The generator contains an encoder of two convolution blocks (each block includes 2D convolutional layers, instance normalization layers and Leaky ReLu activation functions, sequentially) and a decoder of two transpond convolution blocks (each block includes transposed convolutional layers, instance normalization layers and ReLu activation functions). The generator also contains nine residual blocks similar to that in [30], which improve the quality of the image translation task [31]. Each residual block is composed of two 2D reflection padding layers, two 2D convolution layers, two instance normalization layers, a ReLu activation function, and a plus operation, sequentially. Among discriminators, the first discriminator \(D_{1}\) maintains the color patterns of the target domain in generated images. While second discriminator \(D_{2}\) preserves the structure details of the source domain in generated images. These two discriminators (\(D_{1}\) & \(D_{2}\)) have similar architectures of four convolutional blocks (including a 2D convolution layer, instance normalization layer, and the ReLu activation function) and are followed by a fully connected layer. The workflow diagram of SA-GAN is shown in Figure 2.  
Color attribute constraint metric: Two types of stains are used in histopathology images, i.e., hematoxylin and eosin (H&E) stain. Hematoxylin stains the nuclei and eosin mainly stains the cytoplasm and stroma tissues. The majority of pixels in images alternatively contain H or E stains and a third channel called residual channel D, which should be zero in the ideal situation. Thus, it is considered that proportion of the two stains and overall intensity of staining is equally important for the normalization. In our proposed design, to correctly condense the stain variations in the dataset and to easily adjust color attributes (contrast and brightness) of processed images, we selected an image \(I\rightarrow\mathbb{R}^{M\times N\times 3}\) from target domain and computed its color attribute metric \(C\). A color attribute metric for  
Figure 2: Workflow diagram of the proposed SA-GAN network: \(\{\mathbf{x}_{S}\}\) denotes source images drawn from a training set, \(\{\mathbf{x}_{T}\}\) are target images drawn from a test set of different staining properties. \(\{\mathbf{\hat{x}}_{S}\}\) denotes the generated images. The two discriminators \(D_{1}\) & \(D_{2}\) are trained with adversarial losses \(\mathcal{L}_{D1}\) and \(\mathcal{L}_{D2}\), respectively. To retain the texture details the textural loss \(\mathcal{L}_{T}\) is computed from the last convolution layer of the discriminator \(D_{1}\). The generator \(G\) is trained with the color attribute metric \(C\), textural loss \(\mathcal{L}_{T}\), and two adversarial losses \(\mathcal{L}_{D1}\) & \(\mathcal{L}_{D2}\). each stain \(C\to\mathbb{R}^{k\times 3}\) is calculated by applying color deconvolution (CD) method using Beer-Lambert law [32]. CD can be briefly represented with the following equations:  
\[D=-\frac{\ln(I)}{I_{\text{max}}} \tag{1}\]  
\[C=AD \tag{2}\]  
where \(I_{\text{max}}\) denotes maximum of digital image intensity (i.e., 255 for 8-bit data format). The \(D\to\mathbb{R}^{k\times 3}\) denotes the optical density (OD) of RGB channels, \(A\to\mathbb{R}^{3\times 3}\) is a so-called color deconvolution matrix that can be manually measured using an experiment reported in [32]. \(C\to\mathbb{R}^{k\times 3}\), in Equation (2), represents the output that contains stain densities. For H&E-stained image, separate densities of stains can be represented as \(C=\left(H,E,D\right)^{T}\) where H&E are the values for hematoxylin and eosin stains, respectively, and \(D\) represents the residual of the separation.