# Automated petrographic image analysis by supervised and unsupervised machine learning methods

Fares Azzam, Thomas Blaise, Benjamin Brigaud

► To cite this version:

Fares Azzam, Thomas Blaise, Benjamin Brigaud. Automated petrographic image analysis by supervised and unsupervised machine learning methods. Sedimentologika, 2024, 2 (2), pp.1594. 10.57035/journals/sdk.2024.e22.1594. hal-05065352

HAL Id: hal-05065352

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

Submitted on 13 May 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
<figure><img src="image_2.png" /></figure>

# Automated petrographic image analysis by supervised and unsupervised machine learning methods

Fares Azzam* , Thomas Blaise , Benjamin Brigaud

Université Paris-Saclay, CNRS, GEOPS, 91405 Orsay, France

*corresponding author: Fares Azzam (azzamfares.199@gmail.com)

Editors: Giovanna Della Porta and Abosede Abubakre

Reviewers: Georgios Pantopoulos and one anonymous reviewer

Copyediting, layout and production: Romain Vaucher, Georgina Virgo and Faizan Sabir

doi: 10.57035/journals/sdk.2024.e22.1594

Submitted: 17.06.2024

Accepted: 07.10.2024

Published: 01.11.2024

**Abstract** | This study explores the application of machine learning techniques to automate and enhance petrographic workflows, focusing on grain segmentation and feature extraction. We present two novel software tools: GrainSight, which utilizes a supervised deep learning model (FastSAM) for automated grain detection and morphological characterization; and PetroSeg, which employs an unsupervised segmentation approach to explore rock properties and calculate porosity. GrainSight application significantly improves efficiency and accuracy compared to manual methods. The FastSam model enables rapid and accurate grain detection and extraction of morphological features, which can provide insights into depositional environments, sediment routing systems, and reservoir quality. PetroSeg, on the other hand, offers an exploratory approach for porosity quantification, identification of mineral associations, and characterization of textural domains. Both methods offer unique advantages and demonstrate the potential of machine learning in petrographic analysis. Utilizing these tools has the potential to greatly enhance efficiency, objectivity, and data processing, thereby enabling new opportunities for teaching, research, and applications across multiple geological fields. The code of the two applications, GrainSight and PetroSeg, is open-source, available on GitHub and data.gouv.fr.

**Lay summary** | The study of rock samples under a microscope is essential for gaining knowledge about Earth's history and its valuable resources. However, traditional methods are slow, inefficient, and can be biased. This study presents two new computer programs, GrainSight and PetroSeg, powered by artificial intelligence, to automate and improve rock analysis. GrainSight automatically identifies the boundaries of individual grains in a rock and measures their shape, size, and other morphological parameters. This information helps scientists understand how the rock was formed and how the grains were transported. PetroSeg analyzes the distribution of minerals and empty spaces (pores) within the rock. This helps determine important properties like porosity, which is crucial for understanding how fluids, like oil and gas, flow through rocks. These user-friendly programs can significantly speed up analysis, reduce human error, and enable the study of larger datasets, leading to a more comprehensive and objective understanding of rocks and their formation processes.

**Keywords:** Petrographic analysis, Textural analysis, Grain detection, Machine learning, Image segmentation

## 1. Introduction

Machine learning algorithms can be broadly categorized into supervised and unsupervised learning approaches (Hastie et al., 2009; Alpaydin, 2020). Supervised learning involves training models on labeled datasets to make predictions on new data (Hastie et al., 2009), while unsupervised learning aims to identify patterns and structures in unlabeled data without explicit guidance (Jain, 2010). Image segmentation, which involves partitioning an

image into meaningful segments or objects, is a common task in computer vision and plays an increasing role in automated petrographic analysis (Sharma & Aggarwal, 2010; Cheng et al., 2017). Traditional image segmentation techniques, such as thresholding and edge detection (Zhang et al., 2008), often struggle with complex textures and mineral variations. Additionally, camera settings variations, including resolution, focus, and lighting conditions, can further complicate the segmentation process, making it difficult to achieve consistent and reliable results
across different datasets or imaging setups. Deep learning-based methods, particularly convolutional neural networks (CNNs), have demonstrated remarkable success in image segmentation tasks, due to their ability to learn hierarchical features and adapt to diverse image characteristics (Badrinarayanan et al., 2015; LeCun et al., 2015; Ronneberger et al., 2015).

Petrographic analysis, which represents the foundation of understanding rock composition, texture, and formation processes, plays a major role in various geoscience disciplines, including sedimentology, volcanology, and tectonics. By examining thin sections of rocks under a microscope, petrographers can identify constituent minerals and the composition of grain types, characterize their spatial arrangement and grain size distribution, and infer the geological history of the sample (Vernon, 2004). However, petrographic methods rely heavily on time-consuming manual techniques, often leading to subjective interpretations, and limitations in data throughput (Lokier & Al Junaibi, 2016; Dumakor-Dupey & Arya, 2021). The manual identification and characterization of individual grains within a thin section pose significant challenges. Petrographers meticulously trace grain boundaries, measure dimensions, and classify mineral types based on optical properties and visual estimations. This process is laborious and prone to inconsistencies due to human fatigue, inter-observer variability, and potential biases. Furthermore, the manual approach restricts the scope of analysis, hindering the ability to extract statistically robust quantitative data from large sample sets, which is crucial for understanding complex geological phenomena and heterogeneities within rock units.

