This is a self-contained Python playground that simulates, attacks, and evaluates classical edge-detection pipelines (Sobel, Canny, Laplacian of Gaussian, Roberts Cross). It lets you
- preprocess and normalise a set of demo images;
- run a variety of targeted (algorithm-specific) and progressive (generic) adversarial attacks;
- compute effectiveness metrics (edge-density drop, contour-area reduction, fragmentation); and
- save side-by-side artefacts (clean / attacked / edge-maps) plus JSON scorecards for later analysis.
Everything is pure NumPy + OpenCV—no deep-learning toolkit required.
| Module | Purpose |
|---|---|
targeted_attacks.py |
Three attacks that focus on strong-edge pixels (blur, gradient reversal, contour disruption). |
progressive_attacks.py |
Pixel-noise escalation and generic edge/contour attacks executed over multiple “gentle → aggressive” rounds. |
canny_targeted_attacks.py |
Five attacks that exploit specific Canny stages (hysteresis noise, gradient smoothing, non-max-suppression confusion, connectivity gaps, multi-scale perturbations) and sweep three Canny hyper-parameter sets. |
simulation_engine.py |
Object-oriented façade (EdgeAttackSimulationEngine) with > 40 tunable parameters – useful for interactive notebooks or web front-ends. |
Each script deposits PNG artefacts plus a *_results.json manifest in its own output folder (targeted_attacks/, progressive_attacks/, …).
# 1. Clone and cd
git clone https://github.com/<you>/edge-attack-lab.git
cd edge-attack-lab
# 2. Create environment (≈ Python 3.9+)
python -m venv .venv
source .venv/bin/activate # Linux / macOS
# .venv\Scripts\activate.bat # Windows
# 3. Install runtime deps
pip install -r requirements.txt
# requirements.txt
# ├─ numpy
# └─ opencv-pythonTip: add
opencv-contrib-pythonif you later need advanced CV functions.
# 1. Generic Sobel / contour / gradient demo
python targeted_attacks.py
# 2. Six-stage progressive escalation
python progressive_attacks.py
# 3. Canny-specific research sweep
python canny_targeted_attacks.py
# 4. Custom batch with OO engine
python simulation_engine.pyEach run ends with a concise success tally:
Results saved to 'progressive_attacks/'
Successful attacks: 11/18
and drops artefacts such as:
progressive_attacks/
│ street_scene-sobel-gentle_pixels-clean.png
│ street_scene-sobel-gentle_pixels-pert.png
│ street_scene-sobel-gentle_pixels-edges-clean.png
│ street_scene-sobel-gentle_pixels-edges-pert.png
└─ metadata.json
| Metric | Meaning | Success threshold |
|---|---|---|
edge_density_reduction |
Fractional drop in total edge pixels. | > 15 % |
contour_area_reduction |
Drop in largest connected edge region. | > 20 % |
fragmentation_increase |
(Canny-only) rise in contour count. | > 50 % |
attack_success |
True if any threshold is crossed. | – |
-
Add a new attack Implement a function that takes
gray_image: np.ndarrayand returns a perturbed image of identical shape. Register it inside the relevantattack_functionsdictionary. -
Plug in your own images Drop them into
source_images/and extend theIMAGE_SOURCESmapping. -
Integrate with notebooks / web UI Import
EdgeAttackSimulationEngine, tweakSimulationConfig, and callexecute_simulation_on_image(...).
- 🔬 Add patch-wise learned perturbations via gradient-free optimisation.
- 🖥 Streamline a Streamlit or Next.js front-end for interactive exploration.
- 📊 Auto-generate HTML reports comparing detectors, attacks, and thresholds.
Pull requests and issue reports are welcome!