# Machine learning-enhanced optical monitoring for identifying pitting-susceptible zones in 316L stainless steel

Aleksei Makogon, Leonardo Bertolucci Coelho, Jon Ustarroz, Philippe

Decorse, Frédéric Kanoufi, Slava Shkirskiy

► To cite this version:

Aleksei Makogon, Leonardo Bertolucci Coelho, Jon Ustarroz, Philippe Decorse, Frédéric Kanoufi, et al. Machine learning-enhanced optical monitoring for identifying pitting-susceptible zones in 316L stainless steel. Corrosion Science, 2025, 256, pp.113184. 10.1016/j.corsci.2025.113184. hal-05340673

HAL Id: hal-05340673

https://hal.science/hal-05340673v1

Submitted on 31 Oct 2025

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Graphical Abstract

# Machine Learning-Enhanced Optical Monitoring for Identifying Pitting-Susceptible Zones in 316L Stainless Steel

A. Makogon, L.B. Coelho, J. Ustarroz, P. Decorse, F. Kanoufi, V. Shkirskiy

<figure><img src="image_2.png" /></figure>
Highlights

Machine Learning-Enhanced Optical Monitoring for Identifying Pitting-Susceptible Zones
in 316L Stainless Steel

A. Makogon, L.B. Coelho, J. Ustarroz, P. Decorse, F. Kanoufi, V. Shkirskiy

* Unsupervised ML enhances the optical signals of the passive layer on stainless steel

* ML-enhanced optical detection identifies pitting-susceptible zones

* Optical modelling and ex-situ XPS indicate chromium deficiency in pitting-susceptible zones
Machine Learning-Enhanced Optical Monitoring for Identifying
Pitting-Susceptible Zones in 316L Stainless Steel*,**

A. Makogon<sup>a,1</sup>, L.B. Coelho<sup>b,c</sup>, J. Ustarroz<sup>b,d</sup>, P. Decorse<sup>a</sup>, F. Kanoufi<sup>a</sup> and V. Shkirskiy<sup>a,*</sup>

<sup>a</sup>Université Paris Cité, ITODYS, CNRS, 15 Rue Jean Antoine de Baïf, Paris, 75013, France

<sup>b</sup>ChemSIN, Chemistry of Surfaces, Interfaces and Nanomaterials, Université libre de Bruxelles (ULB), Campus de la Plaine, Boulevard du Triomphe 2, 1050, Brussels, Belgium

<sup>c</sup>IAalto Ltda, Taió, Santa Catarina, P. José Moacir Moser, Taió, 8919000, Brazil

<sup>d</sup>Research Group Electrochemical and Surface Engineering (SURF), Vrije Universiteit Brussel, Pleinlaan 2, Brussels, 1050, Belgium

ARTICLE INFO

Keywords:

pitting corrosion

machine learning

reflective microscopy

stainless steel

ABSTRACT

Assessing the susceptibility of stainless steel (SS) to pitting corrosion remains challenging due to the difficulty in identifying nanometre-scale imperfections in the passive surface films. Traditional analytical methods are costly, time-consuming, and limited to model systems with adequate signal-to-noise ratios. We propose an alternative approach that leverages optical signatures of passive layer properties which, when enhanced with unsupervised machine learning (ML) to extract signals even at the noise level, successfully identifies pitting-susceptible zones (PSZs) *in situ* on industrial SS 316L substrates. Complementary optical modelling and X-ray Photoelectron Spectroscopy (XPS) reveal chromium oxide deficiency in surface films over PSZs, consistent with established pitting mechanisms. This proof of concept demonstrates that ML-enhanced optical methods can serve as accessible, precise tools for PSZ identification, advancing the development of optical corrosion monitoring systems.

# 1. Introduction

A key defence against corrosion in passive metals, such as stainless steels (SSs), is the formation of a nanometre-thick oxide/hydroxide layer. [1, 2] Modern structure-sensitive techniques—scanning tunnelling microscopy (STM), atomic force microscopy (AFM), Time-of-Flight Secondary Ion Mass Spectrometry (ToF-SIMS), among others—have revealed that this layer forms almost instantaneously upon metal oxidation, reaches 0.1 to 5 nm in thickness, and exhibits a bi-layered structure. [3–9] The inner layer is compact and Cr-rich, while the outer layer is Fe-rich. Growth kinetics models explain the dissolution of the underlying SS as a process of cation transfer through this protective layer. [1, 10] This cation transport accelerates markedly at defective regions, including oxide and metal grain boundaries, inclusions, second-phase particles, and atomic defects in crystalline oxide structures. [1, 6, 11, 12] The scientific consensus indicates that Cr plays the most critical role in the corrosion protection of SSs. [4, 6, 13, 14] When Cr becomes locally depleted due to defective regions, particularly in solutions containing Cl⁻ or other halides, film breakdown occurs, leading to accelerated localised dissolution, commonly known as pitting. [4, 6, 8] While many theoretical models have been developed to predict film breakdown, they either lack spatial resolution of pit initiation sites (e.g., mean-field point defect [1, 15] and stochastic models [16, 17]) or are limited to idealised single-crystal interfaces and millisecond timescales (e.g., DFT, [18] molecular dynamics [19]), rendering them unsuitable for predictions on in-service industrial samples. On the other hand, a range of high-precision, surface-sensitive *in situ* tools (STM, ToF-SIMS, AFM, etc.) [3–6, 9, 18] have been developed and successfully applied to experimentally monitor local passive film breakdown. Unfortunately, these tools are limited to experimental settings and are unsuitable for real-world monitoring.

A promising approach to address this issue involves the application of low-cost and highly adaptable Reflective Microscopy (RM), which is well-suited to real corrosion conditions. [20] Available in many configurations and known under multiple names (optical microscopy, [21] time-lapse microscopy, [22] two-dimensional surface optical reflectance, [23, 24] spatio-temporal real-time optics, [25, 26] etc.), the basic principle remains the same: the

<figure><img src="image_3.png" /></figure>

viacheslav.shkirskiy@cnrs.fr (V. Shkirskiy)

ORCID(s): 0000-0002-9039-2241 (A. Makogon); 0000-0002-7106-7603 (L.B. Coelho); 0000-0003-0166-6915 (J. Ustarroz); 0000-0002-9784-2380 (F. Kanoufi); 0000-0003-4289-9678 (V. Shkirskiy)

¹A. Makogon is the sole developer of the code for this project, which is available on Zenodo. For further inquiries, please contact makogon422833@gmail.com.

<footnote>*Corresponding author:</footnote>
registration of images of reflected light from an in-situ corroding metal interface. Despite these advantages, RM has historically found only a limited number of applications in corrosion analysis, primarily related to passive film rupture events, such as spatial identification of pit locations and measurement of pit size and morphology, with interpretation based on the localisation of low-contrast reflected light regions. [21, 27–31] This limitation was due to the inability to convert the intensity of reflected light into quantifiable physical parameters, restricting analysis to semi-quantitative estimation of pit locations. However, our recent studies on Al6061 alloy, [32] mild steel, [33] and pure Fe substrates [34]—and independently, research by other groups on Al2024 alloy, [26] duplex stainless steel, [24] and Ni-Cr-Mo alloy [23]—have demonstrated that variations in reflected light intensity can be quantitatively correlated with surface film thickness via the Fresnel equations, the same theoretical framework used in ellipsometry. [35] Despite this advancement, the practical minimum thickness of reliably measured surface films remains in the range of a few nanometres, [23, 24, 32–34] while passive film thickness on SSs can be in the sub-nanometre range, [3–8] highlighting the need for further refinement to make RM a reliable tool for PSZ detection.

One approach to overcoming the detection limitations of RM is through the application of machine learning (ML) procedures, which have recently shown significant potential in enhancing microscopy signal processing capabilities. [36–40] The most prominent examples include supervised and self-supervised ML methods for denoising and image restoration based on deep learning architectures, including convolutional neural networks, [36, 37, 41] generative adversarial networks, [38, 39] and autoencoders. [40] For instance, in a recent study, researchers employed a U-Net architecture with the Noise2Noise framework to create Topaz-Denoise, trained on thousands of micrographs collected from various microscopes and cameras across a wide range of imaging conditions, achieving a 100-fold signal-to-noise ratio improvement over raw cryo-electron microscopy images. [37] This approach could, in principle, be adapted to existing RM platforms. However, implementation would require the creation of a training dataset containing paired noisy optical images and their corresponding denoised versions, which is unfortunately not accessible prior to instrumentation improvements in RM. Furthermore, even with improved instrumentation, each RM platform or use case would require its own training dataset, making this approach impractical, time-consuming, and costly.

In contrast to supervised approaches, we opt for unsupervised ML methods, which can operate without requiring pre-labelled training data. [42–46] Various unsupervised techniques, including K-means clustering, [42] Density-Based Spatial Clustering of Applications with Noise (DBSCAN), [43] and dimensionality reduction methods (Principal Component Analysis (PCA) [44, 45] and t-distributed Stochastic Neighbour Embedding (t-SNE) [46]), have been successfully applied to microscopy signal processing in materials science contexts. While it is challenging to quantify the improvement factor in these cases due to the absence of denoised reference images for comparison, some studies attempt to provide measurable metrics. For instance, research employing non-local means denoising with automatically estimated noise standard deviation, followed by K-means segmentation of secondary electron microscopy (SEM) images, yielded results identical to manual human labelling. [42] Another example utilising 'one-shot' learning for automatic denoising and segmentation of Raman microscopy images based on convolutional autoencoders demonstrated a two-fold improvement in signal-to-noise ratio. [47] This enhancement, while less pronounced than that achieved by supervised methods, should still significantly improve state-of-the-art RM detection capabilities and potentially address challenges associated with PSZ detection.

In this context, the objective of this work was to enhance the detection capabilities of an RM using unsupervised ML methods to identify pitting-susceptible zones (PSZ) on stainless steel substrates. The optical signatures extracted through unsupervised ML techniques were rationalised using optical modelling and complementary ex-situ X-ray photoelectron spectroscopy (XPS) surface analysis. We demonstrate this approach through a case study of SS 316L alloy in NaCl electrolyte under anodic polarisation and, based on our proof-of-concept findings, highlight promising future directions for the development of optical corrosion monitoring technologies.

# 2. Experimental

## 2.1. Materials

