This code repository is the official implementation of the manuscript Enhanced Rock Fracture Detection: Integrating DeepLabv3+ Segmentation with Geometric Pattern Analysis submitted to The Visual Computer.
This project implements an automated rock fracture detection framework integrating an enhanced DeepLabv3+ semantic segmentation with triangular scatter point geometric pattern analysis. It performs pixel-level segmentation, sine curve fitting, geometric parameter extraction, and fracture zone delineation for borehole imaging, addressing challenges such as irregular fracture morphology, significant background interference, and low detection robustness in complex geological contexts.
Core Functions:
-
Specialized preprocessing pipeline for drill hole images (grayscaling, bilateral filtering, CLAHE enhancement, high-pass filtering, image fusion, batch augmentation);
-
DeepLabv3+ fissure segmentation model integrating ASPP multi-scale convolutions with Edge-Aware CBAM attention mechanism;
-
Nonlinear least-squares sine curve fitting based on Hough transform + FFT initialization for extracting slit geometric parameters (amplitude, period, phase, center position);
-
Automatic slit region segmentation, iterative noise point removal, and slit pattern clustering;
-
Model training and testing scripts incorporating evaluation metrics such as Accuracy, Dice, and IoU.
Experimental Results:
Compared to traditional methods and existing deep learning models, this approach achieves a 10% improvement in Dice coefficient. It demonstrates enhanced robustness under conditions of noise, non-uniform rock texture, and varying illumination, enabling engineering-grade quantitative analysis of rock fracture geometry.
This project adopts DeepLabV3+ as the core segmentation network, integrating multiple advanced techniques to achieve high-precision rock fracture detection:
- Function: Multi-scale hierarchical feature extraction
- Characteristics: Uses dilated convolution in the last two layers to expand receptive field while maintaining resolution and increasing global context understanding
- Output: Feature pyramid with 4 different resolutions
This module leverages 4 parallel branches with different dilation rates to perform multi-scale convolution, capturing fracture features at different scales:
Advantages:
- ✓ Multi-scale receptive field fusion, capturing fine fractures to overall fracture texture
- ✓ Lossless spatial information, preserving fine fracture boundaries
An enhanced attention module based on channel attention and spatial attention, additionally fusing image edge information:
|
Channel Attention
Function: Learn the relative importance of features in each channel, enhancing feature channels related to fractures |
Spatial Attention
Function: Emphasize fracture regions, suppress background noise |
Edge-Aware Enhancement:
- Use Sobel operator to compute edge gradients of input image
- Multiply edge map with spatial attention to enhance boundary fineness
- Formula:
$S_{out} = SA(x) \times (1 + E_{edge})$
where
Before entering the model, raw borehole images undergo the following preprocessing steps:
Raw image
↓
Grayscale conversion (RGB → Gray)
↓
CLAHE adaptive contrast enhancement
[clipLimit=3.0, tileGridSize=(8,8)]
Function: Enhance local contrast, highlight fine fractures
↓
Bilateral filtering
[d=9, sigmaColor=75, sigmaSpace=75]
Function: Edge-preserving denoising, smooth background while preserving fracture edges
↓
High-pass filtering
[kernel: [-1,-1,-1; -1,8,-1; -1,-1,-1]]
Function: Enhance edges and texture details
↓
Image fusion
final = bilateral × 1.0 + highpass × 0.7
↓
Data augmentation (circular shift concatenation)
[Divide image into 10 parts, cyclically shift and combine to generate variant samples]
↓
256×256 normalized input
The model training and validation stages employ the following metrics to measure segmentation performance:
| Metric | English Name | Formula | Description |
|---|---|---|---|
| Accuracy | Accuracy | Proportion of correctly classified pixels | |
| IoU | IoU (Intersection over Union) | Overlap degree between predicted and true regions, larger is better (max 1.0) | |
| Dice | Dice Coefficient | Similar to IoU but more sensitive to FN, emphasizes missed detections | |
| Precision | Precision | Proportion of correctly predicted fracture pixels | |
| Recall | Recall | Proportion of true fracture pixels correctly detected | |
| F1 Score | F1 Score | Harmonic mean of Precision and Recall |
Where:
- TP (True Positive): Correctly detected fracture pixels
- FP (False Positive): Background pixels incorrectly identified as fractures (over-detection)
- FN (False Negative): Fracture pixels not detected (missed detection)
- TN (True Negative): Correctly identified background pixels
After obtaining the fracture segmentation results, the project employs nonlinear least-squares fitting combined with FFT initialization and iterative outlier removal to comprehensively extract fracture geometric parameters.
Using parameterized sine function for modeling:
Where:
- A - Amplitude: Maximum deviation distance of waveform
-
k - Wave Number:
$k = \frac{2\pi}{T}$ , T is period - φ - Initial Phase: Horizontal shift of waveform
- y₀ - Vertical Offset: Vertical position of waveform center
Stage 1: FFT Initial Parameter Estimation
- Uniformly interpolate irregular-scale discrete points to 512 sampling points
- Use FFT transform to find the main peak in frequency spectrum
- Automatically extract initial parameters without manual adjustment
Stage 2: Iterative Least-Squares Optimization
- Use Trust Region Reflective (TRF) optimizer
- Dynamically configure constraints: A > 0, 1e-4 < k < π, -4π < φ < 4π
- Multiple iteration rounds, removing outliers each round
Stage 3: Outlier Removal Strategy
- First round: Use P85 percentile (conservative)
- Subsequent rounds: Use P75 percentile (aggressive)
- Retention rate threshold: ≥ 30% and ≥ 5 points, otherwise stop iteration
Stage 4: Multi-initialization Candidates
- FFT estimation, period variation, amplitude variation and other initializations
- Select result with minimum RMSE as optimal solution
| Parameter | Calculation | Physical Meaning | Unit |
|---|---|---|---|
| Period | Periodic length of fracture ripples | Pixels | |
| Frequency | Periods per unit length | 1/Pixels | |
| Amplitude | A | Half of maximum fracture width | Pixels |
| Center Position | y₀ | Vertical position of fracture | Pixels |
| Phase | φ | Initial position of waveform | Radians |
| Fitting Error | RMSE | Model-data fit quality | Pixels |
main2.py generates 2×2 diagnostic plots:
- Top-left, top-right, bottom-left: Show outlier removal process for iterations 0, 1, 2 (blue=retained, red=discarded)
- Bottom-right: Compare fitting results of different initializations, mark optimal solution
Fitting results are saved in JSON format (result/fitting_results.json), containing:
- Optimal parameters for each fracture region
- Retention/discard point statistics for each iteration
- Fitting RMSE and validation metrics
- Outlier sensitivity: P85 → P90 for stricter standard
- Iteration count: Increase
max_iterparameter to improve precision - RMSE threshold: Adjust
rmse_limitbased on actual data - Stability verification: Similar results across multiple initializations indicate stable fitting
Sample segmentation results on typical samples:
Hardware Configuration (Experimental setup for thesis; minimum requirements may be appropriately reduced)
- CPU: Intel Core i5-14600KF @ 3.50 GHz or higher
- GPU: NVIDIA GeForce RTX 4060 Ti 8G or higher (CUDA-enabled)
- RAM: 32 GB or higher
- Storage: 10 GB or more of available space
Base Environment
- OS: Windows 11 / Ubuntu 18.04/20.04
- Python: 3.9 (experimental version used in the paper; compatible with 3.8-3.10)
- CUDA: 12.6
- CUDNN: 12.8
- NVIDIA Driver: 560.94 or later
Python library (includes experimental version from the paper; one-click installation via requirements.txt)
tensorflow==2.13.0
opencv-python==4.8.0.76
numpy==1.26.0
pandas==2.1.1
matplotlib==3.8.0
scipy==1.11.3
scikit-image==0.21.0
labelme==5.2.0
pillow==10.0.1
tqdm==4.66.1
Install dependencies with a single click
# After cloning the repository, navigate to the root directory.
pip install -r requirements.txt
Note: If GPU environment configuration fails, you may switch to the CPU version (performance will decrease; recommended for testing purposes only).
After cloning the repository, navigate to the project root directory and install dependencies:
git clone git@github.com:XXX/RockFracture_DeepLabv3-_Pattern.git
cd RockFracture_DeepLabv3-_Pattern
pip install -r requirements.txtStep 1: Prepare Raw Data
Place borehole images in the dataset/origin/ directory and corresponding label JSON files in dataset/json/:
dataset/
├── origin/ # Original borehole images (jpg/png)
├── json/ # Corresponding LabelMe label files (json)
└── mask/ # Directory for generated binary masks
Step 2: Run Preprocessing Script
python pre.pyThis script will:
- Read raw images and perform enhancement processing (CLAHE, bilateral filtering, high-pass filtering)
- Generate binary masks from JSON labels (fracture=black, background=white)
- Generate segmented dataset, saved to
dataset/images_split/anddataset/masks_split/
Run the training script to train the DeepLabV3+ model:
python deeplab3_train.pyTraining process will:
- Automatically load preprocessed data
- Train on GPU (automatically switches to CPU if GPU not available)
- Save training checkpoints to
training_outputs/checkpoints/ - Save best model as
training_outputs/checkpoints/best_model.pth
Training Parameter Adjustment: Modify learning rate, batch size, number of epochs, etc. in deeplab3_train.py
Note: If you don't want to train it yourself, you can download my model: best_model.pth and place it in the /training_outputs/checkpoints folder in the root directory.
Use the trained model to predict on new samples:
python predict_model.pyThis script will:
- Load the best model (
training_outputs/checkpoints/best_model.pth) - Predict all images in
dataset/origin/ - Generate four-column comparison images (original, ground truth, raw prediction, denoised prediction) saved to
prediction_results/ - Generate binary masks saved to
output/ - Output noise removal rate statistics
Run curve fitting script to extract fracture geometric parameters:
python main2.pyThis script will:
- Perform sine curve fitting on predicted fracture regions
- Extract geometric parameters (amplitude, period, phase, center position, etc.)
- Save fitting results to
result/fitting_results.json
To quickly test the entire workflow, run the following commands in sequence:
python pre.py # 1. Data preprocessing
python deeplab3_train.py # 2. Model training (optional, can use pretrained weights)
python predict_model.py # 3. Prediction and visualization
python main2.py # 4. Parameter extractionNote: If you already have a trained model, you can skip step 2 and start from step 3.
To visualize the stages of image preprocessing and model training process curves, use the plot.py script:
python plot.pyThis script will generate detailed visualization plots, including:
- Loss Curve - Training loss function variation trend
- Accuracy Curve - Accuracy variation process
- IoU Curve - Intersection over Union (most important metric, marked with best value)
- Dice Coefficient Curve - Dice coefficient evolution
- F1 Score Curve - F1 score variation
6 subplots showing all key metrics on one figure: Loss, Accuracy, IoU, Dice, F1, and Epoch Time for easy comparison
- Loss vs IoU - Shows correspondence between loss and performance
- Loss vs Multiple Metrics - Simultaneously compares loss with accuracy, Dice, F1 and other metrics
Shows Precision and Recall evolution during training process
- Training process statistical summary
- Performance distribution and trend analysis
Output Directory Structure:
training_outputs/figures/
├── single_metrics/ # Single metric curve plots
│ ├── 01_loss.png
│ ├── 02_accuracy.png
│ ├── 03_iou.png
│ ├── 04_dice.png
│ └── 05_f1.png
├── comparison/ # Comparative analysis plots
│ ├── 06_comprehensive.png
│ └── 07_loss_vs_metrics.png
├── analysis/ # Statistical analysis plots
└── process/ # Process plots
Tip: plot.py depends on data files generated during training (training_history.pkl and training_history.csv), so you need to complete step 2 model training first
If you find this work useful, please cite our preprint:
APA Style:
Tan, Q., & Qin, Y. (2026). Enhanced Rock Fracture Detection: Integrating DeepLabv3+ Segmentation with Geometric Pattern Analysis. Research Square. https://doi.org/10.21203/rs.3.rs-9160848/v1
BibTeX:
@article{tan2026enhanced,
title={Enhanced Rock Fracture Detection: Integrating DeepLabv3+ Segmentation with Geometric Pattern Analysis},
author={Tan, Qiancheng and Qin, Yonghui},
journal={Research Square (Preprint)},
year={2026},
month={March},
day={18},
version={1},
doi={10.21203/rs.3.rs-9160848/v1},
url={[https://doi.org/10.21203/rs.3.rs-9160848/v1](https://doi.org/10.21203/rs.3.rs-9160848/v1)}
}
This project is licensed under the MIT License. See the LICENSE file for details.
Copyright (c) 2026 Qiancheng Tan & Yonghui Qin.













