Dataset

01. import glob, urllib
02. import Image
03. mmfreedom(2)
04. 
05. def draw_se_axis(f, dX=20, dY=20):
06.     g = zeros((f.shape[0]+2*dY,f.shape[1]+2*dX), bool)
07.     g[dY:-dY,dX:-dX] = f
08.     yc, xc = [x/2 for x in g.shape]
09.     h = mmsubm(g, g)
10.     draw = adDraw(g, rgb=1)
11.     draw.line((xc, yc, 2*xc, yc), width=1, fill='#888')
12.     draw.line((xc, yc,   xc,  0), width=1, fill='#888')
13.     draw.line((2*xc-2, yc-2, 2*xc, yc, 2*xc-2, yc+2), width=1, fill='#888')
14.     draw.line((xc-2, 2, xc, 0, xc+2, 2), width=1, fill='#888')
15.     return draw.get_image()
16. 
17. def thumbnail(f, width, height, filter=Image.NEAREST):
18.     g = array2pil(f)
19.     g.thumbnail((width, height), filter)
20.     return pil2array(g)
21. 
22. def tile_images(fileglob, w=100, h=100):
23.     n = 0
24.     if os.path.isabs(fileglob):
25.           print 'ERRO: absolute path is not allowed here...'
26. 
27.     media_root = config.media_root.replace('\\', '/').rstrip('/')
28.     media_url = config.media_url.replace('\\', '/').rstrip('/')
29.     fileglob = os.path.join(media_root, fileglob)
30.     files = glob.glob(fileglob)
31.     files.sort()
32.     for img in files:
33.        img = img.replace('\\', '/')
34.        basename = os.path.basename(img)
35.        if basename[-3:] not in ['gif', 'jpg', 'png', 'tif', 'bmp', 'pgm', 'ppm', 'pbm']:
36.           continue
37.        try:
38.           f = adread(img)
39.           g = thumbnail(f, w, h)
40.           url = urllib.quote(img.replace(media_root, media_url))
41.           if len(f.shape) == 3:
42.             adshow(g, title='`%s %s (%d,%d,%d)`' % (url, basename,f.shape[-3],f.shape[-2],f.shape[-1]))
43.           else:
44.             adshow(g, title='`%s %s (%d,%d)`' % (url, basename,f.shape[-2],f.shape[-1]))
45.           n += 1
46.        except Exception, e:
47.           print 'ERRO: %s => %s' % (e, basename)
48. 
49.     return n