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
| # -*- coding: UTF-8 -*-
import cv2
import numpy as np
import os
def arnold_decode(image, shuffle_times, a, b, output_file='decoded_image.png'):
"""
Decodes an RGB image that was encoded by the Arnold transformation.
Args:
image (np.array): The RGB image encoded by Arnold transformation.
shuffle_times (int): Number of iterations for shuffling.
a (int): Arnold transformation parameter.
b (int): Arnold transformation parameter.
output_file (str): Filename for saving the decoded image.
Returns:
np.array: The decoded image.
"""
if image is None:
raise ValueError("Image not loaded. Check file path or file integrity.")
# Create a new image with the same shape as the input
decode_image = np.zeros_like(image)
h, w = image.shape[:2]
N = h
for _ in range(shuffle_times):
for ori_x in range(h):
for ori_y in range(w):
new_x = ((a * b + 1) * ori_x - b * ori_y) % N
new_y = (-a * ori_x + ori_y) % N
decode_image[new_x, new_y, :] = image[ori_x, ori_y, :]
cv2.imwrite(output_file, decode_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
return decode_image
image_path = '/home/Work/pcb/00000000.jpg'
img = cv2.imread(image_path)
if img is None:
raise FileNotFoundError(f"Image at path '{image_path}' not found. Please check the file path.")
for i in range(1000):
output_filename = f'./decoded_image_{i}.png'
arnold_decode(img, shuffle_times=7, a=35, b=i, output_file=output_filename)
|