Skip to content

Commit cc78f77

Browse files
Merge pull request #1 from imagejan/ejml-update
Update to ejml-0.41
2 parents cf3735c + 72d165d commit cc78f77

File tree

3 files changed

+98
-31
lines changed

3 files changed

+98
-31
lines changed

pom.xml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,22 @@
5555

5656
<!-- NB: Deploy releases to the SciJava Maven repository. -->
5757
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
58+
59+
<ejml.version>0.41</ejml.version>
5860
</properties>
5961

6062
<dependencies>
6163
<dependency>
6264
<groupId>net.imglib2</groupId>
6365
<artifactId>imglib2-ij</artifactId>
64-
</dependency>
66+
<exclusions>
67+
<exclusion>
68+
<!-- declare the exclusion here -->
69+
<groupId>jitk</groupId>
70+
<artifactId>jitk-tps</artifactId>
71+
</exclusion>
72+
</exclusions>
73+
</dependency>
6574
<dependency>
6675
<groupId>mpicbg</groupId>
6776
<artifactId>mpicbg</artifactId>
@@ -76,10 +85,15 @@
7685
<version>0.1</version>
7786
</dependency>
7887
<dependency>
79-
<groupId>
80-
com.googlecode.efficient-java-matrix-library
81-
</groupId>
82-
<artifactId>ejml</artifactId>
88+
<groupId>org.ejml</groupId>
89+
<artifactId>ejml-all</artifactId>
90+
<version>${ejml.version}</version>
91+
</dependency>
92+
93+
<dependency>
94+
<groupId>junit</groupId>
95+
<artifactId>junit</artifactId>
96+
<scope>test</scope>
8397
</dependency>
8498
</dependencies>
8599

src/main/java/fit/circular/Ellipse.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
import java.util.ArrayList;
3737
import java.util.Collection;
3838

39-
import org.ejml.data.DenseMatrix64F;
40-
import org.ejml.factory.DecompositionFactory;
41-
import org.ejml.factory.LinearSolverFactory;
39+
import org.ejml.data.DMatrixRMaj;
40+
import org.ejml.dense.row.factory.DecompositionFactory_DDRM;
41+
import org.ejml.dense.row.factory.LinearSolverFactory_DDRM;
4242
import org.ejml.interfaces.decomposition.EigenDecomposition;
4343
import org.ejml.interfaces.linsol.LinearSolver;
44-
import org.ejml.ops.CommonOps;
44+
import org.ejml.interfaces.linsol.LinearSolverDense;
45+
import org.ejml.dense.row.CommonOps_DDRM;
4546

4647
import fit.util.TransformUtil;
4748
import ij.ImageJ;
@@ -213,26 +214,26 @@ public void fitFunction( final Collection< Point > points )
213214
// @author Peter Abeles (released under http://www.apache.org/licenses/LICENSE-2.0)
214215

215216
// qudratic part of design matrix
216-
final DenseMatrix64F D1 = new DenseMatrix64F( 3, 1 );
217+
final DMatrixRMaj D1 = new DMatrixRMaj( 3, 1 );
217218
// linear part of design matrix
218-
final DenseMatrix64F D2 = new DenseMatrix64F( 3, 1 );
219+
final DMatrixRMaj D2 = new DMatrixRMaj( 3, 1 );
219220

220221
// quadratic part of scatter matrix
221-
final DenseMatrix64F S1 = new DenseMatrix64F( 3, 3 );
222+
final DMatrixRMaj S1 = new DMatrixRMaj( 3, 3 );
222223
// combined part of scatter matrix
223-
final DenseMatrix64F S2 = new DenseMatrix64F( 3, 3 );
224+
final DMatrixRMaj S2 = new DMatrixRMaj( 3, 3 );
224225
// linear part of scatter matrix
225-
final DenseMatrix64F S3 = new DenseMatrix64F( 3, 3 );
226+
final DMatrixRMaj S3 = new DMatrixRMaj( 3, 3 );
226227
// Reduced scatter matrix
227-
final DenseMatrix64F M = new DenseMatrix64F( 3, 3 );
228+
final DMatrixRMaj M = new DMatrixRMaj( 3, 3 );
228229

229230
// storage for intermediate steps
230-
final DenseMatrix64F T = new DenseMatrix64F( 3, 3 );
231-
final DenseMatrix64F Ta1 = new DenseMatrix64F( 3, 1 );
232-
final DenseMatrix64F S2_tran = new DenseMatrix64F( 3, 3 );
231+
final DMatrixRMaj T = new DMatrixRMaj( 3, 3 );
232+
final DMatrixRMaj Ta1 = new DMatrixRMaj( 3, 1 );
233+
final DMatrixRMaj S2_tran = new DMatrixRMaj( 3, 3 );
233234

234-
final LinearSolver< DenseMatrix64F > solver = LinearSolverFactory.linear( 3 );
235-
final EigenDecomposition< DenseMatrix64F > eigen = DecompositionFactory.eig( 3, true, false );
235+
final LinearSolverDense<DMatrixRMaj> solver = LinearSolverFactory_DDRM.linear( 3 );
236+
final EigenDecomposition< DMatrixRMaj > eigen = DecompositionFactory_DDRM.eig( 3, true, false );
236237

237238
final int N = points.size();
238239

@@ -256,23 +257,23 @@ public void fitFunction( final Collection< Point > points )
256257
}
257258