The 316L-grade SS plates provided by Aperam Industry (France) were cut into rectangles, each measuring ca. 10 mm by 10 mm. The composition and microstructure of the sample were identical to those described in [48]. The sample contains, in addition to Fe, ca. 17% Cr, 10% Ni, and 10% Mo, including some trace elements such as Cu, Mn, and Si. The cut samples were subjected to a series of progressive polishing stages, starting with 320-grit silicon carbide (SiC) and proceeding through 400, 600, and 1200 grit, all cooled with tap water. The samples received their final polish with a 1-micron diamond suspension applied to a PresiTM cloth, resulting in a mirror-smooth surface
finish. AFM measurements revealed a surface roughness of ca. 10–20 nm (Supplementary Information (SI) - 1). The sample was subsequently cleaned with ethanol and deionised water, gently dried with argon, and then placed in the opto-electrochemical cell. Importantly, the surface of the samples exhibited scratches and inclusions after polishing, visible as dark contrasted spots in optical images at *t* = 0 s, prior to pit initiation. However, these areas did not serve as initiation sites for pits (*vide infra*). All experiments were conducted in aqueous solutions of 5 mM–100 mM NaCl (analytical grade, VWR Prolabo), prepared using water purified by a Millipore™ system (18 MOhm×cm).

## 2.2. Reflective microscopy setup

Immediately after polishing and cleaning, the SS 316L plate was fixed at the bottom of a custom-made cylindrical electrochemical cell. The total area of the SS 316L surface exposed to the NaCl electrolyte measured 50 mm², whereas only 1 mm² of this area was examined using an optical microscope. The SS 316L sample served as the working electrode (WE). Above it, a circular platinum net and a leakless 3.4 M Ag/AgCl electrode were placed, serving as the counter (CE) and reference (RE) electrodes, respectively. The electrochemical experiments were conducted using a CHI 660A potentiostat. The electrochemical cell was then placed into an RM setup, where both light illumination and collection occurred from the top (Figure 1a). A detailed description of this setup has been previously documented elsewhere. [32, 34]. In brief, the system incorporated an Olympus microscope fitted with a water immersion objective (magnification ×10, 1.00-NA, Olympus LUMPlanFLN W) with a focal distance of ca. 3.5 mm. Imaging was achieved with an SVCam exo541MU3 CCD camera (SVS-Vistek GmbH, 4496×4504 pixels, 12 bit) operating at 10–25 VDC. To enhance the camera’s acquisition rate, binning was employed, reducing the resolution by a factor of 2 in both x and y dimensions. This adjustment resulted in an individual pixel size of ca. 0.48 µm. A halogen white lamp, filtered to produce λ = 490 nm blue light using an interference filter (with a spectral bandwidth of 20 nm), served as the primary light source. The substrate received top illumination from this blue light beam via the microscope objective. The same objective then collected the reflected light, directing it towards the CCD camera, enabling real-time imaging of the light flux reflected by the analysed surface. Before initiating the electrochemical experiment, the planarity of the SS 316L surface area was ensured (with a precision of 10⁻² °). This was achieved using an interference Mirau objective (magnification ×10 (CF Plan, Nikon)) by minimising the interference fringes over the imaged plane. After confirming the surface planarity, 20 ml of NaCl solutions at neutral pH and varying NaCl concentrations (5 mM, 10 mM, 30 mM, 50 mM, and 100 mM) were introduced into the electrochemical cell. Simultaneously, image acquisition commenced at a frequency of 5 Hz. After adjusting the focus of the optical microscope, we applied a cathodic polarisation of –0.4 V vs 3.4 M Ag/AgCl for 40 s. Subsequently, the sample was left to rest at its open circuit potential (OCP) for 40 s. This procedure was designed to reduce the naturally formed surface layer through cathodic polarisation and then to allow the layer to reform at the OCP. This approach improved the reproducibility of the experiments. After that, a constant potential of +1.6 V vs 3.4 M Ag/AgCl was applied for 3 min. The precise value of the potential was selected based on preliminary tests within the range of 0 V to +1.8 V vs a 3.4 M Ag/AgCl. This ensured the continuous observation of both phenomena (formation of the passive layer and its breakdown) at the same potential over a matter of seconds, thereby guaranteeing a simple and quick experimental protocol. All experiments exhibited consistent trends (*vide infra*), confirming their validity. Repeated trials at 10 mM and 30 mM NaCl further demonstrated reproducibility.

## 2.3. X-ray photoelectron spectroscopy

After the RM experiment, the sample was repolished and allowed to develop a native passive layer under ambient conditions over several hours. This layer was then analysed via XPS. XPS measurements were performed using a K-Alpha+ spectrometer (Thermo Fisher Scientific, East Grinstead, UK) operated in constant analyser energy mode and equipped with a micro-focused and monochromatic Al Kα X-ray source (1486.6 eV, spot size diameter: 400 µm) and a flood gun (charge compensation system for insulating samples). The samples were clipped onto the sample holder and pumped under vacuum overnight. The step size and pass energy used were set to 1 eV/200 eV and 0.1 eV/40 eV for the survey and high-resolution regions, respectively. Data acquisition and processing were carried out using Avantage software, version 5.9902. The surface chemical composition was determined using the manufacturer’s sensitivity factors.

## 2.4. Numerical analysis of optical images

### 2.4.1. Mechanistic aspects of image analysis

Our image analysis procedure is based on the normalisation of light reflectivity (*R*) for two primary reasons. First, the normalised reflectivity expression (1 + Δ*R*/R) accentuates minor variations, making it easier to detect local pits
compared to raw optical images, where such subtle changes may otherwise go unnoticed. [32, 35] Secondly, it enables estimation of variations in surface film thickness on pit-free surfaces. [34] This approach is grounded in the principle of light interference from interfaces and surface films, [23, 24, 32–34] akin to the ellipsometry technique. [35, 49] Normalisation of images was conducted pixelwise by dividing the intensity of the reflected light (I(t)) at each pixel at time (t) by the intensity at that same pixel at the onset of OCP exposure, 40 s prior to chronoamperometry, designated as:

$$1 + \frac{\Delta R}{R} = \frac{I(t)}{I(\text{at OCP})} \qquad (1)$$

Quantitative correlation of 1 + ΔR/R with variations in the thickness of surface films (δ) stems from the Fresnel equations, details of which are available in other sources [23, 24, 32–35] and in SI-2. In brief, correlating such measurements necessitates information on the refractive index (n) of the surface films, which can be estimated based on their known chemical composition, gathered from the literature [3, 5, 50, 51] and XPS analysis herein. In this work, the refractive indices of all used species are n<sub>H₂O</sub> = 1.33, [52] n<sub>Fe</sub> = 1.95 + 3.04i, [53] n<sub>Cr₂O₃</sub> = 2.55, [54] n<sub>Fe₂O₃</sub> = 2.94 + 0.23i. [55]

### 2.4.2. Underlying Machine Learning Concepts in Image Analysis

ML routines were implemented at two stages of image analysis. First, they were utilised for automated pit detection. Second, they were employed to distinguish regions with varying corrosion susceptibility within the passive layer immediately prior to its breakdown.

Identifying autonomous pits numerically resembles anomaly detection. [56] Most optical data exhibit similar patterns, except for pits, which stand out. Anomaly detection is well-established [56] and can be addressed using dimensionality reduction techniques, notably Uniform Manifold Approximation and Projection for Dimension Reduction (UMAP), [57] which has demonstrated strong performance in the literature [58, 59] and in our work. [60] Pitting patterns in UMAP projections were clustered using the Density-Based Spatial Clustering of Applications with Noise (DBSCAN).

Clustering optical signatures of passive layer formation prior to pitting is more nuanced than pit detection. Here, reflectivity changes are more homogeneous with a low signal-to-noise ratio, unlike the stark contrasts of pits, necessitating an algorithm capable of performing image segmentation on noisy time series of optical signatures. Collectively, examples from the literature. [42] and our prior work. [45] demonstrated that the simplest K-means algorithm can be sufficient, which was used herein as a basis to distinguish regions of PSZ. Additional details on the rationale for using UMAP, DBSCAN, and K-means, as well as the tuning of their hyperparameters, can be found in SI-3 and SI-4.

All codes were written in Python using open-source NumPy, OpenCV, Scikit-learn, Matplotlib, and Pandas libraries. Additionally, all developed codes, processed and original data are thoroughly documented and accessible on Zenodo https://doi.org/10.5281/zenodo.14653183, licensed under the Creative Commons Attribution 4.0 International licence.

## 3. Results and discussion

### 3.1. Chronoamperometric initiation of film formation and breakdown processes

To develop a robust approach for detecting regions susceptible to corrosion within the nanometric passive layer, we selected an RM coupled with electrochemistry (Figure 1), which initiates the layer’s formation and subsequent rupture. In this work, we used a mirror-polished SS 316L sample with a surface area of 50 mm² under strong anodic polarisation of +1.6 V vs. Ag/AgCl to induce the formation of a passive layer and subsequent pit initiation within a single experiment. The passive layer initially forms at open circuit potential (OCP) after the reduction of the native oxide, while its further growth continues under strong anodic polarisation. A 1 mm² area of this sample was dynamically monitored optically, with a spatial resolution of 0.48 µm. This field of view enabled simultaneous observation of multiple pit initiation events. This section focuses on the correlation of the chronoamperometry (CA) curve and raw optical images at a 50 mM NaCl concentration to describe the overall observed trends in the film formation and subsequent rupture. The following sections explore a detailed analysis of pit locations in relation to passive film properties, employing unsupervised ML on the entire set of optical images from experiments with NaCl concentrations of 5, 10 (repeated twice), 30 (repeated twice), 50, and 100 mM. Data are available on Zenodo.
<figure><img src="image_4.png" /></figure>

**Figure 1:** (a) Schematic representation of the RM methodology employed to study pitting corrosion in SS 316L. The investigations were conducted under potentiostatic polarisation at +1.6 V vs. the 3 M Ag/AgCl in NaCl solutions ranging from 5 to 100 mM; in total, 7 experiments were performed. The inset illustrates the interference of light beams reflected from the metal/passive layer and passive layer/solution interfaces, utilised to estimate the in-situ thickness of the passive layer via the Fresnel equation (refer to SI-1 for details). (b) Experimental results obtained in the 50 mM NaCl solution, highlighting typical observations. The central panel presents the chronoamperogram recorded after 40 s of OCP, followed by polarisation at +1.6 V vs. 3 M Ag/AgCl, with two distinct periods indicated. Flanking the chronoamperogram are raw optical images captured at 0.0, 0.8, 5.0, and 12.0 s ($t = 0.0$ s marks the onset of potential application). The complete set of images is available in the Zenodo repository. The red square labelled "Pit 1" in the larger optical images denotes the area magnified in the insets below the chronoamperogram, highlighted with a red border. (c) Normalised optical images at $t = 0.0$ and 0.8 s, with normalisation performed pixel-wise using the image captured at the beginning of the 40 s OCP period preceding potential application. The scale bars on the original images are 100 µm and on the magnified images are 10 µm.

