(img, ds=1, sigma=0, k=0.2)
| 33 | return rs, cs, (idx1 + did).reshape((-1,3)) |
| 34 | |
| 35 | def build_surf2d(img, ds=1, sigma=0, k=0.2): |
| 36 | from skimage.filters import sobel_h, sobel_v |
| 37 | from scipy.ndimage import gaussian_filter |
| 38 | #start = time() |
| 39 | img = img[::-ds, ::ds] |
| 40 | img = gaussian_filter(img, sigma) |
| 41 | r, c = img.shape |
| 42 | rs, cs, fs = build_grididx(r, c) |
| 43 | vs = img[rs, cs] |
| 44 | |
| 45 | vts = np.array([cs*ds, rs*ds, vs*k], dtype=np.float32).T |
| 46 | cs = (np.ones((3, r*c))*(vs/255)).astype(np.float32).T |
| 47 | |
| 48 | dx, dy = sobel_h(img), sobel_v(img) |
| 49 | cx, cy = np.zeros((r*c, 3)), np.zeros((r*c, 3)) |
| 50 | cx[:,0], cx[:,2] = 1, dx.ravel() |
| 51 | cy[:,1], cy[:,2] = 1, dy.ravel() |
| 52 | ns = np.cross(cx, cy) |
| 53 | ns = (ns.T/np.linalg.norm(ns, axis=1)).astype(np.float32).T |
| 54 | |
| 55 | #ns = count_ns(vts, fs) |
| 56 | #print(time()-start) |
| 57 | return vts, fs, ns, cs |
| 58 | |
| 59 | def build_surf3d(imgs, ds, level, step=1, c=(1,0,0)): |
| 60 | from skimage.measure import marching_cubes_lewiner |
no test coverage detected