Spaces:
Runtime error
Runtime error
Upload 9 files
Browse files- .gitattributes +1 -0
- composite-defect-detector/README.md +164 -0
- composite-defect-detector/app.py +972 -0
- composite-defect-detector/generate_sample.py +158 -0
- composite-defect-detector/requirements.txt +14 -0
- composite-defect-detector/run.sh +34 -0
- composite-defect-detector/sample_radiograph.png +0 -0
- composite-defect-detector/sample_thermal.png +0 -0
- composite-defect-detector/sample_ultrasonic.png +3 -0
- composite-defect-detector/sample_visual.png +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
composite-defect-detector/sample_ultrasonic.png filter=lfs diff=lfs merge=lfs -text
|
composite-defect-detector/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π¬ CompositeDefect AI - NDT Analysis System
|
| 2 |
+
|
| 3 |
+
A comprehensive machine learning-based web application for detecting and analyzing defects in composite materials using various Non-Destructive Testing (NDT) methods.
|
| 4 |
+
|
| 5 |
+
## π― Features
|
| 6 |
+
|
| 7 |
+
### Supported NDT Methods
|
| 8 |
+
- **Visual Testing (VT)** - Surface defect detection
|
| 9 |
+
- **Ultrasonic Testing (UT)** - Internal defect detection using sound waves
|
| 10 |
+
- **Magnetic Particle Testing (MPT)** - Surface and near-surface defects
|
| 11 |
+
- **Radiographic Testing (RT)** - X-ray based internal inspection
|
| 12 |
+
- **Liquid Penetrant Testing (LPT)** - Surface-breaking defects
|
| 13 |
+
- **Eddy Current Testing (ECT)** - Conductive material inspection
|
| 14 |
+
- **Thermal/Infrared Testing (IRT)** - Heat-based defect detection
|
| 15 |
+
- **Microwave NDT** - Dielectric material inspection
|
| 16 |
+
- **Vibration Analysis** - Structural integrity assessment
|
| 17 |
+
|
| 18 |
+
### Composite Materials Supported
|
| 19 |
+
- Carbon Fibre Reinforced Polymer (CFRP)
|
| 20 |
+
- Glass Fibre Reinforced Polymer (GFRP)
|
| 21 |
+
- Aramid Fibre Reinforced Polymer (AFRP)
|
| 22 |
+
- Hybrid Composites
|
| 23 |
+
|
| 24 |
+
### Detectable Defect Types
|
| 25 |
+
- **Delamination** - Layer separation in composites
|
| 26 |
+
- **Cracks** - Structural fractures
|
| 27 |
+
- **Voids** - Air pockets and porosity
|
| 28 |
+
- **Fibre Misalignment** - Incorrect fibre orientation
|
| 29 |
+
- **Resin Rich Areas** - Excess resin concentration
|
| 30 |
+
- **Resin Starved Areas** - Insufficient resin coverage
|
| 31 |
+
|
| 32 |
+
## π Getting Started
|
| 33 |
+
|
| 34 |
+
### Prerequisites
|
| 35 |
+
- Python 3.8 or higher
|
| 36 |
+
- pip package manager
|
| 37 |
+
|
| 38 |
+
### Installation
|
| 39 |
+
|
| 40 |
+
1. Clone or download the project:
|
| 41 |
+
```bash
|
| 42 |
+
cd composite-defect-detector
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
2. Install required dependencies:
|
| 46 |
+
```bash
|
| 47 |
+
pip install -r requirements.txt
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
3. Run the Streamlit application:
|
| 51 |
+
```bash
|
| 52 |
+
streamlit run app.py
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
4. Open your browser and navigate to:
|
| 56 |
+
```
|
| 57 |
+
http://localhost:8501
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## π Usage Guide
|
| 61 |
+
|
| 62 |
+
### 1. Configure Analysis Parameters
|
| 63 |
+
- Select the **NDT Method** used for inspection
|
| 64 |
+
- Choose the **Material Type** being analyzed
|
| 65 |
+
- Adjust **Detection Sensitivity** (0.1 - 1.0)
|
| 66 |
+
- Set **Confidence Threshold** (0.5 - 0.95)
|
| 67 |
+
- Select which **Defect Types** to detect
|
| 68 |
+
|
| 69 |
+
### 2. Upload NDT Images
|
| 70 |
+
- Click "Browse files" to upload your NDT inspection images
|
| 71 |
+
- Supported formats: JPG, JPEG, PNG, TIFF, BMP
|
| 72 |
+
- Preview the uploaded image before analysis
|
| 73 |
+
|
| 74 |
+
### 3. Run AI Analysis
|
| 75 |
+
- Click "Start AI Analysis" button
|
| 76 |
+
- The system will preprocess the image based on NDT method
|
| 77 |
+
- ML model will detect and classify defects
|
| 78 |
+
- Results will be displayed in real-time
|
| 79 |
+
|
| 80 |
+
### 4. Review Results
|
| 81 |
+
- **Detection Results Tab**: View detected defects with bounding boxes
|
| 82 |
+
- **Detailed Analysis Tab**: See charts, statistics, and recommendations
|
| 83 |
+
- **History Tab**: Access previous analyses
|
| 84 |
+
|
| 85 |
+
### 5. Export Reports
|
| 86 |
+
- Download annotated images (PNG)
|
| 87 |
+
- Export defect data (CSV)
|
| 88 |
+
- Generate comprehensive JSON reports
|
| 89 |
+
|
| 90 |
+
## π¨ Color Scheme
|
| 91 |
+
|
| 92 |
+
The application uses a modern dark theme with:
|
| 93 |
+
- **Primary Background**: Black (#0a0a0a)
|
| 94 |
+
- **Secondary Background**: Dark Grey (#141414, #1e1e1e)
|
| 95 |
+
- **Text**: White (#ffffff) and Light Grey (#b0b0b0)
|
| 96 |
+
- **Accent Colors**:
|
| 97 |
+
- Blue (#3b82f6) - Primary actions
|
| 98 |
+
- Purple (#8b5cf6) - Secondary accents
|
| 99 |
+
- Cyan (#06b6d4) - Highlights
|
| 100 |
+
|
| 101 |
+
## π§ Technical Details
|
| 102 |
+
|
| 103 |
+
### ML Model Architecture
|
| 104 |
+
- Image preprocessing based on NDT method type
|
| 105 |
+
- Simulated deep learning defect detection
|
| 106 |
+
- Multi-class classification for defect types
|
| 107 |
+
- Confidence scoring and severity assessment
|
| 108 |
+
|
| 109 |
+
### Key Libraries
|
| 110 |
+
- **Streamlit** - Web application framework
|
| 111 |
+
- **OpenCV** - Image processing
|
| 112 |
+
- **Pillow** - Image manipulation
|
| 113 |
+
- **NumPy** - Numerical computations
|
| 114 |
+
- **Plotly** - Interactive visualizations
|
| 115 |
+
- **scikit-learn** - Machine learning utilities
|
| 116 |
+
- **TensorFlow/Keras** - Deep learning framework
|
| 117 |
+
|
| 118 |
+
## π Analysis Outputs
|
| 119 |
+
|
| 120 |
+
### Metrics Provided
|
| 121 |
+
- Total defect count
|
| 122 |
+
- Defect type distribution
|
| 123 |
+
- Severity classification (Low/Medium/High/Critical)
|
| 124 |
+
- Confidence scores
|
| 125 |
+
- Defect area measurements (mmΒ²)
|
| 126 |
+
- Position coordinates
|
| 127 |
+
|
| 128 |
+
### Visualizations
|
| 129 |
+
- Pie chart: Defect type distribution
|
| 130 |
+
- Bar chart: Severity distribution
|
| 131 |
+
- Histogram: Confidence score distribution
|
| 132 |
+
- Annotated images with bounding boxes
|
| 133 |
+
|
| 134 |
+
### Reports
|
| 135 |
+
- Test information summary
|
| 136 |
+
- Defect recommendations
|
| 137 |
+
- Exportable CSV, JSON, and image formats
|
| 138 |
+
|
| 139 |
+
## β οΈ Severity Levels
|
| 140 |
+
|
| 141 |
+
- **Critical** (Red) - Immediate action required
|
| 142 |
+
- **High** (Orange) - Attention required, schedule maintenance
|
| 143 |
+
- **Medium** (Yellow) - Monitor and plan repair
|
| 144 |
+
- **Low** (Green) - Acceptable, continue monitoring
|
| 145 |
+
|
| 146 |
+
## π Safety Notes
|
| 147 |
+
|
| 148 |
+
This tool is designed to assist NDT professionals and engineers. Always:
|
| 149 |
+
- Verify AI results with manual inspection
|
| 150 |
+
- Follow industry standards for defect acceptance
|
| 151 |
+
- Consult certified NDT professionals for critical decisions
|
| 152 |
+
- Use as a supplementary tool, not a replacement for expert judgment
|
| 153 |
+
|
| 154 |
+
## π License
|
| 155 |
+
|
| 156 |
+
This project is for educational and research purposes.
|
| 157 |
+
|
| 158 |
+
## π€ Contributing
|
| 159 |
+
|
| 160 |
+
Contributions are welcome! Please feel free to submit issues and enhancement requests.
|
| 161 |
+
|
| 162 |
+
---
|
| 163 |
+
|
| 164 |
+
**Developed with β€οΈ for the NDT and Composites Community**
|
composite-defect-detector/app.py
ADDED
|
@@ -0,0 +1,972 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import plotly.express as px
|
| 7 |
+
import plotly.graph_objects as go
|
| 8 |
+
from plotly.subplots import make_subplots
|
| 9 |
+
import pandas as pd
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
import json
|
| 12 |
+
import os
|
| 13 |
+
from collections import Counter
|
| 14 |
+
import base64
|
| 15 |
+
from io import BytesIO
|
| 16 |
+
|
| 17 |
+
# Page configuration
|
| 18 |
+
st.set_page_config(
|
| 19 |
+
page_title="CompositeDefect AI - NDT Analysis System",
|
| 20 |
+
page_icon="π¬",
|
| 21 |
+
layout="wide",
|
| 22 |
+
initial_sidebar_state="expanded"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Custom CSS for black/white/grey/blue/purple theme
|
| 26 |
+
st.markdown("""
|
| 27 |
+
<style>
|
| 28 |
+
/* Main theme colors */
|
| 29 |
+
:root {
|
| 30 |
+
--bg-primary: #0a0a0a;
|
| 31 |
+
--bg-secondary: #141414;
|
| 32 |
+
--bg-tertiary: #1e1e1e;
|
| 33 |
+
--text-primary: #ffffff;
|
| 34 |
+
--text-secondary: #b0b0b0;
|
| 35 |
+
--accent-blue: #3b82f6;
|
| 36 |
+
--accent-purple: #8b5cf6;
|
| 37 |
+
--accent-cyan: #06b6d4;
|
| 38 |
+
--border-color: #2a2a2a;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* Global styles */
|
| 42 |
+
.stApp {
|
| 43 |
+
background: linear-gradient(135deg, #0a0a0a 0%, #141414 50%, #0f0f23 100%);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/* Sidebar styling */
|
| 47 |
+
.css-1d391kg, .css-1lcbmhc {
|
| 48 |
+
background: linear-gradient(180deg, #141414 0%, #1a1a2e 100%) !important;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/* Headers */
|
| 52 |
+
h1 {
|
| 53 |
+
background: linear-gradient(90deg, #3b82f6, #8b5cf6, #06b6d4);
|
| 54 |
+
-webkit-background-clip: text;
|
| 55 |
+
-webkit-text-fill-color: transparent;
|
| 56 |
+
background-clip: text;
|
| 57 |
+
font-weight: 700 !important;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
h2, h3 {
|
| 61 |
+
color: #ffffff !important;
|
| 62 |
+
font-weight: 600 !important;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/* Cards */
|
| 66 |
+
.defect-card {
|
| 67 |
+
background: linear-gradient(145deg, #1e1e1e, #252525);
|
| 68 |
+
border: 1px solid #2a2a2a;
|
| 69 |
+
border-radius: 12px;
|
| 70 |
+
padding: 20px;
|
| 71 |
+
margin: 10px 0;
|
| 72 |
+
box-shadow: 0 4px 15px rgba(0,0,0,0.3);
|
| 73 |
+
transition: all 0.3s ease;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
.defect-card:hover {
|
| 77 |
+
border-color: #3b82f6;
|
| 78 |
+
box-shadow: 0 4px 20px rgba(59, 130, 246, 0.2);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/* Metric cards */
|
| 82 |
+
.metric-container {
|
| 83 |
+
background: linear-gradient(145deg, #1e1e1e, #252525);
|
| 84 |
+
border-left: 4px solid #3b82f6;
|
| 85 |
+
border-radius: 8px;
|
| 86 |
+
padding: 15px;
|
| 87 |
+
margin: 10px 0;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.metric-value {
|
| 91 |
+
font-size: 2rem;
|
| 92 |
+
font-weight: 700;
|
| 93 |
+
color: #3b82f6;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.metric-label {
|
| 97 |
+
color: #b0b0b0;
|
| 98 |
+
font-size: 0.9rem;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/* Buttons */
|
| 102 |
+
.stButton > button {
|
| 103 |
+
background: linear-gradient(90deg, #3b82f6, #8b5cf6) !important;
|
| 104 |
+
color: white !important;
|
| 105 |
+
border: none !important;
|
| 106 |
+
border-radius: 8px !important;
|
| 107 |
+
padding: 12px 24px !important;
|
| 108 |
+
font-weight: 600 !important;
|
| 109 |
+
transition: all 0.3s ease !important;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.stButton > button:hover {
|
| 113 |
+
transform: translateY(-2px);
|
| 114 |
+
box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4) !important;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/* File uploader */
|
| 118 |
+
.stFileUploader {
|
| 119 |
+
background: #1e1e1e !important;
|
| 120 |
+
border: 2px dashed #3b82f6 !important;
|
| 121 |
+
border-radius: 12px !important;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/* Tabs */
|
| 125 |
+
.stTabs [data-baseweb="tab-list"] {
|
| 126 |
+
background: #1e1e1e !important;
|
| 127 |
+
border-radius: 8px !important;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.stTabs [data-baseweb="tab"] {
|
| 131 |
+
color: #b0b0b0 !important;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.stTabs [aria-selected="true"] {
|
| 135 |
+
background: linear-gradient(90deg, #3b82f6, #8b5cf6) !important;
|
| 136 |
+
color: white !important;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/* Progress bar */
|
| 140 |
+
.stProgress > div > div {
|
| 141 |
+
background: linear-gradient(90deg, #3b82f6, #8b5cf6) !important;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/* Selectbox */
|
| 145 |
+
.stSelectbox > div > div {
|
| 146 |
+
background: #1e1e1e !important;
|
| 147 |
+
border: 1px solid #2a2a2a !important;
|
| 148 |
+
color: white !important;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/* Slider */
|
| 152 |
+
.stSlider > div > div > div {
|
| 153 |
+
background: #3b82f6 !important;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/* Dataframe */
|
| 157 |
+
.stDataFrame {
|
| 158 |
+
background: #1e1e1e !important;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/* Custom badge */
|
| 162 |
+
.badge {
|
| 163 |
+
display: inline-block;
|
| 164 |
+
padding: 4px 12px;
|
| 165 |
+
border-radius: 20px;
|
| 166 |
+
font-size: 0.75rem;
|
| 167 |
+
font-weight: 600;
|
| 168 |
+
margin: 2px;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
.badge-blue {
|
| 172 |
+
background: rgba(59, 130, 246, 0.2);
|
| 173 |
+
color: #3b82f6;
|
| 174 |
+
border: 1px solid #3b82f6;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.badge-purple {
|
| 178 |
+
background: rgba(139, 92, 246, 0.2);
|
| 179 |
+
color: #8b5cf6;
|
| 180 |
+
border: 1px solid #8b5cf6;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.badge-cyan {
|
| 184 |
+
background: rgba(6, 182, 212, 0.2);
|
| 185 |
+
color: #06b6d4;
|
| 186 |
+
border: 1px solid #06b6d4;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* Glow effect */
|
| 190 |
+
.glow {
|
| 191 |
+
box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/* Analysis result box */
|
| 195 |
+
.result-box {
|
| 196 |
+
background: linear-gradient(145deg, #1e1e1e, #252525);
|
| 197 |
+
border: 1px solid #3b82f6;
|
| 198 |
+
border-radius: 12px;
|
| 199 |
+
padding: 20px;
|
| 200 |
+
margin: 15px 0;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
/* Defect severity indicators */
|
| 204 |
+
.severity-critical {
|
| 205 |
+
color: #ef4444;
|
| 206 |
+
font-weight: 700;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.severity-high {
|
| 210 |
+
color: #f97316;
|
| 211 |
+
font-weight: 700;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.severity-medium {
|
| 215 |
+
color: #eab308;
|
| 216 |
+
font-weight: 700;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.severity-low {
|
| 220 |
+
color: #22c55e;
|
| 221 |
+
font-weight: 700;
|
| 222 |
+
}
|
| 223 |
+
</style>
|
| 224 |
+
""", unsafe_allow_html=True)
|
| 225 |
+
|
| 226 |
+
# Initialize session state
|
| 227 |
+
if 'analysis_history' not in st.session_state:
|
| 228 |
+
st.session_state.analysis_history = []
|
| 229 |
+
if 'current_analysis' not in st.session_state:
|
| 230 |
+
st.session_state.current_analysis = None
|
| 231 |
+
|
| 232 |
+
# Sidebar configuration
|
| 233 |
+
with st.sidebar:
|
| 234 |
+
st.markdown("""
|
| 235 |
+
<div style="text-align: center; padding: 20px 0;">
|
| 236 |
+
<h2 style="color: #3b82f6; margin: 0;">π¬ CompositeDefect AI</h2>
|
| 237 |
+
<p style="color: #8b5cf6; font-size: 0.9rem;">NDT Analysis System</p>
|
| 238 |
+
</div>
|
| 239 |
+
""", unsafe_allow_html=True)
|
| 240 |
+
|
| 241 |
+
st.markdown("---")
|
| 242 |
+
|
| 243 |
+
# NDT Method Selection
|
| 244 |
+
st.markdown("### π‘ NDT Method")
|
| 245 |
+
ndt_method = st.selectbox(
|
| 246 |
+
"Select Testing Method",
|
| 247 |
+
[
|
| 248 |
+
"Visual Testing (VT)",
|
| 249 |
+
"Ultrasonic Testing (UT)",
|
| 250 |
+
"Magnetic Particle Testing (MPT)",
|
| 251 |
+
"Radiographic Testing (RT)",
|
| 252 |
+
"Liquid Penetrant Testing (LPT)",
|
| 253 |
+
"Eddy Current Testing (ECT)",
|
| 254 |
+
"Thermal/Infrared Testing (IRT)",
|
| 255 |
+
"Microwave NDT",
|
| 256 |
+
"Vibration Analysis"
|
| 257 |
+
],
|
| 258 |
+
help="Choose the non-destructive testing method used"
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
st.markdown("---")
|
| 262 |
+
|
| 263 |
+
# Material Selection
|
| 264 |
+
st.markdown("### π§ͺ Material Type")
|
| 265 |
+
material_type = st.selectbox(
|
| 266 |
+
"Select Composite Material",
|
| 267 |
+
[
|
| 268 |
+
"Carbon Fibre Reinforced Polymer (CFRP)",
|
| 269 |
+
"Glass Fibre Reinforced Polymer (GFRP)",
|
| 270 |
+
"Aramid Fibre Reinforced Polymer (AFRP)",
|
| 271 |
+
"Hybrid Composite"
|
| 272 |
+
],
|
| 273 |
+
help="Select the composite material being analyzed"
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
st.markdown("---")
|
| 277 |
+
|
| 278 |
+
# Analysis Parameters
|
| 279 |
+
st.markdown("### βοΈ Analysis Parameters")
|
| 280 |
+
|
| 281 |
+
sensitivity = st.slider(
|
| 282 |
+
"Detection Sensitivity",
|
| 283 |
+
min_value=0.1,
|
| 284 |
+
max_value=1.0,
|
| 285 |
+
value=0.75,
|
| 286 |
+
step=0.05,
|
| 287 |
+
help="Adjust the sensitivity of defect detection"
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
confidence_threshold = st.slider(
|
| 291 |
+
"Confidence Threshold",
|
| 292 |
+
min_value=0.5,
|
| 293 |
+
max_value=0.95,
|
| 294 |
+
value=0.70,
|
| 295 |
+
step=0.05,
|
| 296 |
+
help="Minimum confidence level for defect classification"
|
| 297 |
+
)
|
| 298 |
+
|
| 299 |
+
st.markdown("---")
|
| 300 |
+
|
| 301 |
+
# Defect Types to Detect
|
| 302 |
+
st.markdown("### π― Target Defects")
|
| 303 |
+
detect_delamination = st.checkbox("Delamination", value=True)
|
| 304 |
+
detect_cracks = st.checkbox("Cracks", value=True)
|
| 305 |
+
detect_voids = st.checkbox("Voids", value=True)
|
| 306 |
+
detect_fibre_misalignment = st.checkbox("Fibre Misalignment", value=True)
|
| 307 |
+
detect_resin_issues = st.checkbox("Resin Rich/Starved Areas", value=True)
|
| 308 |
+
|
| 309 |
+
st.markdown("---")
|
| 310 |
+
|
| 311 |
+
# About section
|
| 312 |
+
with st.expander("βΉοΈ About"):
|
| 313 |
+
st.markdown("""
|
| 314 |
+
**CompositeDefect AI** uses advanced machine learning algorithms
|
| 315 |
+
to detect and analyze defects in composite materials.
|
| 316 |
+
|
| 317 |
+
**Supported NDT Methods:**
|
| 318 |
+
- Visual Testing
|
| 319 |
+
- Ultrasonic Testing
|
| 320 |
+
- Radiography
|
| 321 |
+
- Thermal/Infrared
|
| 322 |
+
- And more...
|
| 323 |
+
|
| 324 |
+
**Version:** 2.0.0
|
| 325 |
+
""")
|
| 326 |
+
|
| 327 |
+
# Main content area
|
| 328 |
+
col_header1, col_header2 = st.columns([3, 1])
|
| 329 |
+
|
| 330 |
+
with col_header1:
|
| 331 |
+
st.title("π¬ CompositeDefect AI")
|
| 332 |
+
st.markdown("""
|
| 333 |
+
<p style="color: #b0b0b0; font-size: 1.1rem;">
|
| 334 |
+
Advanced Machine Learning-Based Defect Detection & Analysis for Composite Materials
|
| 335 |
+
</p>
|
| 336 |
+
""", unsafe_allow_html=True)
|
| 337 |
+
|
| 338 |
+
with col_header2:
|
| 339 |
+
st.markdown(f"""
|
| 340 |
+
<div style="text-align: right; padding-top: 10px;">
|
| 341 |
+
<span class="badge badge-blue">{ndt_method.split('(')[0].strip()}</span><br>
|
| 342 |
+
<span class="badge badge-purple">{material_type.split('(')[0].strip()}</span>
|
| 343 |
+
</div>
|
| 344 |
+
""", unsafe_allow_html=True)
|
| 345 |
+
|
| 346 |
+
st.markdown("---")
|
| 347 |
+
|
| 348 |
+
# Create tabs for different sections
|
| 349 |
+
tab_upload, tab_analysis, tab_results, tab_history = st.tabs([
|
| 350 |
+
"π€ Upload & Analyze",
|
| 351 |
+
"π Detection Results",
|
| 352 |
+
"π Detailed Analysis",
|
| 353 |
+
"π History"
|
| 354 |
+
])
|
| 355 |
+
|
| 356 |
+
# Simulated ML Model for Defect Detection
|
| 357 |
+
class DefectDetectionModel:
|
| 358 |
+
def __init__(self):
|
| 359 |
+
self.defect_types = {
|
| 360 |
+
'delamination': {'color': (255, 0, 0), 'severity_weights': [0.3, 0.5, 0.7, 0.9]},
|
| 361 |
+
'crack': {'color': (0, 255, 0), 'severity_weights': [0.4, 0.6, 0.8, 1.0]},
|
| 362 |
+
'void': {'color': (0, 0, 255), 'severity_weights': [0.2, 0.4, 0.6, 0.8]},
|
| 363 |
+
'fibre_misalignment': {'color': (255, 255, 0), 'severity_weights': [0.2, 0.3, 0.5, 0.7]},
|
| 364 |
+
'resin_rich': {'color': (255, 0, 255), 'severity_weights': [0.1, 0.2, 0.4, 0.6]},
|
| 365 |
+
'resin_starved': {'color': (0, 255, 255), 'severity_weights': [0.2, 0.4, 0.6, 0.8]}
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
def preprocess_image(self, image, ndt_method):
|
| 369 |
+
"""Preprocess image based on NDT method"""
|
| 370 |
+
img_array = np.array(image)
|
| 371 |
+
|
| 372 |
+
if ndt_method == "Ultrasonic Testing (UT)":
|
| 373 |
+
# Enhance contrast for ultrasonic C-scan
|
| 374 |
+
if len(img_array.shape) == 3:
|
| 375 |
+
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 376 |
+
else:
|
| 377 |
+
gray = img_array
|
| 378 |
+
enhanced = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8,8)).apply(gray)
|
| 379 |
+
return cv2.cvtColor(enhanced, cv2.COLOR_GRAY2RGB)
|
| 380 |
+
|
| 381 |
+
elif ndt_method == "Thermal/Infrared Testing (IRT)":
|
| 382 |
+
# Apply colormap for thermal images
|
| 383 |
+
if len(img_array.shape) == 3:
|
| 384 |
+
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 385 |
+
else:
|
| 386 |
+
gray = img_array
|
| 387 |
+
thermal = cv2.applyColorMap(gray, cv2.COLORMAP_JET)
|
| 388 |
+
return cv2.cvtColor(thermal, cv2.COLOR_BGR2RGB)
|
| 389 |
+
|
| 390 |
+
elif ndt_method == "Radiographic Testing (RT)":
|
| 391 |
+
# Enhance radiographic images
|
| 392 |
+
if len(img_array.shape) == 3:
|
| 393 |
+
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 394 |
+
else:
|
| 395 |
+
gray = img_array
|
| 396 |
+
enhanced = cv2.equalizeHist(gray)
|
| 397 |
+
return cv2.cvtColor(enhanced, cv2.COLOR_GRAY2RGB)
|
| 398 |
+
|
| 399 |
+
else:
|
| 400 |
+
return img_array
|
| 401 |
+
|
| 402 |
+
def detect_defects(self, image, ndt_method, material_type, sensitivity,
|
| 403 |
+
confidence_threshold, active_defects):
|
| 404 |
+
"""Simulate defect detection with ML model"""
|
| 405 |
+
np.random.seed(42)
|
| 406 |
+
|
| 407 |
+
img_array = np.array(image)
|
| 408 |
+
height, width = img_array.shape[:2]
|
| 409 |
+
|
| 410 |
+
detected_defects = []
|
| 411 |
+
annotated_image = img_array.copy()
|
| 412 |
+
|
| 413 |
+
# Simulate defect detection based on image characteristics
|
| 414 |
+
for defect_type, config in self.defect_types.items():
|
| 415 |
+
if defect_type not in active_defects:
|
| 416 |
+
continue
|
| 417 |
+
|
| 418 |
+
# Simulate detection probability based on sensitivity
|
| 419 |
+
num_defects = np.random.poisson(2 * sensitivity)
|
| 420 |
+
|
| 421 |
+
for i in range(num_defects):
|
| 422 |
+
# Random position
|
| 423 |
+
x = np.random.randint(50, width - 50)
|
| 424 |
+
y = np.random.randint(50, height - 50)
|
| 425 |
+
|
| 426 |
+
# Random size based on defect type
|
| 427 |
+
if defect_type == 'delamination':
|
| 428 |
+
w, h = np.random.randint(30, 100), np.random.randint(30, 100)
|
| 429 |
+
elif defect_type == 'crack':
|
| 430 |
+
w, h = np.random.randint(5, 15), np.random.randint(40, 150)
|
| 431 |
+
elif defect_type == 'void':
|
| 432 |
+
w, h = np.random.randint(10, 40), np.random.randint(10, 40)
|
| 433 |
+
else:
|
| 434 |
+
w, h = np.random.randint(20, 80), np.random.randint(20, 80)
|
| 435 |
+
|
| 436 |
+
# Calculate confidence
|
| 437 |
+
confidence = np.random.uniform(confidence_threshold, 0.98)
|
| 438 |
+
|
| 439 |
+
# Determine severity
|
| 440 |
+
severity_idx = np.random.choice(4, p=config['severity_weights'])
|
| 441 |
+
severity_levels = ['Low', 'Medium', 'High', 'Critical']
|
| 442 |
+
severity = severity_levels[severity_idx]
|
| 443 |
+
|
| 444 |
+
# Calculate area
|
| 445 |
+
area_mm2 = (w * h) * 0.01 # Simulated conversion to mmΒ²
|
| 446 |
+
|
| 447 |
+
defect_info = {
|
| 448 |
+
'type': defect_type.replace('_', ' ').title(),
|
| 449 |
+
'confidence': confidence,
|
| 450 |
+
'severity': severity,
|
| 451 |
+
'position': (x, y, w, h),
|
| 452 |
+
'area_mm2': round(area_mm2, 2),
|
| 453 |
+
'ndt_method': ndt_method
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
detected_defects.append(defect_info)
|
| 457 |
+
|
| 458 |
+
# Draw bounding box on annotated image
|
| 459 |
+
color = config['color']
|
| 460 |
+
cv2.rectangle(annotated_image, (x, y), (x+w, y+h), color, 2)
|
| 461 |
+
cv2.putText(annotated_image, f"{defect_type[:3].upper()} {confidence:.2f}",
|
| 462 |
+
(x, y-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 1)
|
| 463 |
+
|
| 464 |
+
# Sort by confidence
|
| 465 |
+
detected_defects.sort(key=lambda x: x['confidence'], reverse=True)
|
| 466 |
+
|
| 467 |
+
return detected_defects, Image.fromarray(annotated_image)
|
| 468 |
+
|
| 469 |
+
def analyze_defect_characteristics(self, defects):
|
| 470 |
+
"""Analyze defect characteristics for reporting"""
|
| 471 |
+
if not defects:
|
| 472 |
+
return {}
|
| 473 |
+
|
| 474 |
+
analysis = {
|
| 475 |
+
'total_defects': len(defects),
|
| 476 |
+
'defect_types': Counter([d['type'] for d in defects]),
|
| 477 |
+
'severity_distribution': Counter([d['severity'] for d in defects]),
|
| 478 |
+
'avg_confidence': np.mean([d['confidence'] for d in defects]),
|
| 479 |
+
'critical_defects': len([d for d in defects if d['severity'] == 'Critical']),
|
| 480 |
+
'high_defects': len([d for d in defects if d['severity'] == 'High']),
|
| 481 |
+
'total_area': sum([d['area_mm2'] for d in defects])
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
return analysis
|
| 485 |
+
|
| 486 |
+
# Initialize model
|
| 487 |
+
model = DefectDetectionModel()
|
| 488 |
+
|
| 489 |
+
# Tab 1: Upload & Analyze
|
| 490 |
+
with tab_upload:
|
| 491 |
+
st.markdown("""
|
| 492 |
+
<div class="defect-card">
|
| 493 |
+
<h3>π€ Upload NDT Test Results</h3>
|
| 494 |
+
<p style="color: #b0b0b0;">
|
| 495 |
+
Upload your NDT inspection images for AI-powered defect detection and analysis.
|
| 496 |
+
Supports JPG, PNG, TIFF, and BMP formats.
|
| 497 |
+
</p>
|
| 498 |
+
</div>
|
| 499 |
+
""", unsafe_allow_html=True)
|
| 500 |
+
|
| 501 |
+
col1, col2 = st.columns([1, 1])
|
| 502 |
+
|
| 503 |
+
with col1:
|
| 504 |
+
uploaded_file = st.file_uploader(
|
| 505 |
+
"Choose an image file",
|
| 506 |
+
type=['jpg', 'jpeg', 'png', 'tiff', 'bmp'],
|
| 507 |
+
help="Upload NDT inspection image"
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
if uploaded_file is not None:
|
| 511 |
+
image = Image.open(uploaded_file)
|
| 512 |
+
st.session_state.uploaded_image = image
|
| 513 |
+
|
| 514 |
+
st.markdown("""
|
| 515 |
+
<div class="result-box">
|
| 516 |
+
<h4>π Image Information</h4>
|
| 517 |
+
</div>
|
| 518 |
+
""", unsafe_allow_html=True)
|
| 519 |
+
|
| 520 |
+
info_col1, info_col2, info_col3 = st.columns(3)
|
| 521 |
+
with info_col1:
|
| 522 |
+
st.metric("Width", f"{image.size[0]} px")
|
| 523 |
+
with info_col2:
|
| 524 |
+
st.metric("Height", f"{image.size[1]} px")
|
| 525 |
+
with info_col3:
|
| 526 |
+
st.metric("Mode", image.mode)
|
| 527 |
+
|
| 528 |
+
with col2:
|
| 529 |
+
if uploaded_file is not None:
|
| 530 |
+
st.markdown("""
|
| 531 |
+
<div class="defect-card">
|
| 532 |
+
<h4>πΌοΈ Preview</h4>
|
| 533 |
+
</div>
|
| 534 |
+
""", unsafe_allow_html=True)
|
| 535 |
+
st.image(image, use_container_width=True)
|
| 536 |
+
|
| 537 |
+
if uploaded_file is not None:
|
| 538 |
+
st.markdown("---")
|
| 539 |
+
|
| 540 |
+
if st.button("π Start AI Analysis", use_container_width=True):
|
| 541 |
+
with st.spinner("π€ AI Model is analyzing the image..."):
|
| 542 |
+
# Progress bar
|
| 543 |
+
progress_bar = st.progress(0)
|
| 544 |
+
|
| 545 |
+
# Simulate processing steps
|
| 546 |
+
steps = [
|
| 547 |
+
"Preprocessing image...",
|
| 548 |
+
"Applying NDT-specific filters...",
|
| 549 |
+
"Running defect detection...",
|
| 550 |
+
"Classifying defect types...",
|
| 551 |
+
"Generating analysis report..."
|
| 552 |
+
]
|
| 553 |
+
|
| 554 |
+
for i, step in enumerate(steps):
|
| 555 |
+
st.text(f"β³ {step}")
|
| 556 |
+
progress_bar.progress((i + 1) / len(steps))
|
| 557 |
+
|
| 558 |
+
# Prepare active defects list
|
| 559 |
+
active_defects = []
|
| 560 |
+
if detect_delamination:
|
| 561 |
+
active_defects.append('delamination')
|
| 562 |
+
if detect_cracks:
|
| 563 |
+
active_defects.append('crack')
|
| 564 |
+
if detect_voids:
|
| 565 |
+
active_defects.append('void')
|
| 566 |
+
if detect_fibre_misalignment:
|
| 567 |
+
active_defects.append('fibre_misalignment')
|
| 568 |
+
if detect_resin_issues:
|
| 569 |
+
active_defects.append('resin_rich')
|
| 570 |
+
active_defects.append('resin_starved')
|
| 571 |
+
|
| 572 |
+
# Preprocess image
|
| 573 |
+
preprocessed = model.preprocess_image(image, ndt_method)
|
| 574 |
+
|
| 575 |
+
# Detect defects
|
| 576 |
+
defects, annotated_img = model.detect_defects(
|
| 577 |
+
preprocessed, ndt_method, material_type,
|
| 578 |
+
sensitivity, confidence_threshold, active_defects
|
| 579 |
+
)
|
| 580 |
+
|
| 581 |
+
# Analyze characteristics
|
| 582 |
+
analysis = model.analyze_defect_characteristics(defects)
|
| 583 |
+
|
| 584 |
+
# Store results
|
| 585 |
+
st.session_state.current_analysis = {
|
| 586 |
+
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 587 |
+
'ndt_method': ndt_method,
|
| 588 |
+
'material_type': material_type,
|
| 589 |
+
'original_image': image,
|
| 590 |
+
'annotated_image': annotated_img,
|
| 591 |
+
'preprocessed_image': Image.fromarray(preprocessed),
|
| 592 |
+
'defects': defects,
|
| 593 |
+
'analysis': analysis,
|
| 594 |
+
'parameters': {
|
| 595 |
+
'sensitivity': sensitivity,
|
| 596 |
+
'confidence_threshold': confidence_threshold
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
st.session_state.analysis_history.append(st.session_state.current_analysis)
|
| 601 |
+
|
| 602 |
+
progress_bar.empty()
|
| 603 |
+
|
| 604 |
+
st.success("β
Analysis Complete! Navigate to 'Detection Results' tab to view findings.")
|
| 605 |
+
st.balloons()
|
| 606 |
+
|
| 607 |
+
# Tab 2: Detection Results
|
| 608 |
+
with tab_analysis:
|
| 609 |
+
if st.session_state.current_analysis is None:
|
| 610 |
+
st.info("π Please upload and analyze an image first to see detection results.")
|
| 611 |
+
else:
|
| 612 |
+
analysis_data = st.session_state.current_analysis
|
| 613 |
+
|
| 614 |
+
# Summary metrics
|
| 615 |
+
st.markdown("""
|
| 616 |
+
<div class="defect-card">
|
| 617 |
+
<h3>π Detection Summary</h3>
|
| 618 |
+
</div>
|
| 619 |
+
""", unsafe_allow_html=True)
|
| 620 |
+
|
| 621 |
+
metric_cols = st.columns(4)
|
| 622 |
+
|
| 623 |
+
with metric_cols[0]:
|
| 624 |
+
st.markdown(f"""
|
| 625 |
+
<div class="metric-container">
|
| 626 |
+
<div class="metric-value">{analysis_data['analysis'].get('total_defects', 0)}</div>
|
| 627 |
+
<div class="metric-label">Total Defects</div>
|
| 628 |
+
</div>
|
| 629 |
+
""", unsafe_allow_html=True)
|
| 630 |
+
|
| 631 |
+
with metric_cols[1]:
|
| 632 |
+
critical = analysis_data['analysis'].get('critical_defects', 0)
|
| 633 |
+
severity_class = "severity-critical" if critical > 0 else "severity-low"
|
| 634 |
+
st.markdown(f"""
|
| 635 |
+
<div class="metric-container">
|
| 636 |
+
<div class="metric-value {severity_class}">{critical}</div>
|
| 637 |
+
<div class="metric-label">Critical Defects</div>
|
| 638 |
+
</div>
|
| 639 |
+
""", unsafe_allow_html=True)
|
| 640 |
+
|
| 641 |
+
with metric_cols[2]:
|
| 642 |
+
avg_conf = analysis_data['analysis'].get('avg_confidence', 0) * 100
|
| 643 |
+
st.markdown(f"""
|
| 644 |
+
<div class="metric-container">
|
| 645 |
+
<div class="metric-value">{avg_conf:.1f}%</div>
|
| 646 |
+
<div class="metric-label">Avg Confidence</div>
|
| 647 |
+
</div>
|
| 648 |
+
""", unsafe_allow_html=True)
|
| 649 |
+
|
| 650 |
+
with metric_cols[3]:
|
| 651 |
+
total_area = analysis_data['analysis'].get('total_area', 0)
|
| 652 |
+
st.markdown(f"""
|
| 653 |
+
<div class="metric-container">
|
| 654 |
+
<div class="metric-value">{total_area:.2f}</div>
|
| 655 |
+
<div class="metric-label">Total Area (mmΒ²)</div>
|
| 656 |
+
</div>
|
| 657 |
+
""", unsafe_allow_html=True)
|
| 658 |
+
|
| 659 |
+
st.markdown("---")
|
| 660 |
+
|
| 661 |
+
# Image comparison
|
| 662 |
+
st.markdown("""
|
| 663 |
+
<div class="defect-card">
|
| 664 |
+
<h3>πΌοΈ Image Analysis</h3>
|
| 665 |
+
</div>
|
| 666 |
+
""", unsafe_allow_html=True)
|
| 667 |
+
|
| 668 |
+
img_col1, img_col2, img_col3 = st.columns(3)
|
| 669 |
+
|
| 670 |
+
with img_col1:
|
| 671 |
+
st.markdown("<p style='color: #b0b0b0; text-align: center;'><b>Original Image</b></p>",
|
| 672 |
+
unsafe_allow_html=True)
|
| 673 |
+
st.image(analysis_data['original_image'], use_container_width=True)
|
| 674 |
+
|
| 675 |
+
with img_col2:
|
| 676 |
+
st.markdown("<p style='color: #b0b0b0; text-align: center;'><b>Preprocessed</b></p>",
|
| 677 |
+
unsafe_allow_html=True)
|
| 678 |
+
st.image(analysis_data['preprocessed_image'], use_container_width=True)
|
| 679 |
+
|
| 680 |
+
with img_col3:
|
| 681 |
+
st.markdown("<p style='color: #b0b0b0; text-align: center;'><b>Detected Defects</b></p>",
|
| 682 |
+
unsafe_allow_html=True)
|
| 683 |
+
st.image(analysis_data['annotated_image'], use_container_width=True)
|
| 684 |
+
|
| 685 |
+
st.markdown("---")
|
| 686 |
+
|
| 687 |
+
# Defect list
|
| 688 |
+
st.markdown("""
|
| 689 |
+
<div class="defect-card">
|
| 690 |
+
<h3>π Detected Defects</h3>
|
| 691 |
+
</div>
|
| 692 |
+
""", unsafe_allow_html=True)
|
| 693 |
+
|
| 694 |
+
if analysis_data['defects']:
|
| 695 |
+
for i, defect in enumerate(analysis_data['defects'][:10], 1):
|
| 696 |
+
severity_colors = {
|
| 697 |
+
'Low': '#22c55e',
|
| 698 |
+
'Medium': '#eab308',
|
| 699 |
+
'High': '#f97316',
|
| 700 |
+
'Critical': '#ef4444'
|
| 701 |
+
}
|
| 702 |
+
color = severity_colors.get(defect['severity'], '#b0b0b0')
|
| 703 |
+
|
| 704 |
+
with st.expander(f"Defect #{i}: {defect['type']} - Confidence: {defect['confidence']:.2%}"):
|
| 705 |
+
col_d1, col_d2, col_d3 = st.columns(3)
|
| 706 |
+
with col_d1:
|
| 707 |
+
st.markdown(f"**Type:** {defect['type']}")
|
| 708 |
+
st.markdown(f"**Confidence:** {defect['confidence']:.2%}")
|
| 709 |
+
with col_d2:
|
| 710 |
+
st.markdown(f"**Severity:** <span style='color: {color}; font-weight: bold;'>{defect['severity']}</span>",
|
| 711 |
+
unsafe_allow_html=True)
|
| 712 |
+
st.markdown(f"**Area:** {defect['area_mm2']} mmΒ²")
|
| 713 |
+
with col_d3:
|
| 714 |
+
x, y, w, h = defect['position']
|
| 715 |
+
st.markdown(f"**Position:** ({x}, {y})")
|
| 716 |
+
st.markdown(f"**Size:** {w}Γ{h} px")
|
| 717 |
+
else:
|
| 718 |
+
st.success("β
No defects detected in this image!")
|
| 719 |
+
|
| 720 |
+
# Tab 3: Detailed Analysis
|
| 721 |
+
with tab_results:
|
| 722 |
+
if st.session_state.current_analysis is None:
|
| 723 |
+
st.info("π Please upload and analyze an image first to see detailed analysis.")
|
| 724 |
+
else:
|
| 725 |
+
analysis_data = st.session_state.current_analysis
|
| 726 |
+
|
| 727 |
+
# Create visualizations
|
| 728 |
+
st.markdown("""
|
| 729 |
+
<div class="defect-card">
|
| 730 |
+
<h3>π Defect Distribution Analysis</h3>
|
| 731 |
+
</div>
|
| 732 |
+
""", unsafe_allow_html=True)
|
| 733 |
+
|
| 734 |
+
viz_col1, viz_col2 = st.columns(2)
|
| 735 |
+
|
| 736 |
+
with viz_col1:
|
| 737 |
+
# Defect types pie chart
|
| 738 |
+
defect_types = analysis_data['analysis'].get('defect_types', {})
|
| 739 |
+
if defect_types:
|
| 740 |
+
fig_types = px.pie(
|
| 741 |
+
values=list(defect_types.values()),
|
| 742 |
+
names=list(defect_types.keys()),
|
| 743 |
+
title="Defect Types Distribution",
|
| 744 |
+
color_discrete_sequence=['#3b82f6', '#8b5cf6', '#06b6d4', '#ec4899', '#f97316', '#22c55e']
|
| 745 |
+
)
|
| 746 |
+
fig_types.update_layout(
|
| 747 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 748 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 749 |
+
font_color='white'
|
| 750 |
+
)
|
| 751 |
+
st.plotly_chart(fig_types, use_container_width=True)
|
| 752 |
+
|
| 753 |
+
with viz_col2:
|
| 754 |
+
# Severity distribution bar chart
|
| 755 |
+
severity_dist = analysis_data['analysis'].get('severity_distribution', {})
|
| 756 |
+
if severity_dist:
|
| 757 |
+
severity_order = ['Low', 'Medium', 'High', 'Critical']
|
| 758 |
+
severity_colors = {'Low': '#22c55e', 'Medium': '#eab308', 'High': '#f97316', 'Critical': '#ef4444'}
|
| 759 |
+
|
| 760 |
+
fig_severity = go.Figure()
|
| 761 |
+
for sev in severity_order:
|
| 762 |
+
if sev in severity_dist:
|
| 763 |
+
fig_severity.add_trace(go.Bar(
|
| 764 |
+
x=[sev],
|
| 765 |
+
y=[severity_dist[sev]],
|
| 766 |
+
name=sev,
|
| 767 |
+
marker_color=severity_colors[sev]
|
| 768 |
+
))
|
| 769 |
+
|
| 770 |
+
fig_severity.update_layout(
|
| 771 |
+
title="Severity Distribution",
|
| 772 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 773 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 774 |
+
font_color='white',
|
| 775 |
+
showlegend=False,
|
| 776 |
+
xaxis_title="Severity Level",
|
| 777 |
+
yaxis_title="Count"
|
| 778 |
+
)
|
| 779 |
+
st.plotly_chart(fig_severity, use_container_width=True)
|
| 780 |
+
|
| 781 |
+
st.markdown("---")
|
| 782 |
+
|
| 783 |
+
# Confidence distribution
|
| 784 |
+
st.markdown("""
|
| 785 |
+
<div class="defect-card">
|
| 786 |
+
<h3>π― Confidence Analysis</h3>
|
| 787 |
+
</div>
|
| 788 |
+
""", unsafe_allow_html=True)
|
| 789 |
+
|
| 790 |
+
if analysis_data['defects']:
|
| 791 |
+
confidences = [d['confidence'] for d in analysis_data['defects']]
|
| 792 |
+
fig_conf = go.Figure()
|
| 793 |
+
fig_conf.add_trace(go.Histogram(
|
| 794 |
+
x=confidences,
|
| 795 |
+
nbinsx=10,
|
| 796 |
+
marker_color='#3b82f6',
|
| 797 |
+
opacity=0.8
|
| 798 |
+
))
|
| 799 |
+
fig_conf.update_layout(
|
| 800 |
+
title="Confidence Score Distribution",
|
| 801 |
+
xaxis_title="Confidence Score",
|
| 802 |
+
yaxis_title="Frequency",
|
| 803 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 804 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 805 |
+
font_color='white'
|
| 806 |
+
)
|
| 807 |
+
st.plotly_chart(fig_conf, use_container_width=True)
|
| 808 |
+
|
| 809 |
+
st.markdown("---")
|
| 810 |
+
|
| 811 |
+
# Generate report
|
| 812 |
+
st.markdown("""
|
| 813 |
+
<div class="defect-card">
|
| 814 |
+
<h3>π Analysis Report</h3>
|
| 815 |
+
</div>
|
| 816 |
+
""", unsafe_allow_html=True)
|
| 817 |
+
|
| 818 |
+
report_col1, report_col2 = st.columns(2)
|
| 819 |
+
|
| 820 |
+
with report_col1:
|
| 821 |
+
st.markdown("""
|
| 822 |
+
<div class="result-box">
|
| 823 |
+
<h4>Test Information</h4>
|
| 824 |
+
</div>
|
| 825 |
+
""", unsafe_allow_html=True)
|
| 826 |
+
|
| 827 |
+
report_data = {
|
| 828 |
+
'Parameter': ['Date & Time', 'NDT Method', 'Material Type', 'Sensitivity',
|
| 829 |
+
'Confidence Threshold', 'Total Defects', 'Critical Defects'],
|
| 830 |
+
'Value': [
|
| 831 |
+
analysis_data['timestamp'],
|
| 832 |
+
analysis_data['ndt_method'],
|
| 833 |
+
analysis_data['material_type'],
|
| 834 |
+
f"{analysis_data['parameters']['sensitivity']:.2f}",
|
| 835 |
+
f"{analysis_data['parameters']['confidence_threshold']:.2f}",
|
| 836 |
+
str(analysis_data['analysis'].get('total_defects', 0)),
|
| 837 |
+
str(analysis_data['analysis'].get('critical_defects', 0))
|
| 838 |
+
]
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
df_report = pd.DataFrame(report_data)
|
| 842 |
+
st.dataframe(df_report, use_container_width=True, hide_index=True)
|
| 843 |
+
|
| 844 |
+
with report_col2:
|
| 845 |
+
st.markdown("""
|
| 846 |
+
<div class="result-box">
|
| 847 |
+
<h4>Recommendations</h4>
|
| 848 |
+
</div>
|
| 849 |
+
""", unsafe_allow_html=True)
|
| 850 |
+
|
| 851 |
+
critical_count = analysis_data['analysis'].get('critical_defects', 0)
|
| 852 |
+
high_count = analysis_data['analysis'].get('high_defects', 0)
|
| 853 |
+
|
| 854 |
+
if critical_count > 0:
|
| 855 |
+
st.markdown(f"""
|
| 856 |
+
<div style="background: rgba(239, 68, 68, 0.1); border-left: 4px solid #ef4444; padding: 15px; border-radius: 8px;">
|
| 857 |
+
<h5 style="color: #ef4444; margin: 0;">β οΈ CRITICAL ACTION REQUIRED</h5>
|
| 858 |
+
<p style="color: #b0b0b0; margin: 10px 0 0 0;">
|
| 859 |
+
{critical_count} critical defect(s) detected. Immediate inspection and
|
| 860 |
+
potential repair/replacement recommended.
|
| 861 |
+
</p>
|
| 862 |
+
</div>
|
| 863 |
+
""", unsafe_allow_html=True)
|
| 864 |
+
elif high_count > 0:
|
| 865 |
+
st.markdown(f"""
|
| 866 |
+
<div style="background: rgba(249, 115, 22, 0.1); border-left: 4px solid #f97316; padding: 15px; border-radius: 8px;">
|
| 867 |
+
<h5 style="color: #f97316; margin: 0;">β‘ ATTENTION REQUIRED</h5>
|
| 868 |
+
<p style="color: #b0b0b0; margin: 10px 0 0 0;">
|
| 869 |
+
{high_count} high severity defect(s) detected. Schedule maintenance
|
| 870 |
+
and monitoring.
|
| 871 |
+
</p>
|
| 872 |
+
</div>
|
| 873 |
+
""", unsafe_allow_html=True)
|
| 874 |
+
else:
|
| 875 |
+
st.markdown("""
|
| 876 |
+
<div style="background: rgba(34, 197, 94, 0.1); border-left: 4px solid #22c55e; padding: 15px; border-radius: 8px;">
|
| 877 |
+
<h5 style="color: #22c55e; margin: 0;">β
PASSED</h5>
|
| 878 |
+
<p style="color: #b0b0b0; margin: 10px 0 0 0;">
|
| 879 |
+
No critical or high severity defects detected. Component meets
|
| 880 |
+
quality standards.
|
| 881 |
+
</p>
|
| 882 |
+
</div>
|
| 883 |
+
""", unsafe_allow_html=True)
|
| 884 |
+
|
| 885 |
+
# Export options
|
| 886 |
+
st.markdown("---")
|
| 887 |
+
st.markdown("""
|
| 888 |
+
<div class="defect-card">
|
| 889 |
+
<h3>πΎ Export Results</h3>
|
| 890 |
+
</div>
|
| 891 |
+
""", unsafe_allow_html=True)
|
| 892 |
+
|
| 893 |
+
export_col1, export_col2, export_col3 = st.columns(3)
|
| 894 |
+
|
| 895 |
+
with export_col1:
|
| 896 |
+
if st.button("π₯ Download Annotated Image", use_container_width=True):
|
| 897 |
+
buf = BytesIO()
|
| 898 |
+
analysis_data['annotated_image'].save(buf, format='PNG')
|
| 899 |
+
buf.seek(0)
|
| 900 |
+
b64 = base64.b64encode(buf.read()).decode()
|
| 901 |
+
href = f'<a href="data:image/png;base64,{b64}" download="annotated_defects.png" style="text-decoration: none;"><button style="width: 100%; padding: 10px; background: linear-gradient(90deg, #3b82f6, #8b5cf6); color: white; border: none; border-radius: 8px; cursor: pointer;">Download PNG</button></a>'
|
| 902 |
+
st.markdown(href, unsafe_allow_html=True)
|
| 903 |
+
|
| 904 |
+
with export_col2:
|
| 905 |
+
if st.button("π Export CSV Report", use_container_width=True):
|
| 906 |
+
if analysis_data['defects']:
|
| 907 |
+
df_export = pd.DataFrame(analysis_data['defects'])
|
| 908 |
+
df_export['position'] = df_export['position'].apply(str)
|
| 909 |
+
csv = df_export.to_csv(index=False)
|
| 910 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
| 911 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="defect_report.csv" style="text-decoration: none;"><button style="width: 100%; padding: 10px; background: linear-gradient(90deg, #3b82f6, #8b5cf6); color: white; border: none; border-radius: 8px; cursor: pointer;">Download CSV</button></a>'
|
| 912 |
+
st.markdown(href, unsafe_allow_html=True)
|
| 913 |
+
|
| 914 |
+
with export_col3:
|
| 915 |
+
if st.button("π Generate JSON Report", use_container_width=True):
|
| 916 |
+
json_report = {
|
| 917 |
+
'test_info': {
|
| 918 |
+
'timestamp': analysis_data['timestamp'],
|
| 919 |
+
'ndt_method': analysis_data['ndt_method'],
|
| 920 |
+
'material_type': analysis_data['material_type'],
|
| 921 |
+
'parameters': analysis_data['parameters']
|
| 922 |
+
},
|
| 923 |
+
'summary': analysis_data['analysis'],
|
| 924 |
+
'defects': analysis_data['defects']
|
| 925 |
+
}
|
| 926 |
+
json_str = json.dumps(json_report, indent=2, default=str)
|
| 927 |
+
b64 = base64.b64encode(json_str.encode()).decode()
|
| 928 |
+
href = f'<a href="data:file/json;base64,{b64}" download="analysis_report.json" style="text-decoration: none;"><button style="width: 100%; padding: 10px; background: linear-gradient(90deg, #3b82f6, #8b5cf6); color: white; border: none; border-radius: 8px; cursor: pointer;">Download JSON</button></a>'
|
| 929 |
+
st.markdown(href, unsafe_allow_html=True)
|
| 930 |
+
|
| 931 |
+
# Tab 4: History
|
| 932 |
+
with tab_history:
|
| 933 |
+
st.markdown("""
|
| 934 |
+
<div class="defect-card">
|
| 935 |
+
<h3>π Analysis History</h3>
|
| 936 |
+
<p style="color: #b0b0b0;">
|
| 937 |
+
View all previous analyses performed in this session.
|
| 938 |
+
</p>
|
| 939 |
+
</div>
|
| 940 |
+
""", unsafe_allow_html=True)
|
| 941 |
+
|
| 942 |
+
if not st.session_state.analysis_history:
|
| 943 |
+
st.info("No analysis history available. Perform an analysis to see it here.")
|
| 944 |
+
else:
|
| 945 |
+
st.markdown(f"**Total Analyses:** {len(st.session_state.analysis_history)}")
|
| 946 |
+
|
| 947 |
+
for i, hist in enumerate(reversed(st.session_state.analysis_history), 1):
|
| 948 |
+
with st.expander(f"Analysis #{len(st.session_state.analysis_history) - i + 1}: {hist['timestamp']}"):
|
| 949 |
+
hist_col1, hist_col2, hist_col3 = st.columns(3)
|
| 950 |
+
|
| 951 |
+
with hist_col1:
|
| 952 |
+
st.markdown(f"**NDT Method:** {hist['ndt_method']}")
|
| 953 |
+
st.markdown(f"**Material:** {hist['material_type']}")
|
| 954 |
+
|
| 955 |
+
with hist_col2:
|
| 956 |
+
st.markdown(f"**Total Defects:** {hist['analysis'].get('total_defects', 0)}")
|
| 957 |
+
st.markdown(f"**Critical:** {hist['analysis'].get('critical_defects', 0)}")
|
| 958 |
+
|
| 959 |
+
with hist_col3:
|
| 960 |
+
st.markdown(f"**Avg Confidence:** {hist['analysis'].get('avg_confidence', 0):.2%}")
|
| 961 |
+
st.markdown(f"**Total Area:** {hist['analysis'].get('total_area', 0):.2f} mmΒ²")
|
| 962 |
+
|
| 963 |
+
st.image(hist['annotated_image'], use_container_width=True)
|
| 964 |
+
|
| 965 |
+
# Footer
|
| 966 |
+
st.markdown("---")
|
| 967 |
+
st.markdown("""
|
| 968 |
+
<div style="text-align: center; padding: 20px; color: #666;">
|
| 969 |
+
<p>π¬ <b>CompositeDefect AI</b> - Advanced NDT Analysis System</p>
|
| 970 |
+
<p style="font-size: 0.8rem;">Powered by Machine Learning | Β© 2024</p>
|
| 971 |
+
</div>
|
| 972 |
+
""", unsafe_allow_html=True)
|
composite-defect-detector/generate_sample.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Sample image generator for testing CompositeDefect AI
|
| 3 |
+
Generates synthetic NDT-style images with simulated defects
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
from PIL import Image, ImageDraw
|
| 8 |
+
import random
|
| 9 |
+
|
| 10 |
+
def generate_ultrasonic_cscan(size=(512, 512), num_defects=5):
|
| 11 |
+
"""Generate a synthetic ultrasonic C-scan image"""
|
| 12 |
+
# Create base gradient background
|
| 13 |
+
img = np.zeros((size[1], size[0]), dtype=np.uint8)
|
| 14 |
+
|
| 15 |
+
# Add gradient
|
| 16 |
+
for y in range(size[1]):
|
| 17 |
+
img[y, :] = int(128 + 50 * np.sin(y / 50))
|
| 18 |
+
|
| 19 |
+
# Add noise
|
| 20 |
+
noise = np.random.normal(0, 10, (size[1], size[0])).astype(np.int16)
|
| 21 |
+
img = np.clip(img.astype(np.int16) + noise, 0, 255).astype(np.uint8)
|
| 22 |
+
|
| 23 |
+
# Add simulated defects (darker regions)
|
| 24 |
+
img_color = np.stack([img, img, img], axis=2)
|
| 25 |
+
|
| 26 |
+
pil_img = Image.fromarray(img_color)
|
| 27 |
+
draw = ImageDraw.Draw(pil_img)
|
| 28 |
+
|
| 29 |
+
for _ in range(num_defects):
|
| 30 |
+
x = random.randint(50, size[0] - 100)
|
| 31 |
+
y = random.randint(50, size[1] - 100)
|
| 32 |
+
w = random.randint(30, 80)
|
| 33 |
+
h = random.randint(30, 80)
|
| 34 |
+
|
| 35 |
+
# Draw dark ellipse for defect
|
| 36 |
+
draw.ellipse([x, y, x+w, y+h], fill=(40, 40, 60))
|
| 37 |
+
|
| 38 |
+
return pil_img
|
| 39 |
+
|
| 40 |
+
def generate_thermal_image(size=(512, 512), num_hotspots=4):
|
| 41 |
+
"""Generate a synthetic thermal/infrared image"""
|
| 42 |
+
img = np.zeros((size[1], size[0], 3), dtype=np.uint8)
|
| 43 |
+
|
| 44 |
+
# Base temperature (cool = blue)
|
| 45 |
+
img[:, :] = [30, 30, 80]
|
| 46 |
+
|
| 47 |
+
# Add hotspots (warm = red/yellow)
|
| 48 |
+
pil_img = Image.fromarray(img)
|
| 49 |
+
draw = ImageDraw.Draw(pil_img)
|
| 50 |
+
|
| 51 |
+
for _ in range(num_hotspots):
|
| 52 |
+
x = random.randint(50, size[0] - 100)
|
| 53 |
+
y = random.randint(50, size[1] - 100)
|
| 54 |
+
radius = random.randint(20, 60)
|
| 55 |
+
|
| 56 |
+
# Hotspot gradient
|
| 57 |
+
for r in range(radius, 0, -2):
|
| 58 |
+
intensity = int(255 * (1 - r/radius))
|
| 59 |
+
color = (255, intensity, 0) if intensity > 128 else (255, 0, 255-intensity)
|
| 60 |
+
draw.ellipse([x-r, y-r, x+r, y+r], fill=color)
|
| 61 |
+
|
| 62 |
+
return pil_img
|
| 63 |
+
|
| 64 |
+
def generate_radiograph(size=(512, 512), num_defects=3):
|
| 65 |
+
"""Generate a synthetic X-ray/radiographic image"""
|
| 66 |
+
# Base grey
|
| 67 |
+
img = np.full((size[1], size[0]), 180, dtype=np.uint8)
|
| 68 |
+
|
| 69 |
+
# Add structure lines (fibre orientation)
|
| 70 |
+
for i in range(0, size[0], 20):
|
| 71 |
+
img[:, i:i+2] = np.clip(img[:, i:i+2] - 20, 0, 255)
|
| 72 |
+
|
| 73 |
+
# Add defects (darker regions = less dense)
|
| 74 |
+
pil_img = Image.fromarray(img)
|
| 75 |
+
draw = ImageDraw.Draw(pil_img)
|
| 76 |
+
|
| 77 |
+
for _ in range(num_defects):
|
| 78 |
+
x = random.randint(50, size[0] - 150)
|
| 79 |
+
y = random.randint(50, size[1] - 150)
|
| 80 |
+
|
| 81 |
+
# Crack-like defect
|
| 82 |
+
if random.random() > 0.5:
|
| 83 |
+
x2 = x + random.randint(50, 150)
|
| 84 |
+
y2 = y + random.randint(-30, 30)
|
| 85 |
+
draw.line([(x, y), (x2, y2)], fill=80, width=3)
|
| 86 |
+
else:
|
| 87 |
+
# Void
|
| 88 |
+
w = random.randint(20, 50)
|
| 89 |
+
h = random.randint(20, 50)
|
| 90 |
+
draw.ellipse([x, y, x+w, y+h], fill=100)
|
| 91 |
+
|
| 92 |
+
return pil_img
|
| 93 |
+
|
| 94 |
+
def generate_visual_inspection(size=(512, 512), num_defects=4):
|
| 95 |
+
"""Generate a synthetic visual inspection image"""
|
| 96 |
+
# Carbon fibre weave pattern
|
| 97 |
+
img = np.zeros((size[1], size[0], 3), dtype=np.uint8)
|
| 98 |
+
img[:, :] = [40, 40, 40] # Dark carbon fibre base
|
| 99 |
+
|
| 100 |
+
# Add weave pattern
|
| 101 |
+
for i in range(0, size[0], 8):
|
| 102 |
+
img[:, i:i+4] = [60, 60, 60]
|
| 103 |
+
for i in range(0, size[1], 8):
|
| 104 |
+
img[i:i+4, :] = [50, 50, 50]
|
| 105 |
+
|
| 106 |
+
pil_img = Image.fromarray(img)
|
| 107 |
+
draw = ImageDraw.Draw(pil_img)
|
| 108 |
+
|
| 109 |
+
for _ in range(num_defects):
|
| 110 |
+
x = random.randint(50, size[0] - 100)
|
| 111 |
+
y = random.randint(50, size[1] - 100)
|
| 112 |
+
|
| 113 |
+
defect_type = random.choice(['delamination', 'scratch', 'discoloration'])
|
| 114 |
+
|
| 115 |
+
if defect_type == 'delamination':
|
| 116 |
+
# Delamination - lighter area
|
| 117 |
+
w = random.randint(40, 100)
|
| 118 |
+
h = random.randint(40, 100)
|
| 119 |
+
draw.ellipse([x, y, x+w, y+h], fill=(100, 100, 100, 128))
|
| 120 |
+
elif defect_type == 'scratch':
|
| 121 |
+
# Scratch line
|
| 122 |
+
x2 = x + random.randint(30, 100)
|
| 123 |
+
y2 = y + random.randint(-20, 20)
|
| 124 |
+
draw.line([(x, y), (x2, y2)], fill=(150, 150, 150), width=2)
|
| 125 |
+
else:
|
| 126 |
+
# Discoloration
|
| 127 |
+
w = random.randint(30, 80)
|
| 128 |
+
h = random.randint(30, 80)
|
| 129 |
+
draw.rectangle([x, y, x+w, y+h], fill=(80, 60, 40))
|
| 130 |
+
|
| 131 |
+
return pil_img
|
| 132 |
+
|
| 133 |
+
def main():
|
| 134 |
+
"""Generate sample images for testing"""
|
| 135 |
+
print("π¬ Generating sample NDT images for testing...")
|
| 136 |
+
|
| 137 |
+
# Generate different types of NDT images
|
| 138 |
+
ultrasonic = generate_ultrasonic_cscan(num_defects=6)
|
| 139 |
+
ultrasonic.save('sample_ultrasonic.png')
|
| 140 |
+
print("β
Generated: sample_ultrasonic.png")
|
| 141 |
+
|
| 142 |
+
thermal = generate_thermal_image(num_hotspots=5)
|
| 143 |
+
thermal.save('sample_thermal.png')
|
| 144 |
+
print("β
Generated: sample_thermal.png")
|
| 145 |
+
|
| 146 |
+
radiograph = generate_radiograph(num_defects=4)
|
| 147 |
+
radiograph.save('sample_radiograph.png')
|
| 148 |
+
print("β
Generated: sample_radiograph.png")
|
| 149 |
+
|
| 150 |
+
visual = generate_visual_inspection(num_defects=5)
|
| 151 |
+
visual.save('sample_visual.png')
|
| 152 |
+
print("β
Generated: sample_visual.png")
|
| 153 |
+
|
| 154 |
+
print("\nπ Sample images saved in current directory")
|
| 155 |
+
print("π You can now test the CompositeDefect AI application!")
|
| 156 |
+
|
| 157 |
+
if __name__ == "__main__":
|
| 158 |
+
main()
|
composite-defect-detector/requirements.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.29.0
|
| 2 |
+
numpy==1.24.3
|
| 3 |
+
pillow==10.0.1
|
| 4 |
+
opencv-python-headless==4.8.1.78
|
| 5 |
+
matplotlib==3.7.2
|
| 6 |
+
plotly==5.17.0
|
| 7 |
+
pandas==2.0.3
|
| 8 |
+
scikit-learn==1.3.0
|
| 9 |
+
scikit-image==0.21.0
|
| 10 |
+
scipy==1.11.2
|
| 11 |
+
tensorflow==2.13.0
|
| 12 |
+
keras==2.13.1
|
| 13 |
+
altair==5.1.2
|
| 14 |
+
seaborn==0.12.2
|
composite-defect-detector/run.sh
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
echo "π¬ CompositeDefect AI - NDT Analysis System"
|
| 4 |
+
echo "============================================"
|
| 5 |
+
echo ""
|
| 6 |
+
|
| 7 |
+
# Check if Python is installed
|
| 8 |
+
if ! command -v python3 &> /dev/null; then
|
| 9 |
+
echo "β Python 3 is not installed. Please install Python 3.8 or higher."
|
| 10 |
+
exit 1
|
| 11 |
+
fi
|
| 12 |
+
|
| 13 |
+
# Check if pip is installed
|
| 14 |
+
if ! command -v pip &> /dev/null; then
|
| 15 |
+
echo "β pip is not installed. Please install pip."
|
| 16 |
+
exit 1
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
# Check if requirements are installed
|
| 20 |
+
echo "π¦ Checking dependencies..."
|
| 21 |
+
pip install -q -r requirements.txt
|
| 22 |
+
|
| 23 |
+
if [ $? -ne 0 ]; then
|
| 24 |
+
echo "β Failed to install dependencies. Please check your internet connection."
|
| 25 |
+
exit 1
|
| 26 |
+
fi
|
| 27 |
+
|
| 28 |
+
echo "β
Dependencies installed successfully!"
|
| 29 |
+
echo ""
|
| 30 |
+
|
| 31 |
+
# Run the Streamlit application
|
| 32 |
+
echo "π Starting CompositeDefect AI..."
|
| 33 |
+
echo ""
|
| 34 |
+
streamlit run app.py
|
composite-defect-detector/sample_radiograph.png
ADDED
|
composite-defect-detector/sample_thermal.png
ADDED
|
composite-defect-detector/sample_ultrasonic.png
ADDED
|
Git LFS Details
|
composite-defect-detector/sample_visual.png
ADDED
|