Skip to content

Detect tampered images using Error Level Analysis (ELA) and deep learning. A custom CNN model trained on ELA-transformed images outperforms transfer learning baselines like VGG16, ResNet50, and MobileNetV2.

License

Notifications You must be signed in to change notification settings

Divyansh-git10/Image-Forgery-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🕵️‍♂️ Image Forgery Detection using ELA and Custom CNN

📌 Project Overview

This project tackles the problem of image forgery detection using deep learning. The objective is to distinguish between authentic and tampered images using visual evidence generated by Error Level Analysis (ELA). While transfer learning models were explored, the best results were achieved using a custom CNN model trained specifically on ELA-transformed images.


🧠 Motivation

With the increasing accessibility of image editing tools, forged images are everywhere — from social media to news. Most forgeries leave subtle compression artifacts. ELA helps expose these inconsistencies, making it a valuable preprocessing tool for image forgery detection.


📂 Dataset

  • CASIA 2.0 Dataset
    • Contains two types of images:
      • Au/ folder → Authentic images
      • Tp/ folder → Tampered images
    • Includes splicing and copy-move forgeries

🖼️ Preprocessing: Error Level Analysis (ELA)

To highlight tampered regions:

  1. Save each image at 90% JPEG quality
  2. Subtract the resaved image from the original
  3. Amplify the difference to highlight compression artifacts
  4. Resize and normalize for model input

All images (authentic & tampered) were transformed into ELA format before model training.


🧪 Models Trained

1. Transfer Learning Models on ELA Images

  • 🔸 VGG16

    • Val Accuracy: 82.37%
    • Precision: 90.91%
    • Recall: 73.17%
  • 🔸 ResNet50

    • Val Accuracy: 85.39%
    • Precision: 88.48%
    • Recall: 82.44%
  • 🔸 MobileNetV2

    • Val Accuracy: 84.38%
    • Precision: 87.83%
    • Recall: 80.98%

Despite their architectural strength, these models couldn’t fully exploit ELA-based features.


2. ✅ Custom CNN (Best Performer)

After observing limited performance from transfer learning, a custom CNN was built from scratch to focus on ELA-specific features.

Final Performance (Epoch 30):

  • Validation Accuracy: 91.18%
  • Precision: 97.75%
  • Recall: 84.88%
  • 🔸 Total Parameters: ~24.2M

🧠 Architecture Overview

Input (150x150x3)
  ↓
Conv2D (32 filters, 5x5) → ReLU  
  ↓
Conv2D (32 filters, 5x5) → ReLU  
  ↓
MaxPooling2D (2x2)
  ↓
Dropout (0.25)
  ↓
Flatten
  ↓
Dense (150) → ReLU  
  ↓
Dropout (0.5)
  ↓
Dense (1) → Sigmoid

🏆 Key Insights

  • All models were trained on ELA-transformed CASIA 2.0 images
  • Transfer learning models underperformed, likely because their pretrained filters were not optimized for ELA noise patterns
  • The custom CNN, being task-specific, generalized better

“Tailored architectures for domain-specific preprocessing like ELA can outperform large pretrained models in real-world forensic tasks.”


📈 Model Comparison

Model 🔍 Val Accuracy 🎯 Precision 🔁 Recall ⚙️ Params
✅ Custom CNN 91.18% 97.75% 84.88% 24.2M
VGG16 82.37% 90.91% 73.17% 14.7M
ResNet50 85.39% 88.48% 82.44% 23.6M
MobileNetV2 84.38% 87.83% 80.98% 2.4M

🧾 Requirements

python>=3.8
tensorflow>=2.9
opencv-python
pillow
matplotlib
scikit-learn

Install with:

pip install -r requirements.txt

📁 Folder Structure

Image-Forgery-Detection-ELA/
├── dataset/
│   ├── Au/              # Authentic images
│   └── Tp/              # Tampered images
├── ela_images/          # ELA-processed images
├── saved_model/         # Saved best model (optional)
├── ML_PROJECT_IMPLEMENTATION.ipynb
├── requirements.txt
└── README.md

📊 Confusion Matrix (Approx. from Evaluation)

  • ✅ True Positives (TP): 45
  • ✅ True Negatives (TN): 47
  • ❌ False Positives (FP): 3
  • ❌ False Negatives (FN): 5

📚 What I Learned

  • How ELA highlights compression artifacts in tampered images
  • Importance of proper preprocessing for visual forensics
  • Transfer learning is not always superior to custom-designed models
  • Designing task-specific CNNs can lead to better generalization

⚠️ Challenges Faced

  • Transfer learning models couldn’t effectively extract ELA features
  • Required large number of ELA-processed images and preprocessing time
  • Needed to manually tune dropout and dense layers to avoid overfitting
  • ELA differences can be subtle and sometimes confuse the model

🔮 Future Improvements

  • Introduce Vision Transformers (ViT) and compare with CNN
  • Build a Streamlit or Flask-based UI to upload & detect forged images
  • Train on a multi-class dataset (copy-move vs splicing vs authentic)
  • Try feature fusion: combine ELA with other forensic indicators

🚀 Run the Project

  1. Clone the repo:
git clone https://github.com/Divyansh-git10/image-forgery-detection
cd image-forgery-detection
  1. Install requirements:
pip install -r requirements.txt
  1. Run the notebook:
jupyter notebook ML_PROJECT_IMPLEMENTATION.ipynb

✨ Author

Divyansh Gautam
AI/ML enthusiast passionate about computer vision, natural language processing (NLP), and deep learning.

About

Detect tampered images using Error Level Analysis (ELA) and deep learning. A custom CNN model trained on ELA-transformed images outperforms transfer learning baselines like VGG16, ResNet50, and MobileNetV2.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published