-
Notifications
You must be signed in to change notification settings - Fork 0
/
ela.py
25 lines (20 loc) · 805 Bytes
/
ela.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import sys
from tqdm import tqdm
from PIL import Image
from PIL import ImageChops
from PIL import ImageEnhance
for filename in tqdm(os.listdir('D:/Code/Tima_Onbroading/ELA/data_4')):
basename, extension = os.path.splitext(filename)
resaved = 'img_train_ela/' + basename + '.resaved.jpg'
ela = 'img_train_ela/' + basename + '.ela.png'
im = Image.open('D:/Code/Tima_Onbroading/ELA/data_4/' + filename)
im.save(resaved, 'JPEG', quality=90)
resaved_im = Image.open(resaved)
ela_im = ImageChops.difference(im, resaved_im)
extrema = ela_im.getextrema()
max_diff = max([ex[1] for ex in extrema])
scale = 255.0/max_diff
ela_im = ImageEnhance.Brightness(ela_im).enhance(scale)
# print('Maximum difference was {}'.format(max_diff))
ela_im.save(ela)