Commit 1cc8ef8f authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Implemented configurable parameters for global matching of affines and

intensities.
parent 75c570c2
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -154,16 +154,12 @@ public class ComboMatch {
		int gpu_width=  clt_parameters.imp.rln_gpu_width; // 3008;
		int gpu_height= clt_parameters.imp.rln_gpu_height; // 3008;
		int zoom_lev = -3; // 0; // +1 - zoom in twice, -1 - zoom out twice
//		boolean show_map_stats =      false;      
		boolean show_combo =          false; // true;
		boolean create_overlaps =     false;
		boolean equalize_overlaps =   false;
		boolean create_map =          false;
		boolean create_equalize =     false;
		
//		boolean show_combo_mask =     false; // generate image mas (where it is defined)_
//		boolean use_alt =             false;
//		boolean show_centers =        true;
		boolean use_saved_collection = true; // false;
		boolean save_collection =     true;
		boolean process_correlation = true; // use false to save new version of data
@@ -780,19 +776,19 @@ public class ComboMatch {
    	}

		if (create_map) {
			OrthoMultiLMA.buildOrthoMap(
			int ok = OrthoMultiLMA.buildOrthoMap(
					clt_parameters,            // CLTParameters       clt_parameters,
					maps_collection, // OrthoMapsCollection maps_collection
					orthoMapsCollection_savepath); // String orthoMapsCollection_path
			return true;
			return (ok >= 0);
		}

		if (create_equalize) {
			OrthoEqualizeLMA.buildEqualize(
			int ok = OrthoEqualizeLMA.buildEqualize(
					clt_parameters,            // CLTParameters       clt_parameters,
					maps_collection, // OrthoMapsCollection maps_collection
					orthoMapsCollection_savepath); // String orthoMapsCollection_path
			return true;
			return (ok >= 0);
		}
		
		if (create_overlaps) {
+77 −18
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.tileprocessor.ImageDtt;

import Jama.Matrix;
@@ -51,30 +52,88 @@ public class OrthoEqualizeLMA {
	private int [][]          pairs =           null;
	private int [][]          pairs_ni =        null; // non-intersecting pairs for multi-threaded processing
	private int []            indices =         null;
//	private double [][]       offsets =         null; // scene offsets (rd)
	private int               num_scenes =      0;
	private int               num_pairs =       0;
	
	public static int buildEqualize(
			CLTParameters       clt_parameters,
			OrthoMapsCollection maps_collection,
			String              orthoMapsCollection_path
			) {
		int     debugLevel =        2;
        boolean use_inv =         false;
		double  scale_weight =    500;     // relative weight of scale differences compared to offset differences
		double  pull_weight =       0.001; // relative weight of offsets and scales differences from 1.0 to pairs mismatch
		double  half_weight_sec = 300.0;   //  - time difference to reduce weight twice
		double  min_weight_sec =    0.01;  //  weight of pairs at very different time
        double  overlap_pow = 2.0; // match weight as overlap fraction to this power
		double rms_diff =          0.000001;
		int    num_iter =        100;    //  50;
			String              orthoMapsCollection_path) {
		boolean ignore_equalize=  clt_parameters.imp.pequ_ignore_equalize; // false; // ignore previous equalization
        boolean use_inv =         clt_parameters.imp.pequ_use_inv;         // false;
		double  scale_weight =    clt_parameters.imp.pequ_scale_weight;    // 500;     // relative weight of scale differences compared to offset differences
		double  pull_weight =     clt_parameters.imp.pequ_pull_weight;     // 0.001; // relative weight of offsets and scales differences from 1.0 to pairs mismatch
		double  half_weight_sec = clt_parameters.imp.pequ_half_weight_sec; // 300.0;   //  - time difference to reduce weight twice
		double  min_weight_sec =  clt_parameters.imp.pequ_min_weight_sec;  // 0.01;  //  weight of pairs at very different time
        double  overlap_pow =     clt_parameters.imp.pequ_overlap_pow;     // 2.0; // match weight as overlap fraction to this power
		double  rms_diff =        clt_parameters.imp.pequ_rms_diff;        // 0.000001;
		int     num_iter =        clt_parameters.imp.pequ_num_iter;        // 100;    //  50;
		int     debugLevel =      clt_parameters.imp.pequ_debugLevel;      // 2;
		
		GenericJTabbedDialog gd = new GenericJTabbedDialog("Pairwise Match Parameters",1200,400);        
		gd.addCheckbox    ("Ignore existing equalization",ignore_equalize, "Ignore existing equalization, start from scratch (a=1, b=0).");
		gd.addCheckbox    ("Use reversed pairs",          use_inv,     "Use reversed (late-early timestamps) pairs.");
		gd.addNumericField("Relative scale weight",       scale_weight,  3,7,"",	"Importance of a-coefficient (scale) relative to b-coefficient (offset).");
		gd.addNumericField("Pull weight",                 pull_weight,  3,7,"",	"Relative weight of offsets and scales differences from 1.0 to pairs mismatch.");
		gd.addNumericField("Half-weight time difference", half_weight_sec,  3,7,"s",	"Time difference (in a pair) to reduce weight twice.");
		gd.addNumericField("Weight for large time offset",min_weight_sec,  3,7,"",	"Weight of pairs at very different time.");
		gd.addNumericField("Overlap inportance",          overlap_pow,  3,7,"",	"Raise overlap fraction (of the smaller image) to this power before using as weight.");
		gd.addNumericField("RMSE relative improvement",   rms_diff,     8,10,"",	"Relative RMSE improvement to exit LMA.");
		gd.addNumericField("LMA iterations",              num_iter, 0,3,"",".Maximal number of the LMA iterations.");
		gd.addNumericField("Debug level for equalization",debugLevel, 0,3,"","Debug level for global (LMA-based) intensity equalization.");
 		gd.showDialog();
		if (gd.wasCanceled()) return -1;
        
        ignore_equalize =           gd.getNextBoolean();
        use_inv =                   gd.getNextBoolean();
        scale_weight =              gd.getNextNumber();
        pull_weight =               gd.getNextNumber();
        half_weight_sec =           gd.getNextNumber();
        min_weight_sec =            gd.getNextNumber();
        overlap_pow =               gd.getNextNumber();
        rms_diff =                  gd.getNextNumber();
        num_iter =            (int) gd.getNextNumber();
        debugLevel =          (int) gd.getNextNumber();
		
		return buildEqualize(
				clt_parameters,           // CLTParameters       clt_parameters,
				maps_collection,          // OrthoMapsCollection maps_collection,
				orthoMapsCollection_path, // String              orthoMapsCollection_path,
				ignore_equalize,          // boolean ignore_equalize,
				use_inv,                  // boolean use_inv,
				scale_weight,             // double  scale_weight,
				pull_weight,              // double  pull_weight,
				half_weight_sec,          // double  half_weight_sec,
				min_weight_sec,           // double  min_weight_sec,
				overlap_pow,              // double  overlap_pow,
				rms_diff,                 // double  rms_diff,
				num_iter,                 // int     num_iter,
				debugLevel);              // int     debugLevel);
	}
		
		
	public static int buildEqualize(
			CLTParameters       clt_parameters,
			OrthoMapsCollection maps_collection,
			String              orthoMapsCollection_path,
			boolean ignore_equalize,
			boolean use_inv,
			double  scale_weight,
			double  pull_weight,
			double  half_weight_sec,
			double  min_weight_sec,
			double  overlap_pow,
			double  rms_diff,
			int     num_iter,
			int     debugLevel) {

		double  lambda =            0.1;
		double  lambda_scale_good = 0.5;
		double  lambda_scale_bad =  8.0;
		double  lambda_max =      100;
		boolean last_run =       false;
		boolean ignore_equalization=false; // ignore previous equalization


		int [] indices = maps_collection.getScenesSelection(
				null, // boolean select_all,
				" to build a map"); // String purpose)
@@ -83,7 +142,7 @@ public class OrthoEqualizeLMA {
				clt_parameters, // CLTParameters       clt_parameters,
				maps_collection, // OrthoMapsCollection maps_collection,
				indices, // int []              indices,
				ignore_equalization, // boolean             ignore_equalization, // ignore previous equalization
				ignore_equalize, // boolean             ignore_equalization, // ignore previous equalization
						// scale_weights applies both to pairs mismatch and per-scene values difference from neutral {1.0, 0.0}
				scale_weight,    // double              scale_weight,    // relative weight of scale differences compared to offset differences  
				pull_weight,     // double              pull_weight,     // relative weight of offsets and scales differences from 1.0 to pairs mismatch
+10 −2
Original line number Diff line number Diff line
@@ -4453,7 +4453,7 @@ 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;
		
		int min_scene =              0;
		GenericJTabbedDialog gd = new GenericJTabbedDialog("Pairwise Match Parameters",1200,1000);
		gd.addMessage("Number of scenes - "+num_scenes+
				", number of pairs (w/o inverse) - "+num_pairs+
@@ -4495,7 +4495,8 @@ 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("Start scene (skip all earlier)",   min_scene, 0,3,"","To be able to continue skipping some.");
		//
		
		gd.showDialog();
		if (gd.wasCanceled()) return false;
@@ -4533,6 +4534,7 @@ public class OrthoMapsCollection implements Serializable{
		fill_fraction =          gd.getNextNumber();  
		fill_fraction_final=     gd.getNextNumber();   
		ease_nosfm =             gd.getNextNumber();
		min_scene =        (int) gd.getNextNumber();
		
		return generatePairwiseMatches(
				clt_parameters,           // CLTParameters clt_parameters,
@@ -4569,6 +4571,7 @@ public class OrthoMapsCollection implements Serializable{
				ease_nosfm,               // double        ease_nosfm,
				double_threshold,         // double        double_threshold,
				max_rms_iter,             // double []     max_rms_iter,
				min_scene,                // int           min_scene,
				debugLevel);              // int          debugLevel
	}
	
@@ -4609,6 +4612,7 @@ public class OrthoMapsCollection implements Serializable{
			double        ease_nosfm,
			double        double_threshold,
			double []     max_rms_iter,
			int           min_scene,
			int           debugLevel) {
		
		boolean batch_mode = true;
@@ -4653,6 +4657,10 @@ public class OrthoMapsCollection implements Serializable{
		ArrayList<Point> new_pairs =    new ArrayList<Point>(); // started from spiral, not from the same or inverse
		for (Point pair:pairs) {
			int [] ipair = {indices[pair.x], indices[pair.y]};
			if (ipair[0] < min_scene) {
				System.out.println ("Skipping "+ipair[0]+":"+ipair[1]+" until "+min_scene);
				continue;
			}
			boolean direct = indices[pair.x] < indices[pair.y];
	    	int min_zoom_lev = ortho_maps[ipair[0]].getOriginalZoomLevel();
	    	int max_zoom_lev = ortho_maps[ipair[0]].getOriginalZoomLevel();
+78 −13
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;

import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.tileprocessor.ImageDtt;

@@ -217,18 +218,84 @@ public class OrthoMultiLMA {
			OrthoMapsCollection maps_collection,
			String              orthoMapsCollection_path
			) {
		int                 debugLevel =         2;
		boolean             move_only =      false;
		boolean move_only =      clt_parameters.imp.pmap_move_only;      // false;
		boolean ignore_affines = clt_parameters.imp.pmap_ignore_affines; // false;
        boolean use_inv =        clt_parameters.imp.pmap_use_inv;        // false;
        double  skew_pull =      clt_parameters.imp.pmap_skew_pull;      // 1.0;
        double  tilt_pull =      clt_parameters.imp.pmap_tilt_pull;      // 1.0;
        double  scale_pull =     clt_parameters.imp.pmap_scale_pull;     // 0.1; // .0;
		double  position_pull =  clt_parameters.imp.pmap_position_pull;  // 0.0001;
        double  overlap_pow =    clt_parameters.imp.pmap_overlap_pow;    // 2.0; // match weight as overlap fraction to this power
		double  rms_diff =       clt_parameters.imp.pmap_rms_diff;       // 0.000001;
		int     num_iter =       clt_parameters.imp.pmap_num_iter;       // 100; //  50;
		boolean show_result =    clt_parameters.imp.pmap_show_result;    // false;
		int     debugLevel =     clt_parameters.imp.pmap_debugLevel;     // 2;

		GenericJTabbedDialog gd = new GenericJTabbedDialog("Pairwise Match Parameters",1200,400);
		gd.addCheckbox    ("Moves only",               move_only,  "Moves only, no affine transform.");
		gd.addCheckbox    ("Ignore existing affines",  ignore_affines, "Start from unity matrices, ignore saved affines.");
		gd.addCheckbox    ("Use reversed pairs",       use_inv,     "Use reversed (late-early timestamps) pairs.");
		gd.addNumericField("Skew pull",                skew_pull,    7,10,"",	"Intention to have axes perpendicular.");
		gd.addNumericField("Tilt pull",                tilt_pull,    7,10,"",	"Intention to have axes same length.");
		gd.addNumericField("Scale pull",               scale_pull,   7,10,"",	"Intention to have average scale of images = 1.0.");
		gd.addNumericField("Position pull",            position_pull,7,10,"",	"Intension to match IMS (GNSS) coordinates.");
		gd.addNumericField("Overlap inportance",       overlap_pow,  3,7,"",	"Raise overlap fraction (of the smaller image) to this power before using as weight.");
		gd.addNumericField("RMSE relative improvement",rms_diff,     8,10,"",	"Relative RMSE improvement to exit LMA.");
		gd.addNumericField("LMA iterations",           num_iter, 0,3,"",".Maximal number of the LMA iterations.");
		gd.addCheckbox    ("Show result image",        show_result, ".");
		gd.addNumericField("Debug level for maps",     debugLevel, 0,3,"","Debug building for LMA building maps.");

 		gd.showDialog();
		if (gd.wasCanceled()) return -1;

        move_only =		      gd.getNextBoolean();
        ignore_affines =      gd.getNextBoolean();
        use_inv =             gd.getNextBoolean();
        skew_pull =           gd.getNextNumber();
        tilt_pull =           gd.getNextNumber();
        scale_pull =          gd.getNextNumber();
        position_pull =       gd.getNextNumber();
        overlap_pow =         gd.getNextNumber();
        rms_diff =            gd.getNextNumber();
        num_iter =      (int) gd.getNextNumber();
        show_result =         gd.getNextBoolean();
        debugLevel =    (int) gd.getNextNumber();
		
		return buildOrthoMap(
				clt_parameters,           // CLTParameters       clt_parameters,
				maps_collection,          // OrthoMapsCollection maps_collection,
				orthoMapsCollection_path, // String              orthoMapsCollection_path,
				move_only,                // boolean             move_only,
				ignore_affines,           // boolean             ignore_affines,
				use_inv,                  // boolean             use_inv,
				skew_pull,                // double              skew_pull,
				tilt_pull,                // double              tilt_pull,
				scale_pull,               // double              scale_pull,
				position_pull,            // double              position_pull,
				overlap_pow,              // double              overlap_pow,
				rms_diff,                 // double              rms_diff,
				num_iter,                 // int                 num_iter,
				show_result,              // boolean             show_result,
				debugLevel);              // int                 debugLevel)		
	}		
		public static int buildOrthoMap(
				CLTParameters       clt_parameters,
				OrthoMapsCollection maps_collection,
				String              orthoMapsCollection_path,
				boolean             move_only,
				boolean             ignore_affines,
		        boolean             use_inv,
		        double              skew_pull,
		        double              tilt_pull,
		        double              scale_pull,
				double              position_pull,
		        double              overlap_pow,
				double              rms_diff,
				int                 num_iter,
				boolean             show_result,
				int                 debugLevel) {
		double []           val_coord =      null; // 1 - valid, 0 - invalid, minimize coordinates errors
		boolean             ignore_affines = false;
        boolean             use_inv =        false;
        double              overlap_pow =    2.0; // match weight as overlap fraction to this power
        double              skew_pull =      1.0;
        double              tilt_pull =      1.0;
        double              scale_pull =     0.1; // .0;
		double              position_pull =  0.0001;
		boolean             corr_avg= (skew_pull > 0) || (tilt_pull > 0) || (scale_pull > 0);
		boolean             show_result_image = false;
		int [] indices = maps_collection.getScenesSelection(
				null, // boolean select_all,
				" to build a map"); // String purpose)
@@ -239,8 +306,6 @@ public class OrthoMultiLMA {
		double lambda_scale_good = 0.5;
		double lambda_scale_bad =  8.0;
		double lambda_max =      100;
		double rms_diff =          0.000001;
		int    num_iter =        100; //  50;
		boolean last_run =       false;
		oml.prepareLMA (
				clt_parameters,   // CLTParameters       clt_parameters,
@@ -274,7 +339,7 @@ public class OrthoMultiLMA {
        
        //Get and apply affines
        oml.updateAffines(maps_collection);
        if (show_result_image) {
        if (show_result) {
        	double [][][] affines = oml.getAffines();
        	double [] fx = oml.getFx();

Loading