Figure 1b presents the CA results for the experiment with 50 mM NaCl solution, identifying two distinct periods. Period 1 begins with the application of potential and persists for ca. 0.8 s, marked by a decrease in current density from 2.4 to 1.1 µA/cm². A comparison of the full raw optical images at the beginning ($t = 0$ s) and end ($t = 0.8$ s) of this period shows no visible changes. However, magnified inset images (marked as Pit 1 in Figure 1b) already show the formation of pits, visible as the appearance of dark, contrast-enhanced spots. The pits appear as dark spots in optical images due to diffuse light scattering within the rough interior of the pit, in contrast to the reflection from the mirror-polished metal surface and light absorption by corrosion products deposited inside the pit. To enhance the
sensitivity of optical detection, we normalised the reflectivity of each pixel relative to the initial OCP image (Figure 1c). The normalised image at *t* = 0 s is uniform, showing no detectable changes with a consistent value of 100%. Compared to the raw optical image at *t* = 0.8 s, the normalised image at the same time in Figure 1c clearly shows a decrease in reflectivity of about 1% on average across the whole image. The decline in current density and light reflectivity points to the formation of a passive layer on the SS 316L surface, which restricts electron transfer and absorbs light. Magnified optical images already reveal the formation of pits, even as the current continues to decline. Note also that the passive layer is highly heterogeneous, as indicated by the normalised image: areas of greater light absorption, which appear more blue in Figure 1c at *t* = 0.8 s, stand in contrast to the whiter regions.

Period 2 commences immediately after Period 1 and is characterised by a distinct increase in current density to 2.2 µA/cm², followed by intermittent spikes until 5 s of polarisation (Figure 1b). At this stage, even unzoomed optical images reveal the formation of dark, contrast-enhanced spots, identified as pits, which are responsible for the sharp rise in current density. The passive film can locally reform after pit initiation and break down again, explaining the intermittent spikes in current density. [28, 61] After 5 s of polarisation, the formation of new pits ceases, while some of the existing ones continue to steadily increase in size, as visible in raw optical images at *t* = 5 s and *t* = 12 s in Figure 1b, accompanied by a steady increase in current density.

All experiments in 5–100 mM NaCl (see datasets in the Zenodo repository) exhibited similar opto-electrochemical patterns: Period 1 with passive film growth ending in breakdown, and Period 2 with pit growth dynamics. Note that although Period 2 could be partitioned into sub-periods based on current density patterns in Figure 1b, we deliberately chose not to perform this subdivision. Instead, we focused on a comprehensive analysis of Period 1 in the present study. The dynamics of preformed pits during Period 2 will be addressed in our forthcoming work.

Key observations from Period 1 that drive further advancement of this work include the following: although surface defects from polishing and surface microstructure are visible at initial times (appearing as dark spots in the optical image at *t* = 0 s in Figure 1b), they are not responsible for pit formation. This is evident from magnified images showing a pit emerging from optically homogeneous regions, indicating that imperfections in the dynamically formed passive layer are the primary cause of pit formation. The normalised image at *t* = 0.8 s in Figure 1c reveals heterogeneities, which can be attributed to these imperfections (such as chromium oxide deficiency. [4, 6, 13, 14]) and linked to the locations of pit formation. In the next section, we further explore this correlation using unsupervised ML approaches.

## 3.2. Identification of pitting-susceptible zones (PSZ)

### 3.2.1. Automated pit detection

The automation of pit detection from optical images served two main purposes: first, to accelerate the otherwise daunting manual data processing; and second, to establish a formal and strict definition of pit detection limits based on optical images. As an example, we analysed the normalised images of Pit 1 in Figure 2a just before pit appearance, where no darkening is observed at *t* = 0 s, slight darkening occurs at *t* = 0.2 s, and distinct darkening appears at *t* = 0.4 s. For clarity, we performed a per-pixel temporal decomposition of this image collection, where the evolution of normalised intensities of individual pixels is plotted as a function of time in Figure 2b. The intensity evolution reveals two distinct patterns: one, depicted with blue curves, shows only a mild decrease over time corresponding to the pit-free interface; while the other, represented by orange curves, exhibits an abrupt decrease at *t* = 0.4 s, corresponding to pit formation. The key question we posed was whether a pit should be considered as already forming at *t* = 0.2 s, where only a mild decrease in intensity is observed, or only at *t* = 0.4 s, where a pronounced and abrupt decrease in intensity occurs.

The intensity at *t* = 0.2 s could have been manually compared to the standard deviation of normalised intensities, but we opted for a more elegant automated solution using UMAP dimensionality reduction. In essence, all individual curves from Figure 2b, representing normalised intensity vs. time, were truncated at predefined cut-off times and transformed into single points in a new coordinate system defined by UMAP axes 1 and 2 (see SI-3 and SI-4 for technical details). According to the rules of this transformation, curves with similar patterns are represented as a single cluster of points, while distinctly different patterns, such as those associated with pitting, form separate clusters. This behaviour is precisely observed in the UMAP projection shown in Figure 2c. At the cut-off time of 0.2 s, only one cluster of points is visible, indicating that the small decrease in intensity at this time remains within the standard deviation of normalised intensities. However, at the cut-off time of 0.4 s, two distinct clusters appear, with the new cluster, depicted in orange, corresponding to pit formation.

The UMAP projections in Figure 2c are reconstructed back into images in Figure 2d to visualise the initial pit area. A comparison of the images at *t* = 0.4 s in Figure 2a and Figure 2d underscores the importance of this procedure, as
<figure><img src="image_5.png" /></figure>

**Figure 2:** Workflow for automatic pit detection illustrated with a single pit (marked as Pit 1 in Figure 1b) example in a 50 mM NaCl solution. A collection of normalised images (shown in (a)) underwent per-pixel temporal decomposition, where normalised light intensities for each pixel were plotted as a function of time frame, as shown in (b). The normalised images were captured during the OCP period (indicated by negative times) and immediately after the onset of polarisation at *t* = 0.0 s. The time interval between consecutive images was 0.2 s, with the curves smoothed using polynomial fitting. To ensure clarity and avoid overcrowding, only 0.2% of all time series is displayed in (b), with orange curves representing a sudden decrease in intensity corresponding to pit formation, and blue curves showing normalised intensity evolution in non-pit areas. The dotted black lines through the orange and blue markers indicate the average behaviour of these two curve types. To identify the onset time of pit initiation, time series data were truncated at predefined cut-off times and subsequently subjected to dimensionality reduction using the UMAP method. The resulting 2D maps are shown in (c) for cut-off times of 0.2 s and 0.4 s. Cut-off times without detected pits are represented by a single cloud of points in the UMAP projection (*t* = 0.2 s, shown in blue). The appearance of pits is marked by the emergence of a second cloud of points in the UMAP projection (*t* = 0.4 s, shown in orange). (d) The UMAP projections were reconstructed back to images, with orange pixels identifying the initially detected pit areas. The size of each pixel (black squares forming the image) is 0.48 µm.

not all dark pixels in the original image correspond to the pit area. This indicates that the intensity in these pixels does not exceed the standard deviation of normalised intensities across the image. This strict formalism allowed us to define pit initiation times and initial pit areas for the entire dataset in 5–100 mM NaCl solutions, as shown in Figure 3. While a similar result could be achieved by defining a threshold in normalised intensity variation, doing so in an unsupervised manner eliminates the need to set this threshold *a priori*, making the approach more objective and data-driven.
<figure><img src="image_6.png" /></figure>

<figure><img src="image_7.png" /></figure>

**Figure 3:** (a) Initiation times for the first appearance of pits vs. the concentration of NaCl solutions. Note that pits appear mostly within one frame or the next (see main text for details). Experiments at 10 mM and 30 mM NaCl were repeated. The dashed red curve is included as a visual reference to highlight the trend between experimental points shown in blue. (b) Quantity of initially detected pits across all experiments vs. the size of these pits, represented on the x-axis in µm² (below) and the corresponding number of pixels (above).

The initiation time of pitting as a function of NaCl concentration, shown in Figure 3a, demonstrates that a decrease in NaCl concentration leads to an increase in initiation time. At 50–100 mM NaCl, the initiation time is 0.4 s, which then gradually increases to 0.5 s (average of two measurements), 0.9 s (average of two measurements), and 1.2 s at 30, 10, and 5 mM NaCl, respectively. This trend aligns well with the literature. [62]. It can be attributed to the more aggressive attack on the passive layer by Cl⁻ anions at higher Cl⁻ concentrations.

It is noteworthy that the majority of pits in all studied NaCl solutions appear within the same frame or, at most, in the subsequent frame. While this suggests that a higher acquisition rate could provide better temporal resolution of pit appearance, the size of initially detected pits rarely exceeds 2–3 pixels or 0.25–1 µm² (Figure 3b). This highlights that, for the given spatial resolution, the chosen 5 Hz acquisition rate is adequately suited to capture the initial pit location, which is of primary importance in this work. However, future studies prioritising a finer resolution of the dynamics of pit appearance may benefit from an improved acquisition rate.

### 3.2.2. Linking passive film optical signatures to pit formation sites

Having identified the exact time frame when pits appear and their initially detected sizes, we sought to investigate whether the locations of their appearance could be deduced based on optical signatures associated solely with the formation of the passive layer. To achieve this, we employed a procedure conceptually similar to pit detection. In the first step, we collected normalised optical images starting from the OCP exposure up until the very last frame before pit formation (Figure 4a), followed by per-pixel temporal decomposition (Figure 4b). In contrast to the pitting detection results shown in Figure 2b, the evolution of normalised intensities in Figure 4b does not exhibit striking differences in behaviour. Instead, all curves follow a consistent trend, with normalised intensities fluctuating within a narrow range of 98% to 102%, showing a slight overall decrease.

