Commit 64394dd7 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Bug fixes, added super-batch run (multiple configs)

parent cdd2bf43
Loading
Loading
Loading
Loading
+59 −2
Original line number Diff line number Diff line
@@ -815,6 +815,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
			addButton("Image Properties", panelLWIR16, color_conf_process);
			addButton("Illustrations Configure", panelLWIR16, color_conf_process);
			addButton("Footage Organize", panelLWIR16, color_conf_process);
			addButton("Super batch",     panelLWIR16, color_process);
			plugInFrame.add(panelLWIR16);
@@ -5433,6 +5434,41 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
			FOOTAGE_ORGANIZE.OrganizeSeries(
					CLT_PARAMETERS,
					CALIBRATION_ILLUSTRATION);
		} else if (label.equals("Super batch")) {
			DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
			EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
			CLT_PARAMETERS.batch_run = true;
			String [] configs = loadMultiProperties(
					CORRECTION_PARAMETERS.resultsDirectory, // String directory,
					true);// boolean useXML,
			if (configs == null) {
				return;
			}
			long startTime = System.nanoTime();
			for (int nc = 0; nc < configs.length; nc++) {
				long startTimeRun = System.nanoTime();
				String config = configs[nc];
				String path = loadProperties(config, CORRECTION_PARAMETERS.resultsDirectory, true, PROPERTIES);
				System.out.println(path);
				if (path != null) {
					getAllProperties(PROPERTIES);
					if (DEBUG_LEVEL > -3)
						System.out.println("Configuration parameters are restored from " + path);
				} else {
					if (DEBUG_LEVEL > -10)
						System.out.println("Failed to restore configuration parameters");
					return;
				}
				batchLwir();
				System.out.println("Super batch: processing of run "+ nc+" (of "+configs.length+"): "+config+ " finished in "
						+ IJ.d2s(0.000000001 * (System.nanoTime() - startTimeRun), 3) + " sec, --- Free memory="
						+ Runtime.getRuntime().freeMemory() + " (of " + Runtime.getRuntime().totalMemory() + ")");
			}
			System.out.println("Super batch: all (of "+configs.length+"): finished at "
					+ IJ.d2s(0.000000001 * (System.nanoTime() - startTime), 3) + " sec, --- Free memory="
					+ Runtime.getRuntime().freeMemory() + " (of " + Runtime.getRuntime().totalMemory() + ")");
			return;
			
			
		} else if (label.equals("Image Properties")) {
			DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
@@ -9136,7 +9172,9 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
									+ ")"), // filter
					directory); // may be ""
		} else
			path += patterns[0];
			if (!path.endsWith(patterns[0])) {
				path += patterns[0]; // where was it used???
			}
		if (path == null)
			return null;
		InputStream is;
@@ -9172,6 +9210,25 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
		return path;
	}
	
	public String [] loadMultiProperties(
			String directory,
			boolean useXML) {
		String[] XMLPatterns = { ".corr-xml", ".xml" };
		String[] confPatterns = { ".conf" };
		String[] patterns = useXML ? XMLPatterns : confPatterns;
		String [] paths = selectFiles(
				false, // boolean save,
				"Multiple configuration file selection", // title
				"Read configuration files", // button
				new MultipleExtensionsFileFilter(patterns,
						(useXML ? "XML " : "") + "Configuration files (" + (useXML ? "*.corr-xml" : "*.conf")
								+ ")"), // filter
				new String[] {directory}); // String[] defaultPaths)
		return paths;
	}
	
	
	/* ======================================================================== */
	public void setAllProperties(Properties properties) {
		properties.setProperty("MASTER_DEBUG_LEVEL", MASTER_DEBUG_LEVEL + "");
+3 −1
Original line number Diff line number Diff line
@@ -201,7 +201,9 @@ public class GpuQuad{ // quad camera description
		resetGeometryCorrectionVector();
		this.gpuTileProcessor.bayer_set =        false;
	}
	
	public void resetBayer() {
		this.gpuTileProcessor.bayer_set =        false;
	}
	public QuadCLT getQuadCLT( ) {
		return this.quadCLT;
	}
+15 −0
Original line number Diff line number Diff line
@@ -1972,6 +1972,21 @@ public class ErsCorrection extends GeometryCorrection {
		
	}

	public static double [][] invertXYZATR(
			double [] source_xyz,
			double [] source_atr)
	{
		Rotation   scene_rotation= new Rotation(RotationOrder.YXZ, ROT_CONV, source_atr[0],    source_atr[1],    source_atr[2]);
		Vector3D   scene_offset =  new Vector3D(-source_xyz[0], -source_xyz[1], -source_xyz[2]);
		Rotation   rotation =      scene_rotation.revert(); // 
		Vector3D   offset = rotation.applyTo(scene_offset); // junk
		double []  angles = rotation.getAngles(RotationOrder.YXZ, ROT_CONV);
		double []  xyz = offset.toArray();
		return new double[][] {xyz,angles};
	}
	
	
	
	public double [] getImageCoordinatesERS(
			double [] xyzw,
			boolean correctDistortions, // correct distortion (will need corrected background too !)
+141 −0
Original line number Diff line number Diff line
@@ -3090,6 +3090,141 @@ public class OpticalFlow {
			double [] new_from_last_xyz = ers_scene_last_known.getSceneXYZ(scene_ts);
			double [] new_from_last_atr = ers_scene_last_known.getSceneATR(scene_ts);
			
			double [][] last_from_new =     ErsCorrection.invertXYZATR(new_from_last_xyz, new_from_last_atr);
			double [][] vfy_new_from_last = ErsCorrection.invertXYZATR(last_from_new[0], last_from_new[1]);
			System.out.println(new_from_last_xyz[0]+","+new_from_last_xyz[1]+","+new_from_last_xyz[2]+","+
					new_from_last_atr[0]+","+new_from_last_atr[1]+","+new_from_last_atr[2]);
			System.out.println(last_from_new[0][0]+","+last_from_new[0][1]+","+last_from_new[0][2]+","+
					last_from_new[1][0]+","+last_from_new[1][1]+","+last_from_new[1][2]);
			System.out.println(vfy_new_from_last[0][0]+","+vfy_new_from_last[0][1]+","+vfy_new_from_last[0][2]+","+
					vfy_new_from_last[1][0]+","+vfy_new_from_last[1][1]+","+vfy_new_from_last[1][2]);
/*			
			double [][] last_from_new1 =     ErsCorrection.invertXYZATR(vfy_new_from_last[0],vfy_new_from_last[1]);
			double [][] vfy_new_from_last1 = ErsCorrection.invertXYZATR(last_from_new1[0], last_from_new1[1]);

			System.out.println(last_from_new1[0][0]+","+last_from_new1[0][1]+","+last_from_new1[0][2]+","+
					last_from_new1[1][0]+","+last_from_new1[1][1]+","+last_from_new1[1][2]);
			System.out.println(vfy_new_from_last1[0][0]+","+vfy_new_from_last1[0][1]+","+vfy_new_from_last1[0][2]+","+
					vfy_new_from_last1[1][0]+","+vfy_new_from_last1[1][1]+","+vfy_new_from_last1[1][2]);
			*/
			
			
			
			// combine two rotations and two translations 
			System.out.println("Processing scene "+i+": "+scene_QuadClt.getImageName());
			double [][] combo_XYZATR = ErsCorrection.combineXYZATR(
					last_known_xyz,     // double [] reference_xyz,
					last_known_atr,     // double [] reference_atr, // null?
					new_from_last_xyz,  // double [] scene_xyz,
					new_from_last_atr); // double [] scene_atr)
			
			// before adjusting - save original ERS, restart afterwards
			double [] ers_scene_original_xyz_dt = ers_scene.getErsXYZ_dt();
			double [] ers_scene_original_atr_dt = ers_scene.getErsATR_dt();
			
			// ers should be correct for both
			
			scenes_xyzatr[i] = adjustPairsLMA(
					clt_parameters,     // CLTParameters  clt_parameters,			
					reference_QuadClt, // QuadCLT reference_QuadCLT,
					scene_QuadClt, // QuadCLT scene_QuadCLT,
					combo_XYZATR[0], // xyz
					combo_XYZATR[1], // atr
					param_select2,             // final boolean[]   param_select,
					param_regweights2, //  final double []   param_regweights,
					debug_level); // int debug_level)
			ers_reference.addScene(scene_QuadClt.getImageName(),
					scenes_xyzatr[i][0],
					scenes_xyzatr[i][1],
					ers_scene.getErsXYZ_dt(),		
					ers_scene.getErsATR_dt()		
					);
			
			// restore original ers data
			ers_scene.setErsDt(
					ers_scene_original_xyz_dt, // double []    ers_xyz_dt,
					ers_scene_original_atr_dt); // double []    ers_atr_dt)(ers_scene_original_xyz_dt);
			ers_scene.setupERS();
			if (debug_level > -1) {
				System.out.println("Pass multi scene "+i+" (of "+ scenes.length+") "+
						reference_QuadClt.getImageName() + "/" + scene_QuadClt.getImageName()+" Done.");
			}
			if (delete_scene_asap) {
				scenes[i+1] = null;
			}
//			Runtime.getRuntime().gc();
//			System.out.println("Scene "+i+", --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
			
		}
		reference_QuadClt.saveInterProperties( // save properties for interscene processing (extrinsics, ers, ...)
	            null, // String path,             // full name with extension or w/o path to use x3d directory
	            debug_level+1);
		if (!delete_scene_asap && (debug_level > -1)) {
			System.out.println("adjustSeries(): preparing image set...");
			int nscenes = scenes.length;
			int indx_ref = nscenes - 1; 
			double [][][] all_scenes_xyzatr = new double [scenes.length][][]; // includes reference (last)
			double [][][] all_scenes_ers_dt = new double [scenes.length][][]; // includes reference (last)
			all_scenes_xyzatr[indx_ref] = new double [][] {ZERO3,ZERO3};
			all_scenes_ers_dt[indx_ref] = new double [][] {
				ers_reference.getErsXYZ_dt(),
				ers_reference.getErsATR_dt()};
				for (int i = 0; i < nscenes; i++) if (i != indx_ref) {
					String ts = scenes[i].getImageName();
					all_scenes_xyzatr[i] = new double[][] {ers_reference.getSceneXYZ(ts),       ers_reference.getSceneATR(ts)}; 		
					all_scenes_ers_dt[i] = new double[][] {ers_reference.getSceneErsXYZ_dt(ts), ers_reference.getSceneErsATR_dt(ts)}; 		
				}
		compareRefSceneTiles(
				"" ,               // String suffix,
				false,             // boolean blur_reference,
				all_scenes_xyzatr, // double [][][] scene_xyzatr, // does not include reference
				all_scenes_ers_dt, // double [][][] scene_ers_dt, // does not include reference
				scenes,            // QuadCLT [] scenes,
				8);                // int iscale) // 8
		}		
		if (debug_level > -1) {
			System.out.println("adjustSeries() Done.");
		}
	}

	public void adjustSeries(
			CLTParameters  clt_parameters,			
			double         k_prev, 
			QuadCLT []     scenes, // ordered by increasing timestamps
			int            ref_index,
			int            debug_level
			)
	{
		double [][][] scenes_xyzatr = new double [scenes.length][][]; // previous scene relative to the next one
		QuadCLT reference_QuadClt = scenes[ref_index]; // scenes.length-1]; // last acquired
		ErsCorrection ers_reference = reference_QuadClt.getErsCorrection();
		// modify LMA parameters to freeze reference ERS, remove pull on scene ERS
		boolean[]   param_select2 =     clt_parameters.ilp.ilma_lma_select.clone();             // final boolean[]   param_select,
		double []   param_regweights2 = clt_parameters.ilp.ilma_regularization_weights; //  final double []   param_regweights,
		boolean delete_scene_asap = (debug_level < 10); // to save memory
		// freeze reference ERS, free scene ERS
		for (int j = 0; j <3; j++) {
			param_select2[ErsCorrection.DP_DVX  + j] = false;
			param_select2[ErsCorrection.DP_DVAZ + j] = false;
			param_regweights2[ErsCorrection.DP_DSVX +  j] = 0.0;
			param_regweights2[ErsCorrection.DP_DSVAZ + j] = 0.0;
		}
		
		// process scenes before reference
		if (ref_index >  1) {
			for (int i =  ref_index - 2; i >=0 ; i--) {
				QuadCLT scene_QuadClt =      scenes[i];
				String last_known_ts =           scenes[i+1].getImageName(); // it should be present in the reference scene scenes
				String scene_ts =                scenes[i].getImageName(); // it should be present in the scenes[i+1] scenes
				ErsCorrection ers_scene_last_known = scenes[i+1].getErsCorrection();
				ErsCorrection ers_scene =            scene_QuadClt.getErsCorrection();

				double [] last_known_xyz = ers_reference.getSceneXYZ(last_known_ts);
				double [] last_known_atr = ers_reference.getSceneATR(last_known_ts);

				double [] new_from_last_xyz = ers_scene_last_known.getSceneXYZ(scene_ts);
				double [] new_from_last_atr = ers_scene_last_known.getSceneATR(scene_ts);

				// combine two rotations and two translations 
				System.out.println("Processing scene "+i+": "+scene_QuadClt.getImageName());
				double [][] combo_XYZATR = ErsCorrection.combineXYZATR(
@@ -3136,6 +3271,12 @@ public class OpticalFlow {
				//			System.out.println("Scene "+i+", --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");

			}
		}
		// process scenes after reference (if it is not the last
		if (ref_index <  (scenes.length - 1)) {
		}		
		
		
		reference_QuadClt.saveInterProperties( // save properties for interscene processing (extrinsics, ers, ...)
	            null, // String path,             // full name with extension or w/o path to use x3d directory
	            debug_level+1);
+6 −0
Original line number Diff line number Diff line
@@ -5532,6 +5532,12 @@ if (debugLevel < -100) {
		  }
	  }
	  
	  public void resetBayer() {
		  if (getGPU() != null) {
			  getGPU().resetBayer();
		  }
	  }
	  
		public QuadCLT spawnQuadCLT(
				String              set_name,
				CLTParameters       clt_parameters,
Loading