Several studies have explored the use of Machine Learning (ML) in petrography, primarily focusing on supervised learning approaches. For example, CNNs have been successfully applied to tasks such as grain boundary detection and mineral identification (Tang et al., 2020; Liu et al., 2022; Nichols et al., 2023; Zhang et al., 2024). However, supervised learning requires substantial training datasets with manually labeled grains and minerals, which can be time-consuming and expensive to create. Unsupervised learning techniques present an alternative approach, segmenting images based on inherent similarities in color, texture, or other features, without the need for prior labeling (Kanezaki, 2018; Harb & Knöbelreiter, 2021). While they may not achieve the same level of distinction as supervised methods, unsupervised approaches offer a valuable tool for exploratory analysis and can be very useful for calculating porosity and grouping mineral associations (Latif et al., 2022).

This paper investigates the application of both supervised and unsupervised machine learning techniques in petrography, aiming to address and overcome the limitations of manual methods and pave the way for automated, data-driven petrographic analysis. We present two software: GrainSight, which uses a deep learning model

for automated grain detection and morphological feature extraction; and PetroSeg, which employs unsupervised segmentation to analyze and quantify mineral distribution without labeled data. By evaluating these methods, we aim to demonstrate how machine learning can improve efficiency, objectivity, and data processing in petrographic workflows. The code of the two applications, GrainSight and PetroSeg, is open-source and available on GitHub and at https://recherche.data.gouv.fr, an online data repository hosted by the French administration. The applications can be found by searching for 'GrainSight' or 'PetroSeg' on the platform.

## 2. Methodology

### 2.1. GrainSight for grain boundary detection and feature extraction

GrainSight uses the Fast Segment Anything Model (FastSAM), a cutting-edge deep learning architecture specifically designed for efficient and accurate image segmentation and object detection (Zhao et al., 2023). FastSAM's ability to generate high-quality object masks at remarkable speeds makes it ideal for identifying and segmenting individual grains within complex thin section images. Unlike the original Segment Anything Model (SAM) developed by Meta that relies on a computationally expensive Transformer-based architecture (Kirillov et al., 2023), FastSAM employs a more efficient CNN-based detector, enabling real-time performance without sacrificing accuracy (Zhao et al., 2023). Implementing GrainSight with FastSAM leverages a YOLOv8-seg model, a powerful instance segmentation model based on the "You Only Look Once (YOLO)" architecture. YOLOv8-seg is renowned for its speed and accuracy in detecting and segmenting individual objects within an image. This specific model has been pre-trained on a subset (2%) of the SA-1B dataset, a massive dataset containing over one billion masks for various objects. This pre-training enables the model to effectively recognize and delineate a wide range of shapes and patterns, including those found in thin section images of geological samples. GrainSight utilizes this pre-trained YOLOv8-seg model as the initial step in its automated grain detection and segmentation pipeline. The model analyzes the input thin section image and identifies all potential objects, including individual grains. The output of this stage is a set of segmentation masks, each highlighting a potential grain within the image. These masks serve as a foundation for further analysis, enabling GrainSight to extract quantitative morphological features for each detected grain and perform subsequent calculations related to grain size distribution.

GrainSight is implemented as a user-friendly web application built using the Streamlit framework (Figure 1). The application allows users to upload thin section images in JPG, PNG, or JPEG formats, adjust segmentation parameters, set the scale for measurements, and visualize the segmented image with grain boundaries and extract-
<figure><img src="image_3.png" /><figcaption>**Figure 1** | User interface of the GrainSight app, featuring adjustable algorithm parameters such as image input size, IoU (Intersection over Union) threshold, and confidence threshold. The analysis results are summarized in a table and displayed as a cumulative frequency plot of grain size distribution. Intersection over Union (IoU) threshold is used to evaluate the performance of object detection by comparing the ground truth bounding box to the predicted bounding box. YOLOv8 also applies a confidence threshold to filter out low-confidence predictions. Predictions below these thresholds are not considered.</figcaption></figure>

ed features displayed in a tabular format. Users can also
download the results as a CSV file for further analysis and
visualization. Morphological features are extracted from
each segmented grain using the OpenCV library. The
extracted features include (1) the area, which represents
the total number of pixels within the segmented grain
area; (2) perimeter, which measures the length of the
boundary enclosing the grain; (3) circularity, calculated as
4 times the area divided by the square of the perimeter,
representing how closely the grain shape resembles a
circle [this measure is sometimes referred to as roundness
in the literature, but we use circularity to avoid confusion
with more complex roundness estimations, see Blott and
Pye (2008)]; (4) aspect ratio, measuring the ratio between
the longest and shortest dimensions of the grain; (5)
longest length, representing the longest Feret diameter
of the grain, which is the maximum distance between any
two points along its boundary. To obtain accurate mea-
surements, pixel-based features are converted to physical
units (e.g., micrometers) using a scale factor determined
from a reference line drawn on the image with a known
length. GrainSight is designed to handle a wide range of
image resolutions and input shapes, offering flexibility for
users with diverse datasets. The app can process images
with both lower and higher resolutions, including resolu-
tions below 72 dpi. Importantly, it provides the option to
redefine the input shape of the image, allowing users to
adjust the image dimensions according to their specific

