# SA-GAN: Stain Aclimation Generative Adversarial Network for Histopathology Image Analysis
## 3 Methodology
We named the stain densities matrix \(C\to\mathbb{R}^{k\times 3}\) as color attribute constraints metric. We encoded numerical values of color constraint metric \(C\to\mathbb{R}^{k\times 3}\) as a feature plane with the selected target image. In training, the encoded values are input to the encoder of the deep SA-GAN model as additional information to correctly adjust the color details of generated images. Problem Setting: We define a set of unseen test data as \(\{\mathbf{x}_{S}\}\) comes from a source pathology center and a set of labeled training data as \(\{\mathbf{x}_{T}\}\) with annotations (either for mitosis cell detection task or for cancer type classification task) comes from a target pathology center. It is assumed that source images \(\{\mathbf{x}_{S}\}\in A\) belong to domain \(A\) and target images \(\{\mathbf{x}_{T}\}\in B\) belong to domain \(B\). The images of both domains have different color appearances due to the originating from different pathology centers. Our objective is to transfer \(\{\mathbf{x}_{S}\}\) from domain \(A\) to domain \(B\): \(\hat{\mathbf{x}}_{S}\) such that generated images \(\{\hat{\mathbf{x}}_{S}\}\) have textural content as in \(A\) and color pattern as in \(B\). Training Functions: Given a histopathology image \(\mathbf{x}_{S}\) and color attribute metric \(C\) the generator \(G\) generates new image \(\hat{\mathbf{x}}_{S}=G(\mathbf{x}_{S},C)\). Among the two discriminators, first discriminator \(D_{1}\) is optimized to distinguish texture details between the generated images \(\{\hat{\mathbf{x}}_{S}\}\) and source images \(\{\mathbf{x}_{S}\}\) by minimizing texture content loss \(\mathcal{L}_{D1}\), and second discriminator \(D_{2}\) is optimized to distinguish the color contents between generated images \(\{\hat{\mathbf{x}}_{S}\}\) and target images \(\{\mathbf{x}_{T}\}\) by minimizing the color content loss \(\mathcal{L}_{D2}\). Further, for satisfactory preservation of texture details in generated images, we propose to compute third loss, i.e., textural loss \(\mathcal{L}_{T}\). \(\mathcal{L}_{T}\) loss is calculated from feature maps of the last convolution layer of the discriminator \(D_{1}\). Two adversarial losses (\(\mathcal{L}_{D1}\),\(\mathcal{L}_{D2}\)) and one textural loss (\(\mathcal{L}_{T}\)) are combined to train the generator G. Aforementioned GAN performs properly on natural images [27]. However, the main objective of stain transfer in histopathology images is not just to extract the information but also to maintain the content details (color and texture). Hence, we believe that \(\mathcal{L}_{D2}\), \(\mathcal{L}_{D1}\), and \(\mathcal{L}_{T}\) losses are more realistic metrics for efficient stain transfer in histopathology images. Conventional methods achieved color normalization by matching the color statistics of source images \(\{\mathbf{x}_{S}\}\) to a single reference image \(\mathbf{x}_{T}\). The proposed network learns to generate images by involving staining properties of the entire domain of images \(\{\mathbf{x}_{T}\}\) instead of relying only on single image \(\mathbf{x}_{T}\). This implies learning the probability distribution of images \(\{\mathbf{x}_{T}\}\), which can be achieved by computing the two adversarial loss functions, i.e., \(\mathcal{L}_{D1}\) and \(\mathcal{L}_{D2}\).The adversarial losses involve the generator \(G(\mathbf{x})\) that maps an input source image \(\mathbf{x}_{S}\) to generate stain normalized image \(\hat{\mathbf{x}}_{S}\). The losses also involve two discriminators \(D_{1}(G(\mathbf{x}))\), and \(D_{2}(G(\mathbf{x}))\) which simultaneously outputs the likelihood of given input images \(\mathbf{x}_{S}\) and \(\mathbf{x}_{T}\) to be sampled from source and target sets, respectively. These losses are used to train the generator (including the encoder and decoder) and discriminators.