-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageProcessor.py
80 lines (74 loc) · 2.15 KB
/
imageProcessor.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
import os
import sys
import Image
from imageSlicer import ImageSlicer
from pymongo import MongoClient
import glob
def processImages():
client = MongoClient()
db = client.instagram_photomosaic
image_pool = db.image_pool_new
imgs = glob.glob("images/*.jpg")
for img in imgs:
if (len(list(image_pool.find({"imgsrc" : img}))) != 0):
continue
print "Adding img %s to db" % img
slicer = ImageSlicer(img, 1)
averages = slicer.get_averages()
mapper = lambda x: (x[0][0], x[0][1], x[0][2])
averages = map(mapper, averages)
imgsmall = img.replace("images", "smallImages").replace(".jpg", "small.jpg")
dbitem = {
"imgsrc" : img,
"srcsmall" : imgsmall,
"averages" : averages
}
image_pool.insert(dbitem)
processImages()
def processImages12():
client = MongoClient()
db = client.instagram_photomosaic
image_pool = db.image_pool_12
imgs = glob.glob("images/*.jpg")
count = 0
for img in imgs:
if (len(list(image_pool.find({"imgsrc" : img}))) != 0):
continue
print "Trying to add img %s " % img
slicer = ImageSlicer(img, 4)
averages = slicer.get_averages()
mapper = lambda x: (x[0][0], x[0][1], x[0][2])
averages = map(mapper, averages)
imgsmall = img.replace("images", "smallImages").replace(".jpg", "small.jpg")
dbitem = {
"imgsrc" : img,
"srcsmall" : imgsmall,
"averages" : averages
}
image_pool.insert(dbitem)
if (count % 100 == 0):
print "Inserted %d photo" % count
count += 1
#processImages12()
def processImagesFull48():
client = MongoClient()
db = client.instagram_photomosaic
image_pool = db.image_pool_48
imgs = glob.glob("smallImages/*.jpg")
count = 0
for img in imgs:
if (len(list(image_pool.find({"srcsmall" : img}))) != 0):
continue
loaded = Image.open(img)
averages = list(loaded.getdata())
largesrc = img.replace("smallImages", "images").replace("small.jpg", ".jpg")
dbitem = {
"imgsrc" : largesrc,
"srcsmall" : img,
"averages" : averages
}
image_pool.insert(dbitem)
if (count % 100 == 0):
print "Inserted %d photo" % count
count += 1
#processImagesFull48()