def find_particle(filename,show=True,debug=False): from find_mask import find_mask hole_mask = find_mask(filename,show=False) p = Pipeline(downsample=20,filename=filename) if debug: p.show() p.open(window_size=(20,20)) p.crop(factor=15) p.threshold() #do adaptive thresholding if debug: p.show() p.connected_components_iterative(full=False) #calculate the connected components p.threshold_component_size() if debug: p.show() #show the mask for debugging p.data = np.max(p.data) - p.data p.erode(factor=1) p.erode(factor=1) if debug: p.show() p.subtract(hole_mask) if debug: p.show() p.convex_hull_per_component() p.mask_original() p.show() #show the mask for debugging
from find_mask import find_mask import time import os l = [n for n in os.walk("jpgs")] num = 0 total = 0 for f in l[0][2]: if "jpg" in f: start_time = time.time() outfile = "output/" + f.split(".")[0] + "_out" + ".jpg" find_mask("jpgs/" + f,outfile=outfile,show=False) duration = time.time()-start_time total += duration num += 1 print "Average time:", str(total/num),"seconds"
import time from find_mask import find_mask import cProfile cProfile.run("find_mask('data/test2.jpg',show=False)") exit() for i in range(10): start_time = time.time() find_mask("data/test2.jpg",show=False) print "Took",time.time()-start_time,"seconds to complete"