A Python-based tool for detecting potential image forgeries using Error Level Analysis (ELA) technique. This project helps identify manipulated regions in JPEG images by analyzing compression artifacts.
- Overview
- Features
- Requirements
- Installation
- Usage
- How It Works
- Parameters
- Output
- Interpretation
- Limitations
- Use Cases
- Contributing
- License
- Disclaimer
This tool implements Error Level Analysis, a forensic technique that detects areas within an image that have been modified or manipulated. When an image is saved as JPEG multiple times, different regions show different error levels depending on how many times they've been compressed. Forged areas typically show different error levels compared to the original parts of the image.
- β ELA Analysis - Performs Error Level Analysis on input images
- β Brightness & Contrast Enhancement - Improves visibility of compression artifacts
- β Block-based Detection - Scans images in blocks to identify potential forgery regions
- β Automated Reporting - Prints coordinates of suspicious blocks
- β Visual Output - Generates ELA difference images for manual inspection
Python 3.x
PIL (Pillow)
git clone https://github.com/yourusername/image-forgery-detection.git
cd image-forgery-detectionpip install Pillow- Update the
image_pathvariable with your input image location - Update the
output_ela_pathvariable with your desired output location - Run the script:
python image_forgery_detection.pyif __name__ == "__main__":
image_path = "path/to/your/image.jpeg"
output_ela_path = "path/to/output/ela_result.jpeg"
forgery_detection(image_path, output_ela_path)You can adjust the detection parameters:
# Adjust JPEG quality for ELA (default: 90)
ela_analysis(image_path, output_path, quality=90)
# Adjust block size and threshold for detection
forgery_detection(image_path, output_path, block_size=16, threshold=30)- Opens the original image
- Saves it at a specified JPEG quality level
- Calculates the difference between original and re-compressed version
- Enhances brightness and contrast for better visibility
- Scales the difference to maximize visibility
- Divides the ELA image into blocks
- Analyzes each block for maximum difference values
- Reports blocks that exceed the threshold as potential forgeries
| Parameter | Description | Default Value | Range |
|---|---|---|---|
quality |
JPEG compression quality for ELA | 90 | 0-100 |
block_size |
Size of blocks for detection (pixels) | 16 | 8-64 |
threshold |
Detection sensitivity | 30 | 0-255 |
- Quality: Lower values (70-85) create more compression artifacts, making differences more visible
- Block Size: Smaller blocks (8-16) provide finer detection but may increase false positives
- Threshold: Higher values reduce sensitivity; lower values increase detection but may cause false positives
The tool generates an ELA image that shows compression artifacts as a visual representation.
The script prints coordinates of blocks with potential forgeries:
Potential forgery detected in block at (128, 64)
Potential forgery detected in block at (144, 64)
Potential forgery detected in block at (160, 80)
- π΄ Bright/White areas - Regions with higher error levels (potentially manipulated)
- β« Dark/Black areas - Consistent compression levels (likely original)
- π‘ Moderate areas - May require further investigation
The tool reports specific block coordinates where the difference exceeds the threshold. These coordinates indicate the top-left corner of each suspicious block.
- Only works with JPEG images
- Results require manual interpretation
- High threshold values may miss subtle forgeries
- Low threshold values may produce false positives
- Not 100% accurate - should be used as one of multiple forensic tools
- Original uncompressed images will show uniform error levels
- π Digital forensics investigations
- βοΈ Image authenticity verification
- πΌοΈ Detecting photo manipulations
- π Educational purposes for learning about image forensics
- π° Verifying news and media images
- π Academic research in digital forensics
Contributions are welcome! Here are some areas for improvement:
- Support for PNG and other image formats
- GUI interface for easier use
- Advanced detection algorithms
- Improved visualization techniques
- Batch processing capability
- Statistical analysis of results
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement) - Make your changes
- Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/improvement) - Create a Pull Request
This project is open-source and available under the MIT License.
Created for Computer Science Digital Forensics (CSDF) coursework.
- Error Level Analysis - Wikipedia
- JPEG compression artifacts and digital image forensics
- Digital image forensics methodologies
β If you find this project helpful, please consider giving it a star!