Commit ef473c40 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

matched interscene pair

parent 468688b4
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import com.elphel.imagej.lwir.LwirReaderParameters;
import com.elphel.imagej.tileprocessor.BiQuadParameters;
import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.ImageDttParameters;
import com.elphel.imagej.tileprocessor.IntersceneLmaParameters;
import com.elphel.imagej.tileprocessor.MeasuredLayersFilterParameters;
import com.elphel.imagej.tileprocessor.OpticalFlowParameters;
import com.elphel.imagej.tileprocessor.PoleProcessorParameters;
@@ -871,6 +872,7 @@ public class CLTParameters {
	public MeasuredLayersFilterParameters mlfp =    new MeasuredLayersFilterParameters();
	public LwirReaderParameters           lwir =    new LwirReaderParameters();
	public OpticalFlowParameters          ofp =     new OpticalFlowParameters();
	public IntersceneLmaParameters        ilp =     new IntersceneLmaParameters();


	public HashMap<String,Double> z_corr_map = new HashMap<String,Double>(); //old one
@@ -1718,6 +1720,7 @@ public class CLTParameters {
		poles.setProperties   (prefix+"_poles",   properties);
		lwir.setProperties    (prefix+"_lwir",    properties);
		ofp.setProperties     (prefix+"_ofp_",    properties);
		ilp.setProperties     (prefix+"_ilp_",    properties);

	}

@@ -2540,6 +2543,7 @@ public class CLTParameters {
		poles.getProperties   (prefix+"_poles",   properties);
		lwir.getProperties    (prefix+"_lwir",    properties);
		ofp.getProperties     (prefix+"_ofp_",    properties);
		ilp.getProperties     (prefix+"_ilp_",    properties);
	}

	public boolean showJDialog() {
@@ -3508,6 +3512,9 @@ public class CLTParameters {
		gd.addTab         ("O-Flow", "parameters for the interscene Optical FLow calculations");
		this.ofp.dialogQuestions(gd);

		gd.addTab         ("Intra-LMA", "parameters for the interscene LMA fitting");
		this.ilp.dialogQuestions(gd);
		
		
		gd.addTab         ("Debug", "Other debug images");
		gd.addMessage     ("--- Other debug images ---");
@@ -4304,6 +4311,7 @@ public class CLTParameters {
		
		this.lwir.dialogAnswers(gd);
		this.ofp.dialogAnswers(gd);
		this.ilp.dialogAnswers(gd);

		this.debug_initial_discriminate= gd.getNextBoolean();
		this.dbg_migrate=                gd.getNextBoolean();
+78 −1
Original line number Diff line number Diff line
@@ -700,6 +700,7 @@ private Panel panel1,
			addButton("DSI histogram",              panelClt5, color_report);
			addButton("ML recalc",                  panelClt5, color_process);
			addButton("Inter Test",                 panelClt5, color_stop);
			addButton("Inter LMA",                  panelClt5, color_stop);
			plugInFrame.add(panelClt5);
		}

@@ -5107,6 +5108,13 @@ private Panel panel1,
        CLT_PARAMETERS.batch_run = true;
        testInterScene();
    	return;
/* ======================================================================== */
    } else if (label.equals("Inter LMA")) {
        DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
    	EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
        CLT_PARAMETERS.batch_run = true;
        testInterLMA();
    	return;
    	
/* ======================================================================== */
    } else if (label.equals("CLT rig edit")) {
@@ -6475,6 +6483,75 @@ private Panel panel1,
	}

	
	public boolean testInterLMA() {
		long startTime=System.nanoTime();
		// load needed sensor and kernels files
		if (!prepareRigImages()) return false;
		String configPath=getSaveCongigPath();
		if (configPath.equals("ABORT")) return false;
		setAllProperties(PROPERTIES); // batchRig may save properties with the model. Extrinsics will be updated, others should be set here
		if (DEBUG_LEVEL > -2){
			System.out.println("++++++++++++++ Testing Interscene processing ++++++++++++++");
		}
		
		if (CLT_PARAMETERS.useGPU()) { // only init GPU instances if it is used
			if (GPU_TILE_PROCESSOR == null) {
				try {
					GPU_TILE_PROCESSOR = new GPUTileProcessor(CORRECTION_PARAMETERS.tile_processor_gpu);
				} catch (Exception e) {
					System.out.println("Failed to initialize GPU class");
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				} //final int        debugLevel);
			}
			if (CLT_PARAMETERS.useGPU(false) && (QUAD_CLT != null) && (GPU_QUAD == null)) { // if GPU main is needed
				try {
					GPU_QUAD = GPU_TILE_PROCESSOR.new GpuQuad(
							QUAD_CLT,
							4,
							3);
				} catch (Exception e) {
					System.out.println("Failed to initialize GpuQuad class");
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				} //final int        debugLevel);
				QUAD_CLT.setGPU(GPU_QUAD);
			}
		}
		
		try {
			TWO_QUAD_CLT.TestInterLMA(
					QUAD_CLT, // QuadCLT quadCLT_main,
//					QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
					CLT_PARAMETERS,  // EyesisCorrectionParameters.DCTParameters           dct_parameters,
					DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters     debayerParameters,
					COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
					COLOR_PROC_PARAMETERS_AUX, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters_aux,
					CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters     channelGainParameters,
					RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters             rgbParameters,
					EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
					PROPERTIES,  // Properties                                           properties,
					THREADS_MAX, //final int          threadsMax,  // maximal number of threads to launch
					UPDATE_STATUS, //final boolean    updateStatus,
					DEBUG_LEVEL);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} //final int        debugLevel);
		if (configPath!=null) {
			saveTimestampedProperties( // save config again
					configPath,      // full path or null
					null, // use as default directory if path==null
					true,
					PROPERTIES);
		}
		System.out.println("batchRig(): Processing finished at "+
				IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
				Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
		return true;
	}
	
	
	
+31 −30
Original line number Diff line number Diff line
@@ -92,33 +92,33 @@ public class ErsCorrection extends GeometryCorrection {
	static final int DW_DZ =  14; // dw_dz};  (m)

	static final String [] DP_DERIV_NAMES = {
			"dp_dpX",   // (pix)     0
			"dp_dpY",   // (pix)     1
			"dp_dd",    // (pix)     2
			"dp_dvaz",  // (rad/sec) 3
			"dp_dvtl",  // (rad/sec) 4
			"dp_dvrl",  // (rad/sec) 5
			"dp_dvx",   // (m/s)     6
			"dp_dvy",   // (m/s)     7
			"dp_dvz",   // (m/s)     8
			"dp_daz",   // (rad)     9
			"dp_dtl",   // (rad)    10
			"dp_drl",   // (rad)    11
			"dp_dx",    // (m)      12
			"dp_dy",    // (m)	    13
			"dp_dz",    // (m)      14
			"dp_dsvaz", // (rad/sec)15
			"dp_dsvtl", // (rad/sec)16
			"dp_dsvrl", // (rad/sec)17
			"dp_dsvx",  // (m/s)    18
			"dp_dsvy",  // (m/s)    19
			"dp_dsvz",  // (m/s)    20
			"dp_dsaz",  // (rad)    21
			"dp_dstl",  // (rad)    22
			"dp_dsrl",  // (rad)    23
			"dp_dsx",   // (m)      24
			"dp_dsy",   // (m)	    25
			"dp_dsz"};  // (m)      26
			"pX",            // (pix)     0
			"pY",            // (pix)     1
			"disp",          // (pix)     2
			"ers_vaz_ref",   // (rad/sec) 3
			"ers_vtl_ref",   // (rad/sec) 4
			"ers_vrl_ref",   // (rad/sec) 5
			"ers_dvx_ref",   // (m/s)     6
			"ers_dvy_ref",   // (m/s)     7
			"ers_dvz_ref",   // (m/s)     8
			"azimuth_ref",   // (rad)     9
			"tilt_ref",      // (rad)    10
			"roll_ref",      // (rad)    11
			"X_ref",         // (m)      12
			"Y_ref",         // (m)	    13
			"Z_ref",         // (m)      14
			"ers_vaz_scene", // (rad/sec)15
			"ers_vtl_scene", // (rad/sec)16
			"ers_vrl_scene", // (rad/sec)17
			"ers_dvx_scene", // (m/s)    18
			"ers_dvy_scene", // (m/s)    19
			"ers_dvz_scene", // (m/s)    20
			"azimuth_scene", // (rad)    21
			"tilt_scene",    // (rad)    22
			"Roll_scene",    // (rad)    23
			"X_scene",       // (m)      24
			"Y_scene",       // (m)	     25
			"Z_scene"};      // (m)      26
	
	// returned arrays have the zero element with coordinates, not derivatives
	// Reference parameters
@@ -150,6 +150,7 @@ public class ErsCorrection extends GeometryCorrection {
	static final int DP_DSX =  24; // dw_dx,   (m)
	static final int DP_DSY =  25; // dw_dy,   (m)
	static final int DP_DSZ =  26; // dw_dz};  (m)
	static final int DP_NUM_PARS = DP_DSZ+1; 
	
	static final RotationConvention ROT_CONV = RotationConvention.FRAME_TRANSFORM;
	static final double THRESHOLD = 1E-10;
@@ -922,7 +923,7 @@ public class ErsCorrection extends GeometryCorrection {
				0.002}; // dw_dz};  (m)      14 was 0.1
		double scale_delta = 1.0; // 0.1; // 1.0; // 0.1; // 0.5;
//		double [] deltas = deltas0.clone();
		double [] deltas = new double [DP_DSZ + 1];
		double [] deltas = new double [DP_NUM_PARS];
		System.arraycopy(deltas0, 0, deltas, 0,              deltas0.length);
		System.arraycopy(deltas0, 3, deltas, deltas0.length, deltas0.length - 3);
		for (int i = 0; i < deltas.length; i++) deltas[i] *= scale_delta;
@@ -2010,7 +2011,7 @@ public class ErsCorrection extends GeometryCorrection {
		
		Matrix dpscene_dxyz = dx_dpscene.inverse();
		Matrix dpscene_dxyz_minus = dpscene_dxyz.times(-1.0); // negated to calculate /d{pX,pY,D) for the scene parameters
		double[][] derivatives = new double[DP_DSZ+2][]; // includes [0] - pXpYD vector
		double[][] derivatives = new double[DP_NUM_PARS+1][]; // includes [0] - pXpYD vector
		// scene pX, pY, Disparity
		derivatives[0] = pXpYD_scene;
		// derivatives by the reference parameters, starting with /dpX, /dpY, /dd
@@ -2026,7 +2027,7 @@ public class ErsCorrection extends GeometryCorrection {
				derivatives[vindx] = matrixTimesVector(dpscene_dxyz, reference_vectors[vindx]).toArray();
			}
		}
		for (int indx = DP_DSVAZ; indx <= DP_DSZ; indx++) { // 15,16, ...
		for (int indx = DP_DSVAZ; indx < DP_NUM_PARS; indx++) { // 15,16, ...
			int indx_out = indx+1; // 16, 17,
			int indx_in =  indx_out - DP_DSVAZ + DW_DVAZ; // 4, 5, ...
			if (is_infinity) {
+1 −67
Original line number Diff line number Diff line
@@ -535,46 +535,6 @@ public class ExtrinsicAdjustment {
	}




/*
	private double [] getYminusFx(
			GeometryCorrection.CorrVector corr_vector)
	{
		int clusters = clustersX * clustersY;
		Matrix []   corr_rots =  corr_vector.getRotMatrices(); // get array of per-sensor rotation matrices
		Matrix [][] deriv_rots = corr_vector.getRotDeriveMatrices();
		double [] y_minus_fx = new double  [clusters * POINTS_SAMPLE];
		double [] imu = corr_vector.getIMU(); // i)
		for (int cluster = 0; cluster < clusters;  cluster++) if (measured_dsxy[cluster] != null){
			double [] ddnd = geometryCorrection.getPortsDDNDAndDerivatives( // USED in lwir
					geometryCorrection,     // GeometryCorrection gc_main,
					use_rig_offsets,        // boolean     use_rig_offsets,
					corr_rots,              // Matrix []   rots,
					deriv_rots,             // Matrix [][] deriv_rots,
					null,                   // double [][] DDNDderiv,     // if not null, should be double[8][]
					dy_ddisparity[cluster], // double []   dy_ddisparity,   // double [][] disp_dist, //disp_dist[i][2] or null
					imu,                    // double []   imu,
					x0y0[cluster],          // double []   pXYND0,        // per-port non-distorted coordinates corresponding to the correlation measurements
					world_xyz[cluster],     // double []   xyz, // world XYZ for ERS correction
					measured_dsxy[cluster][ExtrinsicAdjustment.INDX_PX + 0],  // double      px,
					measured_dsxy[cluster][ExtrinsicAdjustment.INDX_PX + 1],  // double      py,
					measured_dsxy[cluster][ExtrinsicAdjustment.INDX_TARGET]); // double      disparity);
			//arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
			ddnd[0] = -ddnd[0];
			if ((force_disparity != null) && force_disparity[cluster]) {
				ddnd[0] -= measured_dsxy[cluster][ExtrinsicAdjustment.INDX_DIFF];
			}
///			ddnd[0] = -measured_dsxy[cluster][ExtrinsicAdjustment.INDX_DIFF] - ddnd[0];
			for (int i = 0; i < NUM_SENSORS; i++) {
				ddnd[i + 1] = -measured_dsxy[cluster][ExtrinsicAdjustment.INDX_DD0 + i] - ddnd[i + 1];
				ddnd[i + 5] = -measured_dsxy[cluster][ExtrinsicAdjustment.INDX_ND0 + i] - ddnd[i + 5];
			}
			System.arraycopy(ddnd, 0, y_minus_fx, cluster * POINTS_SAMPLE, POINTS_SAMPLE);
		}
		return y_minus_fx;
	}
*/
	private double [] getWYmFxRms( // USED in lwir
			double []   fx) {
		int clusters = clustersX * clustersY;
@@ -1125,7 +1085,7 @@ public class ExtrinsicAdjustment {
		}
		return clouds;
	}

	@Deprecated
	private double [] getWeights(
			double  [][] measured_dsxy,
			boolean [] force_disparity,   // same dimension as dsdn, true if disparity should be controlled
@@ -1395,13 +1355,7 @@ public class ExtrinsicAdjustment {
		double [] imu = corr_vector.getIMU(); // i)
		double [] y_minus_fx = new double  [clusters * POINTS_SAMPLE];
		for (int cluster = 0; cluster < clusters;  cluster++) {
//			if ((cluster == 1892) || (cluster == 1894) ||(cluster == 3205)) {
//				System.out.println("getFx() cluster="+cluster);
//			}
			if (measured_dsxy[cluster] != null){
//				if ((cluster == 1735 ) || (cluster==1736)){
//					System.out.print("");
//				}
				double [] ddnd = geometryCorrection.getPortsDDNDAndDerivativesNew( // USED in lwir
						geometryCorrection,     // GeometryCorrection gc_main,
						use_rig_offsets,        // boolean     use_rig_offsets,
@@ -2220,13 +2174,8 @@ public class ExtrinsicAdjustment {
			double lambda,
			double rms_diff,
			int debug_level) {
//		int num_points = this.weights.length; // includes 2 extra for regularization
//		int num_pars = getNumPars();
		boolean [] rslt = {false,false};
		if (this.last_rms == null) { //first time, need to calculate all (vector is valid)
//			this.last_ymfx = getFxJt(
//					this.vector, // double []   vector,
//					this.last_jt); // double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
			this.last_jt =  getJacobianTransposed(corr_vector); // new double [num_pars][num_points];
			this.last_ymfx = getFx(corr_vector);
			if (debug_level > -1) { // temporary
@@ -2304,19 +2253,10 @@ public class ExtrinsicAdjustment {
		double []  delta = mdelta.getColumnPackedCopy();
		GeometryCorrection.CorrVector corr_delta = geometryCorrection.getCorrVector(delta, par_mask);

///		double [] new_vector = this.vector.clone();
		GeometryCorrection.CorrVector new_vector = this.corr_vector.clone();
		double scale = 1.0;
//		boolean ok =
		new_vector.incrementVector(corr_delta, scale); // ok = false if there are nay NaN-s

///		for (int i = 0; i < num_pars; i++) new_vector[i]+= delta[i];
		// being optimistic, modify jt and last_ymfx in place, restore if failed


///		this.last_ymfx = getFxJt(
///				new_vector, // double []   vector,
///				this.last_jt); // double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
		this.last_jt =  getJacobianTransposed(new_vector); // new double [num_pars][num_points];
		this.last_ymfx = getFx(new_vector);
		if (debug_level > 2) {
@@ -2339,18 +2279,12 @@ public class ExtrinsicAdjustment {
			if (debug_level > 2) {
				System.out.print("delta: "+corr_delta.toString()+"\n");
				System.out.print("New vector: "+new_vector.toString()+"\n");
///				for (int np = 0; np < vector.length; np++) {
///					System.out.print(this.vector[np]+" ");
///				}
				System.out.println();
			}
		} else { // worsened
			rslt[0] = false;
			rslt[1] = false; // do not know, caller will decide
			// restore state
///			this.last_ymfx = getFxJt( // recalculate fx
///					this.vector, // double []   vector,
///					this.last_jt); // double [][] jt) { // should be either [vector.length][samples.size()] or null - then only fx is calculated
			this.last_jt =  getJacobianTransposed(corr_vector); // new double [num_pars][num_points];
			this.last_ymfx = getFx(corr_vector);

Loading