needs and computational resources. This feature is par-
ticularly useful for handling large images or optimizing
processing time on less powerful computers. Higher reso-
lutions can potentially provide more detailed information
for grain boundary detection, but they may also increase
processing time. Ultimately, the choice of image resolution
and input shape depends on the specific requirements of
the analysis and the available computational resources.

## 2.2. PetroSeg: Unsupervised segmentation for quantitative measurements

PetroSeg applies an unsupervised segmentation algo-
rithm, namely an enhanced version of the InfoSeg algo-
rithm for unsupervised semantic image segmentation
(Harb & Knöbelreiter, 2021). This novel approach is particu-
larly important for its focus on segmenting images without
requiring labeled training data, making it highly versatile
for a wide range of applications. This eliminates the reli-
ance on potentially biased and labor-intensive manual
labeling, opening doors for faster and more objective
exploration of diverse datasets. The algorithm begins with
pre-segmentation of the image into small regions with
potentially similar semantic content, using the Felzensz-
walb algorithm (Felzenszwalb & Huttenlocher, 2004). The
convolutional network then extracts features and refines
the segmentation, merging regions with similar semantic
information into larger ones, until a final segmentation is
<figure><img src="image_4.png" /><figcaption>**Figure 2** | User interface of the PetroSeg app, providing users with the ability to investigate and analyze image features using customizable parameters and color-coded labels.</figcaption></figure>

achieved. In petrographic analyses, this approach facilitates the visual exploration of potential mineral associations, which aids in identifying and quantifying mineral phases based on their optical properties, such as color and texture. This enables the estimation of mineral proportions within the sample. PetroSeg is implemented as a user-friendly Streamlit web application (Figure 2). The software has an intuitive interface that allows users to perform various tasks. Users can upload images, adjust segmentation parameters, and explore the segmented results interactively. They also have the option to choose segment colors. Using unsupervised segmentation eliminates the need for prior training data or manual annotations, allowing users to gain insights into the composition and microstructure of their samples.

# 3. Results and discussion

## 3.1. GrainSight: Automated identification of sedimentary rock texture

GrainSight adaptability and use across different thin section images show its potential to improve morphometric analysis. This is especially true for sedimentary rocks, where grain size and shape analysis are essential for inferring depositional environments, reservoir quality, and mechanical properties. However, the principles of this analysis can be extended to a wide range of lithologies, including igneous and metamorphic rocks. For example, grain morphology in volcanic tuffs can provide insights into eruption dynamics and fragmentation processes which can help understand the crystallization history and magmatic processes in granites. Similarly, grain size and shape analysis

in metamorphic rocks can reveal information about deformation mechanisms and metamorphic grade. Future work will explore the application of GrainSight to these diverse lithologies, demonstrating its potential for broader applications across various geological disciplines. The application of GrainSight in petrographic analyses can benefit numerous fields, as illustrated by the following examples.

### 3.1.1. Textural analysis of sandstone

Grain size and shape are key indicators of the transport and depositional processes that have shaped a sandstone. Well-sorted sandstones with rounded grains often suggest deposition in high-energy environments like beaches or aeolian dunes, where prolonged transport and abrasion can reduce angularity and increase sorting (Blott & Pye, 2008). However, it's important to note that roundness can also result from multiple cycles of erosion and redeposition. For instance, well-rounded quartz grains in low-energy settings may have been recycled from older, pre-existing sandstones. Recycling of grains is a key concept in sedimentary geology, as materials can undergo several rounds of erosion, transport, and redeposition before their final deposition. Grains in mature sandstones may show characteristics of several past environments due to these recycling processes (Kleesment, 2009). Conversely, poorly sorted sandstones with angular grains are more indicative of deposition in lower-energy environments such as river floodplains or glacial settings, where transport distances are shorter and there is less opportunity for grain modification (Cheng et al., 2023). Analyzing these textural parameters also provides valuable data for reserving characterization and quality assessment. Well-sorted
sandstones with larger grain sizes typically have higher porosities and permeabilities, making them more favorable for fluid flow and hydrocarbon production. Conversely, poorly sorted sandstones with smaller grain sizes tend to have lower porosities and permeabilities, reducing their reservoir potential.

In our comparative study, we analyzed 25 sandstone thin sections using both manual grain boundary tracing and GrainSight. The studied samples originated mainly from various formations within the North Sea Basin, primarily deposited in shallow and deep-sea environments with complex diagenetic histories (Azzam et al., 2022). Thin sections were examined with a Leica DM750P polarizing petrographic microscope at 4x magnification, producing digital images with an average pixel size of 2.24 µm and a horizontal field of view (HFOV) of 6.38 mm (Figure 3A). In addition to these methods, we attempted object extraction using thresholding techniques, which involved separating objects of interest from the background based on pixel intensity values (Sezgin & Sankur, 2004; Roduit, 2007). For grain boundary detection, we selected a range of pixel intensity values corresponding to the boundaries, and classified pixels within this range as foreground (object) and those outside as background. However, these methods were less efficient and more sensitive to variations in image quality and lighting conditions compared to GrainSight. Therefore, they were not included in the main comparative analysis. The results showed a significant difference in terms of time efficiency between manual tracing and GrainSight. GrainSight achieved a remarkable reduction in analysis time, reducing it from 155 minutes per image to only ~3 minutes per image (Table 1). This gain in efficiency represents a major improvement for petrographers working with large datasets or under time-sensitive project constraints. GrainSight also enabled the analysis of a significantly larger sample size (570 grains on average; Table 1) compared to manual tracing, leading to more representative calculations of the studied sample (Figure 3A, B). This is crucial as manual tracing is subjective and petrographers often overlook smaller grains in favor of larger ones. It's important to note that no grain size cut-off was applied in the current version of GrainSight. Although it is acknowledged that grains smaller than 10 microns can be difficult to measure in thin section reliably, and grains larger than 1–2 mm may not be entirely captured within the field of view. Furthermore, the grain size data presented were not corrected for the potential underestimation inherent in thin section measurements, which can arise due to factors such as mineral type and grain orientation (Ragusa & Kindler, 2018). Also, grain boundaries touching image limits were included in the analysis, as GrainSight can still accurately segment portions of these grains. Future versions of GrainSight will incorporate options for applying both grain size cut-offs and thin section corrections based on user-defined parameters, thereby enhancing the accuracy and flexibility of grain size analysis. The cumulative frequency curves for grain size measurements, obtained through both manual methods and GrainSight,

<table><caption>**Table 1 |** Comparison of Manual Tracing (JMicroVision) and GrainSight for Grain Analysis</caption><thead><tr><td>Parameters</td><td>Manual Tracing (JMicroVision)</td><td>GrainSight</td></tr></thead><tbody><tr><td>Time (minutes)</td><td>~ 155 min</td><td>~ 3 min</td></tr><tr><td>Grain Count</td><td>~ 350</td><td>~ 570</td></tr><tr><td>Precision</td><td>-</td><td>0.96</td></tr><tr><td>Recall</td><td>-</td><td>0.92</td></tr><tr><td>F1-Score</td><td>-</td><td>0.94</td></tr><tr><td>Misidentified grains</td><td>-</td><td>~ 4%</td></tr><tr><td>Memory usage</td><td>Low</td><td>Medium to High</td></tr></tbody></table>

demonstrate a high degree of overlap, indicating strong agreement and validating the accuracy of GrainSight (Figure 3C). However, small deviations were also apparent, potentially attributed to GrainSight's ability to detect a greater number of grains that might be overlooked or difficult to distinguish during manual measurements, including smaller grains or those with less distinct boundaries. This increased sensitivity, while potentially providing a more comprehensive analysis, requires careful inspection to avoid over-segmentation and the inclusion of false positives.

We measured the performance of the FastSam model in identifying grains by assessing the precision, recall, and F1 score achieved in some of the studied samples (Table 1). With an average precision of 0.96, the software correctly classified 96% of identified objects as actual grains, highlighting its accuracy in avoiding false positives. The recall value of 0.92 indicates that the model detected 92% of the grains in the images, showcasing its ability to capture a large portion of the target objects. The F1 score, which balances precision and recall, reached 0.94, confirming the model's reliability and effectiveness in grain identification. While the model exhibits high accuracy, a small portion (4%) of grains were misidentified (including intersected objects or artifacts). Users are also encouraged to carefully review the segmented results and utilize their expertise to identify and correct any potential misidentifications or artifacts, ensuring the accuracy and reliability of the analysis. This underscores the importance of ongoing validation and potential parameter adjustments (e.g., confidence threshold) based on specific research objectives and acceptable error margins. Finally, it is worth noting that GrainSight requires medium to high memory usage, depending on the size of the images and the number of objects detected.

### 3.1.2. Zircon characterization

Zircon plays a crucial role in understanding the age, origin, and tectonic history of rocks, due to its ability to incorporate trace elements and preserve isotopic data (Fonneland et al., 2004). GrainSight high-resolution object detection and precise contour detection capabilities allow for extracting key morphological parameters from zircon grains, including elongation, roundness, surface roughness, and sphericity. As demonstrated in Figures 4A
<figure><img src="image_5.png" /><figcaption>**Figure 3** | (A) Microscopic image of a sandstone sample exhibiting a poorly sorted, medium to coarse-grained texture. (B) The same image after automated grain detection with GrainSight, demonstrating that the software has detected almost all the grains despite the varying texture. (C) Cumulative frequency curves of grain size distributions for five sandstone samples, obtained through both manual measurements and automated image analysis software (GrainSight). A strong agreement between the manual methods and GrainSight is evident.</figcaption></figure>

and 4B, the model clearly identifies and labels each grain, even in images with potential boundary uncertainties. This enables detailed analysis of morphological parameters with a high level of accuracy and minimal misidentification (Figure 4C). These parameters are essential for tracing the origin of zircon grains. For example, elongation helps assess the transport and recycling history, while roundness provides insights into the degree of abrasion and transport processes (Gärtner et al., 2013). By combining these parameters, petrographers can categorize zircon grains into distinct groups, revealing valuable information about their source, depositional environment, and degree of recycling (Azzam et al., 2024).

