-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpj_filter.py
More file actions
50 lines (39 loc) · 1.66 KB
/
pj_filter.py
File metadata and controls
50 lines (39 loc) · 1.66 KB
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
import sys
import os
import glob
import multiprocessing as mp
import subprocess
def process_range(file_list,start,stop):
for i in range(start,stop):
filename = file_list[i]
# print filename
head,tail = os.path.split(filename)
#print "parts = {} {}".format(head, tail)
new_name = "{}{}nobg-{}".format(head,os.sep,tail)
#command = "\"C:\Program Files\ImageMagick-6.8.9-Q16\convert.exe\" -posterize 2 -fill white -opaque black -colors 2 {} {}".format(filename,new_name)
command = "\"C:\Program Files\ImageMagick-6.8.9-Q16\convert.exe\" -posterize 2 -fill white -opaque black -colors 2 {} -median 6 {}".format(filename,new_name)
subprocess.call(command)
if __name__ == "__main__":
if len(sys.argv) < 3 and False:
print "you're doing it wrong"
else:
file_list = glob.glob("laser/camall/rectified/2*.png")
num_cores = 15
num_images = len(file_list)
images_per_core = num_images / num_cores
jobs = []
for i in range(0,num_cores-1):
start_image = i * images_per_core
stop_image = (i+1) * images_per_core
print "starting {} {} {}".format(i,start_image, stop_image)
p = mp.Process(target=process_range,args=(file_list,start_image,stop_image) )
jobs.append(p)
p.start()
i = num_cores-1
start_image = i * images_per_core
stop_image = len(file_list)
p = mp.Process(target=process_range,args=(file_list,start_image,stop_image) )
jobs.append(p)
p.start()
for j in jobs:
j.join()