/** * Gets eigenvalues for the tensor with specified indices. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @return array {au,av} of eigenvalues. */ public float[] getEigenvalues(int i1, int i2) { float[] a = new float[2]; getEigenvalues(i1,i2,a); return a; }
/** * Gets the eigenvector u for the tensor with specified indices. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @return array {u1,u2} of eigenvector components. */ public float[] getEigenvectorU(int i1, int i2) { float[] u = new float[2]; getEigenvectorU(i1,i2,u); return u; }
/** * Gets tensor elements for specified indices. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @return a array {a11,a12,a22} of tensor elements. */ public float[] getTensor(int i1, int i2) { float[] a = new float[3]; getTensor(i1,i2,a); return a; }
/** * Constructs tensors for specified array dimensions and eigenvalues. * @param u1 array of 1st components of u. * @param u2 array of 2nd components of u. * @param au array of 1D eigenvalues. * @param av array of 2D eigenvalues. */ public EigenTensors2( float[][] u1, float[][] u2, float[][] au, float[][] av) { this(u1[0].length,u1.length); for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { float aui = au[i2][i1]; float avi = av[i2][i1]; float u1i = u1[i2][i1]; float u2i = u2[i2][i1]; setEigenvalues(i1,i2,aui,avi); setEigenvectorU(i1,i2,u1i,u2i); } } }
private static void testRandom(double errorAngle, double errorCoeff) { int n1 = 13, n2 = 14; EigenTensors2 et = new EigenTensors2(n1,n2); for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { float[] a = makeRandomEigenvalues(); float[] u = makeRandomEigenvector(); et.setEigenvalues(i1,i2,a); et.setEigenvectorU(i1,i2,u); float[] c; c = et.getEigenvectorU(i1,i2); checkEigenvectors(u,c,errorAngle); c = et.getEigenvalues(i1,i2); checkEigenvalues(c,a,errorCoeff); et.setTensor(i1,i2,et.getTensor(i1,i2)); c = et.getEigenvectorU(i1,i2); checkEigenvectors(u,c,errorAngle); c = et.getEigenvalues(i1,i2); checkEigenvalues(c,a,errorCoeff); } } }
public void apply( Direction2 d, EigenTensors2 t, float[][] f, float[][] g) { if (_scale==0.0f) { copy(f,g); } else { int n1 = f[0].length; int n2 = f.length; float[][] au = new float[n2][n1]; float[][] av = new float[n2][n1]; float[][] sf = new float[n2][n1]; t.getEigenvalues(au,av); setEigenvalues(d,t); _lsf.applySmoothL(_kmax,f,sf); //_lsf.applySmoothS(f,sf); _lsf.apply(t,_scale,sf,g); t.setEigenvalues(au,av); } } public void apply(
for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { _et.getEigenvalues(i1,i2,a); emax = max(emax,a[0],a[1]); int j1 = _s1.indexOfNearest(x1); _et.getEigenvalues(j1,j2,a); _et.getEigenvectorU(j1,j2,u); double u1 = u[0]; double u2 = u[1];
/** * Sets tensor elements for specified indices. * This method first computes an eigen-decomposition of the specified * tensor, and then stores the computed eigenvectors and eigenvalues. * The eigenvalues are ordered such that au >= av >= 0. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param a array {a11,a12,a22} of tensor elements. */ public void setTensor(int i1, int i2, float[] a) { setTensor(i1,i2,a[0],a[1],a[2]); }
/** * Sets eigenvalues for the tensor with specified indices. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param a array {au,av} of eigenvalues. */ public void setEigenvalues(int i1, int i2, float[] a) { setEigenvalues(i1,i2,a[0],a[1]); }
/** * Sets the eigenvector u for the tensor with specified indices. * The specified vector is assumed to have length one. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param u {u1,u2} of eigenvector components. */ public void setEigenvectorU(int i1, int i2, float[] u) { setEigenvectorU(i1,i2,u[0],u[1]); }
/** * Applies this filter to estimate 2-D structure tensors. * @param x input array for 2-D image. * @return structure tensors. */ public EigenTensors2 applyForTensors(float[][] x) { int n1 = x[0].length; int n2 = x.length; float[][] u1 = new float[n2][n1]; float[][] u2 = new float[n2][n1]; float[][] eu = new float[n2][n1]; float[][] ev = new float[n2][n1]; apply(x, null, u1,u2, null,null, eu,ev, null); return new EigenTensors2(u1,u2,eu,ev); }
/** * Gets the eigenvector v for the tensor with specified indices. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @return array {v1,v2} of eigenvector components. */ public float[] getEigenvectorV(int i1, int i2) { float[] v = new float[2]; getEigenvectorV(i1,i2,v); return v; }
/** * Sets tensor elements for specified indices. * This method first computes an eigen-decomposition of the specified * tensor, and then stores the computed eigenvectors and eigenvalues. * The eigenvalues are ordered such that au >= av >= 0. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param a11 tensor element a11. * @param a12 tensor element a12. * @param a22 tensor element a22. */ public void setTensor(int i1, int i2, float a11, float a12, float a22) { float[][] aa = { {a11,a12}, {a12,a22} }; float[][] vv = new float[2][2]; float[] ev = new float[2]; Eigen.solveSymmetric22(aa,vv,ev); float[] u = vv[0]; float au = ev[0]; if (au<0.0f) au = 0.0f; float av = ev[1]; if (av<0.0f) av = 0.0f; setEigenvectorU(i1,i2,u); setEigenvalues(i1,i2,au,av); }
/** * Applies this mask to a specified eigentensor field. * @param efalse eigentensor {e11,e12,e22} to use for samples * where the mask is false. * @param e eigentensors to be masked. */ public void apply(float[] efalse, EigenTensors2 e) { Check.state(_mask2!=null,"mask constructed for a 2D image"); for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { if (!_mask2[i2][i1]) e.setTensor(i1,i2,efalse); } } }
private static void setEigenvalues(Direction2 d, EigenTensors2 t) { float au = 0.0f; float av = 0.0f; if (d==Direction2.U || d==Direction2.UV) au = 1.0f; if (d==Direction2.V || d==Direction2.UV) av = 1.0f; t.setEigenvalues(au,av); } private static void setEigenvalues(Direction3 d, EigenTensors3 t) {