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

Implementing FG/BG split of far tiles with small disparity difference

parent df71e1d0
Loading
Loading
Loading
Loading
+99 −7
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.common.GenericJTabbedDialog;


public class BiQuadParameters {
public class BiQuadParameters {
	private static final String [] FSPLIT_MODES= {"disabled","avg->fg+bg","avg->fg+bg:fg:bg"};
	public boolean rig_mode_debug =            true;
	public boolean rig_mode_debug =            true;
	public boolean no_int_x0 =                 true; // do not offset window to integer maximum for the rig - used when averaging low textures to avoid "jumps" for very wide maximums
	public boolean no_int_x0 =                 true; // do not offset window to integer maximum for the rig - used when averaging low textures to avoid "jumps" for very wide maximums
	public boolean use_poly =                  true;
	public boolean use_poly =                  true;
@@ -249,7 +250,7 @@ public class BiQuadParameters {
	
	
// calculating GT	
// calculating GT	


	
	// now used not just for ML, but for any interscene depth maps
	public double  mll_min_disp_change_pre =   0.03; // stop re-measure when difference is below, no-LMA, 40 pairs
	public double  mll_min_disp_change_pre =   0.03; // stop re-measure when difference is below, no-LMA, 40 pairs
	public int     mll_max_refines_pre =       5;
	public int     mll_max_refines_pre =       5;
	public double  mll_min_disp_change_lma =   0.003; // stop re-measure when difference is below, LMA, 120 pairs
	public double  mll_min_disp_change_lma =   0.003; // stop re-measure when difference is below, LMA, 120 pairs
@@ -257,6 +258,18 @@ public class BiQuadParameters {
	public int     mll_max_refines_bg =        5;
	public int     mll_max_refines_bg =        5;
	public int     mll_max_bg_nearest =        1; // number of selecting BG until switching to "nearest" to prevent switching to BG of BG
	public int     mll_max_bg_nearest =        1; // number of selecting BG until switching to "nearest" to prevent switching to BG of BG
	
	
	// FG/BG split for far tiles where dual max can only be detected with LMA as it is too small 
	public boolean fsplit_en =                 true; // enable split of far tiles into FG/BG with LMA
	public int     fsplit_mode =               1; // 0: disable, 1:avg->fg+bg, 2: avg->fg+fg:fg:bg
	public double  fsplit_str =                0.4; // minimal strength of the tile to split
	public int     fsplit_neibs =              3;   // minimal number of neighbors to consider split
	public int     fsplit_neibs_side =         2;   // *** minimal number of on each side (for thin FG over BG)
	public double  fsplit_neib_str =           0.4; // minimal strength of the neighbor to compare
	public double  fsplit_neib_diff =          1.5; // *** maximal disparity difference to neighbor to use 
	public double  fsplit_disp =               3.0; // maximal tile disparity to consider split.
	public double  fsplit_adiff =              0.04;// minimal tile (combo) absolute disparity difference from neighbors
	public double  fsplit_rdiff =              0.1; // minimal tile (combo) relative disparity difference from neighbors
	public double  fsplit_kfg_min =            0.1; // *** minimal fraction of kfg and (1.0-kfg)
	
	
	public boolean mll_generate_scene_outlines = false; // Uses 2 GB - change format, add dimensions (separate color for ref)
	public boolean mll_generate_scene_outlines = false; // Uses 2 GB - change format, add dimensions (separate color for ref)
	
	
@@ -703,6 +716,33 @@ public class BiQuadParameters {
				"Measure BG disparity for the tiles that have dual correlation maximums");
				"Measure BG disparity for the tiles that have dual correlation maximums");
		gd.addNumericField("Number of BG passes until switching to the \"nearest\" selection",                     this.mll_max_bg_nearest,  0,3,"",
		gd.addNumericField("Number of BG passes until switching to the \"nearest\" selection",                     this.mll_max_bg_nearest,  0,3,"",
				"only for the first BG passes select BG, later switch to \"nearest\" selection to prevent cascade FG->BG,... FG->BG switching");
				"only for the first BG passes select BG, later switch to \"nearest\" selection to prevent cascade FG->BG,... FG->BG switching");
		
		gd.addMessage("FG/BG split for far tiles with LMA");
		gd.addCheckbox    ("Enable far FG/BG split with LMA",                                                      this.fsplit_en,
				"Enable split of far tiles into FG/BG with LMA");
		gd. addChoice("FG/BG split mode",                                               FSPLIT_MODES, FSPLIT_MODES[this.fsplit_mode], 
				"Passes: AVG->.. (start from unresolved maximums), FG - foreground in/out, BG - background in/out");
		gd.addNumericField("Minimal tile strength",                                                                this.fsplit_str,      3,6,"",
				"Minimal tile strength to consider splitting into FG/BG pair.");
		gd.addNumericField("Minimal neighbors",                                                                    this.fsplit_neibs,    0,3,"",
				"Minimal number of tile nighbors (of 8) to consider splitting.");
		gd.addNumericField("Minimal neighbors on each side (for thin FG over BG)",                                 this.fsplit_neibs_side,0,3,"",
				"minimal number of on each side (for thin FG over BG).");
		gd.addNumericField("Minimal neighbor strength",                                                            this.fsplit_neib_str, 3,6,"",
				"Minimal tile neighbor strength to consider use for average.");
		gd.addNumericField("Maximal neighbor difference from center",                                              this.fsplit_neib_diff,3,6,"pix",
				"Maximal disparity difference to neighbor from the center to use.");
		
		gd.addNumericField("Maximal FG/BG split disparity",                                                        this.fsplit_disp, 3,6,"pix",
				"Maximal tile disparity to consider split.");
		gd.addNumericField("Maximal absolute disparity difference for FG/BG split",                                this.fsplit_adiff, 3,6,"pix",
				"Maximal absolute disparity difference from average of neighbors for FG/BG split.");
		gd.addNumericField("Maximal relative disparity difference for FG/BG split",                                this.fsplit_rdiff, 3,6,"",
				"Maximal relative (to average) disparity difference from average of neighbors for FG/BG split.");
		gd.addNumericField("Minimal kFG fraction",                                                                 this.fsplit_kfg_min, 3,6,"",
				"Minimal fraction of kfg and (1.0-kfg).");
		
		gd.addMessage("Other");
		gd.addCheckbox    ("Generate scene outlines",                                                              this.mll_generate_scene_outlines,
		gd.addCheckbox    ("Generate scene outlines",                                                              this.mll_generate_scene_outlines,
				"Generate and save scene outlines for scene series (need to change format, it is 2GB with uncompressed Tiff)");
				"Generate and save scene outlines for scene series (need to change format, it is 2GB with uncompressed Tiff)");
		
		
@@ -1007,6 +1047,19 @@ public class BiQuadParameters {
		this.mll_max_refines_lma=     (int) gd.getNextNumber();
		this.mll_max_refines_lma=     (int) gd.getNextNumber();
		this.mll_max_refines_bg=      (int) gd.getNextNumber();
		this.mll_max_refines_bg=      (int) gd.getNextNumber();
		this.mll_max_bg_nearest=      (int) gd.getNextNumber();
		this.mll_max_bg_nearest=      (int) gd.getNextNumber();

		this.fsplit_en =                    gd.getNextBoolean();
		this.fsplit_mode =                  gd.getNextChoiceIndex();
		this.fsplit_str =                   gd.getNextNumber();
		this.fsplit_neibs =           (int) gd.getNextNumber();
		this.fsplit_neibs_side =      (int) gd.getNextNumber();
		this.fsplit_neib_str =              gd.getNextNumber();
		this.fsplit_neib_diff =             gd.getNextNumber();
		this.fsplit_disp =                  gd.getNextNumber();
		this.fsplit_adiff =                 gd.getNextNumber();
		this.fsplit_rdiff =                 gd.getNextNumber();
		this.fsplit_kfg_min =               gd.getNextNumber();
		
		this.mll_generate_scene_outlines=   gd.getNextBoolean();
		this.mll_generate_scene_outlines=   gd.getNextBoolean();
		
		
		this.mll_add_combo=                 gd.getNextBoolean();
		this.mll_add_combo=                 gd.getNextBoolean();
@@ -1258,6 +1311,19 @@ public class BiQuadParameters {
		properties.setProperty(prefix+"mll_max_refines_lma",       this.mll_max_refines_lma+"");
		properties.setProperty(prefix+"mll_max_refines_lma",       this.mll_max_refines_lma+"");
		properties.setProperty(prefix+"mll_max_refines_bg",        this.mll_max_refines_bg+"");
		properties.setProperty(prefix+"mll_max_refines_bg",        this.mll_max_refines_bg+"");
		properties.setProperty(prefix+"mll_max_bg_nearest",        this.mll_max_bg_nearest+"");
		properties.setProperty(prefix+"mll_max_bg_nearest",        this.mll_max_bg_nearest+"");
		
		properties.setProperty(prefix+"fsplit_en",                 this.fsplit_en+"");        // boolean
		properties.setProperty(prefix+"fsplit_mode",               this.fsplit_mode+"");      // int
		properties.setProperty(prefix+"fsplit_str",                this.fsplit_str+"");       // double
		properties.setProperty(prefix+"fsplit_neibs",              this.fsplit_neibs+"");     // int
		properties.setProperty(prefix+"fsplit_neibs_side",         this.fsplit_neibs_side+"");// int
		properties.setProperty(prefix+"fsplit_neib_str",           this.fsplit_neib_str+"");  // double
		properties.setProperty(prefix+"fsplit_neib_diff",          this.fsplit_neib_diff+""); // double
		properties.setProperty(prefix+"fsplit_disp",               this.fsplit_disp+"");      // double
		properties.setProperty(prefix+"fsplit_adiff",              this.fsplit_adiff+"");     // double
		properties.setProperty(prefix+"fsplit_rdiff",              this.fsplit_rdiff+"");     // double
		properties.setProperty(prefix+"fsplit_kfg_min",            this.fsplit_kfg_min+"");   // double
		
		properties.setProperty(prefix+"mll_generate_scene_outlines",this.mll_generate_scene_outlines+"");
		properties.setProperty(prefix+"mll_generate_scene_outlines",this.mll_generate_scene_outlines+"");
		
		
		properties.setProperty(prefix+"mll_add_combo",             this.mll_add_combo+"");
		properties.setProperty(prefix+"mll_add_combo",             this.mll_add_combo+"");
@@ -1506,6 +1572,19 @@ public class BiQuadParameters {
		if (properties.getProperty(prefix+"mll_max_refines_lma")!=null)     this.mll_max_refines_lma=Integer.parseInt(properties.getProperty(prefix+"mll_max_refines_lma"));
		if (properties.getProperty(prefix+"mll_max_refines_lma")!=null)     this.mll_max_refines_lma=Integer.parseInt(properties.getProperty(prefix+"mll_max_refines_lma"));
		if (properties.getProperty(prefix+"mll_max_refines_bg")!=null)      this.mll_max_refines_bg=Integer.parseInt(properties.getProperty(prefix+"mll_max_refines_bg"));
		if (properties.getProperty(prefix+"mll_max_refines_bg")!=null)      this.mll_max_refines_bg=Integer.parseInt(properties.getProperty(prefix+"mll_max_refines_bg"));
		if (properties.getProperty(prefix+"mll_max_bg_nearest")!=null)      this.mll_max_bg_nearest=Integer.parseInt(properties.getProperty(prefix+"mll_max_bg_nearest"));
		if (properties.getProperty(prefix+"mll_max_bg_nearest")!=null)      this.mll_max_bg_nearest=Integer.parseInt(properties.getProperty(prefix+"mll_max_bg_nearest"));
		
		if (properties.getProperty(prefix+"fsplit_en")!=null)               this.fsplit_en=Boolean.parseBoolean(properties.getProperty(prefix+"fsplit_en"));
		if (properties.getProperty(prefix+"fsplit_mode")!=null)             this.fsplit_mode=Integer.parseInt(properties.getProperty(prefix+"fsplit_mode"));
		if (properties.getProperty(prefix+"fsplit_str")!=null)              this.fsplit_str=Double.parseDouble(properties.getProperty(prefix+"fsplit_str"));
		if (properties.getProperty(prefix+"fsplit_neibs")!=null)            this.fsplit_neibs=Integer.parseInt(properties.getProperty(prefix+"fsplit_neibs"));
		if (properties.getProperty(prefix+"fsplit_neibs_side")!=null)       this.fsplit_neibs_side=Integer.parseInt(properties.getProperty(prefix+"fsplit_neibs_side"));
		if (properties.getProperty(prefix+"fsplit_neib_str")!=null)         this.fsplit_neib_str=Double.parseDouble(properties.getProperty(prefix+"fsplit_neib_str"));
		if (properties.getProperty(prefix+"fsplit_neib_diff")!=null)        this.fsplit_neib_diff=Double.parseDouble(properties.getProperty(prefix+"fsplit_neib_diff"));
		if (properties.getProperty(prefix+"fsplit_disp")!=null)             this.fsplit_disp=Double.parseDouble(properties.getProperty(prefix+"fsplit_disp"));
		if (properties.getProperty(prefix+"fsplit_adiff")!=null)            this.fsplit_adiff=Double.parseDouble(properties.getProperty(prefix+"fsplit_adiff"));
		if (properties.getProperty(prefix+"fsplit_rdiff")!=null)            this.fsplit_rdiff=Double.parseDouble(properties.getProperty(prefix+"fsplit_rdiff"));
		if (properties.getProperty(prefix+"fsplit_kfg_min")!=null)          this.fsplit_kfg_min=Double.parseDouble(properties.getProperty(prefix+"fsplit_kfg_min"));
		
		if (properties.getProperty(prefix+"mll_generate_scene_outlines")!=null) this.mll_generate_scene_outlines=Boolean.parseBoolean(properties.getProperty(prefix+"mll_generate_scene_outlines"));
		if (properties.getProperty(prefix+"mll_generate_scene_outlines")!=null) this.mll_generate_scene_outlines=Boolean.parseBoolean(properties.getProperty(prefix+"mll_generate_scene_outlines"));
		
		
		if (properties.getProperty(prefix+"mll_add_combo")!=null)           this.mll_add_combo=Boolean.parseBoolean(properties.getProperty(prefix+"mll_add_combo"));
		if (properties.getProperty(prefix+"mll_add_combo")!=null)           this.mll_add_combo=Boolean.parseBoolean(properties.getProperty(prefix+"mll_add_combo"));
@@ -1754,6 +1833,19 @@ public class BiQuadParameters {
		bqp.mll_max_refines_lma =       this.mll_max_refines_lma;
		bqp.mll_max_refines_lma =       this.mll_max_refines_lma;
		bqp.mll_max_refines_bg =        this.mll_max_refines_bg;
		bqp.mll_max_refines_bg =        this.mll_max_refines_bg;
		bqp.mll_max_bg_nearest =        this.mll_max_bg_nearest;
		bqp.mll_max_bg_nearest =        this.mll_max_bg_nearest;
		
		bqp.fsplit_en =                 this.fsplit_en;       	
        bqp.fsplit_mode =               this.fsplit_mode;     
        bqp.fsplit_str =                this.fsplit_str;      
        bqp.fsplit_neibs =              this.fsplit_neibs;    
        bqp.fsplit_neibs_side =         this.fsplit_neibs_side;    
        bqp.fsplit_neib_str =           this.fsplit_neib_str; 
        bqp.fsplit_neib_diff =          this.fsplit_neib_diff; 
        bqp.fsplit_disp =               this.fsplit_disp;     
        bqp.fsplit_adiff =              this.fsplit_adiff;    
        bqp.fsplit_rdiff =              this.fsplit_rdiff;    		
        bqp.fsplit_kfg_min =            this.fsplit_kfg_min;    		
		
		bqp.mll_generate_scene_outlines = this.mll_generate_scene_outlines;
		bqp.mll_generate_scene_outlines = this.mll_generate_scene_outlines;
		
		
		bqp.mll_add_combo =             this.mll_add_combo;
		bqp.mll_add_combo =             this.mll_add_combo;
+125 −23
Original line number Original line Diff line number Diff line
@@ -1742,6 +1742,7 @@ public class ImageDtt extends ImageDttCPU {
	        final int                 gpu_corr_rad,    // = transform_size - 1 ?
	        final int                 gpu_corr_rad,    // = transform_size - 1 ?
	        // The tp_tasks data should be decoded from GPU to get coordinates
	        // The tp_tasks data should be decoded from GPU to get coordinates
			final TpTask []           tp_tasks,        // data from the reference frame - will be applied to LMA for the integrated correlations
			final TpTask []           tp_tasks,        // data from the reference frame - will be applied to LMA for the integrated correlations
			final double [][]         far_fgbg,        // null, or [nTile]{disp(fg)-disp(bg), str(fg)-str(bg)} hints for LMA FG/BG split 
			final double [][]         rXY,             // from geometryCorrection
			final double [][]         rXY,             // from geometryCorrection
			// next both can be nulls
			// next both can be nulls
		    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_corr_out,   // sparse (by the first index) [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] or null
@@ -1957,6 +1958,7 @@ public class ImageDtt extends ImageDttCPU {
							if (fcorr_td[tileY][tileX] == null) {
							if (fcorr_td[tileY][tileX] == null) {
								continue; // nothing accumulated for this tile 
								continue; // nothing accumulated for this tile 
							}
							}
//							boolean dbg_val=globalDebugLevel>100;
							nTile = tileY * tilesX + tileX;
							nTile = tileY * tilesX + tileX;
							if (tp_tasks[iTile].getTask() == 0) continue; // nothing to do for this tile
							if (tp_tasks[iTile].getTask() == 0) continue; // nothing to do for this tile
							boolean debugTile0 =(tileX == debug_tileX) && (tileY == debug_tileY) && (globalDebugLevel > 0); // 1);
							boolean debugTile0 =(tileX == debug_tileX) && (tileY == debug_tileY) && (globalDebugLevel > 0); // 1);
@@ -2090,6 +2092,7 @@ public class ImageDtt extends ImageDttCPU {
								double [][] disp_str_sel = null;
								double [][] disp_str_sel = null;
								double [][] disp_str_lma = null;
								double [][] disp_str_lma = null;
								int [] sel_fg_bg = null;
								int [] sel_fg_bg = null;
								boolean use_far_fgbg = false;
								// now use older LMA (single-max) when LY is needed
								// now use older LMA (single-max) when LY is needed
								if (imgdtt_params.bimax_dual_LMA && (ddnd == null)) {
								if (imgdtt_params.bimax_dual_LMA && (ddnd == null)) {
									double [][] maxes = correlation2d.getDoublePoly(
									double [][] maxes = correlation2d.getDoublePoly(
@@ -2098,6 +2101,24 @@ public class ImageDtt extends ImageDttCPU {
											imgdtt_params.mcorr_dual_fract,    // double    min_fraction
											imgdtt_params.mcorr_dual_fract,    // double    min_fraction
											imgdtt_params.mcorr_dual_min_max,  // double    min_max, // =      0.2;  // Minimal absolute strength of the strongest in a dual-max to consider second one
											imgdtt_params.mcorr_dual_min_max,  // double    min_max, // =      0.2;  // Minimal absolute strength of the strongest in a dual-max to consider second one
											imgdtt_params.mcorr_dual_min_min); // double    min_min);  // =      0.08; // Minimal absolute strength of a weakest in a dual-max to consider second one
											imgdtt_params.mcorr_dual_min_min); // double    min_min);  // =      0.08; // Minimal absolute strength of a weakest in a dual-max to consider second one
									// calculate hints for LMA when FG and BG are too close to be separated
									// and separation data is provided externally
									if ((far_fgbg != null)  && (far_fgbg[nTile] != null)) { // only if run_lma
										if (!run_lma) {
											continue; // this mode is defined only for LMA
										}
										if (maxes.length == 1) { // normally should be just one. If 2 - OK, use old splitting (abnormal)
											maxes =  split_far_max(
													maxes[0],           // double [] max,
													far_fgbg[nTile][0], // double diff,
													far_fgbg[nTile][1], // double kfg,
													imgdtt_params.mcorr_dual_fract); // 0.1); // double min_k);
											if (maxes == null) {
												continue;
											}
										}
										use_far_fgbg = true;
									}
									if ((disparity_map != null) && (disparity_map[DISPARITY_VARIATIONS_INDEX] != null)) {
									if ((disparity_map != null) && (disparity_map[DISPARITY_VARIATIONS_INDEX] != null)) {
										disparity_map[DISPARITY_VARIATIONS_INDEX    ][nTile] = maxes.length;
										disparity_map[DISPARITY_VARIATIONS_INDEX    ][nTile] = maxes.length;
									}
									}
@@ -2127,8 +2148,12 @@ public class ImageDtt extends ImageDttCPU {
													imgdtt_params.bimax_combine_mode, // int                 combine_mode,   // 0 - both,  1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
													imgdtt_params.bimax_combine_mode, // int                 combine_mode,   // 0 - both,  1 - strongest, 2 - nearest to zero, 3 - FG, 4 - BG
													maxes);                           // double[][]          disp_str_dual)  // -preliminary center x in pixels for largest baseline
													maxes);                           // double[][]          disp_str_dual)  // -preliminary center x in pixels for largest baseline
											int combine_mode_corrected = imgdtt_params.bimax_combine_mode;
											int combine_mode_corrected = imgdtt_params.bimax_combine_mode;
											// Simplify - no need to backup single max - just fail, it should be already known
											if (    (maxes[sel_fg_bg[0]][1] < imgdtt_params.mcorr_fb_fract * maxes[sel_fg_bg[1]][1]) ||
											if (    (maxes[sel_fg_bg[0]][1] < imgdtt_params.mcorr_fb_fract * maxes[sel_fg_bg[1]][1]) ||
													(maxes[sel_fg_bg[1]][1] < imgdtt_params.mcorr_bf_fract * maxes[sel_fg_bg[0]][1])) {
													(maxes[sel_fg_bg[1]][1] < imgdtt_params.mcorr_bf_fract * maxes[sel_fg_bg[0]][1])) {
												if (use_far_fgbg) {
													continue; // requires both maximums (should not happen)
												}
												//maxes = new double [][] {maxes[0]}; // strongest
												//maxes = new double [][] {maxes[0]}; // strongest
												disp_str_sel = new double [][] {maxes[0]}; // strongest
												disp_str_sel = new double [][] {maxes[0]}; // strongest
												sel_max = 0;
												sel_max = 0;
@@ -2159,7 +2184,7 @@ public class ImageDtt extends ImageDttCPU {
														(debugTile0 ? 1: -2),         // int                 debug_level,
														(debugTile0 ? 1: -2),         // int                 debug_level,
														tileX,                        // int                 tileX, // just for debug output
														tileX,                        // int                 tileX, // just for debug output
														tileY );
														tileY );
												if (debugTile1 && (lma_dual!= null)) { // addad (lma_dual != null)
												if (debugTile1 && (lma_dual!= null)) { // added (lma_dual != null)
													System.out.println("clt_process_tl_correlations() corrLMA2DualMax() done, lma_dual="+
													System.out.println("clt_process_tl_correlations() corrLMA2DualMax() done, lma_dual="+
															((lma_dual== null)? "null": " not null"));
															((lma_dual== null)? "null": " not null"));
												}
												}
@@ -2190,10 +2215,10 @@ public class ImageDtt extends ImageDttCPU {
															}
															}
														}
														}
													}
													}
													if (imgdtt_params.bimax_post_LMA && (sel_max >=0)) {
													if (!use_far_fgbg && imgdtt_params.bimax_post_LMA && (sel_max >=0)) { // ?? 04/09/2023 - added use_far_fgbg
														disp_str_lma = new double [][] {disp_str_lma[sel_max]}; // was already selected before LMA
														disp_str_lma = new double [][] {disp_str_lma[sel_max]}; // was already selected before LMA
													}
													}
												} // if (lma_dual != null) {
												} 
											}
											}
										} // no positive maximums on y==0 - nothing in this tile
										} // no positive maximums on y==0 - nothing in this tile
									}
									}
