*2.5. Fibrosis Segmentation*

The RENFAST algorithm is also able to quantify interstitial fibrosis in TRIC images. After stain normalization (Section 2.2), our method detects all the uncolored regions to process only TRIC stained structures. The normalized TRIC image is first converted to grayscale and Weiner filtered. The resulting image is then thresholded using a value equal to 90% of the image maximum (Figure 6a). Since fibrosis is characterized by a greenish color, the proposed algorithm applies an adaptive stain separation as described in [15]. Thanks to the stain separation (Figure 6b), it is possible to divide the regions that may manifest fibrosis (green channel) from the structural component (red channel). Segmentation of these two channels is performed using an improved version of the MANA (Multiscale Adaptive Nuclei Analysis) algorithm [18]. After min-max scaling, custom object-based thresholding is applied to the green channel (fibrosis) and red channel obtained in the previous step. For each possible threshold point *T* ∈ [0, 1], the RENFAST algorithm computes the following energy function:

$$E(T) = p\_0^2 \cdot var\_0 \cdot log(var\_0) + p\_1^2 \cdot var\_1 \cdot log(var\_1) \tag{4}$$

where *p*0 is the probability of having intensity values lower than *T*, *p*1 is evaluated as 1 − *p*0, while *var*0 and *var*1 represent the variances of the probability functions of the two classes *p*0 and *p*1. The threshold *T* associated with the maximum of the energy function *E* represents the optimal thresholding point. The result of green and red channel segmentation is illustrated in Figure 6c. All remaining pixels not associated with one of the binary masks (white, green, red) are included in the green or red mask based on where they have the highest intensity in the stain separation channel.

**Figure 6.** Steps performed by RENFAST for fibrosis segmentation. (**a**) Normalized image and white detection (in blue); (**b**) Stain separation between green and red channels; (**c**) Segmentation of green and red channels; (**d**) Fibrosis and tissue detection for interstitial fibrosis quantification.

Finally, the RENFAST algorithm quantifies the interstitial fibrosis as the ratio between the fibrotic area (segmented green channel) and the overall tissue area. Tissue detection is performed using an RGB high-pass filter [19] where the RGB color of each pixel is treated as a 3D vector. The strength of the edge is defined as the magnitude of the maximum gradient. The raw tissue mask is generated by choosing a threshold equal to 5% of the maximum gradient. Morphological opening with a disk of 4-μm radius is then carried out to obtain the tissue contour (Figure 6d).
