-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_ela.py
44 lines (28 loc) · 1.04 KB
/
process_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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import os
import sys
from tqdm import tqdm
from PIL import Image
from PIL import ImageChops
from PIL import ImageEnhance
# In[ ]:
for filename in tqdm(os.listdir('D:/Code/Tima_Onbroading/ELA/datatest_private/real')):
basename, extension = os.path.splitext(filename)
resaved = 'real/' + basename + '.resaved.jpg'
ela = 'real/' + basename + '.ela.png'
im = Image.open('D:/Code/Tima_Onbroading/ELA/datatest_private/real/' + 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)
# In[ ]:
for filename in tqdm(os.listdir('D:/Code/Tima_Onbroading/ELA/fake')):
if 'ela' not in filename:
os.remove("D:/Code/Tima_Onbroading/ELA/fake/" + filename)