-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_arg.py
62 lines (57 loc) · 1.8 KB
/
image_arg.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
import numpy as np
import scipy.io as sio
import math
import sys
np.set_printoptions(threshold='nan')
from PIL import Image
directory = "/home/matrices/mtx/" + sys.argv[1] + "/" + sys.argv[2] + "/" + sys.argv[2] + ".mtx"
mtx = sio.mmread(directory)
mtx_row = sio.mminfo(directory)[0]
mtx_col = sio.mminfo(directory)[1]
if mtx_row <= 1000:
coef = 1
elif 1000 < mtx_row <= 5000:
coef = 5
elif 5000 < mtx_row <= 10000:
coef = 10
elif 10000 < mtx_row <= 50000:
coef = 50
elif 50000 < mtx_row <= 100000:
coef = 100
elif 100000 < mtx_row <= 500000:
coef = 500
elif 500000 < mtx_row <= 1000000:
coef = 1000
elif 1000000 < mtx_row <= 5000000:
coef = 5000
else:
coef = 10000
print coef
if (mtx_row % coef) != 0:
img_row = mtx_row + (coef - (mtx_row % coef))
else:
img_row = mtx_row
print img_row
row_cnt = 0
col_cnt = 0
#print mtx
mtx_int = np.zeros((img_row / coef, img_row / coef))
for i in range(len(mtx.col)):
print "num: " + str(mtx.col[i])
print math.ceil((mtx.row[i]+1)/coef)-1
print math.ceil((mtx.col[i]+1)/coef)-1
mtx_int[int(math.ceil((mtx.row[i]+1)/coef)-1)][int(math.ceil((mtx.col[i]+1)/coef)-1)] += 1
print mtx_int
im = Image.new("RGB", (img_row / coef, img_row / coef))
pix = im.load()
for i in range(img_row / coef):
for j in range(img_row / coef):
# print (int(255*mtx_int[i][j]), int(255*mtx_int[i][j]), int(255*mtx_int[i][j]))
c = int(min(mtx_int[i][j], 255))
pix[(i, j)] = (c, c, c)
# for i in range(img_row / coef):
# for j in range(img_row / coef):
# # print (int(255*mtx_int[i][j]), int(255*mtx_int[i][j]), int(255*mtx_int[i][j]))
# pix[(i, j)] = (int(255 * mtx_int[i][j]), int(255 * mtx_int[i][j]), int(255 * mtx_int[i][j]))
inverted = Image.eval(im, lambda (x): 255 - x)
inverted.save(sys.argv[1] + ".png", "PNG")