def gen_coxlab_features(chip_resized, feature_x, feature_y): image_vector = [] im_array = np.asarray(chip_resized).astype('f') # -- get L3 prime SLM description (from sthor) desc = sthor.model.parameters.fg11.fg11_ht_l3_1_description # -- generate random PLOS09 3-layer model #desc = sthor.model.parameters.plos09.get_random_plos09_l3_description() # -- instantiate the SLM model model = SequentialLayeredModel((feature_x, feature_y), desc) # -- compute feature map, shape [height, width, depth] f_map = model.transform(im_array, pad_apron=True, interleave_stride=False) f_map_dims = f_map.shape print "shape", f_map.shape for j in range(f_map_dims[0]): for k in range(f_map_dims[1]): for l in range(f_map_dims[2]): image_vector.append(f_map[j][k][l]) return image_vector
def eDN_features(img, desc, outSize=None): """ Computes eDN features for given image or image sequence 'img' based on the given descriptor(s) 'desc'""" # iterates through individual DN models (Deep Networks) in the blend for i in xrange(len(desc)): imgC = img.copy() if desc[i]['colorSp'] == 'yuv': # either a single image or an image sequence for j in xrange(imgC.shape[2] / 3): imgC[:, :, j * 3:j * 3 + 3] = convertRGB2YUV(imgC[:, :, j * 3:j * 3 + 3]) imgC = imgC.astype('f') model = SequentialLayeredModel((imgC.shape[0], imgC.shape[1]), desc[i]['desc']) fm = model.transform(imgC, pad_apron=True, interleave_stride=False) if outSize: # zoom seems to round down when non-integer shapes are requested # and zoom does not accept an `output_shape` parameter fMap = sp.ndimage.interpolation.zoom( fm, (outSize[0] * (1 + 1e-5) / fm.shape[0], outSize[1] * (1 + 1e-5) / fm.shape[1], 1.0)) else: if i == 0: fmShape = fm.shape[:2] fMap = fm else: if fm.shape[:2] == fmShape: fMap = fm else: # models with different number of layers have different # output sizes, so resizing is necessary fMap = sp.ndimage.interpolation.zoom( fm, (fmShape[0] * (1 + 1e-5) / fm.shape[0], fmShape[1] * (1 + 1e-5) / fm.shape[1], 1.0)) fMap = fMap.reshape(fMap.shape[0] * fMap.shape[1], -1, order='F') if i == 0: fMaps = fMap else: fMaps = np.hstack((fMaps, fMap)) return fMaps, fmShape
def eDN_features(img, desc, outSize=None): """ Computes eDN features for given image or image sequence 'img' based on the given descriptor(s) 'desc'""" # iterates through individual DN models (Deep Networks) in the blend for i in xrange(len(desc)): imgC = img.copy() if desc[i]['colorSp'] == 'yuv': # either a single image or an image sequence for j in xrange(imgC.shape[2]/3): imgC[:,:,j*3:j*3+3] = convertRGB2YUV(imgC[:,:,j*3:j*3+3]) imgC = imgC.astype('f') model = SequentialLayeredModel((imgC.shape[0], imgC.shape[1]), desc[i]['desc']) fm = model.transform(imgC, pad_apron=True, interleave_stride=False) if outSize: # zoom seems to round down when non-integer shapes are requested # and zoom does not accept an `output_shape` parameter fMap = sp.ndimage.interpolation.zoom(fm, (outSize[0]*(1+1e-5)/fm.shape[0], outSize[1]*(1+1e-5)/fm.shape[1], 1.0)) else: if i == 0: fmShape = fm.shape[:2] fMap = fm else: if fm.shape[:2] == fmShape: fMap = fm else: # models with different number of layers have different # output sizes, so resizing is necessary fMap = sp.ndimage.interpolation.zoom(fm, (fmShape[0]*(1+1e-5)/fm.shape[0], fmShape[1]*(1+1e-5)/fm.shape[1], 1.0)) fMap = fMap.reshape(fMap.shape[0]*fMap.shape[1], -1, order='F') if i == 0: fMaps = fMap else: fMaps = np.hstack((fMaps, fMap)) return fMaps, fmShape