### 3.1.3. Applications beyond sedimentary rocks

GrainSight can be applied to various rock types beyond sedimentary rocks. In igneous rocks, it aids in analyzing grain size and shape, identifying phenocrysts, and assessing textural components. In metamorphic rocks, it facilitates

the identification of mineral grains, analysis of foliation, and characterization of mineral zonation (Figure 5A, B). Further fine-tuning of the model on specific cases or rock types is expected to grow the impact of this model across a range of diverse fields.

## 3.2. PetroSeg

### 3.2.1. Porosity calculation

Understanding the distribution and characteristics of pore spaces within rocks is crucial for evaluating reservoir quality, fluid flow, and overall rock properties. Fortunately, most conventional methods for preparing rock thin sections use epoxy resin containing a blue dye injected into the pore system. This distinctive blue coloration allows PetroSeg to distinguish pore spaces from mineral grains easily, enabling quick computation of porosity as a fraction of the total image area (Figure 6A, B). The porosity analysis example presented in Figure 6 was based on 15
<figure><img src="image_6.png" /><figcaption>**Figure 4** | (A) Cathodoluminescence image of a sample featuring various zircon grains in blue fluorescence. (B) The same image after automated processing with GrainSight, shows individual grains that were detected and colored distinctly. (C) Bar chart summarizing the results of the automated grain counting process, presenting the total number of grains, correctly identified grains (True positive), missed grains, and misidentified grains (False positive).</figcaption></figure>

thin section images of sandstones from the Agat Formation (Norway), characterized by varying degrees of porosity and cementation. PetroSeg's results strongly agree with manual point counting methods and offer a significant reduction in analysis time. This is demonstrated by a strong positive correlation (R² = 0.78) between the software porosity calculations and those obtained through point counting (Figure 6C). This highlights its potential for analyzing large datasets and its implication in studies that require statistically robust porosity comparisons across multiple samples. In contrast, traditional image thresholding methods, such as histogram thresholding, have a weak correlation with manual point counting, given their limitations in analyzing complex images (Figure 6C). PetroSeg provides a noticeable improvement in speed and efficiency and can handle complex images.

### 3.3.2. Estimation of cement and other minerals

Differentiating cement from framework grains is very challenging using traditional thresholding techniques. Figure 7A shows an example of a sandstone cemented by calcite that has been stained with alizarin-potassium ferricyanide. By adjusting the segmentation parameters, PetroSeg isolates the cementing materials, allowing for easy calculation of calcite cement volume and highlighting its distribution within the rock sample (Figure 7B). Cementing mate-

rials like siderite, dolomite, hematite, and chlorite can also be easily segmented using PetroSeg. This is crucial for understanding diagenetic processes, evaluating reservoir quality, and assessing the mechanical properties of sedimentary rocks. In addition, the software demonstrates a remarkable proficiency in the analysis of intensely colored minerals, including opaques that generally manifest as dark or black regions, as well as glauconite and chlorite, which exhibit green hues in thin sections (Figure 7C). The software effectively segments these phases, enabling accurate estimation of their abundance and distribution within the rock (Figure 7D).

### 3.2.3. Identifying mineral phases in SEM images

