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

assigning tiles to surfaces

parent 6ae8367c
Loading
Loading
Loading
Loading
+92 −2
Original line number Original line Diff line number Diff line
@@ -2215,6 +2215,18 @@ public class EyesisCorrectionParameters {
  		public double     msScaleProj          =   1.5;  // Scale projection of the plane ellipsoid 
  		public double     msScaleProj          =   1.5;  // Scale projection of the plane ellipsoid 
  		public double     msFractUni           =   0.3;  // Spread this fraction of the ellipsoid weight among extended (double) supertile
  		public double     msFractUni           =   0.3;  // Spread this fraction of the ellipsoid weight among extended (double) supertile
  		
  		
  		public double     tsMaxDiff            = 0.3;    // Maximal disparity difference when assigning tiles
		public double     tsMinDiffOther       = 0.35;   // Minimal disparity difference to be considered as a competitor surface
		public double     tsMinStrength        = 0.05;   // Minimal tile correlation strength to be assigned
		public double     tsMaxStrength        = 10.0;   // Maximal tile correlation strength to be assigned
		public int        tsMoveDirs           = 3;      // Allowed tile disparity correction: 1 increase, 2 - decrease, 3 - both directions
		public boolean    tsEnMulti            = false;  // Allow assignment when several surfaces fit
		public double     tsSurfStrPow         = 0.0;    // Raise surface strengths ratio to this power when comparing candidates
		public double     tsSigma              = 2.0;    // Radius of influence (in tiles) of the previously assigned tiles
		public double     tsNSigma             = 2.0;    // Maximal relative to radius distance to calculate influence
		public double     tsMinAdvantage       = 3.0;    // Minimal ratio of the best surface candidate to the next one to make selection
		public boolean    tsReset              = false;  // Reset tiles to surfaces assignment
  		
  		public boolean    replaceWeakOutlayers =   true; // false; 
  		public boolean    replaceWeakOutlayers =   true; // false; 
  		
  		
  		public boolean    dbg_migrate =            true; 
  		public boolean    dbg_migrate =            true; 
@@ -2519,6 +2531,17 @@ public class EyesisCorrectionParameters {
			properties.setProperty(prefix+"msScaleProj",      this.msScaleProj +"");
			properties.setProperty(prefix+"msScaleProj",      this.msScaleProj +"");
			properties.setProperty(prefix+"msFractUni",       this.msFractUni +"");
			properties.setProperty(prefix+"msFractUni",       this.msFractUni +"");


			properties.setProperty(prefix+"tsMaxDiff",        this.tsMaxDiff +"");
			properties.setProperty(prefix+"tsMinDiffOther",   this.tsMinDiffOther +"");
			properties.setProperty(prefix+"tsMinStrength",    this.tsMinStrength +"");
			properties.setProperty(prefix+"tsMaxStrength",    this.tsMaxStrength +"");
  			properties.setProperty(prefix+"tsMoveDirs",       this.tsMoveDirs+"");
			properties.setProperty(prefix+"tsEnMulti",        this.tsEnMulti+"");
			properties.setProperty(prefix+"tsSurfStrPow",    this.tsSurfStrPow +"");
			properties.setProperty(prefix+"tsSigma",         this.tsSigma +"");
			properties.setProperty(prefix+"tsNSigma",         this.tsNSigma +"");
			properties.setProperty(prefix+"tsMinAdvantage",  this.tsMinAdvantage +"");
			
			properties.setProperty(prefix+"dbg_migrate",            this.dbg_migrate+"");
			properties.setProperty(prefix+"dbg_migrate",            this.dbg_migrate+"");
  			
  			
			properties.setProperty(prefix+"show_ortho_combine",     this.show_ortho_combine+"");
			properties.setProperty(prefix+"show_ortho_combine",     this.show_ortho_combine+"");
@@ -2817,6 +2840,18 @@ public class EyesisCorrectionParameters {
  			if (properties.getProperty(prefix+"msFractUni")!=null)        this.msFractUni=Double.parseDouble(properties.getProperty(prefix+"msFractUni"));
  			if (properties.getProperty(prefix+"msFractUni")!=null)        this.msFractUni=Double.parseDouble(properties.getProperty(prefix+"msFractUni"));




  			if (properties.getProperty(prefix+"tsMaxDiff")!=null)         this.tsMaxDiff=Double.parseDouble(properties.getProperty(prefix+"tsMaxDiff"));
  			if (properties.getProperty(prefix+"tsMinDiffOther")!=null)    this.tsMinDiffOther=Double.parseDouble(properties.getProperty(prefix+"tsMinDiffOther"));
  			if (properties.getProperty(prefix+"tsMinStrength")!=null)     this.tsMinStrength=Double.parseDouble(properties.getProperty(prefix+"tsMinStrength"));
  			if (properties.getProperty(prefix+"tsMaxStrength")!=null)     this.tsMaxStrength=Double.parseDouble(properties.getProperty(prefix+"tsMaxStrength"));
  			if (properties.getProperty(prefix+"tsMoveDirs")!=null)        this.tsMoveDirs=Integer.parseInt(properties.getProperty(prefix+"tsMoveDirs"));
  			if (properties.getProperty(prefix+"tsEnMulti")!=null)         this.tsEnMulti=Boolean.parseBoolean(properties.getProperty(prefix+"tsEnMulti"));
  			if (properties.getProperty(prefix+"tsSurfStrPow")!=null)     this.tsSurfStrPow=Double.parseDouble(properties.getProperty(prefix+"tsSurfStrPow"));
  			if (properties.getProperty(prefix+"tsSigma")!=null)          this.tsSigma=Double.parseDouble(properties.getProperty(prefix+"tsSigma"));
  			if (properties.getProperty(prefix+"tsNSigma")!=null)          this.tsNSigma=Double.parseDouble(properties.getProperty(prefix+"tsNSigma"));
  			if (properties.getProperty(prefix+"tsMinAdvantage")!=null)   this.tsMinAdvantage=Double.parseDouble(properties.getProperty(prefix+"tsMinAdvantage"));
  			
  			
  			if (properties.getProperty(prefix+"dbg_migrate")!=null)       this.dbg_migrate=Boolean.parseBoolean(properties.getProperty(prefix+"dbg_migrate"));
  			if (properties.getProperty(prefix+"dbg_migrate")!=null)       this.dbg_migrate=Boolean.parseBoolean(properties.getProperty(prefix+"dbg_migrate"));


  			if (properties.getProperty(prefix+"show_ortho_combine")!=null)     this.show_ortho_combine=Boolean.parseBoolean(properties.getProperty(prefix+"show_ortho_combine"));
  			if (properties.getProperty(prefix+"show_ortho_combine")!=null)     this.show_ortho_combine=Boolean.parseBoolean(properties.getProperty(prefix+"show_ortho_combine"));
@@ -3139,6 +3174,17 @@ public class EyesisCorrectionParameters {
  			gd.addNumericField("Scale projection of the plane ellipsoid",                                      this.msScaleProj,  6);
  			gd.addNumericField("Scale projection of the plane ellipsoid",                                      this.msScaleProj,  6);
  			gd.addNumericField("Spread this fraction of the ellipsoid weight among extended (double) supertile",this.msFractUni,  6);
  			gd.addNumericField("Spread this fraction of the ellipsoid weight among extended (double) supertile",this.msFractUni,  6);
  			
  			
  			gd.addNumericField("Maximal disparity difference when assigning tiles",                               this.tsMaxDiff,  6);
  			gd.addNumericField("Minimal disparity difference to be considered as a competitor surface",           this.tsMinDiffOther,  6);
  			gd.addNumericField("Minimal tile correlation strength to be assigned",                                this.tsMinStrength,  6);
  			gd.addNumericField("Maximal tile correlation strength to be assigned",                                this.tsMaxStrength,  6);
  			gd.addNumericField("Allowed tile disparity correction: 1 increase, 2 - decrease, 3 - both directions",this.tsMoveDirs,  0);
  			gd.addCheckbox    ("Allow assignment when several surfaces fit",                                      this.tsEnMulti);
  			gd.addNumericField("Raise surface strengths ratio to this power when comparing candidates",           this.tsSurfStrPow,  6);
  			gd.addNumericField("Radius of influence (in tiles) of the previously assigned tiles",                 this.tsSigma,  6);
  			gd.addNumericField("Maximal relative to radius distance to calculate influence",                      this.tsNSigma,  6);
  			gd.addNumericField("Minimal ratio of the best surface candidate to the next one to make selection",   this.tsMinAdvantage,  6);
  			
  			gd.addCheckbox    ("Test new mode after migration",                                                this.dbg_migrate);
  			gd.addCheckbox    ("Test new mode after migration",                                                this.dbg_migrate);


  			gd.addMessage     ("--- Other debug images ---");
  			gd.addMessage     ("--- Other debug images ---");
@@ -3443,6 +3489,18 @@ public class EyesisCorrectionParameters {
  			this.msScaleProj=           gd.getNextNumber();
  			this.msScaleProj=           gd.getNextNumber();
  			this.msFractUni=            gd.getNextNumber();
  			this.msFractUni=            gd.getNextNumber();


  			this.tsMaxDiff=             gd.getNextNumber();
  			this.tsMinDiffOther=        gd.getNextNumber();
  			this.tsMinStrength=         gd.getNextNumber();
  			this.tsMaxStrength=         gd.getNextNumber();
  			this.tsMoveDirs=      (int) gd.getNextNumber();
  			this.tsEnMulti=             gd.getNextBoolean();
  			this.tsSurfStrPow=          gd.getNextNumber();
  			this.tsSigma=               gd.getNextNumber();
  			this.tsNSigma=              gd.getNextNumber();
  			this.tsMinAdvantage=        gd.getNextNumber();
  			this.tsReset              = false;  // Reset tiles to surfaces assignment
  			
  			this.dbg_migrate=           gd.getNextBoolean();
  			this.dbg_migrate=           gd.getNextBoolean();


  			this.show_ortho_combine=    gd.getNextBoolean();
  			this.show_ortho_combine=    gd.getNextBoolean();
@@ -3458,8 +3516,40 @@ public class EyesisCorrectionParameters {
  			this.show_flaps_dirs=       gd.getNextBoolean();
  			this.show_flaps_dirs=       gd.getNextBoolean();
  			this.show_first_clusters=   gd.getNextBoolean();
  			this.show_first_clusters=   gd.getNextBoolean();
  			this.show_planes=           gd.getNextBoolean();
  			this.show_planes=           gd.getNextBoolean();
  			
  			return true;
  			return true;
  		}
  		}
  		
  		public boolean showTsDialog() {
  			GenericDialog gd = new GenericDialog("Set CLT parameters");
  			gd.addNumericField("Maximal disparity difference when assigning tiles",                               this.tsMaxDiff,  6);
  			gd.addNumericField("Minimal disparity difference to be considered as a competitor surface",           this.tsMinDiffOther,  6);
  			gd.addNumericField("Minimal tile correlation strength to be assigned",                                this.tsMinStrength,  6);
  			gd.addNumericField("Maximal tile correlation strength to be assigned",                                this.tsMaxStrength,  6);
  			gd.addNumericField("Allowed tile disparity correction: 1 increase, 2 - decrease, 3 - both directions",this.tsMoveDirs,  0);
  			gd.addCheckbox    ("Allow assignment when several surfaces fit",                                      this.tsEnMulti);
  			gd.addNumericField("Raise surface strengths ratio to this power when comparing candidates",           this.tsSurfStrPow,  6);
  			gd.addNumericField("Radius of influence (in tiles) of the previously assigned tiles",                 this.tsSigma,  6);
  			gd.addNumericField("Maximal relative to radius distance to calculate influence",                      this.tsNSigma,  6);
  			gd.addNumericField("Minimal ratio of the best surface candidate to the next one to make selection",   this.tsMinAdvantage,  6);
  			gd.addCheckbox    ("Reset tiles to surfaces assignment",                                              false);
  			WindowTools.addScrollBars(gd);
  			gd.showDialog();
  			if (gd.wasCanceled()) return false;
  			this.tsMaxDiff=             gd.getNextNumber();
  			this.tsMinDiffOther=        gd.getNextNumber();
  			this.tsMinStrength=         gd.getNextNumber();
  			this.tsMaxStrength=         gd.getNextNumber();
  			this.tsMoveDirs=      (int) gd.getNextNumber();
  			this.tsEnMulti=             gd.getNextBoolean();
  			this.tsSurfStrPow=          gd.getNextNumber();
  			this.tsSigma=               gd.getNextNumber();
  			this.tsNSigma=              gd.getNextNumber();
  			this.tsMinAdvantage=        gd.getNextNumber();
  			this.tsReset=               gd.getNextBoolean();
  			return true;
  		}
  		
    }
    }


    public static class DCTParameters {
    public static class DCTParameters {
+21 −1
Original line number Original line Diff line number Diff line
@@ -507,6 +507,7 @@ private Panel panel1,
			addButton("CLT reset 3D",              panelClt1, color_stop);
			addButton("CLT reset 3D",              panelClt1, color_stop);
			addButton("CLT 3D",                    panelClt1, color_conf_process);
			addButton("CLT 3D",                    panelClt1, color_conf_process);
			addButton("CLT planes",                panelClt1, color_conf_process);
			addButton("CLT planes",                panelClt1, color_conf_process);
			addButton("CLT ASSIGN",                panelClt1, color_process);
			addButton("CLT OUT 3D",                panelClt1, color_process);
			addButton("CLT OUT 3D",                panelClt1, color_process);
						
						
			add(panelClt1);
			add(panelClt1);
@@ -4782,6 +4783,26 @@ private Panel panel1,
        		UPDATE_STATUS, //final boolean    updateStatus,
        		UPDATE_STATUS, //final boolean    updateStatus,
        		DEBUG_LEVEL); //final int        debugLevel);
        		DEBUG_LEVEL); //final int        debugLevel);
        return;
        return;
    } else if (label.equals("CLT ASSIGN")) {
    	DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
    	EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
        if (QUAD_CLT == null){
       		System.out.println("QUAD_CLT is null, nothing to show");
       		return;
        }

    	if (!CLT_PARAMETERS.showTsDialog()) return;
        
        boolean OK = QUAD_CLT.assignCLTPlanes(
        		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);
        if (!OK){
       		System.out.println("Could not assign tiles to surfaces, probably \"CLT planes\" command did not run");
       		return;
        }
        return;
        
        
    } else if (label.equals("CLT OUT 3D")) {
    } else if (label.equals("CLT OUT 3D")) {
    	DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
    	DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
@@ -4791,7 +4812,6 @@ private Panel panel1,
       		return;
       		return;
        }
        }
        
        
        
    	String configPath=null;
    	String configPath=null;
    	if (EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
    	if (EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
    		configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
    		configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
+25 −2
Original line number Original line Diff line number Diff line
@@ -4460,7 +4460,6 @@ public class QuadCLT {
		  }
		  }
		  return rslt;
		  return rslt;
	  }
	  }