@@ -2206,6 +2231,22 @@ public class ImageDtt extends ImageDttCPU {
											}
											}
										}
										}
										if (disparity_map != null) {
										if (disparity_map != null) {
											// In this new mode only set if there are 2 maximums.
											// Set FG DS to DISPARITY_INDEX_POLY, BG DS to DISPARITY_INDEX_POLY (instead of non-LMA)
											if (use_far_fgbg) {
												if ((disp_str_lma!=null) && // only if both maximums are OK, otherwise keep Double.NaN
														(disp_str_lma.length > 1) &&
														!Double.isNaN(disp_str_lma[0][0]) &&
														!Double.isNaN(disp_str_lma[1][0])) {
													int indx = sel_fg_bg[0];
													// set FG to DISPARITY_INDEX_POLY/DISPARITY_INDEX_POLY+1
													disparity_map[DISPARITY_INDEX_POLY    ][nTile] = disp_str_lma[indx][0]; // disparity LMA
													disparity_map[DISPARITY_INDEX_POLY + 1][nTile] = disp_str_lma[indx][2]; // strength LMA
													// set BG to DISPARITY_INDEX_CM/DISPARITY_INDEX_CM+1
													disparity_map[DISPARITY_INDEX_CM    ][nTile] = disp_str_lma[1-indx][0]; // disparity LMA
													disparity_map[DISPARITY_INDEX_CM + 1][nTile] = disp_str_lma[1-indx][2]; // strength LMA
												}
											} else {
												disparity_map[DISPARITY_INDEX_CM      ][nTile] = disp_str_sel[0][0]; // disparity non-LMA
												disparity_map[DISPARITY_INDEX_CM      ][nTile] = disp_str_sel[0][0]; // disparity non-LMA
												disparity_map[DISPARITY_INDEX_CM + 1  ][nTile] = disp_str_sel[0][1]; // strength non-LMA;
												disparity_map[DISPARITY_INDEX_CM + 1  ][nTile] = disp_str_sel[0][1]; // strength non-LMA;
												disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str_sel[0][1]; // strength non-LMA;
												disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str_sel[0][1]; // strength non-LMA;
@@ -2214,16 +2255,13 @@ public class ImageDtt extends ImageDttCPU {
														if (!Double.isNaN(disp_str_lma[0][0])) {
														if (!Double.isNaN(disp_str_lma[0][0])) {
															disparity_map[DISPARITY_INDEX_POLY    ][nTile] = disp_str_lma[0][0]; // disparity LMA
															disparity_map[DISPARITY_INDEX_POLY    ][nTile] = disp_str_lma[0][0]; // disparity LMA
															disparity_map[DISPARITY_INDEX_POLY + 1][nTile] = disp_str_lma[0][2]; // strength LMA
															disparity_map[DISPARITY_INDEX_POLY + 1][nTile] = disp_str_lma[0][2]; // strength LMA
														// keep strength from CM strength (not LMA)
//														disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str_lma[0][1]; // overwrite with LMA strength
														}
														}
													} else {
													} else {
														int indx = sel_fg_bg[0];
														int indx = sel_fg_bg[0];
														if (!Double.isNaN(disp_str_lma[indx][0])) {
														if (!Double.isNaN(disp_str_lma[indx][0])) {
															disparity_map[DISPARITY_INDEX_POLY    ][nTile] = disp_str_lma[indx][0]; // disparity LMA
															disparity_map[DISPARITY_INDEX_POLY    ][nTile] = disp_str_lma[indx][0]; // disparity LMA
															disparity_map[DISPARITY_INDEX_POLY + 1][nTile] = disp_str_lma[indx][2]; // strength LMA
															disparity_map[DISPARITY_INDEX_POLY + 1][nTile] = disp_str_lma[indx][2]; // strength LMA
														// keep strength from CM strength (not LMA)
														}
//														disparity_map[DISPARITY_STRENGTH_INDEX][nTile] = disp_str_lma[indx][1]; // overwrite with LMA strength
													}
													}
												}
												}
											}
											}
