def edge_direction_3D(E, r=4): D = conv_tri_3D(E, r) Ox, Oy, Oz = np.gradient(D) M = np.sqrt(Ox * Ox + Oy * Oy + Oz * Oz) Ox, Oy, Oz = (Ox, Oy, Oz) / maxeps(M, 1e-5) theta = np.arctan(Oy / maxeps(Oz, 1e-5)) phi = np.arctan(Oz / maxeps(M, 1e-5)) Px = np.sin(theta) * np.cos(phi) Py = np.sin(theta) * np.sin(phi) Pz = np.cos(phi) return Px, Py, Pz, D
def edge_direction_3D(E,r=4): D = conv_tri_3D(E,r) Ox,Oy,Oz = np.gradient(D) M = np.sqrt(Ox*Ox+Oy*Oy+Oz*Oz) Ox,Oy,Oz = (Ox,Oy,Oz)/maxeps(M,1e-5) theta = np.arctan(Oy/maxeps(Oz,1e-5)) phi = np.arctan(Oz/maxeps(M,1e-5)) Px= np.sin(theta)*np.cos(phi) Py= np.sin(theta)*np.sin(phi) Pz= np.cos(phi) return Px,Py,Pz,D
def edge_direction_2D(E,r=5): if(r<=1): p=12/r/(r+2)-2;f=np.array([1,p,1])/(2+p); r=1; else: f = np.array(hstack((range(1,r),r+1,range(r,1,-1))),dtype=float)/(r+1)**2 F = np.zeros((len(f),len(f))) F[:,len(f)/2] = f F = signal.convolve2d(F,F.T,mode='full') En = signal.convolve2d(E,F,mode='same') Ox,Oy = np.gradient(En) Oxx,_ = np.gradient(Ox); Oxy,Oyy = np.gradient(Oy); return np.arctan(Oyy*np.sign(-Oxy)/maxeps(Oxx,1e-5))
def edge_direction_2D(E, r=5): if (r <= 1): p = 12 / r / (r + 2) - 2 f = np.array([1, p, 1]) / (2 + p) r = 1 else: f = np.array(hstack((range(1, r), r + 1, range(r, 1, -1))), dtype=float) / (r + 1)**2 F = np.zeros((len(f), len(f))) F[:, len(f) / 2] = f F = signal.convolve2d(F, F.T, mode='full') En = signal.convolve2d(E, F, mode='same') Ox, Oy = np.gradient(En) Oxx, _ = np.gradient(Ox) Oxy, Oyy = np.gradient(Oy) return np.arctan(Oyy * np.sign(-Oxy) / maxeps(Oxx, 1e-5))
def eval_edgemap(E, GT, id=None, res_dir=None, K=99, thin=False): thrs = np.linspace(1.0 / K, 1, K) ret = list() if id is None: id = 'results' if res_dir is not None: fname = os.path.join(res_dir, str(id) + '.txt') else: fname = None print("[", id, "]", end='', sep='') if os.path.exists(fname): ret_t = npa(np.loadtxt(fname)) print(fname, "exists! shape:", ret_t.shape) return ret_t print(K, E.shape, end='') num_dots = 30 dot_on = np.ceil((1.0 + K) / num_dots) for t, th in enumerate(thrs): E1 = (normal_img(E) > maxeps(th)).astype(float) _, _, matchE, matchG = correspondVoxels( (E1 > 0).astype(float), (GT > 0).astype(float), .0075, 8) matchE, matchG = matchE > 0, matchG > 0 d = dict( th=th, #th cntR=np.sum(matchG.astype(int)), #cntR sumR=np.sum(GT.astype(int)), #sumR cntP=np.sum(matchE.astype(int)), #cntP sumP=np.sum(E1.astype(int)) #sumP ) if t % dot_on == 0: print(".", end='') ret.append(d) print("!", end='') if fname is not None: keys = ['th', 'cntR', 'sumR', 'cntP', 'sumP'] ret2 = [[r[k] for k in keys] for r in ret] header = "\t\t{:10s}{:10s}{:10s}{:10s}{:10s}".format(*keys) np.savetxt(fname, ret2, fmt="%10g %10g %10g %10g %10g", header=header) print("!") return ret
def computeRPF(cntR, sumR, cntP, sumP): R = np.divide(cntR.astype(float), maxeps(sumR)) P = np.divide(cntP.astype(float), maxeps(sumP)) d = npa(maxeps(P + R)) F = (2 * R * P) / d return R, P, F