Skip to content

Latest commit

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Casting Defect Detection — Dataset Augmentation Pipeline

Generate a large, labelled casting-defect dataset from just a handful of OK images.


Project Structure

casting_project/
│
├── Data/ ← Put your 6 OK casting images here
├── hand_images/ ← Put your hand image (hand.jpg) here
│
├── run_complete_pipeline.py ← MAIN ENTRY POINT — run this
├── casting_defect_augmentation.py ← Defect generation + albumentations
├── real_hand_overlay.py ← Hand overlay augmentation
├── demo_visualization.py ← Visualization grids
├── advanced_defect_analysis.py ← Post-run selection & analysis tools
│
├── requirements.txt
└── README.md

Quick Start

# 1. Install dependencies
pip install -r requirements.txt
# 2. Add your images# • Place your 6 OK casting images inside Data/# • Place your hand photo inside hand_images/# 3. Run the pipeline
python run_complete_pipeline.py

Output Structure

output/
├── defect_dataset/
│ ├── ok/ (augmented OK images)
│ ├── scratch/
│ ├── crack/
│ ├── porosity/
│ ├── pinhole/
│ ├── inclusion/
│ ├── shrinkage/
│ ├── surface_roughness/
│ ├── dent/
│ ├── cold_shut/
│ ├── flash/
│ ├── mixed_defects/
│ └── dataset_stats.json
│
├── hand_overlays/
│ ├── casting0_hand0/ (44 overlay images per combination)
│ ├── casting1_hand0/
│ ├── casting2_hand0/
│ ├── casting3_hand0/
│ ├── casting4_hand0/
│ └── casting5_hand0/
│
└── visualizations/
├── defect_samples/ (grid of all 12 defect types)
├── intensity_samples/ (scratch intensity comparison)
└── augmentation_samples/(aug pipeline demo)

Pipeline Steps

StepScriptWhat it does
1casting_defect_augmentation.pyInjects 11 defect types on OK images using OpenCV, applies 16-op albumentations pipeline
2real_hand_overlay.pyRemoves hand background (GrabCut), places hand in 24 fixed + 20 random positions
3demo_visualization.pySaves PNG grids showing all defects and augmentation transforms

Defect Types Generated

TypeMethod
ScratchRandom dark lines, Gaussian blur
CrackBranching polylines with sub-cracks
PorosityDark filled circles with subtle edges
PinholeTiny 1–3 px dark circles
InclusionElliptical bright/dark spots with noise
Shrinkage CavityIrregular dark polygons
Surface RoughnessGaussian noise + rough patches
DentGradient shading circle
Cold ShutWavy sinusoidal flow line
FlashBright band on a random edge
Mixed Defects2–3 random defects combined

Hand Overlay Positions (per casting × hand pair)

24 predefined positions: top-left, top-center, top-right, middle-left, center, middle-right, bottom-left, bottom-center, bottom-right, four quarter positions, four partial-frame positions, three centre-scale-rotation variants, four edge-touch positions.

20 random variations: randomised position, scale (0.5–1.3×), rotation (±180°), opacity (0.8–1.0).


Advanced Analysis (Optional)

After running the pipeline, use advanced_defect_analysis.py to:

fromadvanced_defect_analysisimportDefectSelector, VisualSummaryGenerator# Select top 100 per defect typeselector=DefectSelector("output/defect_dataset", output_dir="selected")
images=selector.select_top_n_per_type(n=100)
selector.copy_selected_images(images)
selector.create_selection_report(images)
# Visual summaryviz=VisualSummaryGenerator("visual_summaries")
viz.create_dataset_summary_chart("output/defect_dataset")
viz.create_per_type_grid("output/defect_dataset", n_per_type=5)

Configuration

Edit the bottom of run_complete_pipeline.py:

INPUT_OK_IMAGES="Data"# path to OK casting imagesHAND_IMAGES="hand_images"# path to hand image(s)OUTPUT_DIR="output"# output root folderIMAGES_PER_CLASS=100# 100 for testing, 1000 for full runrun_complete_pipeline(
run_defect_generation=True,
run_hand_overlay=True,
run_visualizations=True,
)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages