Commit 436cf9c1 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

testing/debugging multicam correlations

parent 2a0e3035
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -162,6 +162,8 @@ public class Correlation2d {
	private static int SUB_SAMPLE = 16;  // subsample source pixel in each direction when generating
	public static int THREADS_MAX = 100; 
	
	// All used pairs (but the diameters) are clockwise (end is clockwise of start)
	// Orientation calculations are valid for clockwise only
    private void setupPairs() {
    	int indx = 0;
    	for (int i = 1; i <= numSensors/2; i++) { // CW length
@@ -223,9 +225,10 @@ public class Correlation2d {
    
    public boolean [] selectParallel(boolean [] cur_sel, int start, int end) {
    	boolean [] sel = (cur_sel == null) ? (new boolean[pair_length.length]) : cur_sel;
		int n1 = (2 * start + end) % (2 * numSensors); 
    	int l = (end + numSensors - start) % numSensors; // CCW pairfs will have l > numSensors/2
    	
    	for (int j = 0; j < pair_start_end.length; j++ ) {
		int n1 = (2 * start + l ) % (2 * numSensors); 
    	for (int j = 0; j < pair_start_end.length; j++ ) { // lengths are always positive
    		int n2 = (2 * pair_start_end[j][0] + pair_length[j]) % (2 * numSensors);
    		if ((n2 - n1) % numSensors == 0) { // only parallel or anti-parallel
    			sel[j] = true;
@@ -449,7 +452,8 @@ public class Correlation2d {
								cwrot += Math.PI;
							}
							double pl = 2 * Math.sin(Math.PI* pair_length[num_pair] / numSensors); // length for R=1
							double scale = pl/Math.sqrt(2.0)* mcorr_comb_disp; // Math.sqrt(2.0) - relative to side of a square - may be change later?
//							double scale = pl/Math.sqrt(2.0)* mcorr_comb_disp; // Math.sqrt(2.0) - relative to side of a square - may be change later?
							double scale = pl/2.0* mcorr_comb_disp; // Math.sqrt(2.0) - relative to diameter
							Matrix toPair = new Matrix(new double[][] {
								{scale * Math.cos(cwrot), -scale*Math.sin(cwrot)},
								{scale * Math.sin(cwrot),  scale*Math.cos(cwrot)}});
@@ -558,7 +562,8 @@ public class Correlation2d {
 							}
 							double pl = 2 * Math.sin(Math.PI* pair_length[num_pair] / numSensors); // length for R=1
 							// scale - to get pair (source) radius from combo (destination) radius
 							double scale = pl/Math.sqrt(2.0)* mcorr_comb_disp; // Math.sqrt(2.0) - relative to side of a square - may be change later?
//							double scale = pl/Math.sqrt(2.0)* mcorr_comb_disp; // Math.sqrt(2.0) - relative to side of a square - may be change later?
							double scale = pl/2.0* mcorr_comb_disp; // Math.sqrt(2.0) - relative to diameter
 							Matrix toPair = new Matrix(new double[][] {
 								{scale * Math.cos(cwrot), -scale*Math.sin(cwrot)},
 								{scale * Math.sin(cwrot),  scale*Math.cos(cwrot)}});
@@ -2088,7 +2093,7 @@ public class Correlation2d {
	 * Negative values are ignored!
	 * Both x and y half-windows can be variable length (to reduce calculations with 0.0 elements), normalized
	 * so sums of zero element and twice all others are 1.0
	 * Window in Y direction corresponds to correlation stripe rows, corresponding to sqrt(2)/2 sensor pixels
	 * Window in Y direction corresponds to correlation strip rows, corresponding to sqrt(2)/2 sensor pixels
	 * for the largest baseline pairs,
	 * Window in X direction has the same sqrt(2)/2 step, but it is half of the horizontal steps of the correlation
	 * results strip
+26 −5
Original line number Diff line number Diff line
@@ -2424,7 +2424,7 @@ public class ImageDttCPU {
		    
		    final double [][][][]     clt_corr_out,   // sparse (by the first index) [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] or null
		    final double [][][][]     clt_combo_out,  // sparse (by the first index) [type][tilesY][tilesX][(combo_tile_size] or null
		    
			final double [][][][]     clt_combo_dbg,  // generate sparse  partial rotated/scaled pairs
//			final double [][][][]     clt_corr_combo_in,  // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
			                                           // [type][tilesY][tilesX] should be set by caller
													   // types: 0 - selected correlation (product+offset), 1 - sum
@@ -2497,6 +2497,9 @@ public class ImageDttCPU {
			if (imgdtt_params.getMcorrDia (numSensors)) corr_calculate = correlation2d.selectDiameters  (corr_calculate);
			if (imgdtt_params.getMcorrSq  (numSensors)) corr_calculate = correlation2d.selectSquares    (corr_calculate);
			if (imgdtt_params.getMcorrNeib(numSensors)) corr_calculate = correlation2d.selectNeibs      (corr_calculate);
			if (imgdtt_params.getMcorrHor (numSensors)) corr_calculate = correlation2d.selectHorizontal (corr_calculate);
			if (imgdtt_params.getMcorrVert(numSensors)) corr_calculate = correlation2d.selectVertical   (corr_calculate);
			
			correlation2d.setCorrPairs(corr_calculate); // will limit correlation pairs calculation
			correlation2d.generateResample( // should be called before
					mcorr_comb_width,  // combined correlation tile width
@@ -2539,6 +2542,13 @@ public class ImageDttCPU {
					clt_combo_out[i] = new double[tilesY][tilesX][]; 
				}
			}
			if (clt_combo_dbg != null) {
				boolean [] calc_corr_pairs = correlation2d.getCorrPairs();
				for (int i = 0; i < calc_corr_pairs.length; i++) if (calc_corr_pairs[i]){
					clt_combo_dbg[i] = new double[tilesY][tilesX][]; 
				}
			}
			
		}
		final boolean [][] combo_sels = pcombo_sels; 
		final boolean debug_distort= globalDebugLevel > 0; ///false; // true;
@@ -3110,6 +3120,17 @@ public class ImageDttCPU {
									clt_combo_out[num_comb][tileY][tileX] = corr_combo[num_comb];
								}
							}
						    if (clt_combo_dbg != null) { // debug feature, will re-calculate scaled/rotated pairs
								for (int num_pair = 0; num_pair < corr_tiles.length; num_pair++) if (corr_tiles[num_pair] != null){
									clt_combo_dbg[num_pair][tileY][tileX] = correlation2d.accumulateInit();
									correlation2d.accummulatePair(
											clt_combo_dbg[num_pair][tileY][tileX], // double [] accum_tile,
											corr_tiles[num_pair], // double [] corr_tile,
											num_pair, // int       num_pair,
								    		1.0); // double    weight)
								}
						    }
							
							
						    // calculate CM maximums for all mixed channels
						    // First get integer correlation center, relative to the center
+62 −6
Original line number Diff line number Diff line
@@ -94,6 +94,12 @@ public class ImageDttParameters {
	public boolean mcorr_sq_multi =         true;  // all squares
	public boolean mcorr_neib =             true;  // all neighbors (4 pairs for quad, 16 - for lwir16)
	public boolean mcorr_neib_multi =       true;  // all neighbors
	public boolean mcorr_hor =              true;  // all horizontal (2 pairs for quad, 7 - for lwir16)
	public boolean mcorr_hor_multi =        true;  // all horizontal
	public boolean mcorr_vert =             true;  // all vertical (2 pairs for quad, 8 - for lwir16)
	public boolean mcorr_vert_multi =       true;  // all vertical

	
	public boolean mcorr_cons_all =         true;  // consolidate all available pairs
	public boolean mcorr_cons_dia =         true;  // consolidate all having length of a diameter
	public boolean mcorr_cons_sq =          true;  // consolidate all having length of a square side
@@ -105,7 +111,8 @@ public class ImageDttParameters {
	public int     mcorr_comb_width =       15;
	public int     mcorr_comb_height =      15;
	public int     mcorr_comb_offset =      0;
	public double  mcorr_comb_disp =        1.0; // per-pixel disparity relative to a side of a square
	public double  mcorr_comb_disp =        1.0;   // per-pixel disparity relative to diameter
	public boolean mcorr_comb_dbg =         false; // Generate/show correlation pairs scaled/rotated for combining
	
	// pole window will be inverted
	public int     corr_strip_notch =       11;     // number of rows to calculate for vertical poles
@@ -249,6 +256,14 @@ public class ImageDttParameters {
		return (numSens > mcorr_multi) ? mcorr_neib_multi : mcorr_neib;
	}

	public boolean getMcorrHor(int numSens) {
		return (numSens > mcorr_multi) ? mcorr_hor_multi : mcorr_hor;
	}

	public boolean getMcorrVert(int numSens) {
		return (numSens > mcorr_multi) ? mcorr_vert_multi : mcorr_vert;
	}

	public void dialogQuestions(GenericJTabbedDialog gd) {
		
		    gd.addCheckbox    ("Debug CPU->GPU matching",                                         this.gpu_mode_debug,
@@ -372,6 +387,18 @@ public class ImageDttParameters {
			gd.addCheckbox    ("Calculate neighbor pairs for multi cameras",                     this.mcorr_neib_multi,
					"All neighbor pairs. N: 4 for quad, 16 for lwir16");
			
			gd.addCheckbox    ("Calculate horizontal pairs for small cameras",                   this.mcorr_hor,
					"All horizontal pairs. N: 2 for quad, 7 for lwir16");
			gd.addCheckbox    ("Calculate horizontal pairs for multi cameras",                   this.mcorr_hor_multi,
					"All horizontal pairs. N: 2 for quad, 7 for lwir16");

			gd.addCheckbox    ("Calculate vertical pairs for small cameras",                     this.mcorr_vert,
					"All vertical pairs. N: 2 for quad, 8 for lwir16");
			gd.addCheckbox    ("Calculate vertical pairs for multi cameras",                     this.mcorr_vert_multi,
					"All vertical pairs. N: 2 for quad, 8 for lwir16");

			

			gd.addCheckbox    ("Combine all pairs",                                               this.mcorr_cons_all,
					"Combine all calculated correlation pairs");
			gd.addCheckbox    ("Combine diameters",                                               this.mcorr_cons_dia,
@@ -393,7 +420,9 @@ public class ImageDttParameters {
			gd.addNumericField("Height offset of a combined correlation tile",                    this.mcorr_comb_offset,  0, 3, "pix",
					"0 - centered (-height/2 to height/2), height/2 - only positive (0 to height)");
			gd.addNumericField("Relative per-pixel disparity",                                    this.mcorr_comb_disp,  3,6,"pix",
					"Combined tile per-pixel disparity for baseline == side of a square");
					"Combined tile per-pixel disparity for baseline == diameter");
			gd.addCheckbox    ("Debug correlation scaling/rotation for combining",                this.mcorr_comb_dbg,
					"Generate/show correlation pairs scaled/rotated for combining");
			
			gd.addMessage("Window for pole detection mode");
			gd.addNumericField("Strip height for pole detection",                                 this.corr_strip_notch,  0, 3, "half-pix",
@@ -666,6 +695,12 @@ public class ImageDttParameters {
  			this.mcorr_sq_multi =        gd.getNextBoolean();
  			this.mcorr_neib =            gd.getNextBoolean();
  			this.mcorr_neib_multi =      gd.getNextBoolean();
  			
  			this.mcorr_hor =             gd.getNextBoolean();
  			this.mcorr_hor_multi =       gd.getNextBoolean();
  			this.mcorr_vert =            gd.getNextBoolean();
  			this.mcorr_vert_multi =      gd.getNextBoolean();
  			
  			this.mcorr_cons_all =        gd.getNextBoolean();
  			this.mcorr_cons_dia =        gd.getNextBoolean();
  			this.mcorr_cons_sq =         gd.getNextBoolean();
@@ -677,6 +712,7 @@ public class ImageDttParameters {
  			this.mcorr_comb_height=(int) gd.getNextNumber();
  			this.mcorr_comb_offset=(int) gd.getNextNumber();
  			this.mcorr_comb_disp=        gd.getNextNumber();
  			this.mcorr_comb_dbg =        gd.getNextBoolean();
  			
  			this.corr_strip_notch= (int) gd.getNextNumber();
  			this.corr_notch_hwidth=      gd.getNextNumber();
@@ -840,6 +876,12 @@ public class ImageDttParameters {
		properties.setProperty(prefix+"mcorr_sq_multi",       this.mcorr_sq_multi +"");
		properties.setProperty(prefix+"mcorr_neib",           this.mcorr_neib +"");
		properties.setProperty(prefix+"mcorr_neib_multi",     this.mcorr_neib_multi +"");

		properties.setProperty(prefix+"mcorr_hor",            this.mcorr_hor +"");
		properties.setProperty(prefix+"mcorr_hor_multi",      this.mcorr_hor_multi +"");
		properties.setProperty(prefix+"mcorr_vert",           this.mcorr_vert +"");
		properties.setProperty(prefix+"mcorr_vert_multi",     this.mcorr_vert_multi +"");
		
		properties.setProperty(prefix+"mcorr_cons_all",       this.mcorr_cons_all +"");
		properties.setProperty(prefix+"mcorr_cons_dia",       this.mcorr_cons_dia +"");
		properties.setProperty(prefix+"mcorr_cons_sq",        this.mcorr_cons_sq +"");
@@ -851,6 +893,7 @@ public class ImageDttParameters {
		properties.setProperty(prefix+"mcorr_comb_height",    this.mcorr_comb_height +"");
		properties.setProperty(prefix+"mcorr_comb_offset",    this.mcorr_comb_offset +"");
		properties.setProperty(prefix+"mcorr_comb_disp",      this.mcorr_comb_disp +"");
		properties.setProperty(prefix+"mcorr_comb_dbg",       this.mcorr_comb_dbg +"");
		
		properties.setProperty(prefix+"corr_strip_notch",     this.corr_strip_notch +"");
		properties.setProperty(prefix+"corr_notch_hwidth",    this.corr_notch_hwidth +"");
@@ -1018,6 +1061,11 @@ public class ImageDttParameters {
		if (properties.getProperty(prefix+"mcorr_sq_multi")!=null)       this.mcorr_sq_multi=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_sq_multi"));
		if (properties.getProperty(prefix+"mcorr_neib")!=null)           this.mcorr_neib=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_neib"));
		if (properties.getProperty(prefix+"mcorr_neib_multi")!=null)     this.mcorr_neib_multi=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_neib_multi"));
		if (properties.getProperty(prefix+"mcorr_hor")!=null)            this.mcorr_hor=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_hor"));
		if (properties.getProperty(prefix+"mcorr_hor_multi")!=null)      this.mcorr_hor_multi=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_hor_multi"));
		if (properties.getProperty(prefix+"mcorr_vert")!=null)           this.mcorr_vert=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_vert"));
		if (properties.getProperty(prefix+"mcorr_vert_multi")!=null)     this.mcorr_vert_multi=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_vert_multi"));
		
		if (properties.getProperty(prefix+"mcorr_cons_all")!=null)       this.mcorr_cons_all=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_cons_all"));
		if (properties.getProperty(prefix+"mcorr_cons_dia")!=null)       this.mcorr_cons_dia=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_cons_dia"));
		if (properties.getProperty(prefix+"mcorr_cons_sq")!=null)        this.mcorr_cons_sq=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_cons_sq"));
@@ -1029,6 +1077,7 @@ public class ImageDttParameters {
		if (properties.getProperty(prefix+"mcorr_comb_height")!=null)    this.mcorr_comb_height=Integer.parseInt(properties.getProperty(prefix+"mcorr_comb_height"));
		if (properties.getProperty(prefix+"mcorr_comb_offset")!=null)    this.mcorr_comb_offset=Integer.parseInt(properties.getProperty(prefix+"mcorr_comb_offset"));
		if (properties.getProperty(prefix+"mcorr_comb_disp")!=null)      this.mcorr_comb_disp=Double.parseDouble(properties.getProperty(prefix+"mcorr_comb_disp"));
		if (properties.getProperty(prefix+"mcorr_comb_dbg")!=null)       this.mcorr_comb_dbg=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_comb_dbg"));
		
		if (properties.getProperty(prefix+"corr_strip_notch")!=null)     this.corr_strip_notch=Integer.parseInt(properties.getProperty(prefix+"corr_strip_notch"));
		if (properties.getProperty(prefix+"corr_notch_hwidth")!=null)    this.corr_notch_hwidth=Double.parseDouble(properties.getProperty(prefix+"corr_notch_hwidth"));
@@ -1192,6 +1241,12 @@ public class ImageDttParameters {
		idp.mcorr_sq_multi=          this.mcorr_sq_multi;
		idp.mcorr_neib=              this.mcorr_neib;
		idp.mcorr_neib_multi=        this.mcorr_neib_multi;
		
		idp.mcorr_hor=               this.mcorr_hor;
		idp.mcorr_hor_multi=         this.mcorr_hor_multi;
		idp.mcorr_vert=              this.mcorr_vert;
		idp.mcorr_vert_multi=        this.mcorr_vert_multi;
		
		idp.mcorr_cons_all=          this.mcorr_cons_all;
		idp.mcorr_cons_dia=          this.mcorr_cons_dia;
		idp.mcorr_cons_sq=           this.mcorr_cons_sq;
@@ -1203,6 +1258,7 @@ public class ImageDttParameters {
		idp.mcorr_comb_height=       this.mcorr_comb_height;
		idp.mcorr_comb_offset=       this.mcorr_comb_offset;
		idp.mcorr_comb_disp=         this.mcorr_comb_disp;
		idp.mcorr_comb_dbg=          this.mcorr_comb_dbg;
		
		idp.corr_strip_notch=        this.corr_strip_notch;
		idp.corr_notch_hwidth=       this.corr_notch_hwidth;
+27 −7
Original line number Diff line number Diff line
@@ -4650,6 +4650,7 @@ public class QuadCLTCPU {
//		  double [][][][][]   clt_corr_partial = null; // [tp.tilesY][tp.tilesX][pair][color][(2*transform_size-1)*(2*transform_size-1)]
		  double [][][][]     clt_corr_out =     null; // will be used instead of clt_corr_partial
		  double [][][][]     clt_combo_out =    null; // will be used instead of clt_corr_combo
		  double [][][][]     clt_combo_dbg =    null; // generate partial rotated/scaled pairs
		  double [][][][]     texture_tiles =    null; // [tp.tilesY][tp.tilesX]["RGBA".length()][]; // tiles will be 16x16, 2 visualization mode full 16 or overlapped
		  double [][]         disparity_map =    null;
		  // undecided, so 2 modes of combining alpha - same as rgb, or use center tile only
@@ -4669,14 +4670,9 @@ public class QuadCLTCPU {
				  int num_combo = correlation2d.getComboTitles().length;
				  clt_corr_out = new double [num_pairs][][][];
				  clt_combo_out = new double [num_combo][][][];
				  /*
				  clt_corr_partial = new double [tilesY][tilesX][][][];
				  for (int i = 0; i < tilesY; i++){
					  for (int j = 0; j < tilesX; j++){
						  clt_corr_partial[i][j] = null;
					  }
				  if (clt_parameters.img_dtt.mcorr_comb_dbg) {
					  clt_combo_dbg = new double [num_pairs][][][];
				  }
				  */
			  } // clt_parameters.corr_mismatch = false
			  disparity_map = new double [ImageDtt.DISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging) last 4 - max pixel differences
		  }
@@ -4725,6 +4721,7 @@ public class QuadCLTCPU {
				  // correlation results
				  clt_corr_out,   // final double [][][][]     clt_corr_out,   // sparse (by the first index) [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] or null
				  clt_combo_out,  // final double [][][][]     clt_combo_out,  // sparse (by the first index) [type][tilesY][tilesX][(combo_tile_size] or null
				  clt_combo_dbg,  // final double [][][][]     clt_combo_dbg,  // generate sparse  partial rotated/scaled pairs
				  disparity_map,                // [2][tp.tilesY * tp.tilesX]
	 			  texture_tiles,                // [tp.tilesY][tp.tilesX]["RGBA".length()][];
				  imp_quad[0].getWidth(),       // final int width,
@@ -4778,6 +4775,8 @@ public class QuadCLTCPU {
					  +" clt_data[0]["+first_color+"].length="+clt_data[0][first_color].length+" clt_data[0]["+first_color+"][0].length="+
					  clt_data[0][first_color][0].length);
		  }
		  //clt_corr_out = null;
		  //clt_combo_out = null;
		  // visualize texture tiles as RGBA slices
		  double [][] texture_nonoverlap = null;
		  double [][] texture_overlap = null;
@@ -5065,6 +5064,27 @@ public class QuadCLTCPU {
			  }
		  }
		  
		  if (!batch_mode && !infinity_corr && (clt_combo_dbg != null)){
			  if (debugLevel > -2){ // -1
				  String [] titles =  image_dtt.correlation2d.getCorrTitles();
				  double [][] corr_rslt = ImageDtt.corr_partial_dbg(
						  clt_combo_dbg, // final double [][][][] corr_data,
						  clt_parameters.img_dtt.mcorr_comb_width,	// final int             corr_width,
						  clt_parameters.img_dtt.mcorr_comb_height,	// final int             corr_height
						  threadsMax,
						  debugLevel);
				  // titles.length = 15, corr_rslt_partial.length=16!
				  System.out.println("corr_rslt.length = "+corr_rslt.length+", titles.length = "+titles.length);
				  sdfa_instance.showArrays( // out of boundary 15
						  corr_rslt,
						  tilesX * (clt_parameters.img_dtt.mcorr_comb_width + 1),
						  tilesY * (clt_parameters.img_dtt.mcorr_comb_height + 1),
						  true,
						  image_name+sAux()+"-COMBO-DBG-D"+clt_parameters.disparity,
						  titles);
			  }
		  }
		  
		  double [][][] iclt_data = new double [clt_data.length][][];
		  if (!infinity_corr && (clt_parameters.gen_chn_img || clt_parameters.gen_4_img || clt_parameters.gen_chn_stacks)) {