Identifying patterns in the curve families presented in Figure 4b is not feasible without employing numerical signal enhancement techniques. To this end, K-means clustering has been applied in this study. The first cluster extracted from K-means is represented by blue curves with overall higher intensities, while the second cluster consists of orange curves with overall lower intensity values (Figure 4b). It is important to note that the clustering process considers the behaviour
<figure><img src="image_8.png" /></figure>

**Figure 4:** Workflow for identifying regions susceptible to pitting corrosion using unsupervised ML, exemplified by an experiment in a 50 mM NaCl solution. (a) Collection of normalised images of the entire observed interface, starting from the onset of OCP recording (-40.0 s) up to the frame immediately preceding the first pit formation (t = 0.2 s). These normalised images underwent per-pixel temporal decomposition, shown in (b). To ensure clarity and avoid overcrowding, only 0.001% of all time series is displayed within a limited time range from -0.4 to 0.2 s. All curves were grouped into two clusters using the K-means algorithm (see SI-3 for the elbow plot). The curves for each cluster are displayed in orange and blue, with dotted black lines representing the average behaviour of the two clusters as determined by K-means. After clustering, the time series were reconstructed into a single image (c), ensuring the colour code remained consistent and orange areas were marked as pitting-susceptible zones (PSZ). The orange dots in (c) denote the locations of initially detected pits (at t = 0.4 s for this time series), with some pits labelled and their zoomed-in insets shown around the reconstructed image. The red contour in the zoomed-in insets delineates the region of initially detected pits, identified via a UMAP-based approach; the red cross denotes the calculated centroid of this region. The size of each pixel (black squares forming the inset images) is 0.48 µm. (d) Illustrates the number of pits across all datasets at 5–100 mM NaCl, plotted against the fraction of pit area located in PSZ (left), and against the distribution of pit centroids inside and outside the PSZ (right). The red lines show the cumulative percentage from the total number of pits.

of the entire curve rather than individual intensity values at specific time points. For instance, if a noisy curve exhibits a few outlier values but overall decreases in intensity, it is still assigned to the orange cluster (visible in Figure 4b). This approach of analysing the entire curve with K-means differs significantly from simple thresholding, which relies on intensity values at specific time points and is unsuitable for this context due to the low signal-to-noise ratio.

The assignment of normalised intensity curves to specific clusters is reconstructed into an image in Figure 4c. This visualisation is overlaid with the initially detected pit regions, which were previously identified through UMAP analysis (marked in orange for one exemplar pit in Figure 2d). Higher magnification images in Figure 4c reveal that pits preferentially initiate in pixels assigned to the orange cluster, which corresponds to regions with lower average normalised intensities and are identified as pitting-susceptible zones (PSZ). For example, Pits 2 and 3 are located entirely within orange pixels. Pits 1, 6, and 7 each include only one blue pixel, with all other pixels belonging to the
<figure><img src="image_9.png" /></figure>

**Figure 5:** (a) Ex-situ XPS spectra for Cr and Fe in the naturally formed surface film on SS 316L, with dotted lines representing the spectral fitting. Peak attribution for the top figure (Cr): 586.3 eV – Cr 2p<sub>1/2</sub>, 583.2 eV – satellite of Cr 2p<sub>1/2</sub>, 576.5 eV – Cr 2p<sub>3/2</sub>, 573.7 eV – Cr<sup>0</sup>. [64] Peak attribution for the bottom figure (Fe): 723.5 eV – Fe 2p<sub>1/2</sub>, 710.4 eV – Fe 2p<sub>3/2</sub>, 719.7 eV – satellite of Fe 2p<sub>3/2</sub>, 706.9 eV – Fe<sup>0</sup>. [65] Further details are in the main text. (b) Correlation between the total electrical charge (extracted from in-situ chronoamperograms) consumed during surface film formation and the normalised intensity (from in-situ normalised optical images) before the appearance of pits. Blue dots represent experimental data, with numbers indicating the NaCl concentration in mM. An asterisk denotes repeated experiments. Solid lines show numerically simulated curves based on the Fresnel equation, assuming a bi-layered passive layer structure with Cr<sub>2</sub>O<sub>3</sub> as the first layer and either γ-Fe<sub>2</sub>O<sub>3</sub> or α-Fe<sub>2</sub>O<sub>3</sub> as the second layer. Details are elaborated in the main text, and the survey spectrum is given in SI-6.

orange cluster. Pit 5 shares more than 50% of its area with orange pixels. To establish the general trend and ensure statistical significance, we analysed entire datasets obtained in 5–100 mM NaCl, encompassing a total of 61 pits, to determine the number of pits as a function of the PSZ area fraction within the pit and as a function of pit centroid position (Figure 4d). The overall conclusion is that pits tend to form within the orange area, identified as the PSZ, with ca. 70% of the initially detected pit area residing completely within the PSZ (Figure 4d, left). Cumulatively, ca. 90% of the pit area is at least half within the PSZ, with only a few examples exhibiting no overlap with the PSZ. A similar trend is observed based on analysis of the centroid position of the pits, with ca. 82% of centroids located within the PSZ (Figure 4d, right). It is important to note that the overall proportion of blue and orange areas is approximately 50%, as visible in Figure 4c. This observation is sufficient to rule out the possibility of random coincidence of orange area dominance within pit areas. Nevertheless, we additionally performed a Chi-Square Test of Independence. [63] (SI-5), which further confirmed that the observed trend of pit locations within the PSZ is statistically significant across our datasets.

This observation constitutes the primary finding of this study, demonstrating that, despite optical intensity signals approaching the detection limit, unsupervised ML methods can reliably identify regions of preferential pitting. These regions would otherwise be identifiable only through resource-intensive and time-consuming laboratory analyses employing high-precision instrumentation (e.g., STM, ToF-SIMS, AFM). At this stage, the conclusion remains purely phenomenological and calls for a physically grounded explanation, which will be provided in the following section.

## 3.3. Interpreting optical signatures

The purpose of this section is to assess whether the current understanding of the physical origin of the PSZ—specifically, chromium deficiency in these regions—can account for the observed optical signatures through optical simulations using Fresnel equations (see Experimental section and SI-2 for details). To conduct these simulations, we first determined the chemical composition of the passive films using XPS. The analyses were conducted on samples that were re-polished after the CA experiments to remove the thick corrosion products ejected from the pits. The samples were then left under ambient conditions for several hours, allowing a new passive layer to form via spontaneous oxidation. Although the precise ratios of chemical species may differ from those present during CA due
to this reformation, the principal constituents of the passive layer remain unchanged. [5, 6, 10, 51, 66] This should be
adequate for fitting optical signatures.

XPS results indicate the presence of Fe₂O₃ and Cr₂O₃ oxides (Figure 5a), while no other elements, such as Mo or Ni (reported in some studies), were detected. [6]. Spectra for these elements are provided in SI-6. XPS analysis of the Fe 2p region reveals several features that elucidate the chemical states of iron in the sample. The peak at 706.9 eV is typically assigned to metallic iron (Fe⁰) or a reduced iron species that may coexist with the oxide, suggesting regions of incomplete oxidation. In contrast, the main Fe 2p₃/₂ peak at 710.4 eV is attributed to Fe(III) in iron(III) oxide (Fe₂O₃) and is usually the strongest signal in a well-oxidised sample. Additionally, the shake-up satellite observed at 719.7 eV is interpreted as arising from multiplet splitting and charge-transfer effects characteristic of high-spin Fe(III) in Fe₂O₃, while the peak at 723.5 eV, corresponding to the Fe 2p₁/₂ main emission, typically appears about 13 eV above the Fe 2p₃/₂ peak, further confirming the presence of Fe(III) in the oxide. [65, 67].

The deconvoluted Cr 2p spectrum exhibits several distinct features that reflect the complex electronic structure of the material (Figure 5a). The peak at 586.3 eV is assigned to the Cr 2p₁/₂ main emission of Cr(III) in Cr₂O₃, confirming that the predominant oxidation state of chromium in the film is +3. [64]. A pronounced signal observed at 583.2 eV is interpreted as a shake-up (satellite) feature associated with the Cr 2p₁/₂ emission; such satellites arise from charge transfer processes or multiplet splitting effects characteristic of Cr(III) in an oxidic environment. [64]. The main Cr 2p₃/₂ peak at 576.5 eV further substantiates the formation of Cr₂O₃, while a lower binding energy feature at 573.7 eV is attributed either to a metallic chromium (Cr⁰) component or to a reduced chromium species. In summary, XPS analysis indicates Cr₂O₃ and Fe₂O₃ in the passive film, matching the typical bi-layered structure of stainless steel passive films (inner compact Cr₂O₃, outer less compact Fe₂O₃). [4, 6]. Given the known chemical composition, the passive layer thickness can be estimated from two independent measurements recorded during Period 1 (Figure 5b): the electrical charge (via Faraday's law) and the optical reflectivity change (via Fresnel's law). However, we needed to assume a specific ratio for the thicknesses of Cr₂O₃ and Fe₂O₃. For simplicity, a 1:1 ratio was chosen. While different ratios would affect the absolute thickness estimates, the trend in thickness distribution across the 5–100 mM NaCl concentrations remains unchanged. This is sufficient to rationalise the optical signatures, though future work could improve this by experimental verification, for example, through transmission electron microscopy (TEM) measurements of film thickness and composition. [9] Details of the theoretical calculations can be found in the SI-2.

Figure 5b presents experimental correlations of two independent electrochemical and optical measurements, along with fitted curves of the bi-layered passive layer under the assumptions outlined above. Two polymorphs of Fe₂O₃ were considered for fitting: α-Fe₂O₃ (blue curve) and γ-Fe₂O₃ (orange curve). Both curves exhibit the same trend: a linear decrease in normalised intensity and a linear increase in charge as NaCl concentration increases, with the blue curve more closely matching the experimental observations.

Validated by these results, we applied this optical model to fit maps of the passive layer's normalised optical intensities from Period 1, focusing on areas where two pits later formed during CA in Period 2 (Figure 6). A bilayer structure consisting of Cr₂O₃ and α-Fe₂O₃ was modelled, with each layer being 0.2 nm in thickness, showing a good fit between the experimental and simulated curves. In regions where chromium depletion occurred, iron oxides served as replacement compounds. The experimental normalised intensities (shown in Figure 6a and b) exhibit very slight variations, ranging from 98.8% to 99.4%. Areas where pits eventually formed, at ca. 10 µm and 30 µm, show a slightly lower intensity of 98.8% compared to the rest of the profile. It is important to note that these are not yet pits, as identical values of 98.8% are also observed in other regions, visible as dark blue areas in Figure 6a, where no pits appear. According to the fit in Figure 6b, these slight variations can be attributed to a depletion of Cr₂O₃ (as shown in Figure 6c), which may explain the susceptibility of these regions to pitting, in agreement with the literature. [4–6, 10, 13, 14, 51]

