forked from HunterCSci127/CSci127
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilesCollage.py
107 lines (70 loc) · 2.97 KB
/
tilesCollage.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#CSci 127 Teaching Staff
#January 2021
#A program that creates a tile collage from input image
#Modified by: ADD YOUR NAME HERE , ADD YOUR EMAIL HERE
import numpy as np
import matplotlib.pyplot as plt
def mirror(img, axis):
'''
Creates and returns a mirrored copy of img along axis
Expected values for axis are 'x', 'y', 'xy' (mirrored along both x and y axes)
If the value of axis is not one of the expected, it prints: Invalid axis
'''
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### this is the only section ###
### you change in this program. ###
###################################
def remove_hue(img, hue):
'''
Removes hue from img by turning off the corresponding color channel
Expected values for hue are 'red', 'green', 'blue'
If the value of hue is not one of the expected, it prints: No such hue.
'''
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### this is the only section ###
### you change in this program. ###
###################################
def fourfold_tile(img):
'''
Creates and returns a new image consisting of 4 copies of img
in a tile layout, with 2 copies at the top and 2 copies at the bottom
'''
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### this is the only section ###
### you change in this program. ###
###################################
######################################################################
### DO NOT CHANGE ANYTHING BELOW AND INCLUDING THIS LINE ###
######################################################################
def main():
'''
Creates a tile collage from input image
'''
infile = input('Enter input file name: ')
outFile = input('Enter output file name: ')
img = plt.imread(infile)
#new_img consits of four copies of img, two on top and two ont the bottom
new_img = fourfold_tile(img)
#Remove blue from top-right quarter
remove_hue(new_img[:img.shape[0],img.shape[1]:],'blue')
#Remove green from bottom-left quarter
remove_hue(new_img[img.shape[0]:,:img.shape[1]],'green')
#Remove blue from bottom-right quarter
remove_hue(new_img[img.shape[0]:,img.shape[1]:],'red')
#Mirror top-right quarter along the y-axis
new_img[:img.shape[0],img.shape[1]:] = mirror(new_img[:img.shape[0],img.shape[1]:],"y")
#Mirror bottom-left quarter along the x-axis
new_img[img.shape[0]:,:img.shape[1]] = mirror(new_img[img.shape[0]:,:img.shape[1]],"x")
#Mirror bottom-right quarter along both x and y axis
new_img[img.shape[0]:,img.shape[1]:] = mirror(new_img[img.shape[0]:,img.shape[1]:],"xy")
#Save the tile collage to a file
plt.imsave(outFile, new_img)
#Allow script to be run directly:
if __name__ == '__main__':
main()