Commit 5e03168f authored by Andrey Filippov's avatar Andrey Filippov

Fixed affine inversion

parent 0da53711
...@@ -3005,6 +3005,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -3005,6 +3005,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
} }
return true; return true;
} }
public static double [][] combineAffine( public static double [][] combineAffine(
double [][] ref_affine, double [][] ref_affine,
double [][] other_affine){ double [][] other_affine){
...@@ -3023,6 +3024,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -3023,6 +3024,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
} }
/** /**
* Get planar approximation of the ground * Get planar approximation of the ground
* *
......
...@@ -54,21 +54,26 @@ public class OrthoPairLMA { ...@@ -54,21 +54,26 @@ public class OrthoPairLMA {
private double [][] last_jt = null; private double [][] last_jt = null;
private boolean origin_center = false; // true - origin in overlap center, false - top left corner (as it was) private boolean origin_center = false; // true - origin in overlap center, false - top left corner (as it was)
private double [] origin = null; // either {0,0} for top-left or center of the woi private double [] origin = null; // either {0,0} for top-left or center of the woi
public int num_good_tiles = 0;
public OrthoPairLMA (boolean origin_center) { public OrthoPairLMA (boolean origin_center) {
this.origin_center = origin_center; this.origin_center = origin_center;
} }
public void prepareLMA( public int prepareLMA(
// will always calculate relative affine, starting with unity // will always calculate relative affine, starting with unity
int width, // tilesX int width, // tilesX
double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate() double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
double [][] centers, // tile centers (in pixels) double [][] centers, // tile centers (in pixels)
double [] weights_extra, // optional, may be null double [] weights_extra, // optional, may be null
boolean first_run, boolean first_run,
int min_good_tiles,
double max_std, // maximal standard deviation to limit center area
double min_std_rad, // minimal radius of the central area (if less - fail)
final int debug_level) { final int debug_level) {
tile_centers = centers; tile_centers = centers;
this.width = width; this.width = width;
int height = vector_XYS.length / width; int height = vector_XYS.length / width;
int min_x = width, min_y=height, max_x = -1, max_y=-1; int min_x = width, min_y=height, max_x = -1, max_y=-1;
num_good_tiles = 0;
for (int tile = 0; tile < vector_XYS.length; tile++) if ((vector_XYS[tile] !=null)) { for (int tile = 0; tile < vector_XYS.length; tile++) if ((vector_XYS[tile] !=null)) {
int tileX = tile % width; int tileX = tile % width;
int tileY = tile / width; int tileY = tile / width;
...@@ -76,8 +81,12 @@ public class OrthoPairLMA { ...@@ -76,8 +81,12 @@ public class OrthoPairLMA {
if (tileX > max_x) max_x = tileX; if (tileX > max_x) max_x = tileX;
if (tileY < min_y) min_y = tileY; if (tileY < min_y) min_y = tileY;
if (tileY > max_y) max_y = tileY; if (tileY > max_y) max_y = tileY;
num_good_tiles++;
} }
woi = new Rectangle (min_x, min_y, max_x - min_x + 1, max_y - min_y + 1); woi = new Rectangle (min_x, min_y, max_x - min_x + 1, max_y - min_y + 1);
if (num_good_tiles < min_good_tiles) {
return num_good_tiles;
}
origin = new double[2]; origin = new double[2];
if (origin_center) { if (origin_center) {
origin = new double [] { origin = new double [] {
...@@ -98,7 +107,7 @@ public class OrthoPairLMA { ...@@ -98,7 +107,7 @@ public class OrthoPairLMA {
last_rms = new double [2]; last_rms = new double [2];
initial_rms = last_rms.clone(); initial_rms = last_rms.clone();
good_or_bad_rms = this.last_rms.clone(); good_or_bad_rms = this.last_rms.clone();
return num_good_tiles;
} }
public double [][] getAffine(){ public double [][] getAffine(){
......
...@@ -14,10 +14,40 @@ public class PairwiseOrthoMatch implements Serializable { ...@@ -14,10 +14,40 @@ public class PairwiseOrthoMatch implements Serializable {
public PairwiseOrthoMatch() { public PairwiseOrthoMatch() {
} }
public PairwiseOrthoMatch(double [][] affine, double [][] jtj, double rms, int zoom_lev) { public PairwiseOrthoMatch(
double [][] affine,
double [][] jtj,
double rms,
int zoom_lev) {
this.affine = affine; this.affine = affine;
this.jtj = jtj; this.jtj = jtj;
this.zoom_lev=zoom_lev;
} }
public PairwiseOrthoMatch getInverse(double [] rd) {
double [][] affine = OrthoMap.invertAffine(getAffine());
PairwiseOrthoMatch inverted_match = new PairwiseOrthoMatch(
affine, // double [][] affine,
null, // double [][] jtj,
rms, // double rms,
zoom_lev); // int zoom_lev)
double [] corr = {
rd[0] * (affine[0][0]-1.0)+ rd[1]*affine[0][1],
rd[0] * affine[1][0]+ rd[1]*(affine[1][1]-1.0)};
affine[0][2] += corr[0];
affine[1][2] += corr[1];
return inverted_match;
}
public PairwiseOrthoMatch getInverse() {
PairwiseOrthoMatch inverted_match = new PairwiseOrthoMatch(
OrthoMap.invertAffine(getAffine()), // double [][] affine,
null, // double [][] jtj,
rms, // double rms,
zoom_lev); // int zoom_lev)
return inverted_match;
}
public double [][] getAffine(){ public double [][] getAffine(){
return affine; return affine;
} }
......
...@@ -100,11 +100,12 @@ public class IntersceneMatchParameters { ...@@ -100,11 +100,12 @@ public class IntersceneMatchParameters {
public double rln_fat_zero = 10000.0; // phase correlation fat zero public double rln_fat_zero = 10000.0; // phase correlation fat zero
public boolean rln_use_neibs = true; // calculate TD neighbors in phase correlation public boolean rln_use_neibs = true; // calculate TD neighbors in phase correlation
public boolean rln_neibs_fill = false; // fill empty neighbors centers public boolean rln_neibs_fill = false; // fill empty neighbors centers
public double rln_neib_radius = 2.9; // neighbors radius (tiles) public double rln_neib_radius = 5.9; // neighbors radius (tiles)
public double rln_radius_frac = 0.1; // rln_neib_radius not less than this fraction of woi width/height
public double rln_cent_radius = 4.0; // centroids center radius public double rln_cent_radius = 4.0; // centroids center radius
public int rln_n_recenter = 2; // when cosine window, re-center window these many times public int rln_n_recenter = 2; // when cosine window, re-center window these many times
public double rln_sngl_rstr = 0.3; // minimal single-tile phase correlation maximums relative to max str public double rln_sngl_rstr = 0.3; // minimal single-tile phase correlation maximums relative to max str
public double rln_neib_rstr = 0.5; // minimal neighbors phase correlation maximums relative to max str public double rln_neib_rstr = 0.4; // minimal neighbors phase correlation maximums relative to max str
public double [] getImsMountATR() { public double [] getImsMountATR() {
return new double [] { return new double [] {
...@@ -683,6 +684,8 @@ public class IntersceneMatchParameters { ...@@ -683,6 +684,8 @@ public class IntersceneMatchParameters {
"Fill empty neighbors centers (false - only non-empty)."); "Fill empty neighbors centers (false - only non-empty).");
gd.addNumericField("Neighbors radius", this.rln_neib_radius, 5,8,"tiles", gd.addNumericField("Neighbors radius", this.rln_neib_radius, 5,8,"tiles",
"Use these tiles around the center one."); "Use these tiles around the center one.");
gd.addNumericField("Neighbors radius fraction woi", this.rln_radius_frac, 5,8,"",
"Naighbors radius not less than this fraction of tiles WOI.");
gd.addNumericField("Centroids radius", this.rln_cent_radius, 5,8,"", gd.addNumericField("Centroids radius", this.rln_cent_radius, 5,8,"",
"Centroids radius for maximums isolation."); "Centroids radius for maximums isolation.");
gd.addNumericField("Recenter centroid", this.rln_n_recenter, 0,3,"", gd.addNumericField("Recenter centroid", this.rln_n_recenter, 0,3,"",
...@@ -1526,6 +1529,7 @@ public class IntersceneMatchParameters { ...@@ -1526,6 +1529,7 @@ public class IntersceneMatchParameters {
this.rln_use_neibs = gd.getNextBoolean(); this.rln_use_neibs = gd.getNextBoolean();
this.rln_neibs_fill = gd.getNextBoolean(); this.rln_neibs_fill = gd.getNextBoolean();
this.rln_neib_radius = gd.getNextNumber(); this.rln_neib_radius = gd.getNextNumber();
this.rln_radius_frac = gd.getNextNumber();
this.rln_cent_radius = gd.getNextNumber(); this.rln_cent_radius = gd.getNextNumber();
this.rln_n_recenter = (int) gd.getNextNumber(); this.rln_n_recenter = (int) gd.getNextNumber();
this.rln_sngl_rstr = gd.getNextNumber(); this.rln_sngl_rstr = gd.getNextNumber();
...@@ -1986,6 +1990,7 @@ public class IntersceneMatchParameters { ...@@ -1986,6 +1990,7 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"rln_use_neibs", this.rln_use_neibs + ""); // boolean properties.setProperty(prefix+"rln_use_neibs", this.rln_use_neibs + ""); // boolean
properties.setProperty(prefix+"rln_neibs_fill", this.rln_neibs_fill + ""); // boolean properties.setProperty(prefix+"rln_neibs_fill", this.rln_neibs_fill + ""); // boolean
properties.setProperty(prefix+"rln_neib_radius", this.rln_neib_radius +""); // double properties.setProperty(prefix+"rln_neib_radius", this.rln_neib_radius +""); // double
properties.setProperty(prefix+"rln_radius_frac", this.rln_radius_frac +""); // double
properties.setProperty(prefix+"rln_cent_radius", this.rln_cent_radius +""); // double properties.setProperty(prefix+"rln_cent_radius", this.rln_cent_radius +""); // double
properties.setProperty(prefix+"rln_n_recenter", this.rln_n_recenter+""); // int properties.setProperty(prefix+"rln_n_recenter", this.rln_n_recenter+""); // int
properties.setProperty(prefix+"rln_sngl_rstr", this.rln_sngl_rstr +""); // double properties.setProperty(prefix+"rln_sngl_rstr", this.rln_sngl_rstr +""); // double
...@@ -2409,6 +2414,7 @@ public class IntersceneMatchParameters { ...@@ -2409,6 +2414,7 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"rln_use_neibs")!=null) this.rln_use_neibs=Boolean.parseBoolean(properties.getProperty(prefix+"rln_use_neibs")); if (properties.getProperty(prefix+"rln_use_neibs")!=null) this.rln_use_neibs=Boolean.parseBoolean(properties.getProperty(prefix+"rln_use_neibs"));
if (properties.getProperty(prefix+"rln_neibs_fill")!=null) this.rln_neibs_fill=Boolean.parseBoolean(properties.getProperty(prefix+"rln_neibs_fill")); if (properties.getProperty(prefix+"rln_neibs_fill")!=null) this.rln_neibs_fill=Boolean.parseBoolean(properties.getProperty(prefix+"rln_neibs_fill"));
if (properties.getProperty(prefix+"rln_neib_radius")!=null) this.rln_neib_radius=Double.parseDouble(properties.getProperty(prefix+"rln_neib_radius")); if (properties.getProperty(prefix+"rln_neib_radius")!=null) this.rln_neib_radius=Double.parseDouble(properties.getProperty(prefix+"rln_neib_radius"));
if (properties.getProperty(prefix+"rln_radius_frac")!=null) this.rln_radius_frac=Double.parseDouble(properties.getProperty(prefix+"rln_radius_frac"));
if (properties.getProperty(prefix+"rln_cent_radius")!=null) this.rln_cent_radius=Double.parseDouble(properties.getProperty(prefix+"rln_cent_radius")); if (properties.getProperty(prefix+"rln_cent_radius")!=null) this.rln_cent_radius=Double.parseDouble(properties.getProperty(prefix+"rln_cent_radius"));
if (properties.getProperty(prefix+"rln_n_recenter")!=null) this.rln_n_recenter=Integer.parseInt(properties.getProperty(prefix+"rln_n_recenter")); if (properties.getProperty(prefix+"rln_n_recenter")!=null) this.rln_n_recenter=Integer.parseInt(properties.getProperty(prefix+"rln_n_recenter"));
if (properties.getProperty(prefix+"rln_sngl_rstr")!=null) this.rln_sngl_rstr=Double.parseDouble(properties.getProperty(prefix+"rln_sngl_rstr")); if (properties.getProperty(prefix+"rln_sngl_rstr")!=null) this.rln_sngl_rstr=Double.parseDouble(properties.getProperty(prefix+"rln_sngl_rstr"));
...@@ -2860,6 +2866,8 @@ public class IntersceneMatchParameters { ...@@ -2860,6 +2866,8 @@ public class IntersceneMatchParameters {
imp.rln_use_neibs = this.rln_use_neibs; imp.rln_use_neibs = this.rln_use_neibs;
imp.rln_neibs_fill = this.rln_neibs_fill; imp.rln_neibs_fill = this.rln_neibs_fill;
imp.rln_neib_radius = this.rln_neib_radius; imp.rln_neib_radius = this.rln_neib_radius;
imp.rln_radius_frac = this.rln_radius_frac;
imp.rln_cent_radius = this.rln_cent_radius; imp.rln_cent_radius = this.rln_cent_radius;
imp.rln_n_recenter = this.rln_n_recenter; imp.rln_n_recenter = this.rln_n_recenter;
imp.rln_sngl_rstr = this.rln_sngl_rstr; imp.rln_sngl_rstr = this.rln_sngl_rstr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment