satyaki-mitra/ImageForensics-AI
<div align="center">
ImageForensics-AI
          
A transparent, multi-tier evidence-first screening system for identifying images requiring human review in production workflows
</div>
๐ Table of Contents
- Overview
- Key Features
- Architecture Overview
- Documentation
- Technical Details
- API Documentation
- System Architecture
- Detection Approach
- Decision Policy Rules
- Installation
- Quick Start
- Configuration
- Performance & Accuracy
- Ethical Considerations & Limitations
- License
๐ฏ Overview
ImageForensics-AI is a Two-Tiered evidence-first screening tool designed to reduce manual review workload by analyzing images through statistical metrics (Tier-1) and declarative evidence (Tier-2), then resolving through a deterministic decision policy.
What This Is
โ A workflow efficiency tool with evidence-first architecture โ A transparent, explainable multi-tier detector โ A model-agnostic screening system with declarative evidence โ A first-pass filter with policy-based decisions
What This Is Not
โ A definitive "real vs fake" classifier โ A black-box deep learning detector โ A system claiming near-perfect accuracy on 2025 AI models
๐ Key Features
- Tiered Analysis:
- Tier-1: 5 statistical metric detectors
- Tier-2: Declarative evidence analyzers (EXIF, watermark)
- Decision Layer: Evidence-first policy engine
- Multi-Class Decisions: Four nuanced outcomes beyond binary classification
- Full Explainability: Per-metric scores, evidence findings, and human-readable explanations
- Batch Processing: Parallel analysis of up to 50 images with progress tracking
- Multiple Export Formats: CSV, JSON reports for integration into existing workflows
- No External Dependencies: No ML models, no cloud APIs - fully self-contained
- Production Ready: FastAPI backend, comprehensive error handling, configurable thresholds
๐๏ธ Architecture Overview
Two-Tier Analysis with Evidence-First Decision
flowchart TD
%% Overall System Flow
Input[๐ Input: Image File]
%% Tier 1: Statistical Metrics
subgraph Tier1 [Tier 1: Statistical Metrics]
Gradient[Gradient PCA<br/>Eigenvalue Analysis]
Frequency[Frequency FFT<br/>Spectral Analysis]
Noise[Noise Pattern<br/>Sensor Noise Analysis]
Texture[Texture Stats<br/>Smoothness Detection]
Color[Color Distribution<br/>Saturation & Hue Analysis]
end
%% Tier 1 Aggregation
Aggregator1[Signal Aggregator<br/>Weighted Ensemble]
Status1{Detection Status}
%% Tier 2: Declarative Evidence
subgraph Tier2 [Tier 2: Declarative Evidence]
EXIF[EXIF Analyzer<br/>Metadata Forensics]
Watermark[Watermark Detector<br/>Statistical Patterns]
Future[C2PA Analyzer<br/>Provenance - Future]
end
%% Tier 2 Aggregation
Aggregator2[Evidence Aggregator<br/>Deduplication & Ranking]
Evidence[(Evidence Results<br/>with Strength & Direction)]
%% Decision Engine
subgraph Decision [Decision Policy Engine]
Rule1[Rule 1: Conclusive evidence<br/>overrides all]
Rule2[Rule 2: Strong evidence ><br/>statistical metrics]
Rule3[Rule 3: Conflicting evidence โ Review Required]
Rule4[Rule 4: No evidence โ<br/>fallback to Tier 1]
end
%% Final Decisions
Final1[โ
CONFIRMED_AI_GENERATED<br/>Conclusive evidence]
Final2[โ ๏ธ SUSPICIOUS_AI_LIKELY<br/>Strong evidence/metrics]
Final3[๐ AUTHENTIC_BUT_REVIEW<br/>Conflicting/weak evidence]
Final4[โ MOSTLY_AUTHENTIC<br/>Strong authentic evidence]
%% Connections
Input --> Tier1
Input --> Tier2
Gradient --> Aggregator1
Frequency --> Aggregator1
Noise --> Aggregator1
Texture --> Aggregator1
Color --> Aggregator1
Aggregator1 --> Status1
EXIF --> Aggregator2
Watermark --> Aggregator2
Future -.-> Aggregator2
Aggregator2 --> Evidence
Status1 --> Decision
Evidence --> Decision
Decision --> Rule1
Decision --> Rule2
Decision --> Rule3
Decision --> Rule4
Rule1 --> Final1
Rule2 --> Final2
Rule3 --> Final3
Rule4 --> Final4
%% Styling
classDef tier1 fill:#e1f5fe,stroke:#01579b,stroke-width:2px
classDef tier2 fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#ff6f00,stroke-width:2px
classDef final fill:#e8f5e8,stroke:#2e7d32,stroke-width:2px
class Tier1 tier1
class Tier2 tier2
class Decision decision
class Final1,Final2,Final3,Final4 final๐ Documentation
For detailed technical information, see our comprehensive documentation:
- [API Documentation](docs/API_DOCUMENTATION.md) - Complete API reference, endpoints, request/response formats, and examples
- [Technical Documentation](docs/TECHNICAL_DOCUMENTATION.md) - In-depth technical details, algorithms, mathematical formulations, and implementation specifics
- [Architecture Guide](docs/ARCHITECTURE.md) - System architecture, component interactions, data flow, and deployment diagrams
๐ฌ Technical Details
For those interested in the underlying algorithms and implementation:
Algorithmic Foundations
a) Gradient-Field PCA Analysis
For each color channel $C \in \{R, G, B\}$:
- Compute Sobel gradients:
$$Gx = Sx C, \quad G_y = S_y C$$
where $Sx, Sy$ are Sobel operators
- Construct gradient matrix:
$$M = [\text{vec}(Gx), \text{vec}(Gy)]^T$$
- Perform PCA:
$$\text{cov} = M^T M, \quad \text{eigenvalues} = \text{eig}(\text{cov})$$
- Compute eigenvalue ratio:
$$\text{ratio} = \frac{\lambda2}{\lambda1 + \lambda_2}$$
b) Frequency Domain Analysis
Let $I(x,y)$ be the luminance channel:
- Compute 2D FFT:
$$F(u,v) = \mathcal{F}\{I(x,y)\}$$
- Radial spectrum:
$$P(r) = \frac{1}{Nr} \sum{r \leq \sqrt{u^2+v^2} < r+1} |F(u,v)|^2$$
- High-frequency ratio:
$$\text{HF ratio} = \frac{\sum{r>Rc} P(r)}{\sum_{r} P(r)}$$
where $R_c$ is the cutoff radius
c) LSB Steganography Detection
For each color channel $C$:
$$\text{LSB}(C) = C \wedge 1$$
Statistical test:
$$\chi^2 = \sum_{b=0}^{1} \frac{(H(b) - E)^2}{E}$$
where $H(b)$ is the histogram of LSB values and $E = \frac{H}{2}$
๐ API Documentation
REST API Endpoints
POST /analyze/image
Analyze a single image file.
Request:
curl -X POST http://localhost:8005/analyze/image \
-F "file=@image.jpg" \
-H "Accept: application/json"Response:
{
"image_id": "img_abc123",
"filename": "image.jpg",
"decision": "MOSTLY_AUTHENTIC",
"confidence": 0.85,
"tier1_metrics": {
"gradient_pca": {"score": 0.72, "status": "REVIEW_REQUIRED"},
"frequency_fft": {"score": 0.91, "status": "LIKELY_AUTHENTIC"},
"...": "..."
},
"evidence_findings": [
{"type": "EXIF", "direction": "AUTHENTIC", "strength": "MODERATE"}
],
"explanation": "Image shows strong authentic EXIF data..."
}For complete API documentation, see API Documentation
๐๏ธ System Architecture
Component Structure
ImageForensics-AI/
โโโ app.py # FastAPI application
โโโ config/
โ โโโ settings.py # Environment config
โ โโโ constants.py # Enums, parameters, explanations
โ โโโ schemas.py # Pydantic models
โโโ metrics/ # TIER 1: Statistical detectors
โ โโโ gradient_field_pca.py
โ โโโ frequency_analyzer.py
โ โโโ noise_analyzer.py
โ โโโ texture_analyzer.py
โ โโโ color_analyzer.py
โ โโโ signal_aggregator.py # Metric orchestration
โโโ evidence_analyzers/ # TIER 2: Declarative evidence
โ โโโ exif_analyzer.py
โ โโโ watermark_analyzer.py
โ โโโ evidence_aggregator.py # Evidence orchestration
โโโ decision_builders/
โ โโโ decision_policy.py # Evidence-first decision rules
โโโ features/
โ โโโ batch_processor.py # Batch orchestration
โ โโโ threshold_manager.py # Runtime configuration
โ โโโ detailed_result_maker.py # Explainability extraction
โโโ reporter/
โ โโโ csv_reporter.py # CSV export
โ โโโ json_reporter.py # JSON API responses
โโโ utils/
โ โโโ logger.py # Structured logging
โ โโโ image_processor.py # Image utilities
โ โโโ validators.py # File validation
โ โโโ helpers.py # General utilities
โโโ ui/
โโโ index.html # Web interfaceData Flow
Image โ Validation โ [Tier-1 Metrics + Tier-2 Evidence] โ Aggregation โ Decision Policy โ Final Decision โ Reporting
โ โ โ
SignalAggregator EvidenceAggregator DecisionPolicyComponent Interactions
flowchart TD
subgraph "API Layer"
API[FastAPI Server]
VALIDATOR[Image Validator]
end
subgraph "Processing Layer"
BATCH[Batch Processor]
end
subgraph "Detection Layer"
METRICS[Tier-1 Metrics]
EVIDENCE[Tier-2 Evidence]
end
subgraph "Decision Layer"
POLICY[Decision Policy Engine]
end
API --> VALIDATOR
VALIDATOR --> BATCH
BATCH --> METRICS
BATCH --> EVIDENCE
METRICS --> POLICY
EVIDENCE --> POLICYFor detailed architecture diagrams and component specifications, see Architecture Guide
๐ฌ Detection Approach
Core Philosophy: Evidence-First Decision Making
Instead of probabilistic inference, we apply deterministic rules:
- Conclusive Evidence (e.g., cryptographic watermarks) โ Immediate decision
- Strong Evidence (e.g., AI tool fingerprints) โ Overrides statistical metrics
- Moderate Evidence โ Combined with statistical assessment
- No Evidence โ Fallback to statistical metrics
Tier-1: Statistical Metrics (Unsupervised)
Five orthogonal metrics targeting different AI generation failure modes:
1. Gradient-Field PCA (30% weight)
- Target: Lighting inconsistencies in diffusion models
- Method: Sobel gradients โ PCA โ eigenvalue ratio analysis
- Threshold: Eigenvalue ratio < 0.85 indicates suspicious structure
- Research Basis: Gragnaniello et al. 2021
2. Frequency Analysis (FFT) (25% weight)
- Target: Unnatural spectral energy distributions
- Method: 2D FFT โ radial spectrum โ HF ratio + roughness + deviation
- Thresholds: HF ratio outside [0.08, 0.35] indicates anomalies
- Research Basis: Dzanic et al. 2020
3. Noise Pattern Analysis (20% weight)
- Target: Missing or artificial sensor noise
- Method: Patch-based Laplacian filtering โ MAD estimation โ CV + IQR analysis
- Thresholds: CV < 0.15 (too uniform) or > 1.2 (too variable)
- Research Basis: Kirchner & Johnson 2019
4. Texture Statistics (15% weight)
- Target: Overly smooth or repetitive regions
- Method: Patch-based entropy, contrast, edge density โ distribution analysis
- Thresholds: >40% smooth patches (smoothness > 0.5) indicates anomalies
- Research Basis: Nataraj et al. 2019
5. Color Distribution (10% weight)
- Target: Impossible or unlikely color patterns
- Method: RGBโHSV โ saturation analysis + histogram roughness + hue concentration
- Thresholds: Mean saturation > 0.65 or top-3 hue bins > 60%
- Research Basis: Marra et al. 2019
Tier-2: Declarative Evidence (Non-Scoring)
EXIF Analyzer
- Purpose: Extract and analyze metadata for authenticity indicators
- Checks: AI software fingerprints, camera metadata consistency, timestamp plausibility
- Output: Directional evidence (AI_GENERATED/AUTHENTIC/INDETERMINATE) with confidence
Watermark Analyzer
- Purpose: Detect statistical patterns of invisible watermarks
- Methods: Wavelet decomposition, frequency domain analysis, LSB steganography detection
- Output: Evidence of potential watermarking with strength assessment
๐ Decision Policy Rules
Authority Hierarchy
- Conclusive Evidence (EvidenceStrength.CONCLUSIVE) โ Immediate override
- Strong Evidence (EvidenceStrength.STRONG) โ Overrides contradictory metrics
- Moderate Evidence โ Combined with metric confidence
- Weak/Indeterminate Evidence โ Supplementary only
Conflict Resolution
- AI vs Authentic Evidence: Strongest evidence type wins; ties โ "REVIEW_REQUIRED"
- Multiple Indeterminate Findings: โฅ2 indeterminate items โ "AUTHENTICBUTREVIEW"
- No Evidence: Fallback to Tier-1 metric status
Final Decision Mapping
# Evidence rules take precedence
if conclusive_ai_evidence:
return FinalDecision.CONFIRMED_AI_GENERATED
elif strong_ai_evidence:
return FinalDecision.SUSPICIOUS_AI_LIKELY
elif strong_authentic_evidence:
return FinalDecision.MOSTLY_AUTHENTIC
elif conflicting_moderate_evidence:
return FinalDecision.AUTHENTIC_BUT_REVIEW
# Fallback to Tier-1 metrics
elif (tier1_status == "REVIEW_REQUIRED"):
return FinalDecision.SUSPICIOUS_AI_LIKELY
else:
return FinalDecision.MOSTLY_AUTHENTIC๐ฆ Installation
Prerequisites
- Python 3.11+
- pip
Setup
# Clone repository
git clone https://github.com/satyaki-mitra/ImageForensics-AI.git
cd ImageForensics-AI
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create required directories
mkdir -p data/{uploads,reports,cache} logs
# Run server
python app.py- Server starts at
http://localhost:8005
๐ Quick Start
Web Interface
- Open
http://localhost:8005in browser
- Upload images (single or batch)
- View results with evidence breakdown
- Export reports (CSV/JSON)
API Usage
# Single image analysis
curl -X POST http://localhost:8005/analyze/image \
-F "file=@example.jpg"
# Batch analysis
curl -X POST http://localhost:8005/analyze/batch \
-F "files=@img1.jpg" \
-F "files=@img2.png"
# Get batch progress
curl http://localhost:8005/batch/{batch_id}/progress
# Download CSV report
curl http://localhost:8005/report/csv/{batch_id} -o report.csvโ๏ธ Configuration
Environment Variables (.env)
# Server
HOST=localhost
PORT=8005
DEBUG=False
# Detection Thresholds
REVIEW_THRESHOLD=0.65
# Tier-1 Metric Weights (must sum to 1.0)
GRADIENT_WEIGHT=0.30
FREQUENCY_WEIGHT=0.25
NOISE_WEIGHT=0.20
TEXTURE_WEIGHT=0.15
COLOR_WEIGHT=0.10
# Processing
MAX_FILE_SIZE_MB=10
MAX_BATCH_SIZE=50
PARALLEL_PROCESSING=True
MAX_WORKERS=4Runtime Configuration via API
# Adjust thresholds dynamically
threshold_manager.set_review_threshold(0.70)
threshold_manager.set_metric_weight(MetricType.GRADIENT, 0.35)
# Get recommendations
recommendations = threshold_manager.get_recommendations(score=0.85)๐ Performance & Accuracy
Expected Detection Rates
Processing Performance
- Single Image: 2โ4 seconds (metrics + evidence)
- Batch (10): 15โ25 seconds (parallel)
- Memory: 50โ150 MB per image
- Concurrency: 4 workers (configurable)
โ ๏ธ Ethical Considerations & Limitations
Appropriate Use Cases
โ Content moderation pre-screening: Reduces human workload โ Journalism verification workflows: Identifies images needing source checking โ Stock media platforms: Flags for manual review before publication โ Academic research: Transparent methodology for study
Not Suitable For
โ Law enforcement as sole evidence: Always requires human verification โ Automated content rejection without review: Human-in-loop required โ High-stakes individual decisions: e.g., employment, legal proceedings
Known Limitations
- Evolving Generators: Detection rates decline as AI models improve
- Adversarial Evasion: Intentional post-processing can defeat statistical detectors
- Cultural Bias: Training data biases may affect certain image types
- No Ground Truth: Statistical anomalies don't guarantee AI origin
๐ License
MIT License - see LICENSE file for details.
๐ค Author
Satyaki Mitra Data Scientist | AI-ML Practitioner
๐ Acknowledgments
- Research papers cited for theoretical foundations
- FastAPI team for excellent web framework
- OpenCV and SciPy communities for image processing tools
๐ Resources
- ๐ API Documentation - Complete API reference, endpoints, request/response formats
- ๐ฌ Technical Documentation - Algorithms, mathematical formulations, implementation details
- ๐๏ธ Architecture Guide - System architecture, component interactions, data flow diagrams
<div align="center">
<i>Built with transparency and evidence-first principles.</i> <br> <i>Screening, not certainty. Evidence, not guesswork.</i>
</div>
