def _pyramid(store, key, new, pars): """Pyramid store. """ # this needs the cv module from osdf. chunk, schema, params = pars[0], pars[1], pars[2] depth = 0 if schema is "laplace": from osdfcv.pyramid.laplacian import build_pil build_pyr = build_pil depth = params[0] elif schema is "lcn": from osdfcv.pyramid.lcn import build_pil depth, width, sigma = params shape = store[key].shape dx = int(np.sqrt(shape[1])) shape = (dx, dx) lcns = _build_lcns(shape, depth, width, sigma) from functools import partial build_pyr = partial(build_pil, lcns=lcns) elif schema is "fovea": from osdfcv.pyramid.fovea import build depth = params[0] build_pyr = build else: assert False, "Don't know pyramid schmema %s"%schema assert depth > 0, "Need a decent depth: %d"%depth # collect inputs in group grp = new.create_group(name=key) dsets = [] dtype = store[key].dtype shape = store[key].shape dx = int(np.sqrt(shape[1])) for d in xrange(depth): dsets.append(grp.create_dataset(name=key+str(d), shape=shape, dtype=dtype)) shape = (shape[0], shape[1]/4) k = 0 # global counter, not nice for i in xrange(0, store[key].shape[0], chunk): for l in store[key][i:i+chunk]: pyramid = build_pyr(l.reshape(dx, dx), depth) for j, img in enumerate(pyramid): dsets[j][k] = img.ravel() k = k + 1 for attrs in store.attrs: grp.attrs[attrs] = store.attrs[attrs] for d in xrange(depth): dsets[d].attrs["patch_shape"] = (dx, dx) dx = dx/2 grp.attrs['depth'] = depth grp.attrs['schema'] = schema
def _pyramid_fuse(store, key, new, pars): """Pyramid store. All stages of a pyramid fused into one row vector. """ # this needs the cv module from osdf. chunk, schema, shapes = pars[0], pars[1], pars[2] depth = len(shapes) if schema is "laplace": from osdfcv.pyramid.laplacian import build_pil dtype = store[key].dtype n, x = store[key].shape dx = int(np.sqrt(x)) shape = 0 for sh in shapes: shape = shape + sh[0]*sh[1] dset = new.create_dataset(name=key+"_pyr", shape=(n, shape), dtype=dtype) k = 0 # global counter, not nice for i in xrange(0, store[key].shape[0], chunk): for l in store[key][i:i+chunk]: pyramid = build_pil(l.reshape(dx, dx), depth) start = 0 for j, img in enumerate(pyramid): stop = start + shapes[j][0]*shapes[j][1] dset[k][start:stop] = img.ravel() print dset[k] start = stop k = k + 1 print k for attrs in store.attrs: new.attrs[attrs] = store.attrs[attrs] new.attrs['depth'] = depth new.attrs['schema'] = schema