Reputation: 11
I’ve been experimenting with Error Level Analysis (ELA) in Python to detect digital image manipulation. However, I’m now interested in the reverse process: removing or minimizing ELA from an image.
Here’s what I’ve tried so far:
I applied ELA to an original image using Python code. I observed differences in size before and after processing. I tested the processed image with Ghiro digital forensics, which confirmed that ELA was applied. Now, my goal is to either remove ELA entirely or reduce it to as close to zero as possible without compromising the original image.
the problem is here that the image processed it shows that the image has always ELA
Questions:Is it feasible to completely remove ELA from an image If not, what techniques can I use to minimize ELA while preserving the original image content?
import cv2
import numpy as np
# Control
scale = 35
quality = 95
# Image containers
input_image = None
compressed_image = None
def processImage(val):
global input_image, compressed_image
# Setting up parameters and JPEG compression
parameters = [cv2.IMWRITE_JPEG_QUALITY, quality]
cv2.imwrite("temp.jpg", input_image, parameters)
# Reading temp image from the disk
compressed_image = cv2.imread("temp.jpg")
if compressed_image is None:
print("> Error loading temp image")
return
output_image = np.zeros(input_image.shape, dtype=np.uint8)
# Compare values through matrices
for row in range(input_image.shape[0]):
for column in range(input_image.shape[1]):
# Calc abs diff for each color channel multiplying by a scale factor
output_image[row][column][0] = abs(input_image[row][column][0] - compressed_image[row][column][0]) * scale
output_image[row][column][1] = abs(input_image[row][column][1] - compressed_image[row][column][1]) * scale
output_image[row][column][2] = abs(input_image[row][column][2] - compressed_image[row][column][2]) * scale
# Shows processed image
cv2.imshow("Error Level Analysis", output_image)
def removeELA(original, ela):
result = original - ela
cv2.normalize(result, result, 0, 255, cv2.NORM_MINMAX)
return result
def main():
global input_image
# Verify if the required number of parameters was provided
# Read the image
image_path = "C:\\Users\\ghazali\\Desktop\\DSC_0079 2023-2024.jpg" #actual path
input_image = cv2.imread(image_path)
# Check image load
if input_image is None:
print("> Error loading input image")
return
# Set up window and trackbar
cv2.namedWindow("Error Level Analysis", cv2.WINDOW_AUTOSIZE)
cv2.imshow("Error Level Analysis", input_image)
cv2.createTrackbar("Scale", "Error Level Analysis", scale, 100, lambda x: processImage(0))
cv2.createTrackbar("Quality", "Error Level Analysis", quality, 100, lambda x: processImage(0))
# Process the image to get the ELA
processImage(0)
# Remove ELA from the original image
output_image = removeELA(input_image, compressed_image)
# Save the result to the desktop
desktop_path = "C:\\Users\\ghazali\\Desktop\\removed_ela_image.jpg"
cv2.imwrite(desktop_path, output_image)
print("Image with removed ELA saved to: " + desktop_path)
# Press 'q' to quit
while True:
if cv2.waitKey(0) == ord('q'):
break
return
if __name__ == "__main__":
main()
Upvotes: 1
Views: 76