In spite of the plausibility of this explanation, it is noteworthy that only a small fraction of all areas identified as PSZ (Figure 4c) ultimately evolve into sites of pit formation, suggesting at least two possibilities. The first is that the entirety of the PSZ comprises Cr-depleted passive layer regions, with the areas where pits form experiencing a more extreme deficiency not detectable with the current setup. The second possibility is that the change in normalised optical intensities may not be solely attributable to chromium deficiency, but also to other factors unrelated to the chromium layer. These may include the presence of trace amounts of Mo and Ni, as reported in the literature. [1, 2, 4, 6, 9, 13, 14] While these avenues suggest compelling future research directions, we emphasise that the presented ML-enhanced optical methodology has demonstrated efficacy in identifying regions susceptible to pitting corrosion, correlated to nanoscale heterogeneities within the passive layer. Furthermore, the described analysis of optical signatures provides proof of concept and is, in principle, scalable and applicable to metallic surfaces
<figure><img src="image_10.png" /></figure>

**Figure 6:** Cr deficiency as an explanation for ML clustering of optical signatures in pre-formed passive layers. (a) Normalised intensity around Pits 6 and 7 (as marked in Figure 4c) at *t* = 0.2 s, immediately before their appearance. The solid red contour represents the initially detected size of the pits at the cut-off *t* = 0.4 s of UMAP pit detection. (b) Variation in normalised intensity along the black dotted line shown in (a), plotted as the orange solid curve. This is overlaid with numerical simulations of the optical response for a bi-layered structure comprising 0.2 nm of Cr₂O₃ and 0.2 nm of α-Fe₂O₃ (blue dotted curve). Regions of lower normalised intensity correlate with Cr₂O₃ depletion, modelled as areas with 0.4 nm thick α-Fe₂O₃. (c) Schematic representation of the modelled optical response, illustrating the transition from Cr₂O₃ to α-Fe₂O₃ thickness variations. All figures share the same spatial scale, with the x-axis in (b) cross-referenced with the red dashed lines in (a) to ensure spatial alignment.

employed in structural engineering—for example, in bridges and aircraft—to facilitate the development of optical corrosion monitoring systems. However, systematic validation on materials with realistic surface conditions—such as contamination, roughness, and prior corrosion—remains essential for industrial implementation and constitutes our future focus.

**4. Conclusion**

This work demonstrates that unsupervised machine learning can significantly enhance the capability of reflective microscopy to identify nanoscale heterogeneities in passive films on 316L stainless steel before visible pitting occurs. By applying K-means clustering to optical signatures, we successfully identified pitting-susceptible zones (PSZs) that strongly correlate with subsequent pit formation sites, with 82% of pit centroids located within these zones. This correlation was statistically validated across multiple experiments at varying NaCl concentrations.

Complementary optical modelling and XPS analysis correlated the identified PSZ with chromium-deficient regions in the bi-layered passive film, consistent with established pitting mechanisms. Future work should enhance detection sensitivity to differentiate chromium deficiency levels and explore additional factors affecting pitting. The capability to discern nanoscopic variations in passive film composition via ML-enhanced optical techniques provides an accessible, non-destructive, in-situ approach to corrosion monitoring, potentially suitable for deployment beyond laboratory settings in the future.

**5. Acknowledgements**

This work was financially supported by the Agence Nationale de la Recherche (ANR) Jeunes chercheuses, jeunes chercheurs ANR JCJC programme (OCTAWA project, ANR-22-CE29-0010-01).
# 6. Data Availability Statement

The raw and processed data, along with the Python codes used to reproduce the above findings, are available for download from https://doi.org/10.5281/zenodo.14653183.

# 7. Declaration of Generative AI and AI-assisted technologies in the writing process

During the preparation of this work, the authors utilized commercially available LLM tools, including ChatGPT-4o, to enhance readability and language via API calls in a custom-developed routine available at https://github.com/Shkirskiy/interactive_proofreader.git. Additionally, Claude Sonnet 4 was used to assist with Python code editing. All content and code were subsequently reviewed and edited by the authors, who take full responsibility for the final version of the publication.

# CRediT authorship contribution statement

**A. Makogon:** Conceptualization, Methodology, Software, Validation, Formal analysis, Investigation, Data Curation, Visualization, Writing - Original Draft. **L.B. Coelho:** Conceptualization, Writing - Review & Editing. **J. Ustarroz:** Conceptualization, Writing - Review & Editing. **P. Decorse:** Investigation. **F. Kanoufi:** Conceptualization, Resources, Writing - Review & Editing. **V. Shkirskiy:** Conceptualization, Resources, Writing - Original Draft, Supervision, Funding acquisition.

# References

[1] D. D. Macdonald, Passivity - the key to our metals-based civilization, Pure and Applied Chemistry 71 (1999) 951-978. doi:10.1351/pac199971060951.

[2] S. Choudhary, V. Cruz, A. Pandey, S. Thomas, N. Birbilis, Element-resolved electrochemical analysis of the passivity of additively manufactured stainless steel 316l, Corrosion Science 189 (2021) 109576. doi:https://doi.org/10.1016/j.corsci.2021.109576.

[3] J. J. Kim, Y. M. Young, Study on the passive film of type 316 stainless steel, International Journal of Electrochemical Science 8 (2013) 11847-11859. doi:https://doi.org/10.1016/S1452-3981(23)13227-5.

[4] C.-O. Olsson, D. Landolt, Passive films on stainless steels—chemistry, structure and growth, Electrochimica Acta 48 (2003) 1093-1104. doi:https://doi.org/10.1016/S0013-4686(02)00841-1.

[5] B. Lynch, S. Neupane, F. Wiamé, A. Syeux, V. Maurice, P. Marcus, An xps and tof-sims study of the passive film formed on a model ferrimno stainless steel surface in aqueous media after thermal pre-oxidation at ultra-low oxygen pressure, Applied Surface Science 554 (2021) 149435. doi:10.1016/j.apsusc.2021.149435.

[6] V. Maurice, P. Marcus, Passive films at the nanoscale, Electrochimica Acta 84 (2012) 129-138. doi:https://doi.org/10.1016/j.electacta.2012.03.158.

[7] T. Shibata, T. Takeyama, Pitting corrosion as a stochastic process, Nature 260 (1976) 315-316. doi:10.1038/260315a0.

[8] G. S. Frankel, Pitting corrosion of metals: A review of the critical factors, Journal of The Electrochemical Society 145 (1998) 2186. doi:10.1149/1.1838615.

[9] B. Zhang, J. Wang, B. Wu, X. W. Guo, Y. J. Wang, D. Chen, Y. C. Zhang, K. Du, E. E. Oguzie, X. L. Ma, Unmasking chloride attack on the passive film of metals, Nature Communications 9 (2018). doi:10.1038/s41467-018-04942-x.

[10] L. Wang, S. Voyshnis, A. Syeux, P. Marcus, Ion transport mechanisms in the passive film formed on 304l stainless steel studied by tof-sims with 180° isotopic tracer, Corrosion Science 173 (2020) 108779. doi:https://doi.org/10.1016/j.corsci.2020.108779.

[11] R. C. Newman, 2001 w.r. whitney award lecture: Understanding the corrosion of stainless steel, Corrosion 57 (2001) 1030-1041. doi:10.5006/1.3281676.

[12] P. M. Natishan, W. E. O'Grady, Chloride ion interactions with oxide-covered aluminum leading to pitting corrosion: A review, Journal of The Electrochemical Society 161 (2014) C421. doi:10.1149/2.1011409jes.

[13] R. Wang, Y. Li, T. Xiao, L. Cong, Y. Ling, Z. Lu, C. Fukushima, I. Tsuchitori, M. Bazzaoui, Using atomic force microscopy to measure thickness of passive film on stainless steel immersed in aqueous solution, Sci Rep 9 (2019) 13094.

[14] R. Jung, H. Tsuchiya, S. Fujimoto, Growth process of passive films on austenitic stainless steels under wet-dry cyclic condition, ISIJ International 52 (2012) 1356-1361. doi:10.2355/isijinternational.52.1356.

[15] D. D. Macdonald, The history of the point defect model for the passive state: A brief review of film growth aspects, Electrochimica Acta 56 (2011) 1761-1772. doi:10.1016/j.electacta.2010.11.005.

[16] A. Valor, F. Caleyo, L. Alfonso, D. Rivas, J. M. Hallen, Stochastic modeling of pitting corrosion: A new model for initiation and growth of multiple corrosion pits, Corrosion Science 49 (2007) 559-579. doi:10.1016/j.corsci.2006.05.049.

[17] T. Shibata, T. Takeyama, Stochastic theory of pitting corrosion, Corrosion 33 (2013) 243-251. doi:10.5006/0010-9312-33.7.243.

[18] V. Maurice, P. Marcus, Molybdenum effects on the stability of passive films unraveled at the nanometer and atomic scales, npj Materials Degradation 8 (2024). doi:10.1038/s41529-023-00418-6.

[19] V. Jamebozorgi, K. Rasim, C. Schröder, Computational chemistry analysis of passive layer formation and breakdown mechanisms in ferritic stainless steels, Corrosion Science 235 (2024) 112194. doi:10.1016/j.corsci.2024.112194.
[20] V. Shkirskiy, F. Kanoufi, Reflective microscopy for mechanistic insights in corrosion research, Current Opinion in Electrochemistry 39 (2023) 101259. doi:https://doi.org/10.1016/j.coelec.2023.101259.

[21] R. B. Ribeiro, J. W. de Jesus Silva, L. R. de Oliveira Hein, E. N. Codaro, N. T. Matias, Analysis of surface and profile of pits in austenitic stainless steel aisi 310s by optical microscopy, in: Advanced Powder Technology IX, volume 802 of Materials Science Forum, Trans Tech Publications Ltd, 2014, pp. 446–451. doi:10.4028/www.scientific.net/MSF.802.446.

[22] J. Sullivan, S. Mehraban, J. Elvins, In situ monitoring of the microstructural corrosion mechanisms of zinc–magnesium–aluminium alloys using time lapse microscopy, Corrosion Science 53 (2011) 2208–2215. doi:https://doi.org/10.1016/j.corsci.2011.02.043.

