Skip to content

Commit

Permalink
Add 1D specializations of Point and PointMatch for intensity matching
Browse files Browse the repository at this point in the history
  • Loading branch information
minnerbe committed Jan 20, 2025
1 parent 6d5189d commit e4f6d0a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ij.process.ColorProcessor;
import ij.process.FloatProcessor;
import mpicbg.models.Affine1D;
import mpicbg.models.Point;
import mpicbg.models.PointMatch;
import mpicbg.models.Tile;
import net.imglib2.util.Pair;
Expand Down Expand Up @@ -93,7 +92,7 @@ public void match(final TileSpec p1, final TileSpec p2, final HashMap<String, Ar
if (matchCanContribute) {
final double p = pixels1.getf(i);
final double q = pixels2.getf(i);
final PointMatch pq = new PointMatch(new Point(new double[]{p}), new Point(new double[]{q}), weight1 * weight2);
final PointMatch pq = new PointMatch1D(new Point1D(p), new Point1D(q), weight1 * weight2);

/* first sub-tile label is 1 */
final List<PointMatch> matches = get(matrix, label1 - 1, label2 - 1, nCoefficientTiles);
Expand Down Expand Up @@ -176,9 +175,9 @@ private static List<PointMatch> compressByBinning(final List<PointMatch> candida
for (final Map.Entry<Pair<Integer, Integer>, Double> entry : pairToWeights.entrySet()) {
final Pair<Integer, Integer> pair = entry.getKey();
final double weight = entry.getValue();
final Point p1 = new Point(new double[]{ (double) pair.getA() / nBins });
final Point p2 = new Point(new double[]{ (double) pair.getB() / nBins });
compressedCandidates.add(new PointMatch(p1, p2, weight));
final Point1D p1 = new Point1D((double) pair.getA() / nBins);
final Point1D p2 = new Point1D((double) pair.getB() / nBins);
compressedCandidates.add(new PointMatch1D(p1, p2, weight));
}

return compressedCandidates;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.janelia.render.client.newsolver.solvers.intensity;

import mpicbg.models.CoordinateTransform;
import mpicbg.models.Point;

/**
* A 1D point. This is used in the intensity matching algorithm and adds an optimized method for applying a
* transformation a 1D point. The method doesn't overwrite {@link Point#apply(CoordinateTransform)} since this method
* is marked as final in the superclass.
*/
public class Point1D extends Point {
public Point1D(final double l, final double w) {
super(new double[] { l }, new double[] { w });
}

public Point1D(final double l) {
this(l, l);
}

public void applyFast(final CoordinateTransform t) {
w[0] = l[0];
t.applyInPlace(w);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.janelia.render.client.newsolver.solvers.intensity;

import mpicbg.models.CoordinateTransform;
import mpicbg.models.PointMatch;

/**
* A match of two 1D points. This is used in the intensity matching algorithm and adds an optimized method for computing
* the distance of two 1D points.
*/
public class PointMatch1D extends PointMatch {
public PointMatch1D(final Point1D p1, final Point1D p2) {
super(p1, p2);
}

public PointMatch1D(final Point1D p1, final Point1D p2, final double weight) {
super(p1, p2, weight);
}

@Override
public void apply(final CoordinateTransform t) {
final Point1D p1 = (Point1D) this.p1;
p1.applyFast(t);
}

@Override
public double getDistance(){
final Point1D p1 = (Point1D) this.p1;
final Point1D p2 = (Point1D) this.p2;
return Math.abs(p1.getL()[0] - p2.getL()[0]);
}
}

0 comments on commit e4f6d0a

Please sign in to comment.