//	  public ImagePlus [] cltDisparityScan(
	  public void showCLTPlanes(
	  public void showCLTPlanes(
			  EyesisCorrectionParameters.CLTParameters           clt_parameters,
			  EyesisCorrectionParameters.CLTParameters           clt_parameters,
			  final int          threadsMax,  // maximal number of threads to launch                         
			  final int          threadsMax,  // maximal number of threads to launch                         
@@ -4481,9 +4480,33 @@ public class QuadCLT {
		  			threadsMax,
		  			threadsMax,
		  			updateStatus,
		  			updateStatus,
		  			debugLevel);
		  			debugLevel);
//		  	CLTPass3d last_scan = tp.clt_3d_passes.get(tp.clt_3d_passes.size() -1); // get last one
		  	
		  	
	  }
	  }
	  
	  public boolean assignCLTPlanes(
			  EyesisCorrectionParameters.CLTParameters           clt_parameters,
			  final int          threadsMax,  // maximal number of threads to launch                         
			  final boolean    updateStatus,
			  final int        debugLevel)
	  {
		  	if (tp == null){
		  		System.out.println("showCLTPlanes(): tp is null");
		  		return false;
		  	}
		  	if (tp.clt_3d_passes == null){
		  		System.out.println("showCLTPlanes(): tp.clt_3d_passes is null");
		  		return false;
		  	}
		  	return tp.assignTilesToSurfaces(
		  			clt_parameters,
		  			geometryCorrection,		  			
		  			threadsMax,
		  			updateStatus,
		  			debugLevel);
		  	
	  }
	  
	  
	  public void out3d(
	  public void out3d(
			  EyesisCorrectionParameters.CLTParameters           clt_parameters,
			  EyesisCorrectionParameters.CLTParameters           clt_parameters,
			  final int          threadsMax,  // maximal number of threads to launch                         
			  final int          threadsMax,  // maximal number of threads to launch                         
+12 −0
Original line number Original line Diff line number Diff line
@@ -73,6 +73,9 @@ public class SuperTiles{
	int [][]    shell_map = null;   // per supertile, per disparity plane - shell index + 1 (0 - none)
	int [][]    shell_map = null;   // per supertile, per disparity plane - shell index + 1 (0 - none)
	double [][] surfaces;  // per shell, per tile (linescan order) disparity value or NaN in missing supertiles
	double [][] surfaces;  // per shell, per tile (linescan order) disparity value or NaN in missing supertiles
	
	
	TileSurface tileSurface = null;	
	

	/**
	/**
	 * currently lowest plane for each includes all tiles, so do not use it. May change in the future
	 * currently lowest plane for each includes all tiles, so do not use it. May change in the future
	 * @param np total number of planes in a supertile
	 * @param np total number of planes in a supertile
@@ -185,6 +188,15 @@ public class SuperTiles{
		}
		}
	}
	}
	
	
	public void setTileSurface( TileSurface tileSurface)
	{
		this.tileSurface = tileSurface;
	}
	public TileSurface getTileSurface()
	{
		return tileSurface;
	}
	
	public void initFuseCoeff(
	public void initFuseCoeff(
			double scale_diag,
			double scale_diag,
			boolean debug)
			boolean debug)
+63 −12
Original line number Original line Diff line number Diff line
@@ -2942,6 +2942,53 @@ public class TileProcessor {
	}
	}




	public boolean assignTilesToSurfaces(
			EyesisCorrectionParameters.CLTParameters           clt_parameters,
			GeometryCorrection geometryCorrection,
			final int         threadsMax,  // maximal number of threads to launch                         
			final boolean     updateStatus,
			final int         debugLevel)
	{
		CLTPass3d scan_prev = clt_3d_passes.get(clt_3d_passes.size() -1); // get last one
//		boolean show_st =    clt_parameters.stShow || (debugLevel > 1);
		SuperTiles st = scan_prev.getSuperTiles();
		TileSurface tileSurface = st.getTileSurface();
		if (tileSurface == null){
			return false;
		}

		double [][][]  dispStrength = st.getDisparityStrengths(
				clt_parameters.stMeasSel); // int        stMeasSel) //            = 1;      // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)

		boolean [][] tileSel =  st.getMeasurementSelections(
				clt_parameters.stMeasSel); // int        stMeasSel) //            = 1;      // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)

		tileSurface.InitTilesAssignment(
				clt_parameters.tsReset,
				dispStrength, // final double [][][]                            dispStrength,
				tileSel,      // final boolean [][]                             tileSel,
                debugLevel);    // final int                                    debugLevel,

		 int [] stats=  tileSurface.assignTilesToSurfaces(
				clt_parameters.tsMaxDiff,       //final double        maxDiff,
				clt_parameters.tsMinDiffOther,  //final double        minDiffOther, // should be >= maxDiff
				clt_parameters.tsMinStrength,   //final double        minStrength,
				clt_parameters.tsMaxStrength,   //final double        maxStrength,
				clt_parameters.tsMoveDirs,      //final int           moveDirs, // 1 increase disparity, 2 - decrease disparity, 3 - both directions
				clt_parameters.tsEnMulti,       //final boolean       enMulti,
				clt_parameters.tsSurfStrPow,    //final double        surfStrPow, // surface strength power
				clt_parameters.tsSigma,         //final double        sigma,
				clt_parameters.tsNSigma,        //final double        nSigma,
				clt_parameters.tsMinAdvantage,  //final double        minAdvantage,
				clt_parameters.plDispNorm,      // final double        dispNorm, // disparity normalize (proportionally scale down disparity difference if above
				dispStrength,                   // final double [][][] dispStrength,
				0, // -1,                       // debugLevel,                  // final int        debugLevel)
				clt_parameters.tileX,
				clt_parameters.tileY);
		 tileSurface.printStats(stats);
		return true;
	}	
	
//======================
//======================
	public void showPlanes(
	public void showPlanes(
			EyesisCorrectionParameters.CLTParameters           clt_parameters,
			EyesisCorrectionParameters.CLTParameters           clt_parameters,
@@ -3174,9 +3221,11 @@ public class TileProcessor {
				st.tileProcessor.getTilesY(),        // int tilesY,
				st.tileProcessor.getTilesY(),        // int tilesY,
				geometryCorrection,               // GeometryCorrection geometryCorrection,
				geometryCorrection,               // GeometryCorrection geometryCorrection,
				st.tileProcessor.threadsMax);        // int threadsMax); 
				st.tileProcessor.threadsMax);        // int threadsMax); 
		st.setTileSurface(tileSurface);
		
		
		
		
		TileSurface.TileData [][] tileData = tileSurface.createTileShells (
//		TileSurface.TileData [][] tileData = 
				tileSurface.createTileShells (
				clt_parameters.msUseSel,            // final boolean                   use_sel,
				clt_parameters.msUseSel,            // final boolean                   use_sel,
				clt_parameters.msDivideByArea,      // final boolean                   divide_by_area,
				clt_parameters.msDivideByArea,      // final boolean                   divide_by_area,
				clt_parameters.msScaleProj,         // final double                    scale_projection,
				clt_parameters.msScaleProj,         // final double                    scale_projection,
@@ -3186,16 +3235,14 @@ public class TileProcessor {
				clt_parameters.tileX,
				clt_parameters.tileX,
				clt_parameters.tileY);
				clt_parameters.tileY);


		int [][] tiles_layers = tileSurface.sortTilesToSurfaces(
		tileSurface.InitTilesAssignment(
				true,
				dispStrength, // final double [][][]                            dispStrength,
				dispStrength, // final double [][][]                            dispStrength,
				tileSel,      // final boolean [][]                             tileSel,
				tileSel,      // final boolean [][]                             tileSel,
				tileData,     // final TileData [][]                            tileData_src,
                debugLevel);    // final int                                      debugLevel,
				// parameters
		if (debugLevel > -10){
				clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
			return; // just cut off the rest
                debugLevel,    // final int                                      debugLevel,
		}
				clt_parameters.tileX,
				clt_parameters.tileY);
		
		
		


		
		
@@ -3572,6 +3619,10 @@ public class TileProcessor {
		}
		}
	}
	}


	
	
	
	
	public void secondPassSetup( // prepare tile tasks for the second pass based on the previous one(s)
	public void secondPassSetup( // prepare tile tasks for the second pass based on the previous one(s)
			//			  final double [][][]       image_data, // first index - number of image in a quad
			//			  final double [][][]       image_data, // first index - number of image in a quad
			EyesisCorrectionParameters.CLTParameters           clt_parameters,
			EyesisCorrectionParameters.CLTParameters           clt_parameters,
Loading