[23] A. Larsson, M. Vorobyova, S. Pfaff, G. Abbondanza, J. Pan, J. Zetterberg, E. Lundgren, Operando surface optical reflectance microscopy study of corrosion film growth on a ni–cr–mo alloy during anodic polarization, The Journal of Physical Chemistry C 127 (2023) 21871–21877. doi:10.1021/acs.jpcc.3c05984. arXiv:https://doi.org/10.1021/acs.jpcc.3c05984.

[24] S. Pfaff, A. Larsson, D. Orlov, G. S. Harlow, G. Abbondanza, W. Linpé, L. Rämisch, S. M. Gericke, J. Zetterberg, E. Lundgren, Operando reflectance microscopy on polycrystalline surfaces in thermal catalysis, electrocatalysis, and corrosion, ACS Applied Materials & Interfaces 13 (2021) 19530–19540. doi:10.1021/acsami.1c04961. arXiv:https://doi.org/10.1021/acsami.1c04961, pMID: 33870682.

[25] P. J. Denissen, A. M. Homborg, S. J. Garcia, Interpreting electrochemical noise and monitoring local corrosion by means of highly resolved spatiotemporal real-time optics, Journal of The Electrochemical Society 166 (2019) C3275. doi:10.1149/2.0341911jes.

[26] A. Homborg, M. Olgiati, P. Denissen, S. Garcia, An integral non-intrusive electrochemical and in-situ optical technique for the study of the effectiveness of corrosion inhibition, Electrochimica Acta 403 (2022) 139619. doi:https://doi.org/10.1016/j.electacta.2021.139619.

[27] W. Zhang, G. Frankel, Transitions between pitting and intergranular corrosion in aa2024, Electrochimica Acta 48 (2003) 1193–1210. doi:https://doi.org/10.1016/S0013-4682(02)00828-9.

[28] S. Choudhary, R. Kelly, N. Birbilis, On the origin of passive film breakdown and metastable pitting for stainless steel 316l, Corrosion Science 230 (2024) 111911. doi:https://doi.org/10.1016/j.corsci.2024.111911.

[29] C. Punckt, M. Bölscher, H. H. Rotermund, A. S. Mikhailov, L. Organ, N. Budiansky, J. R. Scully, J. L. Hudson, Sudden onset of pitting corrosion on stainless steel as a critical phenomenon, Science 305 (2004) 1133–1136. doi:10.1126/science.1101358. arXiv:https://www.science.org/doi/pdf/10.1126/science.1101358.

[30] M. Dornhege, C. Punckt, J. L. Hudson, H. H. Rotermund, Spreading of corrosion on stainless steel: Simultaneous observation of metastable pits and oxide film, Journal of The Electrochemical Society 154 (2006) C24. doi:10.1149/1.2387061.

[31] L. Grandy, R. Lacasse, J. R. Adsetts, C. Hitz, D. Chhin, J. Mauzeroll, Observation of natural convection and particle ejection from stainless steel single pits, Corrosion Science 241 (2024) 112518. doi:https://doi.org/10.1016/j.corsci.2024.112518.

[32] L. Godeffroy, A. Makogon, S. G. Derouich, F. Kanoufi, V. Shkirskiy, Imaging and quantifying the chemical communication between single particles in metal alloys, Analytical Chemistry 95 (2023) 9999–10007. doi:10.1021/acs.analchem.3c01258.

[33] S. Chakri, A. N. Patel, I. Frateur, F. Kanoufi, E. M. M. Sutter, T. T. M. Tran, B. Tribollet, V. Vivier, Imaging of a thin oxide film formation from the combination of surface reflectivity and electrochemical methods, Analytical Chemistry 89 (2017) 5303–5310. doi:10.1021/acs. analchem.6b04921.

[34] A. Makogon, J.-M. Noël, F. Kanoufi, V. Shkirskiy, Deciphering the interplay between local and global dynamics of anodic metal oxidation, Analytical Chemistry 96 (2024) 1129–1137. doi:10.1021/acs.analchem.3c04160.

[35] F. Kanoufi, Electrochemistry and Optical Microscopy, John Wiley and Sons, Ltd, 2021, pp. 1–80. doi:https://doi.org/10.1002/ 9783527610426.bard030108. arXiv:https://onlinelibrary.wiley.com/doi/pdf/10.1002/9783527610426.bard030108.

[36] K. Zhang, T.-T. Nguyen, Z. Su, A. Demortière, Self-supervised image quality assessment for x-ray tomographic images of li-ion battery, njp Computational Materials 8 (2022) 194. doi:10.1038/s41524-022-00870-z.

[37] T. Bepler, K. Kelley, A. J. Noble, B. Berger, Topaz-denoise: general deep denoising models for cryoem and cryoet, Nature Communications 11 (2020) 5208. doi:10.1038/s41467-020-18952-1.

[38] M. Dai, G. Xiao, L. Fiondella, M. Shao, Y. S. Zhang, Deep learning-enabled resolution-enhancement in mini- and regular microscopy for biomedical imaging, Sensors and Actuators A: Physical 331 (2021) 112928. doi:10.1016/j.sna.2021.112928.

[39] H. Wang, Y. Rivenson, Y. Jin, Z. Wei, R. Gao, H. Günaydin, L. A. Bentolila, C. Kural, A. Ozcan, Deep learning enables cross-modality super-resolution in fluorescence microscopy, Nature Methods 16 (2019) 103–110. doi:10.1038/s41592-018-0239-0.

[40] L. Gambini, T. Mullarkey, L. Jones, S. Sanvito, Machine-learning approach for quantified resolvability enhancement of low-dose stem data, Machine Learning: Science and Technology 4 (2023) 015025. doi:10.1088/2632-2153/acbb52.

[41] A. Moncomble, D. Alloyeau, M. Moreaud, A. Khelfa, G. Wang, N. Ortiz-Peña, H. Amara, R. Gatti, R. Moreau, C. Ricolleau, J. Nelayah, aquadenoising: Ai-enhancement of in situ liquid phase stem video for automated quantification of nanoparticles growth, Ultramicroscopy 271 (2025) 114121. doi:https://doi.org/10.1016/j.ultramic.2025.114121.

[42] D. Alagić, J. Pilz, Unsupervised algorithm to detect damage patterns in microstructure images of metal films, in: 2018 IEEE International Conference on Image Processing, Applications and Systems (IPAS), 2018, pp. 67–72. doi:10.1109/IPAS.2018.8708852.

[43] X. Duan, F. Yang, E. Antono, W. Yang, P. Pianetta, S. Ermon, A. Mehta, Y. Liu, Unsupervised data mining in nanoscale x-ray spectro-microscopic study of ndfeb magnet, Scientific Reports 6 (2016) 34406. doi:10.1038/srep34406.

[44] H. Jia, C. Wang, C. Wang, P. Clancy, Machine learning approach to enable spectral imaging analysis for particularly complex nanomaterial systems, ACS Nano 17 (2023) 453–460. doi:10.1021/acsnano.2c08884. arXiv:https://doi.org/10.1021/acsnano.2c08884, pMID: 36537569.

[45] R. Li, A. Makogon, T. Galochkina, J.-F. Lemineur, F. Kanoufi, V. Shkirskiy, Unsupervised analysis of optical imaging data for the discovery of reactivity patterns in metal alloy, Small Methods 7 (2023) 2300214. doi:https://doi.org/10.1002/smdt.202300214.

[46] A. R. Kitahara, E. A. Holm, Microstructure cluster analysis with transfer learning and unsupervised learning, Integrating Materials and Manufacturing Innovation 7 (2018) 148–156. doi:10.1007/s40192-018-0116-9.
[47] P. Abdolghader, A. Ridsdale, T. Grammatikopoulos, G. Resch, F. Légaré, A. Stolow, A. F. Pegoraro, I. Tamblyn, Unsupervised hyperspectral stimulated raman microscopy image enhancement: denoising and segmentation via one-shot deep learning, Opt. Express 29 (2021) 34205–34219. doi:10.1364/0E.439662.

[48] L. B. Coelho, D. Torres, M. Bernal, G. M. Paldino, G. Bontempi, J. Ustarroz, Probing the randomness of the local current distributions of 316 l stainless steel corrosion in nacl solution, Corrosion Science 217 (2023) 111104. doi:10.1016/j.corsci.2023.111104.

[49] J. Kruger, J. Ambrose, Qualitative use of ellipsometry to study localized corrosion processes, Surface Science 56 (1976) 394–412. doi:https://doi.org/10.1016/0039-6028(76)90461-1.

[50] N. E. Hakiki, Comparative study of structural and semiconducting properties of passive films and thermally grown oxides on aisi 304 stainless steel, Corrosion Science 53 (2011) 2688–2699. doi:https://doi.org/10.1016/j.corsci.2011.05.012.

[51] E. Gardin, S. Zanna, A. Syeux, A. Allion-Maurer, P. Marcus, Xps and tof-sims characterization of the surface oxides on lean duplex stainless steel – global and local approaches, Corrosion Science 155 (2019) 121–133. doi:https://doi.org/10.1016/j.corsci.2019.04.039.

[52] G. M. Hale, M. R. Querry, Optical constants of water in the 200-nm to 200-µm wavelength region, Appl. Opt. 12 (1973) 555–563. doi:10.1364/A0.12.000555.

[53] M. R. Querry, Optical constants, Contractor rept. (1985) 415.

[54] R. C. Weast, Handbook of Chemistry and Physics, 68th Edition, CRC Press, Boca Ranton, 1987.

[55] M. N. Polyanskiy, Refractiveindex.info database of optical constants, Scientific Data 11 (2024) 94. doi:10.1038/s41597-023-02898-2.

[56] V. Chandola, A. Banerjee, V. Kumar, Anomaly detection: A survey, ACM Comput. Surv. 41 (2009). doi:10.1145/1541880.1541882.

[57] L. McInnes, J. Healy, J. Melville, Umap: Uniform manifold approximation and projection for dimension reduction, 2020. arXiv:1802.03426.

[58] Q. Zhang, Y. Liu, H. Fang, Manifold learning-based umap method for geochemical anomaly identification, Geochemistry (2024) 126157. doi:https://doi.org/10.1016/j.chemer.2024.126157.

[59] L. Weijler, F. Kowarsch, M. Wödlinger, M. Reiter, M. Maurer-Granofszky, A. Schumich, M. N. Dworzak, Umap based anomaly detection for minimal residual disease quantification within acute myeloid leukemia, Cancers 14 (2022). doi:10.3390/cancers14040898.

