-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The JAMA subproject now provides its own solver implementation for im…
…age-registration.
- Loading branch information
1 parent
f55c724
commit 826cbaa
Showing
8 changed files
with
322 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
/** | ||
* JAMA: A Java Matrix Package | ||
* (also usable as a solver for image registration) | ||
*/ | ||
open module net.raumzeitfalle.jama { | ||
requires transitive net.raumzeitfalle.registration.solver; | ||
exports net.raumzeitfalle.jama; | ||
|
||
provides net.raumzeitfalle.registration.solver.spi.SolverAdapter | ||
with net.raumzeitfalle.jama.Solver; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*- | ||
* #%L | ||
* Image-Registration | ||
* %% | ||
* Copyright (C) 2019, 2021 Oliver Loeffler, Raumzeitfalle.net | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package net.raumzeitfalle.jama; | ||
|
||
import net.raumzeitfalle.registration.solver.Deltas; | ||
import net.raumzeitfalle.registration.solver.References; | ||
import net.raumzeitfalle.registration.solver.Solution; | ||
import net.raumzeitfalle.registration.solver.Solutions; | ||
import net.raumzeitfalle.registration.solver.spi.SolverAdapter; | ||
|
||
public class Solver implements SolverAdapter { | ||
|
||
public Solution solve(References references, Deltas deviations) { | ||
|
||
Matrix refs = new Matrix(references.getArray()); | ||
Matrix deltas = new Matrix(deviations.getArray(), deviations.rows()); | ||
|
||
QRDecomposition qr = new QRDecomposition(refs); | ||
|
||
Matrix rInverse = qr.getR().inverse(); | ||
Matrix qTransposed = qr.getQ().transpose(); | ||
Matrix solution = rInverse.times(qTransposed) | ||
.times(deltas); | ||
|
||
double[] firstColumn = getFirstColumn(solution); | ||
return Solutions.fromArray(firstColumn); | ||
|
||
} | ||
|
||
private double[] getFirstColumn(Matrix solution) { | ||
double[] column = new double[solution.getRowDimension()]; | ||
for (int row = 0; row < column.length; row++) { | ||
column[row] = solution.get(row, 0); | ||
} | ||
return column; | ||
} | ||
|
||
@Override | ||
public Solution apply(References t, Deltas u) { | ||
return solve(t, u); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../main/resources/META-INF/services/net.raumzeitfalle.registration.solver.spi.SolverAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
net.raumzeitfalle.jama.Solver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*- | ||
* #%L | ||
* Image-Registration | ||
* %% | ||
* Copyright (C) 2019, 2021 Oliver Loeffler, Raumzeitfalle.net | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package net.raumzeitfalle.jama; | ||
|
||
import net.raumzeitfalle.registration.solver.Solution; | ||
import net.raumzeitfalle.registration.solver.spi.SolverAdapter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class SolverTest { | ||
|
||
private final SolverAdapter classUnderTest = new Solver(); | ||
|
||
private static final double TOLERANCE = 1E-11; | ||
|
||
@Test | ||
void test() { | ||
|
||
double[][] design = { | ||
{ -75000.0, 0.0, 0.0, -70000.0, 1.0, 0.0 }, | ||
{ 0.0, -70000.0, 75000.0, 0.0, 0.0, 1.0 }, | ||
{ -75000.0, 0.0, 0.0, 70000.0, 1.0, 0.0 }, | ||
{ 0.0, 70000.0, 75000.0, 0.0, 0.0, 1.0 }, | ||
{ 75000.0, 0.0, 0.0, 70000.0, 1.0, 0.0 }, | ||
{ 0.0, 70000.0, -75000.0, 0.0, 0.0, 1.0 }, | ||
{ 75000.0, 0.0, 0.0, -70000.0, 1.0, 0.0 }, | ||
{ 0.0, -70000.0, -75000.0, 0.0, 0.0, 1.0 } }; | ||
|
||
double[] differences = { -0.075, 0.140, -0.075, -0.140, 0.075, -0.140, 0.075, 0.140 }; | ||
|
||
|
||
Solution solution = classUnderTest.apply(() -> design, () -> differences); | ||
|
||
double[] result = { 1.0E-6, -2.0E-6, 0.0, 0.0, 0.0, 0.0 }; | ||
|
||
assertAll(() -> assertNotNull(solution, "must not be null"), | ||
|
||
() -> assertEquals(result[0], solution.get(0), TOLERANCE, "scale x"), | ||
() -> assertEquals(result[1], solution.get(1), TOLERANCE, "scale y"), | ||
|
||
() -> assertEquals(result[2], solution.get(2), TOLERANCE, "ortho x"), | ||
() -> assertEquals(result[3], solution.get(3), TOLERANCE, "ortho y"), | ||
|
||
() -> assertEquals(result[4], solution.get(4), TOLERANCE, "trans x"), | ||
() -> assertEquals(result[5], solution.get(5), TOLERANCE, "trans y")); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.