258259
// Compute scatter matrix
259-
CommonOps.multTransA( D1, D1, S1 ); // S1 = D1'*D1
260-
CommonOps.multTransA( D1, D2, S2 ); // S2 = D1'*D2
261-
CommonOps.multTransA( D2, D2, S3 ); // S3 = D2'*D2
260+
CommonOps_DDRM.multTransA( D1, D1, S1 ); // S1 = D1'*D1
261+
CommonOps_DDRM.multTransA( D1, D2, S2 ); // S2 = D1'*D2
262+
CommonOps_DDRM.multTransA( D2, D2, S3 ); // S3 = D2'*D2
262263

263264
// for getting a2 from a1
264265
// T = -inv(S3)*S2'
265266
if ( !solver.setA( S3 ) )
266267
throw new IllDefinedDataPointsException( "Could not fit ellipse, failed at T = -inv(S3)*S2'" );
267268

268-
CommonOps.transpose( S2, S2_tran );
269-
CommonOps.changeSign( S2_tran );
269+
CommonOps_DDRM.transpose( S2, S2_tran );
270+
CommonOps_DDRM.changeSign( S2_tran );
270271
solver.solve( S2_tran, T );
271272

272273
// Compute reduced scatter matrix
273274
// M = S1 + S2*T
274-
CommonOps.mult( S2, T, M );
275-
CommonOps.add( M, S1, M );
275+
CommonOps_DDRM.mult( S2, T, M );
276+
CommonOps_DDRM.add( M, S1, M );
276277

277278
// Premultiply by inv(C1). inverse of constraint matrix
278279
for (int col = 0; col < 3; col++)
@@ -289,12 +290,12 @@ public void fitFunction( final Collection< Point > points )
289290
if ( !eigen.decompose( M ) )
290291
throw new IllDefinedDataPointsException( "Could not fit ellipse, failed at eigen.decompose( M )" );
291292

292-
final DenseMatrix64F a1 = selectBestEigenVector( eigen );
293+
DMatrixRMaj a1 = selectBestEigenVector( eigen );
293294
if ( a1 == null )
294295
throw new IllDefinedDataPointsException( "Could not fit ellipse, could not find best eigenvector." );
295296

296297
// ellipse coefficients
297-
CommonOps.mult( T, a1, Ta1 );
298+
CommonOps_DDRM.mult( T, a1, Ta1 );
298299

299300
this.a = a1.data[ 0 ];
300301
this.b = a1.data[ 1 ] / 2;
@@ -381,14 +382,14 @@ public void intersectsAt( final double[] p, final double[] i )
381382
}
382383
}
383384

384-
protected DenseMatrix64F selectBestEigenVector( final EigenDecomposition< DenseMatrix64F > eigen )
385+
protected DMatrixRMaj selectBestEigenVector( final EigenDecomposition< DMatrixRMaj > eigen )
385386
{
386387
int bestIndex = -1;
387388
double bestCond = Double.MAX_VALUE;
388389

389390
for (int i = 0; i < eigen.getNumberOfEigenvalues(); i++)
390391
{
391-
final DenseMatrix64F v = eigen.getEigenVector( i );
392+
final DMatrixRMaj v = eigen.getEigenVector( i );
392393

393394
if ( v == null ) // TODO WTF?!?!
394395
continue;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package fit.circular;
2+
3+
import org.junit.Test;
4+
5+
import mpicbg.models.IllDefinedDataPointsException;
6+
import mpicbg.models.NotEnoughDataPointsException;
7+
8+
import static org.junit.Assert.assertTrue;
9+
10+
11+
public class EllipseTest {
12+
13+
@Test
14+
public void test() throws NotEnoughDataPointsException, IllDefinedDataPointsException {
15+
final double[][] points = new double[ 8 ][ 2 ];
16+
17+
points[ 0 ][ 0 ] = 320;
18+
points[ 0 ][ 1 ] = 443;
19+
20+
points[ 0 ][ 0 ] = 0; // non-axis-aligned ellipse
21+
points[ 0 ][ 1 ] = 17;
22+
23+
points[ 1 ][ 0 ] = 377;
24+
points[ 1 ][ 1 ] = 377;
25+
26+
points[ 2 ][ 0 ] = 507;
27+
points[ 2 ][ 1 ] = 350;
28+
29+
points[ 3 ][ 0 ] = 640;
30+
points[ 3 ][ 1 ] = 378;
31+
32+
points[ 4 ][ 0 ] = 694;
33+
points[ 4 ][ 1 ] = 444;
34+
35+
points[ 5 ][ 0 ] = 639;
36+
points[ 5 ][ 1 ] = 511;
37+
38+
points[ 6 ][ 0 ] = 508;
39+
points[ 6 ][ 1 ] = 538;
40+
41+
points[ 7 ][ 0 ] = 376;
42+
points[ 7 ][ 1 ] = 511;
43+
44+
//final ShapePointDistanceFactory< Ellipse, ?, ? > factory = new BruteForceShapePointDistanceFactory< Ellipse >( 0.001 );
45+
final ShapePointDistanceFactory< Ellipse, ?, ? > factory = new EllipsePointDistanceFactory( 10 );
46+
47+
final Ellipse ellipse = new Ellipse( factory );
48+
ellipse.fitFunction( Ellipse.toPoints( points ) );
49+
50+
assertTrue(ellipse.isEllipse());
51+
}
52+
}

0 commit comments

Comments
 (0)