-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_matrix.py
76 lines (67 loc) · 1.27 KB
/
pixel_matrix.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
#coding:utf-8
import sys
import numpy as np
from PIL import Image
args = sys.argv
R = np.zeros([16,16])
G = np.zeros([16,16])
B = np.zeros([16,16])
#画像の読み込み
im = Image.open('emoji/' + args[1] + '.png')
#RGBに変換
rgb_im = im.convert('RGB')
#画像をリサイズ・左右反転
rgb_im = rgb_im.resize((16, 16), Image.LANCZOS)
rgb_im.save(('emoji_256/' + args[1] + '_256.png'))
rgb_im = rgb_im.transpose(Image.FLIP_LEFT_RIGHT)
#画像サイズを取得
size = rgb_im.size
print(size)
#loop
#x
for x in range(size[0]):
#y
for y in range(size[1]):
#ピクセルを取得
r,g,b = rgb_im.getpixel((x,y))
R[x][y] = r
G[x][y] = g
B[x][y] = b
np.save('rgb/' + args[1] + '_R.npy', R)
np.save('rgb/' + args[1] + '_G.npy', G)
np.save('rgb/' + args[1] + '_B.npy', B)
#
# R2 = np.load('test_R.npy')
# G2 = np.load('test_G.npy')
# B2 = np.load('test_B.npy')
#
# print('')
# print('')
# print('R = ')
# print('')
# print(R)
# print('')
# print('')
# print('G = ')
# print('')
# print(G)
# print('')
# print('')
# print('B = ')
# print('')
# print(B)
# print('')
# print('')
# print('R2 = ')
# print('')
# print(R2)
# print('')
# print('')
# print('G2 = ')
# print('')
# print(G2)
# print('')
# print('')
# print('B2 = ')
# print('')
# print(B2)