The grayscale values observed in backscattered electron-scanning electron microscope (BSE-SEM) images correspond directly to the density of the constituent materials. This density is, in turn, related to the atomic number of the present elements. PetroSeg leverages this relationship by analyzing these grayscale values to distinguish and segment different mineral phases within the image effectively. When supplemented with additional data sources, such as the elemental composition obtained through energy-dispersive X-ray spectroscopy (EDS), PetroSeg can generate maps of mineral associations and provide quantification. The use of PetroSeg for SEM image anal-
<figure><img src="image_7.png" /><figcaption>**Figure 5** | (A) Example of GrainSight application on a polarized light micrograph of a thin section of mica schist. (Image from https://www.sciencephoto.com/media/135371/view/mica-schist-thin-section-polarised-lm). (B) Segmented image of the same rock sample. Note the complexity of the sample.</figcaption></figure>

<figure><img src="image_8.png" /><figcaption>**Figure 6** | (A) Thin section image of a sandstone with various minerals showing high visible porosity. (B) PetroSeg segmentation of the same image, with color-coded labels and calculated percentages of each component. (C) Left: Scatter plot comparing the porosity obtained by manual point-counting and PetroSeg segmentation, revealing a strong positive correlation ($R^2$ = 0.78). Right: Scatter plot comparing the porosity percentage obtained by manual point-counting and histogram thresholding, showing no correlation ($R^2$ = 0.38). This highlights the superior accuracy of PetroSeg for automated mineral quantification compared to traditional thresholding methods.</figcaption></figure>

ysis offers several key advantages. Firstly, the segmented images enhance visualization of the different mineral phases and their spatial distribution. This is particularly valuable in cases where chemical mapping is not available (Figure 8A). Additionally, the software allows for the customization of the segmented image by assigning specific colors to each identified phase, thereby facilitating visual interpretation and analysis (Figure 8B). An excellent

example of this is demonstrated in Figure 8C, where the distribution of chlorite coats around quartz grains can be easily mapped and quantified using PetroSeg (Figure 8D). However, certain challenges can arise when analyzing SEM images, particularly those with variations in brightness, contrast, or surface topography. For example, minerals with similar grayscale values, such as quartz and feldspar or calcite and aragonite, may be difficult to distinguish
<figure><img src="image_9.png" /><figcaption>**Figure 7** | (A) Thin section image of a calcite-cemented sample before segmentation. (B) Same image after segmentation; PetroSeg effectively isolates the calcite materials from the framework grains. (C) Thin section image of a sandstone cemented by chlorite and illite. (D) Same image after segmentation showing clear separation of mineral groups through proper parameter selection.</figcaption></figure>

solely based on grayscale information. This can lead to inaccuracies in mineral identification and quantification. To overcome these challenges, it is crucial to optimize the segmentation parameters and implement appropriate pre-processing steps to achieve optimal results. Integrating complementary data sources, such as EDS elemental mapping, can further enhance the accuracy of mineral identification and resolve ambiguities caused by similar grayscale values. Despite these challenges, unsupervised segmentation offers a valuable tool for applications across various geological samples.

## 4. Limitations and perspectives

While both supervised and unsupervised methods hold great potential for advancing petrographic analysis through automation, it is essential to recognize their limitations and consider future improvements. GrainSight is great for grain detection and morphological analysis but lacks direct mineral identification capabilities. Integrating the current model with other deep learning algorithms trained on specific mineral types could address this gap, and further automate thin section analysis in sedimentary geology. Moreover, GrainSight may encounter difficulties with complex lithologies that exhibit poorly defined grain boundaries or significant textural variations, necessitating

further model fine-tuning for specific use cases. As an example, the automated distinction between a detrital quartz grain and a quartz overgrowth is very difficult to achieve. Similarly, PetroSeg faces challenges in mineral distinction due to its reliance on features like color and texture for segmentation, which may not always correspond to distinct mineral phases. Combining PetroSeg with other techniques such as EDS or Fourier-transform infrared spectroscopy (FTIR) could enhance mineral identification accuracy. Furthermore, optimizing segmentation parameters in the algorithm may require some experimentation and domain knowledge to achieve the best result. Complex textures with subtle mineral variations may also pose difficulties for PetroSeg, requiring the exploration of advanced image processing techniques or the development of more sophisticated unsupervised algorithms.

Addressing these limitations through further research and development will solidify the role of machine learning as an indispensable tool in petrographic analysis.

## 5. Conclusion

This work offers an insight into the potential of machine learning in transforming the field of petrography. Both supervised and unsupervised methods offer significant
<figure><img src="image_10.png" /><figcaption>**Figure 8** | PetroSeg analysis of BSE-SEM images of sandstones. (A) BSE-SEM image of a sandstone sample before PetroSeg segmentation. (B) The same image after segmentation by PetroSeg, shows the effective delineation of various minerals and cement. (C) BSE-SEM image of a sandstone with chlorite coating before PetroSeg segmentation. (D) The same image after segmentation by PetroSeg, enables easy mapping and quantification of the chlorite.</figcaption></figure>

advances in efficiency, objectivity, and image processing capabilities, promoting a wider range of applications across various geological disciplines. GrainSight, based on FastSam, a novel supervised deep learning model, excels in automated grain detection and morphological feature extraction. This significantly reduces analysis time and removes subjective bias, allowing petrographers to quickly understand sedimentary rock textures, zircon characteristics, and features in igneous and metamorphic rocks. On the other hand, PetroSeg employs an unsupervised segmentation approach to quantify mineral distributions and calculate porosity without the need for labeled training data. It has proved valuable for investigating mineral associations, diagenetic processes, and reservoir quality. However, several challenges remain in the application of these methods. Improvements in the performance of the FastSam model can be achieved by fine-tuning the model for specific applications. PetroSeg may also face challenges in interpreting complex images, which may require careful tuning of the parameters for individual

image analyses. As these tools advance, machine learning will increasingly transform petrography, revolutionizing how geologists examine and analyze geological samples.

## 6. Code availability and online demo

The open-source code for the two applications, GrainSight and PetroSeg, is available on GitHub (https://github.com/fazzam12345/grainsight, https://github.com/fazzam12345/PetroSeg) and can be directly accessed via data.gouv.fr (https://www.data.gouv.fr/fr/datasets/grainsight/, https://www.data.gouv.fr/fr/datasets/petroseg/). We highly recommend running the applications on local computers for optimal performance and functionality. However, for convenience and quick testing, online demos are available on Hugging Face Spaces (https://hugging-face.co/spaces/fazzam/GrainSight, https://huggingface.co/spaces/fazzam/PetroSeg). These online demos allow users to explore the basic features of the applications without the need for local installation. When using the
two apps, consider the following recommendations. For GrainSight, the input image size plays an important role in object detection and contour tracing. More objects can be detected when increasing the size of the input image, resulting in smoother contours, however, choosing a larger size can increase the processing time, especially on computing-limited PCs. Users are encouraged to experiment with different settings to find the optimal balance between accuracy and efficiency for their datasets. Another important parameter is the confidence threshold, where lower values may result in more detected objects but can increase false positives or intersected objects. Careful experimentation with these two parameters is essential for optimal results. For PetroSeg, the performance may vary significantly depending on the type of thin sections and images. Complex images may require higher training epochs (the number of times the model iterates through the entire training dataset) to obtain representative segments, but this can increase the processing time per image. Lowering the model dimensions can speed up the training and processing and lead to a faster convergence of segments, but it can also lead to undesired results. For fine-grained segmentation, we recommend increasing the size of the input image, however, the default values work very well in most cases. Finally, some experimentation with the model's parameters may be necessary for optimal performance.

## Acknowledgments

We thank the Geops (Geoscience Paris Saclay) laboratory for access to the thin section samples. We also appreciate the insightful feedback from the reviewers: Georgios Pantopoulos, an anonymous reviewer, and Associate Editor Dr. Abosede Abubakre, which greatly improved this manuscript. Lastly, we acknowledge Sedimentologika and DOAJ for their commitment to open, accessible science.

## Authors contribution

Fares Azzam conceptualized the study, developed the methodology, designed and implemented the code for GrainSight and PetroSeg, performed the formal analysis and data investigation, curated the datasets, wrote the original draft of the manuscript, and oversaw the project's execution. Benjamin Brigaud provided insights on the interpretation of the results and contributed to the review and editing of the manuscript. Thomas Blaise conducted extensive testing of the software applications and contributed to the review and editing of the manuscript.

## Conflict of interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

## References

Alpaydin, E. (2020). Introduction to Machine Learning (4th ed.). MIT Press. ISBN 9780262043793.

Azzam, F., Blaise, T., Patrier, P., Abd-Elmola, A., Beaufort, D., Portier, E., Brigaud, B., Barbarand, J., & Clerc, S. (2022). Diagenesis and reservoir quality evolution of the Lower Cretaceous turbidite sandstones of the Agat Formation (Norwegian North Sea): Impact of clay grain coating and carbonate cement. Marine and Petroleum Geology, 142, 105768. https://doi.org/10.1016/j.marpetgeo.2022.105768

Azzam, F., Blaise, T., Patrier, P., Beaufort, D., Barbarand, J., Elmola, A. A., Brigaud, B., Portier, E., & Clerc, S. (2024). Impact of sediment provenance and depositional setting on chlorite content in Cretaceous turbiditic sandstones, Norway. Basin Research, 36(3), e12867. https://doi.org/10.1111/bre.12867

Badrinarayanan, V., Kendall, A., & Cipolla, R. (2015). SegNet: A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation. IEEE Transactions on Pattern Analysis and Machine Intelligence, 39(12), 2481-2495. https://doi.org/10.1109/TPAMI.2016.2644615

Blott, S. J., & Pye, K. (2008). Particle shape: A review and new methods of characterization and classification. Sedimentology, 55(1), 31-63. https://doi.org/10.1111/j.1365-3091.2007.00892.x

Cheng, G., Han, J., & Lu, X. (2017). Remote Sensing Image Scene Classification: Benchmark and State of the Art. Proceedings of the IEEE, 105(10), 1865-1883. https://doi.org/10.1109/JPROC.2017.2675998

Cheng, W., Chen, S., Zhu, J., Zhong, X., Hu, J., & Guo, J. (2023). Identification of the Sediment Movement Mechanism via Grain Size and Shape: A Case Study of a Beach in Eastern Hainan Island in South China. Water, 15(20), 3637. https://doi.org/10.3390/w15203637

Dumakor-Dupey, N., & Arya, S. (2021). Machine Learning—A Review of Applications in Mineral Resource Estimation. Energies, 14(14), 4079. https://doi.org/10.3390/en14144079

Felzenszwalb, P. F., & Huttenlocher, D. P. (2004). Efficient Graph-Based Image Segmentation. International Journal of Computer Vision, 59(2), 167-181. https://doi.org/10.1023/B:VISI.0000022288.19776.77

Fonneland, H. C., Lien, T., Martinsen, O. J., Pedersen, R. B., & Košler, J. (2004). Detrital zircon ages: A key to understanding the deposition of deep marine sandstones in the Norwegian Sea. Sedimentary Geology, 164(1), 147-159. https://doi.org/10.1016/j.sedgeo.2003.09.005

Gärtner, A., Linnemann, U., Sagawe, A., Hofmann, M., Ullrich, B., & Kleber, A. (2013). Morphology of zircon crystal grains in sediments—Characteristics, classifications, definitions Morphologie von Zirkonen in Sedimenten—Merkmale, Klassifikationen, Definitionen. Journal of Central European Geology, 59, 65-73.

Harb, R., & Knöbelreiter, P. (2021). InfoSeg: Unsupervised Semantic Image Segmentation with Mutual Information Maximization. In C. Bauckhage, J. Gall, & A. Schwing (Eds.), Lecture notes in computer science: Vol. 13024. Pattern Recognition (pp.18-32). Springer. https://doi.org/10.48550/arXiv.2110.03477
Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer Series in Statistics.

Jain, A. K. (2010). Data clustering: 50 years beyond K-means. Pattern Recognition Letters, 31(8), 651–666. https://doi.org/10.1016/j.patrec.2009.09.011

Kanezaki, A. (2018). Unsupervised Image Segmentation by Backpropagation. In 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), 1543–1547.

Kirillov, A., Mintun, E., Ravi, N., Mao, H., Rolland, C., Gustafson, L., Xiao, T., Whitehead, S., Berg, A. C., Lo, W. Y., Dollár, P., & Girshick, R. (2023). Segment Anything. In Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV), 4015–4026. https://doi.org/10.48550/arXiv.2304.02643