@@ -2397,8 +2435,72 @@ public class ImageDtt extends ImageDttCPU {
		return;
		return;
	}	
	}	
	
	
	/**
	 * Helper method for clt_process_tl_correlations - split unresolved dual maximum for far (low disparity) tiles
	 * into a pair of FG and BG one to use as initial settings for LMA.
	 * 
	 * There are 3 operation modes encoded by 0.0 for one of the diff or kfg parameters:
	 *    a) Target disparity used for 2D phase correlations was provided for combined (unresolved) maximums.
	 *       Calculated maximums are around the unresolved disparity, at diff distance, sum of weights equals
	 *       to the max[1] (combined strength). 
	 *    b) Target disparity was provided for FG maximum. This is indicated by diff = 0.0. In this case
	 *       disparity of the FG is 0.0, disparity of the BG is calculated so their center of mass is at max[0].
	 *    c) Target disparity is provided for BG - it is calculated after FG is known, so the caller knows diff.
	 *       This mode is indicated by kfg = 0.0. Disparity of BG is set to 0, disparity of FG - to diff, and
	 *       weights are calculated   
	 * @param max a pair of {disparity,strength} calculated from the correlation without resolving dual maximim.
	 * @param diff expected difference between FG and BG disparities provided by the caller.
	 * @param kfg fraction (0..1) of FG maximum weight of the full max[1] strength
	 * @param min_k minimal kfg and (1-kfg) if one maximum is much weaker than another
	 * @return a pair of {disparity, strength} pairs for FG and BG maximums as a seed for LMA, ordered starting
	 *        with a stronger maximums (same as maxes[][] in the caller). Returns null if result does not make sense.  
	 */
	public static double [][] split_far_max(
			double [] max,
			double diff,
			double kfg,
			double min_k){
		if ((kfg > 0) && ((kfg < min_k) || ((1.0 - kfg) < min_k))) {
			return null; // one of the maximums is too weak with respect to the other
		}
		double [][] maxes = new double [2][2];
		if (diff == 0) { // target is FG
			if (kfg <= 0) {
				return null; //diff and kfg can not be 0.0 simultaneously (or use this case for something?)
			}
			if (max[0] >= 0) { // combo disparity should be negative
				return null;
			}
			maxes[0][0] = 0.0;                               // disparity(FG)
			maxes[1][0] = max[0] / kfg;                      // disparity(BG)
			maxes[0][1] = max[1] * kfg;                      // strength(FG)
			maxes[1][1] = max[1] * (1.0 - kfg);              // strength(BG)
			
			
		} else if (kfg == 0) { // target is BG
			if ((max[0] <= 0.0) || (max[0] >= diff)) {
				return null; // averaged max should have positive disparity < diff
			}
			maxes[0][0] = diff;                              // disparity(FG)
			maxes[1][0] = 0.0;                               // disparity(BG)
			maxes[0][1] = max[1] * (max[0] / diff);          // strength(FG)
			maxes[1][1] = max[1] * ((diff - max[0]) / diff); // strength(BG)
		} else { // target is unresolved merged maximums
			maxes[0][0] = max[0] + diff * (1.0 - kfg);                // disparity(FG)
			maxes[1][0] = max[0] - diff * kfg;                        // disparity(BG)
			maxes[0][1] = max[1] * kfg;                               // strength(FG)
			maxes[1][1] = max[1] * (1.0 - kfg);                       // strength(BG)
		}
		if (maxes[1][1] > maxes[0][1]) {
			double [] tmp = maxes[0];
			maxes[0] = maxes[1];
			maxes[1]= tmp;
		}
		if ((maxes[0][1] / maxes[1][1]) > (1.0 - min_k)/min_k) {
			return null; // too large difference between strong and weak;  
		}
		return maxes;
		
		
	}
	
	
	
	
	
	
