# Error Level Analysis (ELA) Detector This module provides a function to perform Error Level Analysis (ELA) on images to detect potential manipulations or edits. ## Function: `run_ela` ```python def run_ela(image: Image.Image, quality: int = 90, threshold: int = 15) -> bool: ``` ### Description Error Level Analysis (ELA) works by recompressing an image at a specified JPEG quality level and comparing it to the original image. Differences between the two images reveal areas with inconsistent compression artifacts — often indicating image manipulation. The function computes the maximum pixel difference across all color channels and uses a threshold to determine if the image is likely edited. ### Parameters | Parameter | Type | Default | Description | | ----------- | ----------- | ------- | ------------------------------------------------------------------------------------------- | | `image` | `PIL.Image` | N/A | Input image in RGB mode to analyze. | | `quality` | `int` | 90 | JPEG compression quality used for recompression during analysis (lower = more compression). | | `threshold` | `int` | 15 | Pixel difference threshold to flag the image as edited. | ### Returns `bool` * `True` if the image is likely edited (max pixel difference > threshold). * `False` if the image appears unedited. ### Usage Example ```python from PIL import Image from detectors.ela import run_ela # Open and convert image to RGB img = Image.open("example.jpg").convert("RGB") # Run ELA detection is_edited = run_ela(img, quality=90, threshold=15) print("Image edited:", is_edited) ``` ### Notes * The input image **must** be in RGB mode for accurate analysis. * ELA is a heuristic technique; combining it with other detection methods increases reliability. * Visualizing the enhanced difference image can help identify edited regions (not returned by this function but possible to add). ### Installation Make sure you have Pillow installed: ```bash pip install pillow ``` ### Running Locally Just put the function in a notebook or script file and run it with your image. It works well for basic images. ### Developer Pujan Neupane