Skip to content

Create a gif of an image as it is increasingly compressed using error analysis to show where abnormal degradation can be observed.

License

Notifications You must be signed in to change notification settings

maxedonia/ela_mate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ELA Mate

Error Level Analysis

Digitally editing photos can quickly diminish the original image's contrast, lighting, sharpness, color & gradation. By comparison, unedited versions of the same photo maintain these touchstone characteristics of fidelity, and thereby reflect the accuracy of a digital photo's composition. This cohesion of content at lower resolution, or the lack thereof, can also be observable when an image is compressed to only a fraction of it's original fidelity.

Error Level Analysis (ELA) is a tool that identifies 'noise' that doesn't reflect a normal compression of the image in question, wherein portions of a photo that do not accurately reflect the expected output of the composition can quickly become noticeable and apparent. These artifacts are often left behind in an image that has signs of distortion (warping, facetuning, filtering, cloning, etc.), and therefore only become more difficult to separate from the image or any future iterations of it over time. In addition, many beauty filters, editing tools, and similar manipulations warp across large bands that leave ripples in the image that don't match the siginifiers of the original, and therefore become tell-tale signs of manipulation when coupled with any evidence of forced perspective, dysmorphic proportion, or the sight of an uncanny face.

These artifacts, whether big or small, won't easily disappear when one resizes the image, or when converting it into another different format. Any additional manipulations will only compound the artifacts that were already left behind, and reduce the overall image quality & fidelity even further with each passing. This loss in fidelity is often indicative of a greater distance between the image in question and its point of origin, digitally speaking.

A more thorough explanation of ELA can be found here.

ELA Mate & Forensic Analysis

ELA Mate works by compressing and filtering an image at incremental stages of decreased resolution. These results are then compiled into an animated GIF. The options for GIF output also includes the speed at which the frames of each image are referenced, the scale of error analysis shown, and the ability to blend the ELA output with the original reference image for comparison.

That said, ELA is just one of many tools that can be used in forensics. All of them require insight, experience, digital literacy, and an attention to detail in order to be used properly. If someone has a reason to doubt an image's authenticity, then the onus is on them to make a strong enough statement for that to be the case. In an age where finding authenticity in our social feeds is getting harder to find, the case for creating tools like this one has only gotten stronger. Taking a photo without AI filtering on iOS in 2024 is already a very difficult process. AI trained by our pervasive and willful use only grows exponentially unrealistic. And if reality is on pace to favor the fake, then this tool is just one small attempt to confront that notion in some way.

Note: This script was written with digital literacy in mind. It is not meant for legal or forensic use. Any conclusions or assessements made from using ELA Mate are not reflective nor endorsed by those of the author. Please use tools like this one responsibly.

Installation

To run the script, which includes image processing and manipulation functionalities, you'll need Python installed along with specific libraries that the script depends upon:

  1. Python Ensure that Python is installed on your system. The script was written for Python 3, so make sure you have a compatible version (Python 3.6 or newer is recommended). You can download Python from python.org. Additionally, you can verify any prior installation and/or upgrade python using:

    python -m pip install --upgrade pip

  2. Pillow (PIL Fork) The script uses the Pillow library, which is a fork of the Python Imaging Library (PIL). It provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities. To install Pillow, run:

    pip install Pillow

  3. Optional Libraries (these libraries are not required, but are worth mentioning) If your script extends to handling metadata extraction or other specialized image processing tasks, you might also consider installing:

    • pyexiv2: For metadata handling, especially if you plan to manipulate or read EXIF data.

      pip install pyexiv2

    • NumPy: Sometimes used in image processing for more complex numerical operations.

      pip install NumPy

Start ELA Mate

Navigate to the directory containing ELA Mate and run it as a .py file or by using the following console command:

python ELA Mate_v1.py

Note: Ensure any paths to files and output directories are correct and accessible to the script, including writing permissions when applicable.

File Selection & Directory Allocation

If all conditions have been met, the terminal will open and the following prompt will appear:

'Enter the path to the image file (JPG, PNG, or WEBP):'

Input the file address of the image to be used, or simply drag and drop directly into terminal window. Then press enter.

Note: At this time, only JPG, PNG, or WEBP files have been tested with this script.

'Enter the base output directory:'

Input the directory address of the folder you wish to use, or simply drag and drop the folder directly into terminal window. Then press enter.

Parameter Selection

settingsscrop

'Enter the ELA analysis scale factor (usual range 1-20):'

Input the amount of ELA presence in the GIF output. A higher number means more prominent ELA, a lower number will be more subtle. Whether a higher or lower scale is more useful depends upon attenuating this input with the other parameters you select.

'Enter the image alpha value (0.0 to 1.0):

Input the degree of opacity the original image will have in output GIF. A lower value will output less ELA in the blended GIF and a higher value will output more ELA by comparison. Entering 0.0 will show almost no ELA in the GIF output whatsoever. Entering 1.0 will result in almost only the ELA in the GIF output.

Note: If the output GIF is exceedingly bright, consider using a lower alpha value, or attenuating the ELA scale factor differently to achieve a more desired result.

Enter the GIF frame duration in milliseconds:

The value input in this parameter is a general sliding scale for the speed between changes in each reference frame. A lower value will produce a shorter GIF, a higher value a longer one. For example, entering in a value of '100' will output a GIF approximately 10 seconds long. Adjust as needed.

Running ELA Mate

Your console window should look similar to the one below before you execute. settings

Upon pressing enter, the script will do the following actions in sequence:

  • Create a new folder in the selected output directory that is timestamped and labeled with the parameters you selected.
  • Generate two sets of images
    • A total of 99 images generated with the length and width of the reference image, and with each image in the set having a higher incremental degree of compression relative to the original reference image.
    • A total of 99 error level analysis images generated from the set of compressed images with the user defined ELA scale factor parameter upon output.
  • A GIF of the ELA generated images in sequence from highest to lowest quality and in a interval of time based upon the user defined frame duration parameter.
  • The GIF output compiled with the reference image that has a visibility that is determined by the user defined alpha value parameter upon final output.

Note: Though the file size of images generated by the script will vary, keep in mind that the original image's resolution/aspect ratio will remain the same for each instance. Therefore, the contents of a folder that is generated from a 6000x4000 image will be significantly larger and take longer to generate than an reference image that is 600x400.

Basic Operation

The following image was taken on a Canon EOS Rebel T7i with an ultra-wide lens: ELA example1

After starting the script a new folder in the output directory appears and will begin to populate itself with the two image sets...

output example1 cropped

output example1 small size

... followed by the compiled GIF with the user defined parameters applied to it in the destination folder. ELA_Original_Blended_Animation_resized_1

A final prompt should appear when the script has completed.

settings2

Do you want to process another image? (yes/no/repeat):

  • Typing 'yes' or 'y' allows for a different image to be used in a new analysis.

  • Typing 'no' or 'n' will shut down the script and exit the terminal window.

  • Typing 'repeat' or 'r' will automatically re-select the last reference image and base output directory, allowing for quick tweaking of settings of the output using the same image as the previous analysis.

    Note: The console window should close automatically if no is selected.

Examples of Differentiated Output

Reference Photo

Here are some side-by-side comparison GIFs of the same source image as before. Each one is labelled with the parameters used during generation:

gid example A gid example B gid example C gid example D

Touch Up Artifacts in Windows Photos App

Here we have is the same photograph, but one picture has had the Edison Bulbs at the top of the image edited out using AI assisted touch-ups possible within the Photos app in Windows 10.

gid example2 A gid example2 B

Note: parameters have been added to example GIFs for clarity and are not currently featured in ELA Mate's output at this time.