+2 −2
Original line number Original line Diff line number Diff line
@@ -516,8 +516,8 @@ public class IntersceneMatchParameters {
				"Blur weak sigma");
				"Blur weak sigma");
		gd.addNumericField("Number of blur passes",                  this.num_blur, 0,3,"",
		gd.addNumericField("Number of blur passes",                  this.num_blur, 0,3,"",
				"Number of blur passes");
				"Number of blur passes");
		gd.addNumericField("Disparity offset (not used)",            this.disparity_corr, 5,7,"",
		gd.addNumericField("*** Disparity offset (used 04/07/2023) ***",     this.disparity_corr, 5,7,"",
				"for setInterTasks() - currently not used ");
				"for setInterTasks() - used 04/07/2023.");
		gd.addNumericField("Outlier N-th from extreme",              this.outliers_nth_fromextrem, 0,3,"",
		gd.addNumericField("Outlier N-th from extreme",              this.outliers_nth_fromextrem, 0,3,"",
				"0 - use min/max, 1 - use second min/max, ... second from min/max - removes dual-tile clusters max/mins");
				"0 - use min/max, 1 - use second min/max, ... second from min/max - removes dual-tile clusters max/mins");
		gd.addNumericField("Outliers tolerance absolute",            this.outliers_tolerance_absolute, 5,7,"pix",
		gd.addNumericField("Outliers tolerance absolute",            this.outliers_tolerance_absolute, 5,7,"pix",
+2 −1
Original line number Original line Diff line number Diff line
@@ -870,7 +870,7 @@ public class MultisceneLY {
	    final double gpu_sigma_corr =     clt_parameters.getGpuCorrSigma(last_scene.isMonochrome());
	    final double gpu_sigma_corr =     clt_parameters.getGpuCorrSigma(last_scene.isMonochrome());
	    final double gpu_sigma_rb_corr =  last_scene.isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr;
	    final double gpu_sigma_rb_corr =  last_scene.isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr;
	    final double gpu_sigma_log_corr = clt_parameters.getGpuCorrLoGSigma(last_scene.isMonochrome());
	    final double gpu_sigma_log_corr = clt_parameters.getGpuCorrLoGSigma(last_scene.isMonochrome());
	    double              disparity_corr = 0.0;
	    final double disparity_corr = clt_parameters.imp.disparity_corr; // 04/07/2023 // 0.0;
		int debugLevel = debug_level;
		int debugLevel = debug_level;
		final double [][] lazy_eye_data = new double [clustersY*clustersX][];
		final double [][] lazy_eye_data = new double [clustersY*clustersX][];
		ImageDtt image_dtt= new ImageDtt(
		ImageDtt image_dtt= new ImageDtt(
@@ -1029,6 +1029,7 @@ public class MultisceneLY {
					image_dtt.transform_size - 1,  // final int                 gpu_corr_rad,    // = transform_size - 1 ?
					image_dtt.transform_size - 1,  // final int                 gpu_corr_rad,    // = transform_size - 1 ?
			        // The tp_tasks data should be decoded from GPU to get coordinates
			        // The tp_tasks data should be decoded from GPU to get coordinates
					tp_tasks_combo,                  // final TpTask []           tp_tasks,        // data from the reference frame - will be applied to LMW for the integrated correlations
					tp_tasks_combo,                  // final TpTask []           tp_tasks,        // data from the reference frame - will be applied to LMW for the integrated correlations
					null, // final double [][][]       far_fgbg,        // null, or [tilesY][tilesX]{disp(fg)-disp(bg), str(fg)-str(bg)} hints for LMA FG/BG split 
					last_scene.getErsCorrection().getRXY(false), // final double [][]         rXY,             // from geometryCorrection
					last_scene.getErsCorrection().getRXY(false), // final double [][]         rXY,             // from geometryCorrection
					// next both can be nulls
					// next both can be nulls
					null,                          // final double [][][][]     clt_corr_out,   // sparse (by the first index) [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] or null
					null,                          // final double [][][][]     clt_corr_out,   // sparse (by the first index) [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] or null
+726 −113

File changed.

Preview size limit exceeded, changes collapsed.

Loading