Kleesment, A. (2009). Roundness and surface features of quartz grains in Middle Devonian deposits of the East Baltic and their palaeogeographical implications. Estonian Journal of Earth Sciences, 58(1). https://doi.org/10.3176/earth.2009.1.07

Latif, G., Bouchard, K., Maitre, J., Back, A., & Bédard, L. P. (2022). Deep-Learning-Based Automatic Mineral Grain Segmentation and Recognition. Minerals, 12(4), 455. https://doi.org/10.3390/min12040455

LeCun, Y., Bengio, Y., & Hinton, G. (2015). Deep learning. Nature, 521(7553), 436–444. https://doi.org/10.1038/nature14539

Liu, H., Ren, Y. L., Li, X., Hu, Y. X., Wu, J. P., Li, B., Luo, L., Tao, Z., Liu, X., Liang, J., Zhang, Y. Y., An, X. Y., & Fang, W. K. (2022). Rock thin-section analysis and identification based on artificial intelligent technique. Petroleum Science, 19(4), 1605–1621. https://doi.org/10.1016/j.petsci.2022.03.011

Lokier, S. W., & Al Junaibi, M. (2016). The petrographic description of carbonate facies: Are we all speaking the same language? Sedimentology, 63(7), 1843–1885. https://doi.org/10.1111/sed.12293

