## 2 Materials and Methods  
We used image set BBBC038v1, available from the Broad Bioimage Benchmark Collection [25]. The dataset contains 670 images, which are highly varied because they came from many contexts: different organisms (humans, mice, flies), different nuclei treatments, different imaging conditions (fluorescent, histology stains), several magnifications and varying qualities of illumination, different states of nuclei including monolayers, tissues, embryos, cell division, genotoxic stress and differentiation (for example, see Figure 1). The dataset was constructed to challenge newly developed algorithms be able to generalise across these variations. As such, the dataset represents true variability, which is faced at biotechs, hospitals and by research groups at universities. Therefore, it was desirable to have a segmentation method with capacity enough to learn various aspects of each type of image in the dataset. In the current study, two different state-of-the-art CNN architectures--ResNet and DenseNet--were implemented to build the customised deep neural network. These architectures included the typically used building blocks, but the composition of the layers was modified by introducing metric embeddings such as contrastive loss and triplet loss with semi-hard negative mining. In particular, we designed ResNet-68, ResNet-104 and DenseNet-71 architectures (see Section 2.1) and used them in the experimental study for multi-tissue cell nuclei segmentation. The implementation code can be found in the reference provided in the subsection \"Supplementary Materials\". It is important to note that the metric embedding was used as an addition to the cross-entropy and Dice losses. Therefore, in total, we implemented 9 models: 3 architectures \(\times\) (2 metric embeddings \(+\) no metric embedding). Comparatively, in our recent study [26], we investigated a few more architectures, including DenseNet-27, DenseNet-71, ResNet-68, ResNet-104 and Vanilla UNet-54; however, some of them demonstrated a poor performance in segmenting the images, and therefore were not considered in the current paper. Notably, some adjustments in the learning strategy were made in order to use the selected metric embeddings, i.e., contrastive loss and triplet loss with semi-hard negative mining. First, for each image, 200 pixels that included the nucleus and 200 pixels from the background were selected (400 pixels in total). This sampling was made randomly at each training iteration. Then, the predicted embeddings were extracted from the 12 th network layer for those 400 pixels and fed into the metric learning loss function. Lastly, the results from the metric learning loss function were combined with the classical metrics used for the segmentation, such as Dice loss and cross-entropy loss. In other words, the final loss function \(\mathcal{L}\text{{oss}}\) was constructed from three different subfunctions: metric learning loss \(L_{MetricLearning}\) (which encourages clustering of pixels), Dice loss, and cross-entropy loss with equal weights, which is given by  
\[\mathcal{L}\text{{oss}}\left(y,\hat{y},y_{M},\hat{y}_{M}\right)= -\frac{1}{n\ N^{2}}\sum_{i=1}^{n}\sum_{j=1}^{N^{2}}\left[y_{ij} \log\hat{y}_{ij}+\left(1-y_{ij}\right)\log\left(1-\hat{y}_{ij}\right)\ \right]+\] \[\frac{1}{n}\sum_{i=1}^{n}\left[1-\frac{2\sum_{j=1}^{N^{2}}\left(y _{ij}\ \hat{y}_{ij}\right)}{\sum_{j=1}^{N^{2}}y_{ij}+\sum_{j=1}^{N^{2}}\hat{y}_{ij}} \right]+L_{MetricLearning}\left(y_{M},\hat{y}_{M}\ \right),\]  
where \(y\) is a true mask matrix with each column representing one mask of images (of size \(N\times N\)) reshaped into a column, in which there exist \(n\) such columns for \(n\) images in a single batch; \(\hat{y}\) denotes the predicted segmentation for the entire batch; \(y_{M}\) represents \(M\) mask pixels, which were randomly selected to calculate the metric learning loss function value; \(\hat{y}_{M}\) are embeddings of those \(M\) pixels from the 12 th layer. Each architecture was trained with the Adam optimiser.