Skip to content

SimranShaikh20/Defect-Detection-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

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

Defect Types Generated

Type Method
Scratch Random dark lines, Gaussian blur
Crack Branching polylines with sub-cracks
Porosity Dark filled circles with subtle edges
Pinhole Tiny 1–3 px dark circles
Inclusion Elliptical bright/dark spots with noise
Shrinkage Cavity Irregular dark polygons
Surface Roughness Gaussian noise + rough patches
Dent Gradient shading circle
Cold Shut Wavy sinusoidal flow line
Flash Bright band on a random edge
Mixed Defects 2–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:

from advanced_defect_analysis import DefectSelector, VisualSummaryGenerator

# Select top 100 per defect type
selector = 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 summary
viz = 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 images
HAND_IMAGES      = "hand_images" # path to hand image(s)
OUTPUT_DIR       = "output"      # output root folder
IMAGES_PER_CLASS = 100           # 100 for testing, 1000 for full run

run_complete_pipeline(
    run_defect_generation=True,
    run_hand_overlay=True,
    run_visualizations=True,
)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors