def compute_sift(dir_imgs, dir_sift, iname, compute_sift_image): ipath = os.path.join(dir_imgs, iname) im = read_grayscale(ipath) if im is None: print('Failed:', ipath) return None sift = compute_sift_image(im) sift = (sift * 255).astype('uint8') spath = os.path.join(dir_sift, iname)[:-4] # remove .jpg sdir = os.path.dirname(spath) os.makedirs(sdir, exist_ok=True) np.save(spath, sift) return sift
def get_regions_and_sifts(dir_sc, inames): from sift import compute_sift_image vdpaths = [os.path.join(dir_sc, iname) for iname in inames] regions = [] sift = [] for path in vdpaths: im = read_grayscale(path) regions.append(compute_regions(im)) sift.append(compute_sift_image(im)) k = regions[0].shape[-1] n_reg = np.array([r.shape[0] * r.shape[1] for r in regions]) cs_reg = np.cumsum(n_reg) regions = [r.reshape(-1, k, k) for r in regions] regions = np.concatenate(regions, axis=0) sift = [s.reshape(-1, sift[0].shape[-1]) for s in sift] sift = np.concatenate(sift, axis=0) return regions, sift