-
Notifications
You must be signed in to change notification settings - Fork 2
/
tester.py
80 lines (56 loc) · 2.85 KB
/
tester.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import processor, glob, datetime, time, tabulate, util, logging, os
def test():
logger = logging.LoggerAdapter(logging.getLogger(), {"caller":__name__})
src_image_folder = "test/images/*.png"
src_images = []
for src_img in glob.glob(src_image_folder):
src_images.append(src_img)
payloads_folder = "test/payloads/*.test"
payloads = []
for payload in glob.glob(payloads_folder):
payloads.append(payload)
tmp_payload_output_path = "test/test_payload_extracted"
tmp_output_image = "test/test_processed_image.png"
test_methods = ["LSB", "PVD"]
logger.info("Beginning StegArmory test!")
total_iterations = len(src_images) * len(payloads) * len(test_methods)
logger.info("Running %d test cases!" % total_iterations)
results = []
i = 0
for src_img in src_images:
for payload in payloads:
for method in test_methods:
src_img_filename = os.path.basename(src_img)
payload_filename = os.path.basename(payload)
tmp_output_img_filename = os.path.basename(tmp_output_image)
logger.info("Testing %s embed on image %s with payload %s" % (method, src_img_filename, payload_filename))
if method == "LSB":
proc = processor.LSBProcessor(src_img)
elif method == "PVD":
proc = processor.PVDProcessor(src_img)
embed_time_a = time.perf_counter()
proc.embed_payload(payload, tmp_output_image)
embed_time_b = time.perf_counter()
embed_time = round(embed_time_b - embed_time_a, 4)
logger.info("Testing %s extract on image %s with payload %s" % (method, tmp_output_img_filename, payload_filename))
proc2 = type(proc)(tmp_output_image)
extract_time_a = time.perf_counter()
proc2.extract_payload(tmp_payload_output_path)
extract_time_b = time.perf_counter()
extract_time = round(extract_time_b - extract_time_a, 4)
proc.compare(proc2)
results.append(
[
src_img,
method,
payload,
embed_time,
extract_time,
util.human_readable_size(proc.max_payload_size // 8, 2),
proc.comparison_stats['psnr'],
proc.comparison_stats['ssim']
]
)
i += 1
logger.info("Overall Progress: %d/%d (%s%%)" % (i, total_iterations, str(round((i / total_iterations) * 100, 2))))
print(tabulate.tabulate(results, headers=["Source Image", "Method", "Payload", "Embed Time", "Extract Time", "Max Payload Size", "PSNR", "SSIM"]))