Nichols, T. E., Worden, R. H., Houghton, J. E., Duller, R. A., Griffiths, J., & Utley, J. E. P. (2023). Sediment texture and geochemistry as predictors of sub-depositional environment in a modern estuary using machine learning: A framework for investigating clay-coated sand grains. Sedimentary Geology, 458, 106530. https://doi.org/10.1016/j.sedgeo.2023.106530

Ragusa, J., & Kindler, P. (2018). Compositional variations in deep-sea gravity-flow deposits. A case study from the Voirons Flysch (Voirons-Wâgital complex, Chablais Prealps, France). Sedimentary Geology, 377, 111–130. https://doi.org/10.1016/j.sedgeo.2018.08.010

Roduit, N. (2007). Un logiciel d'analyse d'images pétrographiques polyvalent (Thesis No. 3830) [Doctoral dissertation, Universite de Geneve]. http://www.jmicrovision.com/resources.htm.

Ronneberger, O., Fischer, P., & Brox, T. (2015). U-Net: Convolutional Networks for Biomedical Image Segmentation. In N. Navab, J. Hornegger, W. M. Wells, & A. F. Frangi (Eds.), Lecture notes in computer science: Vol. 9351. Medical Image Computing and Computer-Assisted Intervention – MICCAI 2015 (pp. 234–241). Springer. https://doi.org/10.48550/arXiv.1505.04597

Sezgin, M., & Sankur, B. (2004). Survey over image thresholding techniques and quantitative performance evaluation. Journal of Electronic Imaging, 13(1), 146–168. https://doi.org/10.1117/1.1631315

Sharma, N., & Aggarwal, L. M. (2010). Automated medical image segmentation techniques. Journal of Medical Physics, 35(1), 3–14. https://doi.org/10.4103/0971-6203.58777

Tang, D. G., Milliken, K. L., & Spikes, K. T. (2020). Machine learning for point counting and segmentation of arenite in thin section. Marine and Petroleum Geology, 120, 104518. https://doi.org/10.1016/j.marpetgeo.2020.104518

Vernon, R. H. (2004). A Practical Guide to Rock Microstructure. Cambridge University Press. https://doi.org/10.1017/CBO9780511807206

Zhang, H., Fritts, J. E., & Goldman, S. A. (2008). Image segmentation evaluation: A survey of unsupervised methods. Computer Vision and Image Understanding, 110(2), 260–280. https://doi.org/10.1016/j.cviu.2007.08.003

Zhang, P., Zhou, J., Zhao, W., Li, X., & Pu, L. (2024). The edge segmentation of grains in thin-section petrographic images utilising extinction consistency perception network. Complex & Intelligent Systems, 10(1), 1231–1245. https://doi.org/10.1007/s40747-023-01208-y

Zhao, X., Ding, W., An, Y., Du, Y., Yu, T., Li, M., Tang, M., & Wang, J. (2023). Fast Segment Anything. ArXiv, abs/2306.12156. https://doi.org/10.48550/arXiv.2306.12156

How to cite: Azzam, F., Blaise, T., & Brigaud, B. (2024). Automated petrographic image analysis by supervised and unsupervised machine learning methods. Sedimentologika, 2(2), 1–12. https://doi.org/10.57035/journals/sdk.2024.e22.1594