10
10
import numpy as np
11
11
import random
12
12
13
- Dim = collections .namedtuple (' Dim' , ' w h' )
13
+ Dim = collections .namedtuple (" Dim" , " w h" )
14
14
15
15
files = [
16
- ' tv.png' ,
17
- ' lg.png' ,
18
- ' 24.png' ,
19
- ' tr3.png' ,
16
+ " tv.png" ,
17
+ " lg.png" ,
18
+ " 24.png" ,
19
+ " tr3.png" ,
20
20
]
21
21
22
+
22
23
def autopad (img , dim = Dim (800 , 600 )):
23
24
"""
24
25
Autopad creates an image of a given size and will center the given image
@@ -28,19 +29,21 @@ def autopad(img, dim=Dim(800, 600)):
28
29
if c == 3 :
29
30
img = np .dstack ([img , np .zeros ((h , w , 1 ))])
30
31
if w > dim .w or h > dim .h :
31
- raise ValueError (f' downsizing not yet supported: w={ w } h={ h } ' )
32
- norm_img = np .zeros ([dim .h , dim .w , 4 ],dtype = np .uint8 )
32
+ raise ValueError (f" downsizing not yet supported: w={ w } h={ h } " )
33
+ norm_img = np .zeros ([dim .h , dim .w , 4 ], dtype = np .uint8 )
33
34
norm_img [:, :, 3 ] = 255
34
35
r = (dim .h - h ) // 2
35
36
c = (dim .w - w ) // 2
36
- norm_img [r : r + h , c : c + w , :] = img
37
+ norm_img [r : r + h , c : c + w , :] = img
37
38
return norm_img
38
39
40
+
39
41
def make_empty_image (dim = Dim (800 , 600 )):
40
- img = np .zeros ([dim .h , dim .w , 4 ],dtype = np .uint8 )
42
+ img = np .zeros ([dim .h , dim .w , 4 ], dtype = np .uint8 )
41
43
img [:, :, 3 ] = 255
42
44
return img
43
45
46
+
44
47
def noisy (img ):
45
48
alpha = img [:, :, 3 ]
46
49
rgb = img [:, :, :3 ]
@@ -65,9 +68,8 @@ def main():
65
68
images .extend ([noisy (img ) for _ in range (7 )])
66
69
images .extend ([empty_image for _ in range (1 )])
67
70
68
-
69
71
imageio .mimsave ("anim.gif" , images , fps = 7 , loop = 0 )
70
72
71
- if __name__ == '__main__' :
72
- main ()
73
73
74
+ if __name__ == "__main__" :
75
+ main ()
0 commit comments