-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssudoku.py
54 lines (46 loc) · 1.67 KB
/
ssudoku.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
from PIL import Image
import numpy as np
def shuffle_pixels(image_path, perm):
img = Image.open(image_path)
pixels = np.array(img)
pixels = pixels[:, perm]
shuffled_img = Image.fromarray(pixels)
shuffled_img.save('shuffled_image.png')
def shuffle_rows(image_path, perm):
img = Image.open(image_path)
pixels = np.array(img)
pixels = pixels[perm, :]
shuffled_img = Image.fromarray(pixels)
shuffled_img.save('shuffled_rows_image.png')
def rotate_image(image_path):
img = Image.open(image_path)
rotated_img = img.rotate(-90)
rotated_img.save('rotated_image.png')
def unshuffle_pixels(image_path, perm):
img = Image.open(image_path)
pixels = np.array(img)
inv_perm = np.argsort(perm)
pixels = pixels[:, inv_perm]
unshuffled_img = Image.fromarray(pixels)
unshuffled_img.save('unshuffled_image.png')
def unshuffle_rows(image_path, perm):
img = Image.open(image_path)
pixels = np.array(img)
inv_perm = np.argsort(perm)
pixels = pixels[inv_perm, :]
unshuffled_img = Image.fromarray(pixels)
unshuffled_img.save('unshuffled_rows_image.png')
def rotate_image_counter_clockwise(image_path):
img = Image.open(image_path)
rotated_img = img.rotate(90)
rotated_img.save('rotated_image_counter_clockwise.png')
def sudoku_e(image_path, seed):
perm = np.random.permutation(seed)
shuffle_pixels(image_path, perm)
shuffle_rows("shuffled_image.png", perm)
rotate_image("shuffled_rows_image.png")
rotate_image_counter_clockwise('rotated_image.png')
unshuffle_rows('rotated_image_counter_clockwise.png', perm)
unshuffle_pixels('unshuffled_rows_image.png', perm)
def sudoku_d():
pass