def create_summary_html(basedir): print 'Creating html files in {}'.format(basedir) ensure_dir(basedir) main_sessions, other_sessions = find_sessions(basedir) shutil.copy(join(this_dir(),'figures.css'), basedir) figures = [ 'speeds', 'time-courses', 'sigma-ratios-over-time', 'jancke-ratios-over-time', ] html = Template(""" <html> <head> <link rel="stylesheet" type="text/css" href="figures.css"> </head> <body> <H1>Figures for each Session</H1> {% for session in main_sessions %} <a href="{{session}}/session_figures.html">{{session}}</a>         {% endfor %} </br> </br> {% if other_sessions %} Additional Sessions (not used for summaries):</br> {% endif %} {% for session in other_sessions %} <a href="{{session}}/session_figures.html">{{session}}</a>         {% endfor %} </br> <H1>Summaries over all sessions</H1> <a href="PCs-explained-variance-summary.png"><img src="PCs-explained-variance-summary.png" width=50%></img></a> <P> <table width=100%> <tr> <td class="tableHeading"><b>No PCA</b></td> <td class="tableHeading"><b>PCA</b></td> </tr> {% for figure in figures %} <tr> <td><a href="{{figure}}-no-PCA.png"><img src="{{figure}}-no-PCA.png" width=100%></img></a></td> <td><a href="{{figure}}-PCA.png"><img src="{{figure}}-PCA.png" width=100%></img></a></td> </tr> {% endfor %} </table> </P> </body> </html> """).render(**locals()) with open(join(basedir,'summary.html'), 'w') as f: f.write(html)
def image_crop(main_path='',sub_path='',subdir_crop='no',ext='.png'): # sdfsdfsk #main_path = '\\\\W8881\\datadrive2\\nikel\\LDST\\2013-11-29 V117 3.3MW HH141.5 DIBt2 LDST\\LDST_ite0\\Tower-to-foundation\\plot_SCF' if main_path == '': import this_dir main_path = this_dir.this_dir() main_path = main_path + '\\' + sub_path print main_path path = path_finder.path_finder(main_path,ext,subdir=subdir_crop) #path = r"C:\Users\nikel\Local Documents\2013-10-07 LDST\results\CrossSection 35-36\plot_35-36_MY_sub2t_S1 weld" # r in front for i in range(len(path)): print "Image cropping " + str(100*float(i)/float(len(path)))[0:4] + "% Done" fp = open(path[i], "rb") image = Image.open(fp) image.load() import sys imageSize = image.size from PIL import ImageOps if image.mode == 'RGBA': # http://stackoverflow.com/questions/2498875/how-to-invert-colors-of-image-with-pil-python-imaging r,g,b,a = image.split() rgb_image = Image.merge('RGB', (r,g,b)) invert_im = ImageOps.invert(rgb_image) else: invert_im = ImageOps.invert(image) imageBox = invert_im.getbbox() # white edge removed #imageBox = image.getbbox() cropped=image.crop(imageBox) fp.close() cropped.save(path[i])
def image_crop(main_path='',sub_path='',subdir_crop='no',ext='.png',workbench='no',pre_cut='no'): if main_path == '': import this_dir main_path = this_dir.this_dir() main_path = main_path + '\\' + sub_path print "main_path:", main_path path = path_finder.path_finder(main_path,ext,subdir=subdir_crop) #path = r"C:\Users\nikel\Local Documents\2013-10-07 LDST\results\CrossSection 35-36\plot_35-36_MY_sub2t_S1 weld" # r in front print path for i in range(len(path)-1,-1,-1): if path[i].find('_cropped') > -1: path.pop(i) print path for i in range(len(path)): print "Image cropping " + str(100*float(i)/float(len(path)))[0:4] + "% Done" fp = open(path[i], "rb") image = Image.open(fp) image.load() if pre_cut == 'yes': bbox = image.getbbox() bbox = (bbox[0],bbox[1]+250,bbox[2],bbox[3]-250) print bbox cropped = image.crop(bbox) image = cropped if workbench == 'no': import sys imageSize = image.size from PIL import ImageOps if image.mode == 'RGBA': # http://stackoverflow.com/questions/2498875/how-to-invert-colors-of-image-with-pil-python-imaging r,g,b,a = image.split() rgb_image = Image.merge('RGB', (r,g,b)) invert_im = ImageOps.invert(rgb_image) else: invert_im = ImageOps.invert(image) imageBox = invert_im.getbbox() # white edge removed print "imageBox =", imageBox #imageBox = image.getbbox() cropped=image.crop(imageBox) elif workbench == 'yes': crop_coord,last_temp_bbox = workbench_crop(path[i]) if i == 0: crop_coord_first,last_temp_bbox_first = crop_coord,last_temp_bbox elif float(crop_coord_first[0][1])/crop_coord[0][1] > 1.1 or float(crop_coord_first[0][0])/crop_coord[0][0] > 1.1 or float(crop_coord_first[1][1])/crop_coord[1][1] > 1.1 or float(crop_coord_first[1][0])/crop_coord[1][0] > 1.1 or float(crop_coord_first[0][1])/crop_coord[0][1] > 0.9 or float(crop_coord_first[0][0])/crop_coord[0][0] > 0.9 or float(crop_coord_first[1][1])/crop_coord[1][1] > 0.9 or float(crop_coord_first[1][0])/crop_coord[1][0] > 0.9: crop_coord,last_temp_bbox = crop_coord_first,last_temp_bbox_first print crop_coord path[i] = path[i] + '_cropped.png' cropped = image.crop((crop_coord[0][1],crop_coord[0][0],crop_coord[1][1]+last_temp_bbox[2],crop_coord[1][0]+last_temp_bbox[3]-22))#+last_temp_bbox[2])) fp.close() print path[i] cropped.save(path[i])# + '_cropped.png')