Commit 81d74a44 authored by Andrey Filippov's avatar Andrey Filippov

snapshot before interruption for proposals

parent b7a494a1
......@@ -987,6 +987,10 @@ public class ComboMatch {
double fill_fraction = clt_parameters.imp.pmtch_cent_fill; // should be populated not less than this
double fill_fraction_final = clt_parameters.imp.pmtch_cent_final; // should be populated not less than this during final pass
double ease_nosfm = clt_parameters.imp.pmtch_ease_nosfm; // ease metric_error when no SfM gain == 0;
double pull_skew = clt_parameters.imp.pmtch_pull_skew; // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt = clt_parameters.imp.pmtch_pull_tilt; // > 0
double pull_scale = clt_parameters.imp.pmtch_pull_scale; // = 0
for (int zi = 0; zi < zooms.length; zi++) {
zoom_lev = zooms[zi];
if (zoom_lev >=1000) {
......@@ -998,6 +1002,7 @@ public class ComboMatch {
}
// will modify affines[1], later add jtj, weight, smth. else?
PairwiseOrthoMatch pmatch = process_correlation? pairwiseOrthoMatch: null;
FineXYCorr warp = maps_collection.correlateOrthoPair(
clt_parameters, // CLTParameters clt_parameters,
(process_correlation? pairwiseOrthoMatch: null), //PairwiseOrthoMatch pairwiseOrthoMatch, // will return statistics
......@@ -1022,6 +1027,9 @@ public class ComboMatch {
fill_fraction_final, // double fill_fraction_final,
ease_nosfm, // double ease_nosfm,
null, // double [] max_rms_iter, // = {1.0, 0.6};//
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
debugLevel); // final int debugLevel)
if ((warp == null) || ((pmatch != null) && Double.isNaN(pmatch.rms))) {
System.out.println("Failed correlateOrthoPair()");
......@@ -1153,6 +1161,9 @@ public class ComboMatch {
double fill_fraction = clt_parameters.imp.pmtch_cent_fill; // should be populated not less than this
double fill_fraction_final = clt_parameters.imp.pmtch_cent_final; // should be populated not less than this during final pass
double ease_nosfm = clt_parameters.imp.pmtch_ease_nosfm; // ease metric_error when no SfM gain == 0;
double pull_skew = clt_parameters.imp.pmtch_pull_skew; // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt = clt_parameters.imp.pmtch_pull_tilt; // > 0
double pull_scale = clt_parameters.imp.pmtch_pull_scale; // = 0
GenericJTabbedDialog gd = new GenericJTabbedDialog("Setup Spiral Match",1200,350);
if (pairwiseOrthoMatch != null) {
......@@ -1185,6 +1196,9 @@ public class ComboMatch {
gd.addNumericField("Central area minimal fill", fill_fraction, 3,7,"", "Central area minimal fill for all but the last iteration.");
gd.addNumericField("Central area minimal fill final", fill_fraction_final, 3,7,"", "Central area minimal fill for the last iteration.");
gd.addNumericField("Relax metric error for no-SfM", ease_nosfm, 3,7,"", "Relax metric error for no-SfM scenes (sfm_gain==0).");
gd.addNumericField("Pull skew (rotation)", pull_skew, 3,7,"", "Prevent pairwise match from rotation.");
gd.addNumericField("Pull tilt", pull_tilt, 3,7,"", "Prevent pairwise match from tilt.");
gd.addNumericField("Pull scale", pull_scale, 3,7,"", "Prevent pairwise match from scaling.");
gd.showDialog();
......@@ -1214,6 +1228,9 @@ public class ComboMatch {
fill_fraction= gd.getNextNumber();
fill_fraction_final= gd.getNextNumber();
ease_nosfm= gd.getNextNumber();
pull_skew = gd.getNextNumber();
pull_tilt = gd.getNextNumber();
pull_scale = gd.getNextNumber();
if (use_existing_pair) {
if (invert_exixting_pair) {
......@@ -1254,6 +1271,9 @@ public class ComboMatch {
ignore_rms, // boolean ignore_rms,
null,//double [] max_rms_iter, // = {1.0, 0.6};//
1.0, // double overlap,
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
spiral_debug); // int debugLevel){
if (log_append && (log_path != null)) { // assuming directory exists
StringBuffer sb = new StringBuffer();
......
......@@ -1129,6 +1129,9 @@ public class OrthoMapsCollection implements Serializable{
boolean ignore_rms,
double [] max_rms_iter, // = {1.0, 0.6};//
double overlap,
double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt, // > 0
double pull_scale, // = 0
int debugLevel){
double [][] affine1 = new double [][] {affines_init[1][0].clone(),affines_init[1][1].clone()};
double [][][] affines = new double [][][] {affines_init[0],affine1};
......@@ -1180,6 +1183,9 @@ public class OrthoMapsCollection implements Serializable{
fill_fraction_final, // double fill_fraction_final,
ease_nosfm, // double ease_nosfm,
max_rms_iter, // double [] max_rms_iter, // = {1.0, 0.6};//
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
debugLevel-4); // final int debugLevel)
pairwiseOrthoMatch.setAffine(affines[1]); // modified by correlateOrthoPair
if (debugLevel > -4) {
......@@ -1305,6 +1311,9 @@ public class OrthoMapsCollection implements Serializable{
double fill_fraction_final,
double ease_nosfm,
double [] max_rms_iter, // = {1.0, 0.6};//
double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt, // > 0
double pull_scale, // = 0
int debugLevel){
double vf_drop_big = 0.9; // 0.5? If vector_field threshold drops more, allow RMS to increase
// double rad_fraction = 0.5; // center circle radius fraction of 0.5* min(width, height) in tiles
......@@ -1443,7 +1452,7 @@ public class OrthoMapsCollection implements Serializable{
TpTask [][] tp_tasks = new TpTask [2][];
// int num_tries = 5;
double prev_rms = Double.NaN;
double [] prev_rms = {Double.NaN,Double.NaN};
double rel_improve = 1E-3;
double [][] elevations = new double [tp_tasks.length][];
double [][] ground_planes_metric = new double [tp_tasks.length][];
......@@ -1454,7 +1463,8 @@ public class OrthoMapsCollection implements Serializable{
double frac_above = 0.5; // 0.3;
double frac_below = 0.01; // 0.1;
double [][] jtj = null;
double rms = Double.NaN;
double [] rms = {Double.NaN, Double.NaN};
double [] rms_pure = {Double.NaN, Double.NaN};
double last_center_radius = 0;
double previous_center_radius = 1.0;
OrthoPairLMA orthoPairLMA = null;
......@@ -1717,6 +1727,10 @@ public class OrthoMapsCollection implements Serializable{
min_std_rad, // double min_std_rad, // minimal radius of the central area (if less - fail)
tile_rad , // double tile_rad,
min_tiles_rad, // int min_tiles_rad,
affines_gpu[1], // double [][] src_affine,
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
debugLevel); // final int debug_level)
last_center_radius = orthoPairLMA.getCenterRadius();
double center_radius_increase =
......@@ -1763,25 +1777,26 @@ public class OrthoMapsCollection implements Serializable{
}
rms = orthoPairLMA.getRms();
if (debugLevel > -3) {
System.out.println("RMS= "+rms+" ("+orthoPairLMA.getInitialRms()+")");
System.out.println("RMS= "+rms[0]+" ("+orthoPairLMA.getInitialRms()[0]+
"), RMS pure="+rms[1]+" ("+orthoPairLMA.getInitialRms()[1]+")");
}
if (max_rms_iter != null) {
int max_rms_index = Math.min(max_rms_iter.length-1, ntry);
if (rms > max_rms_iter[max_rms_index]) {
if (rms[0] > max_rms_iter[max_rms_index]) {
if (debugLevel > -3) {
System.out.println("RMS= "+rms+" > max_rms_iter["+
System.out.println("RMS= "+rms[0]+" > max_rms_iter["+
max_rms_index+"] = "+max_rms_iter[max_rms_index]);
}
return null;
}
}
if (rms > prev_rms) {
if (rms[0] > prev_rms[0]) {
if (debugLevel > -3) {
if ((rms-prev_rms)/prev_rms < rel_improve) {
System.out.println("LMA RMSE worsened, but less than improvement threshold: new "+rms+" ("+ orthoPairLMA.getInitialRms()+"), prev="+prev_rms);
if ((rms[0]-prev_rms[0])/prev_rms[0] < rel_improve) {
System.out.println("LMA RMSE worsened, but less than improvement threshold: new "+rms[0]+" ("+ orthoPairLMA.getInitialRms()[0]+"), prev="+prev_rms[0]);
} else {
System.out.println("LMA RMSE worsened: new "+rms+" ("+ orthoPairLMA.getInitialRms()+"), prev="+prev_rms);
System.out.println("LMA RMSE worsened: new "+rms[0]+" ("+ orthoPairLMA.getInitialRms()[0]+"), prev="+prev_rms[0]);
}
}
if (ignore_prev_rms) {
......@@ -1810,9 +1825,9 @@ public class OrthoMapsCollection implements Serializable{
}
affines_gpu[1]=OrthoMap.combineAffine(affines_gpu[1], orthoPairLMA.getAffine());
jtj = orthoPairLMA.getLastJtJ();
if ((rms <= prev_rms) && ((prev_rms - rms)/prev_rms < rel_improve)) {
if ((rms[0] <= prev_rms[0]) && ((prev_rms[0] - rms[0])/prev_rms[0] < rel_improve)) {
if (debugLevel > -2) {
System.out.println("LMA relative RMSE improvement = "+((prev_rms - rms)/prev_rms)+" < "+rel_improve+", exiting.");
System.out.println("LMA relative RMSE improvement = "+((prev_rms[0] - rms[0])/prev_rms[0])+" < "+rel_improve+", exiting.");
}
if (ignore_prev_rms) {
if (debugLevel > -3) {
......@@ -1849,7 +1864,7 @@ public class OrthoMapsCollection implements Serializable{
}
prev_rms=rms;
prev_rms=rms.clone();
previous_center_radius = last_center_radius;
previous_vf_threshold = vf_threshold;
......@@ -1877,7 +1892,7 @@ public class OrthoMapsCollection implements Serializable{
if (pairwiseOrthoMatch != null) {
pairwiseOrthoMatch.jtj = jtj;
pairwiseOrthoMatch.rms= rms;
pairwiseOrthoMatch.rms= rms[1]; // pure rms
pairwiseOrthoMatch.zoom_lev = zoom_lev;
}
......@@ -4617,6 +4632,10 @@ public class OrthoMapsCollection implements Serializable{
double fill_fraction = clt_parameters.imp.pmtch_cent_fill; // should be populated not less than this
double fill_fraction_final = clt_parameters.imp.pmtch_cent_final; // should be populated not less than this during final pass
double ease_nosfm = clt_parameters.imp.pmtch_ease_nosfm; // ease metric_error when no SfM gain == 0;
double pull_skew = clt_parameters.imp.pmtch_pull_skew; // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt = clt_parameters.imp.pmtch_pull_tilt; // > 0
double pull_scale = clt_parameters.imp.pmtch_pull_scale; // = 0
int min_scene = 0;
GenericJTabbedDialog gd = new GenericJTabbedDialog("Pairwise Match Parameters",1200,1000);
gd.addMessage("Number of scenes - "+num_scenes+
......@@ -4659,6 +4678,9 @@ public class OrthoMapsCollection implements Serializable{
gd.addNumericField("Central area minimal fill", fill_fraction, 3,7,"", "Central area minimal fill for all but the last iteration.");
gd.addNumericField("Central area minimal fill final", fill_fraction_final, 3,7,"", "Central area minimal fill for the last iteration.");
gd.addNumericField("Relax metric error for no-SfM", ease_nosfm, 3,7,"", "Relax metric error for no-SfM scenes (sfm_gain==0).");
gd.addNumericField("Pull skew (rotation)", pull_skew, 3,7,"", "Prevent pairwise match from rotation.");
gd.addNumericField("Pull tilt", pull_tilt, 3,7,"", "Prevent pairwise match from tilt.");
gd.addNumericField("Pull scale", pull_scale, 3,7,"", "Prevent pairwise match from scaling.");
gd.addNumericField("Start scene (skip all earlier)", min_scene, 0,3,"","To be able to continue skipping some.");
//
......@@ -4698,6 +4720,9 @@ public class OrthoMapsCollection implements Serializable{
fill_fraction = gd.getNextNumber();
fill_fraction_final= gd.getNextNumber();
ease_nosfm = gd.getNextNumber();
pull_skew = gd.getNextNumber();
pull_tilt = gd.getNextNumber();
pull_scale = gd.getNextNumber();
min_scene = (int) gd.getNextNumber();
return generatePairwiseMatches(
......@@ -4736,6 +4761,9 @@ public class OrthoMapsCollection implements Serializable{
double_threshold, // double double_threshold,
max_rms_iter, // double [] max_rms_iter,
min_scene, // int min_scene,
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
debugLevel); // int debugLevel
}
......@@ -4777,6 +4805,9 @@ public class OrthoMapsCollection implements Serializable{
double double_threshold,
double [] max_rms_iter,
int min_scene,
double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt, // > 0
double pull_scale, // = 0
int debugLevel) {
boolean batch_mode = true;
......@@ -4924,6 +4955,9 @@ public class OrthoMapsCollection implements Serializable{
ignore_rms, // boolean ignore_rms,
max_rms_iter, // double [] max_rms_iter, // = {1.0, 0.6};//
overlaps[overlap_indx], // double overlap,
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
spiral_debug); // int debugLevel)
if ((pairwiseOrthoMatch == null) || Double.isNaN(pairwiseOrthoMatch.rms)) {
if (delete_failed) {
......@@ -4976,6 +5010,9 @@ public class OrthoMapsCollection implements Serializable{
fill_fraction_final, // double fill_fraction_final,
ease_nosfm, // double ease_nosfm,
null, // double [] max_rms_iter, // = {1.0, 0.6};//
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
debugLevel-4); // final int debugLevel)
boolean failed_refine = Double.isNaN(pairwiseOrthoMatch.rms);
// Create log line and write it
......@@ -5136,6 +5173,11 @@ public class OrthoMapsCollection implements Serializable{
double fill_fraction = clt_parameters.imp.pmtch_cent_fill; // should be populated not less than this
double fill_fraction_final = clt_parameters.imp.pmtch_cent_final; // should be populated not less than this during final pass
double ease_nosfm = clt_parameters.imp.pmtch_ease_nosfm; // ease metric_error when no SfM gain == 0;
double pull_skew = clt_parameters.imp.pmtch_pull_skew; // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt = clt_parameters.imp.pmtch_pull_tilt; // > 0
double pull_scale = clt_parameters.imp.pmtch_pull_scale; // = 0
// double max_rmse_reuse = 0.35;
boolean use_multi = true;
int heur = 15;
......@@ -5186,6 +5228,11 @@ public class OrthoMapsCollection implements Serializable{
gd.addNumericField("Central area minimal fill", fill_fraction, 3,7,"", "Central area minimal fill for all but the last iteration.");
gd.addNumericField("Central area minimal fill final", fill_fraction_final, 3,7,"", "Central area minimal fill for the last iteration.");
gd.addNumericField("Relax metric error for no-SfM", ease_nosfm, 3,7,"", "Relax metric error for no-SfM scenes (sfm_gain==0).");
gd.addNumericField("Pull skew (rotation)", pull_skew, 3,7,"", "Prevent pairwise match from rotation.");
gd.addNumericField("Pull tilt", pull_tilt, 3,7,"", "Prevent pairwise match from tilt.");
gd.addNumericField("Pull scale", pull_scale, 3,7,"", "Prevent pairwise match from scaling.");
gd.addNumericField("Start scene (skip all earlier)", min_scene, 0,3,"","To be able to continue skipping some.");
gd.addNumericField("Heuristics bitmap", heur, 0,3,"","Bitmap of modes to suggest the next pair.");
gd.addCheckbox ("Use multiple threads", use_multi, "Use multipl tghreads (may be disabled in debug mode).");
......@@ -5229,6 +5276,11 @@ public class OrthoMapsCollection implements Serializable{
fill_fraction = gd.getNextNumber();
fill_fraction_final= gd.getNextNumber();
ease_nosfm = gd.getNextNumber();
pull_skew = gd.getNextNumber();
pull_tilt = gd.getNextNumber();
pull_scale = gd.getNextNumber();
min_scene = (int) gd.getNextNumber();
heur = (int) gd.getNextNumber();
use_multi = gd.getNextBoolean();
......@@ -5324,6 +5376,9 @@ public class OrthoMapsCollection implements Serializable{
double_threshold, // double double_threshold,
max_rms_iter, // double [] max_rms_iter,
min_scene, // int min_scene,
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
debugLevel); // int debugLevel
}
}
......@@ -5368,6 +5423,9 @@ public class OrthoMapsCollection implements Serializable{
double double_threshold,
double [] max_rms_iter,
int min_scene,
double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt, // > 0
double pull_scale, // = 0
int debugLevel) {
int [] indices = pairsGraph.getIndices();
boolean batch_mode = true;
......@@ -5469,6 +5527,9 @@ public class OrthoMapsCollection implements Serializable{
ignore_rms, // boolean ignore_rms,
max_rms_iter, // double [] max_rms_iter, // = {1.0, 0.6};//
overlap_frac, // double overlap, // OR IS IT overlap_frac_mod ?
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
spiral_debug); // int debugLevel)
Point pair = new Point(next_pair[0],next_pair[1]);
boolean success = (pairwiseOrthoMatch != null) && !Double.isNaN(pairwiseOrthoMatch.rms);
......@@ -5520,6 +5581,9 @@ public class OrthoMapsCollection implements Serializable{
fill_fraction_final, // double fill_fraction_final,
ease_nosfm, // double ease_nosfm,
null, // double [] max_rms_iter, // = {1.0, 0.6};//
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale, // double pull_scale, // = 0
debugLevel-4); // final int debugLevel)
boolean failed_refine = Double.isNaN(pairwiseOrthoMatch.rms) || (pairwiseOrthoMatch.rms > max_rms_refine);
// Create log line and write it
......
......@@ -40,6 +40,7 @@ import Jama.Matrix;
public class OrthoPairLMA {
private boolean thread_invariant= true;
private int N = 0; // number of tiles in WOI: woi.width * woi.height
private double [][] aff = null; // source affine transform to be combined with the LMA-adjusted
private Rectangle woi = null; // in tiles
private int width;
private double [] last_rms = null; // {rms, rms_pure}, matching this.vector
......@@ -50,6 +51,7 @@ public class OrthoPairLMA {
private double [] y_vector = null;
private double [][] tile_centers = null;
private double weight = 0; // total weight
private double weight_pure = 0;
private double [] weights; // normalized so sum is 1.0 for all - samples and extra regularization
// private double pure_weight; // weight of samples only
private double [] last_ymfx = null;
......@@ -58,6 +60,7 @@ public class OrthoPairLMA {
private double [] origin = null; // in pixels either {0,0} for top-left or center of the woi
private double center_radius = 0; // center zone radius (in tiles) that has limited standard deviation
public int num_good_tiles = 0;
public boolean last3only = true;
public OrthoPairLMA (boolean origin_center) {
this.origin_center = origin_center;
}
......@@ -108,7 +111,14 @@ public class OrthoPairLMA {
double min_std_rad, // minimal radius of the central area (if less - fail)
double tile_rad,
int min_tiles_rad,
double [][] src_affine,
double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
double pull_tilt, // > 0
double pull_scale, // = 0
final int debug_level) {
aff = new double [][] {src_affine[0].clone(),src_affine[1].clone()};
tile_centers = centers;
this.width = width;
int height = vector_XYS.length / width;
......@@ -157,7 +167,11 @@ public class OrthoPairLMA {
setSamplesWeightsYCenters(
vector_XYS,
weights_extra, // null or additional weights (such as elevation-based)
centers);
centers,
pull_skew, // double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
pull_tilt, // double pull_tilt, // > 0
pull_scale); // double pull_scale);, // = 0
last_jt = new double [parameters_vector.length][];
if (debug_level > 1) {
System.out.println("prepareLMA() 1");
......@@ -177,14 +191,14 @@ public class OrthoPairLMA {
affine[1][2] -= affine[1][0]*origin[0] + (affine[1][1] - 1) * origin[1];
return affine;
}
public double getRms() {
return last_rms[0];
public double [] getRms() {
return last_rms;
}
public double getInitialRms() {
return initial_rms[0];
public double [] getInitialRms() {
return initial_rms;
}
public double getWeight() {
public double getWeight() { // no used
return weight;
}
public double [][] getLastJtJ(){
......@@ -437,11 +451,13 @@ public class OrthoPairLMA {
private void setSamplesWeightsYCenters(
final double [][] vector_XYS,
final double [] weights_extra, // null or additional weights (such as elevation-based)
final double [][] centers)
{
final double [][] centers,
final double pull_skew, // ~rotation, = 0 fraction of the total weight == 1
final double pull_tilt, // > 0
final double pull_scale){ // = 0
//num_components 2 - old, 3 - with disparity
this.weights = new double [2*N]; // same for X and Y
y_vector = new double[2*N];
this.weights = new double [2*N+3]; // same for X and Y
y_vector = new double[2*N+3];
tile_centers = new double [N][];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
......@@ -479,9 +495,15 @@ public class OrthoPairLMA {
if (weight <= 1E-8) {
System.out.println("!!!!!! setSamplesWeights(): sum_weights="+weight+" <= 1E-8");
}
ai.set(0);
final double s = 1.0/weight; // Was 0.5 - already taken care of
double sum_pure = pull_skew + pull_tilt + pull_scale;
double scale_pure = 1.0;
if (sum_pure > 1.0) {
System.out.println("sum_pure="+sum_pure+" > 1.0, reducing each component to make it 0.5");
scale_pure = 0.5/sum_pure;
}
weight_pure = 1.0 - scale_pure * sum_pure;
final double s = weight_pure/weight; // Was 0.5 - already taken care of
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
......@@ -493,6 +515,9 @@ public class OrthoPairLMA {
};
}
ImageDtt.startAndJoin(threads);
weights[2 * N + 0] = pull_skew * scale_pure;
weights[2 * N + 1] = pull_tilt * scale_pure;
weights[2 * N + 2] = pull_scale * scale_pure;
}
public int runLma( // <0 - failed, >=0 iteration number (1 - immediately)
......@@ -614,6 +639,13 @@ public class OrthoPairLMA {
}
// TODO: Restore/implement
if (debug_level > 3) {
double delta = 1E-5;
double delta_err=compareJT(
parameters_vector, // double [] vector,
delta, // double delta,
last3only); // boolean last3only); // do not process samples - they are tested before
System.out.println("\nMaximal error = "+delta_err);
/*
dbgJacobians(
corr_vector, // GeometryCorrection.CorrVector corr_vector,
......@@ -622,6 +654,22 @@ public class OrthoPairLMA {
*/
}
}
if (debug_level > 0) {
double delta = 1E-5;
double delta_err=compareJT(
parameters_vector, // double [] vector,
delta, // double delta,
last3only); // boolean last3only); // do not process samples - they are tested before
System.out.println("\nMaximal error = "+delta_err);
/*
dbgJacobians(
corr_vector, // GeometryCorrection.CorrVector corr_vector,
1E-5, // double delta,
true); //boolean graphic)
*/
}
Matrix y_minus_fx_weighted = new Matrix(this.last_ymfx, this.last_ymfx.length);
Matrix wjtjlambda = new Matrix(getWJtJlambda(
......@@ -813,9 +861,63 @@ public class OrthoPairLMA {
};
}
ImageDtt.startAndJoin(threads);
double [][] A = {
{vector[0]*aff[0][0] + vector[1]*aff[1][0], vector[0]*aff[0][1] + vector[1]*aff[1][1]},
{vector[2]*aff[0][0] + vector[3]*aff[1][0], vector[2]*aff[0][1] + vector[3]*aff[1][1]}};
double aa0 = A[0][0]*A[0][1]+A[1][0]*A[1][1];
double aa1 = 0.5*(A[0][0]*A[0][0] + A[1][0]*A[1][0]);
double aa2 = 0.5*(A[0][1]*A[0][1] + A[1][1]*A[1][1]);
fx[2 * N + 0] = 1000*aa0;
fx[2 * N + 1] = 1000*(aa1-aa2);
fx[2 * N + 2] = 1000*(aa1+aa2-1.0);
if (jt != null) {
double [][][] dA_dp = {
{{aff[0][0], aff[0][1]},{ 0, 0}},
{{aff[1][0], aff[1][1]},{ 0, 0}},
{{ 0, 0},{aff[0][0], aff[0][1]}},
{{ 0, 0},{aff[1][0], aff[1][1]}}};
double [] daa0_dp = new double[4];
double [] daa1_dp = new double[4];
double [] daa2_dp = new double[4];
for (int i = 0; i <4; i++) {
daa0_dp[i] = (dA_dp[i][0][0]*A[0][1] + A[0][0]*dA_dp[i][0][1]) + (dA_dp[i][1][0]*A[1][1]+A[1][0]*dA_dp[i][1][1]);
daa1_dp[i] = (dA_dp[i][0][0]*A[0][0]) + (dA_dp[i][1][0]*A[1][0]);
daa2_dp[i] = (dA_dp[i][0][1]*A[0][1]) + (dA_dp[i][1][1]*A[1][1]);
jt[i][2 * N + 0] = 1000*(daa0_dp[i]);
jt[i][2 * N + 1] = 1000*(daa1_dp[i]-daa2_dp[i]);
jt[i][2 * N + 2] = 1000*(daa1_dp[i]+daa2_dp[i]);
}
}
return fx;
}
private double [][] getFxDerivsDelta(
double [] vector,
final double delta,
final int debug_level) {
double [][] jt = new double [vector.length][weights.length];
for (int nv = 0; nv < vector.length; nv++) {
double [] vpm = vector.clone();
vpm[nv]+= 0.5*delta;
double [] fx_p = getFxDerivs(
vpm,
null, // final double [][] jt, // should be null or initialized with [vector.length][]
debug_level);
vpm[nv]-= delta;
double [] fx_m = getFxDerivs(
vpm,
null, // final double [][] jt, // should be null or initialized with [vector.length][]
debug_level);
for (int i = 0; i < weights.length; i++) if (weights[i] > 0) {
jt[nv][i] = (fx_p[i]-fx_m[i])/delta;
}
}
return jt;
}
private double [] getYminusFxWeighted(
final double [] fx,
final double [] rms_fp // null or [2]
......@@ -859,9 +961,18 @@ public class OrthoPairLMA {
for (double l2:l2_arr) {
s_rms += l2;
}
double rms = Math.sqrt(s_rms); // assuming sum_weights == 1.0; /pure_weight); shey should be re-normalized after adding regularization
double rms_pure = Math.sqrt(s_rms/weight_pure);
for (int i = num_samples; i < fx.length; i++) {
double d = y_vector[i] - fx[i];
double wd = d * weights[i];
wymfw[i] = wd;
s_rms += d * wd;
// num_samples
}
double rms = Math.sqrt(s_rms); // assuming sum_weights == 1.0; /pure_weight); they should be re-normalized after adding regularization
if (rms_fp != null) {
rms_fp[0] = rms;
rms_fp[1] = rms_pure;
}
return wymfw;
}
......@@ -898,13 +1009,83 @@ public class OrthoPairLMA {
for (double l2:l2_arr) {
s_rms += l2;
}
double rms = Math.sqrt(s_rms); // assuming sum_weights == 1.0; /pure_weight); shey should be re-normalized after adding regularization
double rms_pure = Math.sqrt(s_rms/weight_pure);
for (int i = num_samples; i < fx.length; i++) {
double d = y_vector[i] - fx[i];
double wd = d * weights[i];
wymfw[i] = wd;
s_rms += d * wd;
}
double rms = Math.sqrt(s_rms); // assuming sum_weights == 1.0; /pure_weight); they should be re-normalized after adding regularization
if (rms_fp != null) {
rms_fp[0] = rms;
rms_fp[1] = rms_pure;
}
return wymfw;
}
private double compareJT(
double [] vector,
double delta,
boolean last3only) { // do not process samples - they are tested before
double [] errors=new double [vector.length];
double [][] jt = new double [vector.length][];
System.out.print("Parameters vector = [");
for (int i = 0; i < vector.length; i++) {
System.out.print(vector[i]);
if (i < (vector.length -1)) System.out.print(", ");
}
System.out.println("]");
getFxDerivs(
vector,
jt, // final double [][] jt, // should be null or initialized with [vector.length][]
1); // debug_level);
double [][] jt_delta = getFxDerivsDelta(
vector, // double [] vector,
delta, // final double delta,
-1); // final int debug_level)
int start_index = last3only? (weights.length-3) : 0;
for (int n = start_index; n < weights.length; n++) if (weights[n] > 0) {
System.out.print(String.format("%3d",n));
for (int i = 0; i < vector.length; i++) {
System.out.print(String.format("\t%12.9f",jt[i][n]));
}
for (int i = 0; i < vector.length; i++) {
System.out.print(String.format("\t%12.9f",jt_delta[i][n]));
}
for (int i = 0; i < vector.length; i++) {
System.out.print(String.format("\t%12.9f",jt[i][n]-jt_delta[i][n]));
}
System.out.println();
/*
System.out.println(String.format(
"%3d\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f\t%12.9f",
n, jt[0][n], jt[1][n], jt[2][n], jt[3][n],
jt_delta[0][n], jt_delta[1][n], jt_delta[2][n], jt_delta[3][n],
jt[0][n]-jt_delta[0][n],jt[1][n]-jt_delta[1][n],jt[2][n]-jt_delta[2][n],jt[3][n]-jt_delta[3][n]));
*/
for (int i = 0; i < vector.length; i++) {
errors[i] = Math.max(errors[i], jt[i][n]-jt_delta[i][n]);
}
}
for (int i = 0; i < vector.length; i++) {
System.out.print("\t\t");
}
for (int i = 0; i < vector.length; i++) {
System.out.print(String.format("\t%12.9f",errors[i]));
}
/*
System.out.println(String.format(
"-\t-\t-\t-\t-\t-\t-\t-\t-\t%12.9f\t%12.9f\t%12.9f\t%12.9f",
errors[0], errors[1], errors[2], errors[3]));
*/
double err=0;
for (int i = 0; i < vector.length; i++) {
err = Math.max(errors[i], err);
}
return err;
}
}
......@@ -120,6 +120,10 @@ public class IntersceneMatchParameters {
public boolean pmtch_ignore_rms = true;
public int pmtch_num_iter = 10;
public double pmtch_pull_skew = 0.0; // ~rotation, = 0 fraction of the total weight == 1
public double pmtch_pull_tilt = 0.1; // > 0
public double pmtch_pull_scale = 0.0; // = 0
public double pmtch_cent_rad = 0.6; // center circle radius fraction of 0.5* min(width, height) in tiles
public double pmtch_max_cent_rad =40; // 30; // maximal center radius in tiles (limit pmtch_cent_rad)
public double pmtch_cent_fill = 0.2; // 25; // should be populated not less than this
......@@ -782,6 +786,11 @@ public class IntersceneMatchParameters {
gd.addNumericField("Central area minimal radius", this.pmtch_min_std_rad, 3,7,"tile", "Minimal radius of the central area after all LMA passes.");
gd.addCheckbox ("Ignore previous RMSE", this.pmtch_ignore_rms, "Do not exit full fitting cycles if the RMSE worsened/not improved.");
gd.addNumericField("Number of fitting iterations", this.pmtch_num_iter, 0,3,"","number of full fittng iterations.");
gd.addNumericField("Pull skew (rotation)", this.pmtch_pull_skew, 3,7,"", "Prevent pairwise match from rotation.");
gd.addNumericField("Pull tilt", this.pmtch_pull_tilt, 3,7,"", "Prevent pairwise match from tilt.");
gd.addNumericField("Pull scale", this.pmtch_pull_scale, 3,7,"", "Prevent pairwise match from scaling.");
gd.addNumericField("Central area radius as fraction", this.pmtch_cent_rad, 3,7,"", "Central area radius as fraction of half minimal WOI dimension.");
gd.addNumericField("Maximal central area radius", this.pmtch_max_cent_rad, 3,7,"tiles", "Absolute limit to the center area radius (eases bad peripheral matching).");
gd.addNumericField("Central area minimal fill", this.pmtch_cent_fill, 3,7,"", "Central area minimal fill for all but the last iteration.");
......@@ -1701,6 +1710,11 @@ public class IntersceneMatchParameters {
this.pmtch_min_std_rad = gd.getNextNumber();
this.pmtch_ignore_rms = gd.getNextBoolean();
this.pmtch_num_iter = (int) gd.getNextNumber();
this.pmtch_pull_skew = gd.getNextNumber();
this.pmtch_pull_tilt = gd.getNextNumber();
this.pmtch_pull_scale = gd.getNextNumber();
this.pmtch_cent_rad = gd.getNextNumber();
this.pmtch_max_cent_rad = gd.getNextNumber();
this.pmtch_cent_fill = gd.getNextNumber();
......@@ -2229,6 +2243,11 @@ public class IntersceneMatchParameters {
properties.setProperty(prefix+"pmtch_min_std_rad", this.pmtch_min_std_rad +""); // double
properties.setProperty(prefix+"pmtch_ignore_rms", this.pmtch_ignore_rms +""); // boolean
properties.setProperty(prefix+"pmtch_num_iter", this.pmtch_num_iter +""); // int
properties.setProperty(prefix+"pmtch_pull_skew", this.pmtch_pull_skew + ""); // double
properties.setProperty(prefix+"pmtch_pull_tilt", this.pmtch_pull_tilt + ""); // double
properties.setProperty(prefix+"pmtch_pull_scale", this.pmtch_pull_scale + ""); // double
properties.setProperty(prefix+"pmtch_cent_rad", this.pmtch_cent_rad + ""); // double
properties.setProperty(prefix+"pmtch_max_cent_rad", this.pmtch_max_cent_rad + ""); // double
properties.setProperty(prefix+"pmtch_cent_fill", this.pmtch_cent_fill + ""); // double
......@@ -2723,6 +2742,11 @@ public class IntersceneMatchParameters {
if (properties.getProperty(prefix+"pmtch_min_std_rad")!=null) this.pmtch_min_std_rad=Double.parseDouble(properties.getProperty(prefix+ "pmtch_min_std_rad"));
if (properties.getProperty(prefix+"pmtch_ignore_rms")!=null) this.pmtch_ignore_rms= Boolean.parseBoolean(properties.getProperty(prefix+"pmtch_ignore_rms"));
if (properties.getProperty(prefix+"pmtch_num_iter")!=null) this.pmtch_num_iter= Integer.parseInt(properties.getProperty(prefix+ "pmtch_num_iter"));
if (properties.getProperty(prefix+"pmtch_pull_skew")!=null) this.pmtch_pull_skew= Double.parseDouble(properties.getProperty(prefix+ "pmtch_pull_skew"));
if (properties.getProperty(prefix+"pmtch_pull_tilt")!=null) this.pmtch_pull_tilt= Double.parseDouble(properties.getProperty(prefix+ "pmtch_pull_tilt"));
if (properties.getProperty(prefix+"pmtch_pull_scale")!=null) this.pmtch_pull_scale= Double.parseDouble(properties.getProperty(prefix+ "pmtch_pull_scale"));
if (properties.getProperty(prefix+"pmtch_cent_rad" )!=null) this.pmtch_cent_rad= Double.parseDouble(properties.getProperty(prefix+ "pmtch_cent_rad"));
if (properties.getProperty(prefix+"pmtch_max_cent_rad")!=null) this.pmtch_max_cent_rad=Double.parseDouble(properties.getProperty(prefix+ "pmtch_max_cent_rad"));
if (properties.getProperty(prefix+"pmtch_cent_fill" )!=null) this.pmtch_cent_fill= Double.parseDouble(properties.getProperty(prefix+ "pmtch_cent_fill"));
......@@ -3243,6 +3267,9 @@ public class IntersceneMatchParameters {
imp.pmtch_min_std_rad = this.pmtch_min_std_rad;
imp.pmtch_ignore_rms = this.pmtch_ignore_rms;
imp.pmtch_num_iter = this.pmtch_num_iter;
imp.pmtch_pull_skew = this.pmtch_pull_skew;
imp.pmtch_pull_tilt = this.pmtch_pull_tilt;
imp.pmtch_pull_scale = this.pmtch_pull_scale;
imp.pmtch_cent_rad = this.pmtch_cent_rad;
imp.pmtch_max_cent_rad = this.pmtch_max_cent_rad;
imp.pmtch_cent_fill = this.pmtch_cent_fill;
......
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