-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo-img-glitcher.py
56 lines (42 loc) · 1.73 KB
/
two-img-glitcher.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
from PIL import Image
import numpy as np
import random
from collections import deque
# Randomly shifts pixel rows / columns from two provided images and reassembles them into one image,
# repeats based on how many images you want
# ASSUMES YOU HAVE TWO IMAGES OF IDENTICAL SIZE
def image_shifter(count, first, second):
rotate = random.choice([True, False])
im_one = np.asarray(Image.open(first + ".png"))
im_two = np.asarray(Image.open(second + ".png"))
randomimg = random.choice([im_one, im_two])
# By default, function slices/moves pixels across the horizontal axis
# 'Rotate' changes it to the vertical axis
if rotate == True:
im_one = np.rot90(im_one, 1, (1,0))
im_two = np.rot90(im_two, 1, (1,0))
# play with count/shift values as you please
newim = []
rowcount = random.randint(40, 200)
rowstart = 1
rowshift = random.randint(-30, 30)
direction = random.choice([True, False])
for rownum in range(0, (len(im_one))):
randomimg = random.choice([im_one, im_two])
temprow = deque(randomimg[rownum])
temprow.rotate(rowshift)
newim.append(list(temprow))
rowstart += 1
if rowstart == rowcount:
rowstart = 1
rowshift = random.randint(-30, 30)
rowcount = random.randint(40, 200)
newim = np.asarray(newim)
if rotate == True:
newim = np.rot90(newim, 1, (0, 1))
Image.fromarray(newim).save(f"modified_{str(count).zfill(2)}.png")
# raw filenames, no extension, assumes they're in the same directory as this file
firstfile = input("Give me the first filename: ")
secondfile = input("Give me the second filename: ")
for num in range(1, 100):
image_shifter(num, firstfile, secondfile)