[60] A. Makogon, F. Kanoufi, V. Shkirskiy, Is unsupervised dimensionality reduction sufficient to decode the complexities of electrochemical impedance spectra?, ChemElectroChem 11 (2024) e202300738. doi:https://doi.org/10.1002/celc.202300738.

[61] M. Bernal, D. Torres, S. S. Parapari, L. B. Coelho, S. Delfosse, M. Čeh, K. Žužek, S. Šturm, J. Ustarroz, A microscopic view on the electrochemical deposition and dissolution of au with scanning electrochemical cell microscopy – part ii: Potentiostatic dissolution and correlation with in-situ ec-tem, Electrochimica Acta 492 (2024) 144302. doi:https://doi.org/10.1016/j.electacta.2024.144302.

[62] S. Heurtault, R. Robin, F. Rouillard, V. Vivier, Initiation and propagation of a single pit on stainless steel using a local probe technique, Faraday Discuss. 180 (2015) 267–282. doi:10.1039/C4FD00252K.

[63] M. L. McHugh, The chi-square test of independence, Biochem Med 23 (2013) 143–149. doi:10.11613/BM.2013.018.

[64] M. C. Biesinger, C. Brown, J. R. Mycroft, R. D. Davidson, N. S. McIntyre, X-ray photoelectron spectroscopy studies of chromium compounds, Surface and Interface Analysis 36 (2004) 1550–1563. doi:https://doi.org/10.1002/sia.1983. arXiv:https://analyticalsciencejournals.onlinelibrary.wiley.com/doi/pdf/10.1002/sia.1983.

[65] T. Yamashita, P. Hayes, Analysis of xps spectra of fe2+ and fe3+ ions oxide materials, Applied Surface Science 254 (2008) 2441–2449. doi:10.1016/j.apsusc.2007.09.063.

[66] S. Deng, S. Wang, L. Wang, J. Liu, Y. Wang, Influence of chloride on passive film chemistry of 304 stainless steel in sulphuric acid solution by glow discharge optical emission spectrometry analysis, International Journal of Electrochemical Science 12 (2017) 1106–1117. doi:https://doi.org/10.20964/2017.02.43.

[67] M. C. Biesinger, B. P. Payne, A. P. Grosvenor, L. W. Lau, A. R. Gerson, R. S. Smart, Resolving surface chemical states in xps analysis of first row transition metals, oxides and hydroxides: Cr, mn, fe, co and ni, Applied Surface Science 257 (2011) 2717–2730. doi:https://doi.org/10.1016/j.apsusc.2010.10.051.
## Supporting Information:

# Machine Learning-Enhanced Optical Monitoring for Identifying Pitting-Susceptible Zones in 316L Stainless Steel

A. Makogon<fnref n="1" />, L.B. Coelho<fnref n="2" />,<fnref n="3" />,<fnref n="4" />, J. Ustarroz<fnref n="2" />,<fnref n="3" />, P. Decorse<fnref n="1" />, F. Kanoufi<fnref n="1" />, V. Shkirskiy<fnref n="1" />

Emails: aleksei.makogon@cnrs.fr, viacheslav.shkirskiy@cnrs.fr

<footnote n="1">¹ Université Paris Cité, ITODYS, CNRS, 15 Rue Jean Antoine de Baïf, 75013 Paris, France</footnote>

<footnote n="2">² ChemSIN, Chemistry of Surfaces, Interfaces and Nanomaterials, Université libre de Bruxelles (ULB), Campus de la Plaine, Boulevard du Triomphe 2, 1050 Brussels, Belgium</footnote>

<footnote n="3">³ Research Group Electrochemical and Surface Engineering (SURF), Vrije Universiteit Brussel, Pleinlaan 2, 1050 Brussels, Belgium</footnote>

<footnote n="4">⁴ IAlto Ltda, Taió, Santa Catarina, P. José Moacir Moser, 8919000 Taió, Brazil</footnote>
# Contents

<table><tr><td>SI - 1 AFM measurements</td><td>2</td></tr><tr><td>SI - 2. Estimation of surface film thickness from optical and electrochemical signal</td><td>2</td></tr><tr><td>SI - 3. Image analysis procedure</td><td>3</td></tr><tr><td>SI - 4. UMAP hyperparameters exploration</td><td>5</td></tr><tr><td>SI - 5. Details on Statistical Analysis</td><td>6</td></tr><tr><td>Chi-Square Test of Independence</td><td>6</td></tr><tr><td>Hypotheses</td><td>6</td></tr><tr><td>Test Procedure</td><td>7</td></tr><tr><td>Results and Interpretation</td><td>7</td></tr><tr><td>Conclusion</td><td>7</td></tr><tr><td>SI - 6. XPS measurements</td><td>7</td></tr><tr><td>Code Availability</td><td>8</td></tr></table>
## 1. SI - 1 AFM measurements

AFM images were recorded using an NT-MDT Solver Pro scanning probe microscope operating in tapping mode. Topography images were acquired with standard silicon cantilevers. The images were processed using Gwyddion software.

<figure><img src="image_11.png" /><figcaption>**Figure SI1-1:** Atomic Force Microscopy (AFM) topography image of the steel sample surface, showing polishing lines and height variations. (b) Corresponding height profiles along two selected cross-sections, indicating surface roughness variations in the range of 40–60 nm, primarily caused by polishing.</figcaption></figure>

AFM analysis of the steel sample surface revealed that the roughness is characterised by height variations in the range of 10–20 nm, primarily caused by the polishing process. The AFM topography image SI1-1a shows visible polishing lines, indicating the directional nature of the surface modification. The corresponding height profiles SI1-1b further confirm this roughness range, with no significant features beyond the expected variations from polishing.

## 2. SI - 2. Estimation of surface film thickness from optical and electrochemical signal

Estimation of thickness with optical modeling Description of the Fresnel model for the conversion of reflectivity changes to the changes of surface film thickness. In the case of a normal incidence, the light reflectivity (R) of an electromagnetic wave propagating in a medium A (characterized by its real index nA) reflecting on a plane substrate S (characterized by its complex refractive index nS), is the square of the modulus of the reflection coefficient and is given by equation:

$$R_{AS} = |r_{AS}|^2 = \left| \frac{n_A - n_S}{n_A + n_S} \right|^2 \quad (1)$$

When an intermediate thin film of thickness δ (with refractive index nF) is formed between the substrate and the medium (such as chromium/iron oxides located between the stainless steel interface and the electrolytic solution), the expression for the light reflectivity can be written as

$$R_{AFS} = \left| \frac{r_{AF} + r_{FS} e^{\frac{2i2\pi}{\lambda} n_F \delta}}{1 + r_{AF} r_{FS} e^{\frac{2i2\pi}{\lambda} n_F \delta}} \right|^2 \quad (2)$$

where λ is the wavelength of the incident light, rAF and rFS are the reflection coefficients at the medium A/surface film and surface film/substrate interfaces, respectively. The intensity of the reflected light as a function of time (Ir(t)), normalised by the light intensity at t = 0 (Ir(0)), is then linked to the relative variation of the reflectivity as

$$\frac{I_r(t)}{I_r(0)} = 1 + \frac{\Delta R_{AFS}}{R_{AFS}(t=0)} \quad (3)$$

where ΔRAFS = RAFS(t) - RAFS(t = 0).

Reflectivity for a two-layered system.
In our system, we consider a two-layered structure consisting of a hematite (α-Fe₂O₃) film and a chromium oxide (Cr₂O₃) film, both of which are sufficiently thin (nanometre scale) to justify the use of an additive approximation for reflectivity changes. Since the total film thickness remains small compared to the wavelength of incident light, multiple reflections and interference effects between the two layers can be neglected. To account for the contribution of each film, we separately compute the reflectivity change induced by each layer using the Fresnel model and then take a weighted sum of their individual contributions. The weighting is determined by the relative thickness of each layer, allowing us to approximate the total reflectivity change as a function of the evolving oxide film composition. This approach simplifies the analysis while maintaining accuracy in capturing the optical response of the system.

The surface film thickness can also be estimated electrochemically by assuming 100% Faradaic efficiency. The thickness δ is calculated using the total charge (Q) consumed in the oxidation reaction, as follows:

For iron oxide:

$$ \delta(t) = \frac{Q(t) M_{Fe_2O_3}}{2nF\rho_{Fe_2O_3}} \qquad (4) $$

For chromium oxide:

$$ \delta(t) = \frac{Q(t) M_{Cr_2O_3}}{2nF\rho_{Cr_2O_3}} \qquad (5) $$

Where Q(t) is the cumulative charge normalised by the electrode surface area of 0.5 cm². M<sub>Fe₂O₃</sub> and M<sub>Cr₂O₃</sub> are the molar masses of α-Fe₂O₃ (160 g/mol) and Cr₂O₃ (152 g/mol), respectively. ρ<sub>Fe₂O₃</sub> and ρ<sub>Cr₂O₃</sub> are the densities of α-Fe₂O₃ (5.3 g/cm³) and Cr₂O₃ (5.22 g/cm³), respectively. n = 3 (number of electrons transferred). A factor of 2 was added to account for the stoichiometry between Fe and Fe₂O₃, and Cr and Cr₂O₃, in:

$$ 2\text{Fe} + 3\text{H}_2\text{O} \rightleftharpoons \text{Fe}_2\text{O}_3 + 6\text{H}^+ + 6\text{e}^- $$

$$ 2\text{Cr} + 3\text{H}_2\text{O} \rightleftharpoons \text{Cr}_2\text{O}_3 + 6\text{H}^+ + 6\text{e}^- $$

By combining optical and electrochemical estimations, we validate the evolution of surface film thickness during passivation. The experimental data shown in Figure 5b (main text) demonstrate a clear correlation between charge transfer and normalised optical intensity across different NaCl concentrations. Notably, the model assuming a bilayer structure of Cr₂O₃/α-Fe₂O₃ exhibits better agreement with experimental reflectivity changes compared to the Cr₂O₃/γ-Fe₂O₃ model. This suggests that the passive film formed under these conditions is more accurately described by a Cr₂O₃/α-Fe₂O₃ configuration, reinforcing the validity of our approach in characterising the oxidation process.

### 3. SI - 3. Image analysis procedure

To investigate the correlation between passive film properties and pit formation, microscopy image sequences of stainless steel samples were processed using a machine-learning-based pipeline. The image treatment methodology consisted of the following key steps:

