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

building models from bi-quad data

parent 4ea50500
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -197,6 +197,24 @@ public class BiCamDSI {
		return selection;
	}

	public double [][] filterDisparityStrength(
			double  min_disparity,
			double [] disparity,
			double [] strength,
			boolean [] selected){
		int num_tiles = disparity.length;
		double [][] fds = new double [2][num_tiles];
		for (int nTile = 0; nTile < num_tiles; nTile++) {
			fds[0][nTile] = Double.NaN;
			if ((strength[nTile] > 0.0) && (disparity[nTile] >= min_disparity) && ((selected == null) || selected[nTile])) {
				fds[0][nTile] = disparity[nTile];
				fds[1][nTile] = strength[nTile];
			}
		}
		return fds;
	}


	/**
	 * Filter selection by expending, then shrinking (fills small gaps) shrinking (combined with
	 * previous step) and expanding again (removes small clusters)
+20 −0
Original line number Diff line number Diff line
@@ -128,6 +128,9 @@ public class BiQuadParameters {
	public int     rf_shrink_near =           8;       // Shrink selection after expanding
	public int     rf_post_expand_near =      4;       // Expand selection after shrinking

	public double  rf_min_disp =              0.02;    // Minimal tile disparity to keep in scan
	public boolean rf_remove_unselected =     true;    // Remove tiles that are not selected

	public int     ml_hwidth =                 2;      // Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)
	public double  ml_disparity_sweep  =       2.0;    // Disparity sweep around ground truth, each side
	public int     ml_sweep_steps =            5;      // Number of disparity sweep steps
@@ -325,6 +328,11 @@ public class BiQuadParameters {
		gd.addNumericField("Expand selection after shrinking (non-infinity regions only)",                         this.rf_post_expand_near,  0,3,"",
				"Last step of expand-shrink-expand filtering (1 - only vert/hor, 2 -vert/hor/diagonal)");

		gd.addNumericField("Minimal usable disparity for tile to be preserved",                                    this.rf_min_disp,  4,6,"pix",
				"Minimal disparity (in master camera pixels) for the tile to be saved for plane extraction");
		gd.addCheckbox    ("Remove tiles that are not selected",                                                   this.rf_remove_unselected,
				"Remove (set strength to 0.0, disparity to Double.NaN for all tiles that are not selected");

        gd.addTab("ML","Parameters related to the ML files generation for the dual-quad camera rig");

		gd.addNumericField("Half-width of the ML tiles to export (0-> 1x1, 1->3x3, 2 -> 5x5)",                    this.ml_hwidth,  0,3,"",
@@ -443,6 +451,9 @@ public class BiQuadParameters {
		this.rf_shrink_near=         (int)  gd.getNextNumber();
		this.rf_post_expand_near=    (int)  gd.getNextNumber();

		this.rf_min_disp=                   gd.getNextNumber();
		this.rf_remove_unselected=          gd.getNextBoolean();

		this.ml_hwidth=               (int) gd.getNextNumber();
		this.ml_disparity_sweep=            gd.getNextNumber();
		this.ml_sweep_steps=          (int) gd.getNextNumber();
@@ -549,6 +560,9 @@ public class BiQuadParameters {
		properties.setProperty(prefix+"rf_shrink_near",            this.rf_shrink_near+"");
		properties.setProperty(prefix+"rf_post_expand_near",       this.rf_post_expand_near+"");

		properties.setProperty(prefix+"rf_min_disp",               this.rf_min_disp+"");
		properties.setProperty(prefix+"rf_remove_unselected",      this.rf_remove_unselected+"");

		properties.setProperty(prefix+"ml_hwidth",                 this.ml_hwidth+"");
		properties.setProperty(prefix+"ml_disparity_sweep",        this.ml_disparity_sweep+"");
		properties.setProperty(prefix+"ml_sweep_steps",            this.ml_sweep_steps+"");
@@ -654,6 +668,9 @@ public class BiQuadParameters {
		if (properties.getProperty(prefix+"rf_shrink_near")!=null)          this.rf_shrink_near=Integer.parseInt(properties.getProperty(prefix+"rf_shrink_near"));
		if (properties.getProperty(prefix+"rf_post_expand_near")!=null)     this.rf_post_expand_near=Integer.parseInt(properties.getProperty(prefix+"rf_post_expand_near"));

		if (properties.getProperty(prefix+"rf_min_disp")!=null)             this.rf_min_disp=Double.parseDouble(properties.getProperty(prefix+"rf_min_disp"));
		if (properties.getProperty(prefix+"rf_remove_unselected")!=null)    this.rf_remove_unselected=Boolean.parseBoolean(properties.getProperty(prefix+"rf_remove_unselected"));

		if (properties.getProperty(prefix+"ml_disparity_sweep")!=null)      this.ml_disparity_sweep=Double.parseDouble(properties.getProperty(prefix+"ml_disparity_sweep"));
		if (properties.getProperty(prefix+"ml_sweep_steps")!=null)          this.ml_sweep_steps=Integer.parseInt(properties.getProperty(prefix+"ml_sweep_steps"));
		if (properties.getProperty(prefix+"ml_keep_aux")!=null)             this.ml_keep_aux=Boolean.parseBoolean(properties.getProperty(prefix+"ml_keep_aux"));
@@ -757,6 +774,9 @@ public class BiQuadParameters {
		bqp.rf_shrink_near=             this.rf_shrink_near;
		bqp.rf_post_expand_near=        this.rf_post_expand_near;

		bqp.rf_min_disp=                this.rf_min_disp;
		bqp.rf_remove_unselected=       this.rf_remove_unselected;

		bqp.ml_hwidth=                  this.ml_hwidth;
		bqp.ml_disparity_sweep=         this.ml_disparity_sweep;
		bqp.ml_sweep_steps=             this.ml_sweep_steps;
+2 −1
Original line number Diff line number Diff line
@@ -392,7 +392,8 @@ public class CLTPass3d{
		 * @return line-scan array of per-tile horizontal pairs correlation strength by reference (not a copy)
		 */
		public double [] getOriginalStrength(){
			return disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX];
			if (disparity_map != null) return disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX];
			else return getStrength(); // after replacing with rig data
		}
		/**
		 * Get horizontal pairs correlation strength for vertical features. Not a copy
+43 −1
Original line number Diff line number Diff line
@@ -590,6 +590,8 @@ private Panel panel1,
//			addButton("Rig enhance",                panelClt4, color_conf_process);
			addButton("Ground truth",               panelClt4, color_conf_process);
			addButton("ML export",                  panelClt4, color_conf_process);
			addButton("Rig planes",                 panelClt4, color_conf_process);


			add(panelClt4);
		}
@@ -4598,6 +4600,14 @@ private Panel panel1,
    	enhanceByRig();

    	return;
    	/* ======================================================================== */
    } else if (label.equals("CLT planes")) {
    	DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
    	EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
    	rigPlanes();
        return;


/* ======================================================================== */
    } else if (label.equals("ML export")) {
        DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
@@ -5020,8 +5030,32 @@ private Panel panel1,
		return true;
	}

	public boolean rigPlanes() {
		if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
			String msg = "DSI data is not available. Please run \"CLT 3D\" first";
			IJ.showMessage("Error",msg);
			System.out.println(msg);
			return false;
		}
		if (!prepareRigImages()) return false;
    	String configPath=getSaveCongigPath();
    	if (configPath.equals("ABORT")) return false;

    	if (DEBUG_LEVEL > -2){
    		System.out.println("++++++++++++++ Extracting  planes using a dual-quad camera rig DSI data ++++++++++++++");
    	}
		QUAD_CLT.showCLTPlanes(
				CLT_PARAMETERS,  // EyesisCorrectionParameters.DCTParameters           dct_parameters,
				THREADS_MAX, //final int          threadsMax,  // maximal number of threads to launch
				UPDATE_STATUS, //final boolean    updateStatus,
				DEBUG_LEVEL); //final int        debugLevel);
		return true;

	}

	public boolean enhanceByRig() {
		long startTime=System.nanoTime();

		if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
			String msg = "DSI data is not available. Please run \"CLT 3D\" first";
			IJ.showMessage("Error",msg);
@@ -5055,10 +5089,15 @@ private Panel panel1,
    				true,
    				PROPERTIES);
    	}
		System.out.println("enhanceByRig(): Processing finished at "+
				  IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
				Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");

    	return true;
	}

	public boolean exportMLData() {
		long startTime=System.nanoTime();
		if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null)) {
			String msg = "DSI data is not available. Please run \"CLT 3D\" first";
			IJ.showMessage("Error",msg);
@@ -5092,10 +5131,13 @@ private Panel panel1,
    				true,
    				PROPERTIES);
    	}
		System.out.println("exportMLData(): Processing finished at "+
				  IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
				Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");

    	return true;
	}


	public boolean infinityRig() {
		if (!prepareRigImages()) return false;
    	String configPath=getSaveCongigPath();
+27 −3
Original line number Diff line number Diff line
@@ -1101,7 +1101,10 @@ public class MeasuredLayers {
					if (weight[indxe_center] >= mlfp.strength_sure) { // tile does not need filtering
						ds[0][indx] = disp[indxe_center];
						ds[1][indx] = weight[indxe_center];

						if (Double.isNaN(ds[0][indx])){
							System.out.println("**** this is a BUG6 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
//							break;
						}
					} else {
						int num_in_sample = 0;
						double sum_wnd = 0.0;
@@ -1124,6 +1127,10 @@ public class MeasuredLayers {
									int indxs = sy * mlfp.smplSide + sx;
									smpl_sel[indxs] = true;
									smpl_d[indxs] = disp[indxe];
									if (Double.isNaN(smpl_d[indxs])){
										System.out.println("**** this is a BUG5 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
//										break;
									}
									smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
									sum_wnd += smpl_weights[indxs];
									num_in_sample ++;
@@ -1292,15 +1299,27 @@ public class MeasuredLayers {
										tiltXY = atiltXY[0]; // common for all tiles (such as constant disparity)
									} else if (atiltXY[indx] != null){
										tiltXY = atiltXY[indx];
										if (Double.isNaN(tiltXY[0]) || Double.isNaN(tiltXY[1])){
											System.out.println("**** this is a BUG4A in getDisparityStrengthML() ****");
											System.out.println("atilt["+indx+"]= {"+tiltXY[0]+","+tiltXY[1]+"}");
											tiltXY[0] = 0.0;
											tiltXY[1] = 0.0;
										}

									}
								}

								if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){
								if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){ // {NaN,NaN}
									for (int sy = 0; sy < mlfp.smplSide; sy++){
										for (int sx = 0; sx < mlfp.smplSide; sx++){
											int indxs = sy * mlfp.smplSide + sx;
											if (smpl_w[indxs] > 0.0) {
												smpl_d[indxs] -= tiltXY[0]* (sx - smpl_dcenter) + tiltXY[1]* (sy - smpl_dcenter);
												if (Double.isNaN(smpl_d[indxs])){
													System.out.println("**** this is a BUG4 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
//													break;
												}

											}
										}
									}
@@ -1310,6 +1329,11 @@ public class MeasuredLayers {
								// calculate
								double sd=0.0, sd2 = 0.0, sw = 0.0;
								for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
									if (Double.isNaN(smpl_d[i])){
										System.out.println("**** this is a BUG3 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
//										break;
									}

									double dw = smpl_d[i] * smpl_w[i];
									sd += dw;
									sd2 += dw * smpl_d[i];
@@ -1330,7 +1354,7 @@ public class MeasuredLayers {
										//remove_far_only
									}
									if (iworst < 0){
										System.out.println("**** this is a BUG2 in getDisparityStrengthML() ****");
										System.out.println("**** this is a BUG2 in getDisparityStrengthML() ****"); // all smpl_d are NaNs
										break;
									}
									// remove worst sample
Loading