* Transformation of Image Sequences into Pixel-Wise Arrays

Each microscopy image sequence was converted into an array representation, where each pixel was tracked across multiple frames. The intensity values were normalised, and temporal changes were recorded, creating a time series for each pixel. This transformation allowed not only the analysis of absolute intensity values but also the characterisation of the shapes of intensity change curves. By analysing these curves rather than single intensity values, we gained deeper insight into the dynamic behaviour of the passive film leading up to pitting events.

* Dimensionality Reduction with UMAP for Pattern Recognition The high-dimensional pixel-wise time series data were projected into a lower-dimensional space using Uniform Manifold Approximation and Projection (UMAP). [1] UMAP is an unsupervised, non-linear dimensionality reduction technique that preserves both local and global structures of high-dimensional data. Here, it was employed as a computer vision tool to detect patterns in the temporal evolution of light intensity at each pixel. By embedding the pixel-wise arrays into a 2D space, UMAP revealed similarities and differences in the oxidation dynamics across the sample surface.
<figure><img src="image_12.png" /><figcaption>**Figure SI3-1:** Elbow plot showing the distortion as a function of the number of clusters (*k*). The most significant reduction in distortion occurs when increasing *k* from 1 to 2, justifying the choice of *k* = 2. Beyond this point, additional clusters provide diminishing returns, indicating that further segmentation may lead to overfitting rather than meaningful differentiation.</figcaption></figure>

Importantly, this transformation was performed without prior knowledge of pit locations, making it a fully data-
driven approach to detecting changes that precede pitting. UMAP is not completely parameter-free. The choice
of parameters depends on the structure of the data. The analysis of the parameters is presented in the following
section

* Clustering with DBSCAN for Pitting Detection To identify when and where pits emerged, we applied the Density-Based Spatial Clustering of Applications with Noise (DBSCAN) algorithm [2] to the 2D UMAP representation. Before pitting, all pixel-wise time series belonged to a single cluster, reflecting uniform oxidation and a gradual decrease in intensity. However, when an additional frame was introduced, a small subset of pixels separated into a distinct cluster. These pixels corresponded to locations where pits appeared, enabling precise detection of both the critical frame when pits became visible and their spatial distribution on the surface.

* Pre-Pitting Segmentation Using K-Means Clustering To explore whether specific regions of the passive film exhibited distinct properties before pitting, we performed K-Means clustering on the arrays from one frame before UMAP separation occurred. This step allowed segmentation of the sample surface into two categories based on the temporal intensity evolution of pixels. The mechanistic interpretation of these clusters, provided in the main text, suggests that they correspond to differences in the passive film's local stability. A silhouette plot SI3-1 was used to assess clustering quality.

To determine the appropriate number of clusters, we employed the elbow method. [3] As shown in Fig. SI3-1, the plot illustrates the distortion (sum of squared distances from points to their assigned cluster centroids) as a function of the number of clusters (*k*). A sharp decrease in distortion is observed when increasing *k* from 1 to 2, representing the most significant improvement in clustering quality. Beyond this point, additional clusters yield diminishing returns, as indicated by the more gradual reduction in distortion. Given that the primary goal of segmentation was to distinguish key differences in the passive film rather than over-segment the data, we selected *k* = 2 to balance accuracy and interpretability. This choice minimises overfitting while still capturing the essential variation in the system.

* Correlation of Pre-Pitting Film Properties with Pit Locations After clustering the pre-pitting arrays, we reconstructed the K-Means labels into a binary image corresponding to the original microscopy frames. A statistical analysis was then conducted to determine whether pits preferentially formed in specific pre-pitting clusters. The results demonstrated a strong correlation: the vast majority of pits appeared within a single cluster, indicating that certain regions of the passive film were more susceptible to breakdown. This finding suggests that the passive film exhibited spatial heterogeneity before pitting initiation, with one region displaying characteristics that made it more prone to localized failure. The details of the statistical analysis are provided in the next section.
This image processing workflow enabled precise detection of pitting events both spatially and temporally, offering a
robust framework for understanding corrosion mechanisms in stainless steel under chloride exposure.

4. SI - 4. UMAP hyperparameters exploration

The Uniform Manifold Approximation and Projection (UMAP) algorithm has two primary hyperparameters that significantly influence the embedding: *n_neighbors* and *min_dist*. In this analysis, we explore the effect of *n_neighbors*, which controls the balance between local and global structure preservation. A lower value emphasizes fine-grained local relationships, while a higher value prioritizes global structure, smoothing the representation. We present UMAP projections of pixel sequences for three different *n_neighbors* values while keeping *min_dist* constant at 0.5 (the default value). The results are shown in SI4-1

* (a) *n_neighbors* = 5: This setting captures highly localized structures, resulting in a more fragmented embedding with noticeable noise. While small-scale variations are well-preserved, the increased noise may obscure broader patterns.

* (b) *n_neighbors* = 15: A balance between local and global structure is achieved. The projection appears smoother than in (a), with distinct clusters still clearly visible.

* (c) *n_neighbors* = 50: The embedding prioritizes global structure, reducing fragmentation but leading to less pronounced cluster separation. Some finer details present in (a) are lost, though the overall organization remains stable.
<figure><img src="image_13.png" /></figure>

<figure><img src="image_14.png" /></figure>

<figure><img src="image_15.png" /></figure>

**Figure SI4-1:** UMAP projections of pixel sequences for different values of *n_neighbors*, with *min_dist* fixed at 0.5. (a) *n_neighbors* = 5: Captures fine-grained local structures but introduces noise. (b) *n_neighbors* = 15: Balances local and global structure, reducing noise while maintaining distinct clusters. (c) *n_neighbors* = 50: Prioritises global structure, leading to smoother embeddings but less pronounced cluster separation. Note that UMAP hyperparameter optimisation was performed on 1/4 of the images to improve computational efficiency.

Across all values of *n_neighbors*, distinct clusters can be identified. However, as *n_neighbors* increases, the separation between clusters becomes less pronounced. This highlights the trade-off in choosing *n_neighbors* depending on whether local details or global relationships are of greater interest in the analysis.

# 5. SI - 5. Details on Statistical Analysis

## 5.1. Chi-Square Test of Independence

The Chi-Square Test of Independence [4] is a statistical hypothesis test used to determine whether two categorical or nominal variables are likely to be related.

### 5.1.1. Hypotheses

* Null Hypothesis ($H_0$): The detected object centers are equally likely to belong to any K-means cluster (no association).
* **Alternative Hypothesis (H<sub>A</sub>):** The detected object centers are disproportionately associated with one K-means cluster (indicating a relationship).

### 5.1.2. Test Procedure

**Data Preparation:** The K-means clustering algorithm classified each pixel in the image into one of two clusters: cluster 0 and cluster 1. A total of 17 centroids of detected objects were identified in the image, representing the centers of the detected objects.

**Observed and Expected Counts:** The observed data consisted of 53 centroids in cluster 0 and 9 centroids in cluster 1. Under the null hypothesis, an equal distribution would result in approximately 31 centroids in each cluster.

**Statistical Testing:** The Chi-Square Test of Independence was performed to compare the observed distribution of centroids in each cluster to the expected distribution under the assumption of equal likelihood.

### 5.1.3. Results and Interpretation

The p-value obtained from the Chi-Square test was less than 0.05, indicating statistical significance. This suggests that the detected object centers are not equally distributed between the two clusters. Specifically, a much larger proportion of the centroids (53 out of 62) belonged to cluster 0, demonstrating a strong association between the detected objects and cluster 0 in the K-means clustering results.

### 5.1.4. Conclusion

Given the statistical evidence, we reject the null hypothesis (*H*<sub>0</sub>). This result suggests that the detected objects predominantly belong to cluster 0, indicating a strong alignment between the clustering algorithm's output and the object detection results. For the code implementation of CHI square test see [5]

## 6. SI - 6. XPS measurements

The XPS spectra for Fe, Cr, Ni, and Mo are presented in the SI6-1. Distinct peaks corresponding to Fe and Cr are observed, confirming their presence in the film. The Cr spectrum shows characteristic peaks at binding energies of 586.3 eV, 583.2 eV, 576.5 eV, and 573.7 eV, while the Fe spectrum exhibits peaks at 710.4 eV, 706.9 eV, 723.5 eV, and 719.7 eV. Additionally, the survey spectrum reveals a peak around 346 eV, which corresponds to the Ca 2p region, suggesting the presence of calcium. This calcium signal is most likely due to surface contamination. In contrast, the spectra for Ni and Mo do not show clear peaks, indicating that their signals are at or below the detection limit. The same observation can be made from the survey spectrum.
<figure><img src="image_16.png" /><figcaption>**Figure SI6-1:** XPS spectra for Cr, Fe, Ni, and Mo show distinct peaks for Cr and Fe, indicating their presence in the passive film. The Ni and Mo spectra exhibit only trace amounts.</figcaption></figure>

## 7. Code Availability

The code developed for this study and the original data are available on Zenodo: https://zenodo.org/uploads/14653184.

## References

[1] L. McInnes, J. Healy, J. Melville, Umap: Uniform manifold approximation and projection for dimension reduction, 2020. URL: https://arxiv.org/abs/1802.03426. arXiv:1802.03426.

[2] M. Ester, H.-P. Kriegel, J. Sander, X. Xu, A density-based algorithm for discovering clusters in large spatial databases with noise, KDD'96, AAAI Press, 1996, pp. 226-231.

[3] E. Umargono, J. E. Suseno, S. V. Gunawan, K-means clustering optimization using the elbow method and early centroid determination based on mean and median formula, in: Proceedings of the 2nd International Seminar on Science and Technology (ISSTEC 2019), Atlantis Press, 2020, pp. 121-129. URL: https://doi.org/10.2991/assehr.k.201010.019. doi:10.2991/assehr.k.201010.019.

[4] M. L. McHugh, The chi-square test of independence, Biochem Med 23 (2013) 143-149. URL: https://www.biochemia-medica.com/en/journal/23/2/10.11613/BM.2013.018. doi:10.11613/BM.2013.018.

[5] A. Makogon, L. Coelho, J. Ustarroz, P. Decorse, F. Kanoufi, V. Shkirskiy, Original data and codes for "machine learning-enhanced optical monitoring for identifying pitting-susceptible zones in 316l stainless steel" article, Zenodo (2025). URL: https://zenodo.org/record/14653184. doi:10.5281/zenodo.14653184.