Commit 84eeaf35 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Added GPU 2D phase correlation, related and debug functionality

parent dc4e1f60
Loading
Loading
Loading
Loading
+88 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ public class CLTParameters {
	public int        dbg_mode =            0;  // 0 - normal, +1 - no DCT/IDCT
	public int        ishift_x =            0;  // debug feature - shift source image by this pixels left
	public int        ishift_y =            0;  // debug feature - shift source image by this pixels down

	private double    fat_zero =          0.05; // modify phase correlation to prevent division by very small numbers
	private double    fat_zero_mono =     0.1;  // modify phase correlation to prevent division by very small numbers
	private double    corr_sigma =        0.8;  // LPF correlation sigma
@@ -763,7 +764,18 @@ public class CLTParameters {
	public boolean    taEnFlaps            = true;   // Enable cost of using supertile "flaps" (not in the center 8x8 tiles area)
	public boolean    taEnMismatch         = false;  // Enable cost of a measurement layer not having same layer in the same location or near


// gpu processing parameters
	public int        gpu_corr_rad =        7;  // size of the correlation to save - initially only 15x15
	public double     gpu_weight_r =      0.25;
	public double     gpu_weight_b =      0.25; // weight g = 1.0 - gpu_weight_r - gpu_weight_b
	public double     gpu_sigma_r =       1.1;
	public double     gpu_sigma_b =       1.1;
	public double     gpu_sigma_g =       0.7;
	public double     gpu_sigma_m =       0.7;
	public double     gpu_sigma_corr =    0.9;
	public double     gpu_sigma_corr_m =  0.15;
	public double     gpu_fatz =          30.0;
	public double     gpu_fatz_m =        30.0;

	public boolean    replaceWeakOutliers =   true; // false;

@@ -817,6 +829,15 @@ public class CLTParameters {
		return monochrome ? fat_zero_mono : fat_zero;
	}

	public double getGpuFatZero(boolean monochrome) {
		return monochrome ? gpu_fatz_m : gpu_fatz;
	}

	public double getGpuCorrSigma(boolean monochrome) {
		return monochrome ? gpu_sigma_corr_m : gpu_sigma_corr;
	}


	public double getScaleStrength(boolean aux) {
		return aux ? scale_strength_aux : scale_strength_main;
	}
@@ -1512,6 +1533,18 @@ public class CLTParameters {
		properties.setProperty(prefix+"taEnMismatch",               this.taEnMismatch +"");


		properties.setProperty(prefix+"gpu_corr_rad",               this.gpu_corr_rad +"");
		properties.setProperty(prefix+"gpu_weight_r",               this.gpu_weight_r +"");
		properties.setProperty(prefix+"gpu_weight_b",               this.gpu_weight_b +"");
		properties.setProperty(prefix+"gpu_sigma_r",                this.gpu_sigma_r +"");
		properties.setProperty(prefix+"gpu_sigma_b",                this.gpu_sigma_b +"");
		properties.setProperty(prefix+"gpu_sigma_g",                this.gpu_sigma_g +"");
		properties.setProperty(prefix+"gpu_sigma_m",                this.gpu_sigma_m +"");
		properties.setProperty(prefix+"gpu_sigma_corr",             this.gpu_sigma_corr +"");
		properties.setProperty(prefix+"gpu_sigma_corr_m",           this.gpu_sigma_corr_m +"");
		properties.setProperty(prefix+"gpu_fatz",                   this.gpu_fatz +"");
		properties.setProperty(prefix+"gpu_fatz_m",                 this.gpu_fatz_m +"");

		properties.setProperty(prefix+"debug_initial_discriminate",           this.debug_initial_discriminate+"");
		properties.setProperty(prefix+"dbg_migrate",                          this.dbg_migrate+"");

@@ -2265,6 +2298,17 @@ public class CLTParameters {
		if (properties.getProperty(prefix+"taEnFlaps")!=null)                   this.taEnFlaps=Boolean.parseBoolean(properties.getProperty(prefix+"taEnFlaps"));
		if (properties.getProperty(prefix+"taEnMismatch")!=null)                this.taEnMismatch=Boolean.parseBoolean(properties.getProperty(prefix+"taEnMismatch"));

		if (properties.getProperty(prefix+"gpu_corr_rad")!=null)                this.gpu_corr_rad=Integer.parseInt(properties.getProperty(prefix+"gpu_corr_rad"));
		if (properties.getProperty(prefix+"gpu_weight_r")!=null)                this.gpu_weight_r=Double.parseDouble(properties.getProperty(prefix+"gpu_weight_r"));
		if (properties.getProperty(prefix+"gpu_weight_b")!=null)                this.gpu_weight_b=Double.parseDouble(properties.getProperty(prefix+"gpu_weight_b"));
		if (properties.getProperty(prefix+"gpu_sigma_r")!=null)                 this.gpu_sigma_r=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_r"));
		if (properties.getProperty(prefix+"gpu_sigma_b")!=null)                 this.gpu_sigma_b=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_b"));
		if (properties.getProperty(prefix+"gpu_sigma_g")!=null)                 this.gpu_sigma_g=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_g"));
		if (properties.getProperty(prefix+"gpu_sigma_m")!=null)                 this.gpu_sigma_m=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_m"));
		if (properties.getProperty(prefix+"gpu_sigma_corr")!=null)              this.gpu_sigma_corr=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_corr"));
		if (properties.getProperty(prefix+"gpu_sigma_corr_m")!=null)            this.gpu_sigma_corr_m=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_corr_m"));
		if (properties.getProperty(prefix+"gpu_fatz")!=null)                    this.gpu_fatz=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz"));
		if (properties.getProperty(prefix+"gpu_fatz_m")!=null)                  this.gpu_fatz_m=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz_m"));

		if (properties.getProperty(prefix+"debug_initial_discriminate")!=null)           this.debug_initial_discriminate=Boolean.parseBoolean(properties.getProperty(prefix+"debug_initial_discriminate"));
		if (properties.getProperty(prefix+"dbg_migrate")!=null)                          this.dbg_migrate=Boolean.parseBoolean(properties.getProperty(prefix+"dbg_migrate"));
@@ -3159,6 +3203,35 @@ public class CLTParameters {
		gd.addCheckbox    ("Cost of using supertile \"flaps\" (not in the center 8x8 tiles area)",                      this.taEnFlaps);
		gd.addCheckbox    ("Cost of a measurement layer not having same layer in the same location or near",            this.taEnMismatch);

		gd.addTab         ("GPU", "Parameters for GPU development");
		gd.addMessage     ("--- GPU processing parameters ---");
		gd.addNumericField("Correlation radius",                                                                        this.gpu_corr_rad, 0, 6,"pix",
				"Size of the 2D correlation - maximal radius = 7 corresponds to full 15x15 pixel tile");
		gd.addNumericField("Correlation weight R",                                                                      this.gpu_weight_r, 4, 6,"",
				"Weight of R for composite 2D correlation (green weight is 1.0 -gpu_weight_r - gpu_weight_b");
		gd.addNumericField("Correlation weight B",                                                                      this.gpu_weight_b, 4, 6,"",
				"Weight of R for composite 2D correlation (green weight is 1.0 -gpu_weight_r - gpu_weight_b");
		gd.addNumericField("Color LPF sigma R",                                                                         this.gpu_sigma_r, 4, 6,"pix",
				"LPF sigma to process color components during aberration correction");
		gd.addNumericField("Color LPF sigma B",                                                                         this.gpu_sigma_b, 4, 6,"pix",
				"LPF sigma to process color components during aberration correction");
		gd.addNumericField("Color LPF sigma G",                                                                         this.gpu_sigma_g, 4, 6,"pix",
				"LPF sigma to process color components during aberration correction");
		gd.addNumericField("Monochrome LPF sigma",                                                                      this.gpu_sigma_m, 4, 6,"pix",
				"LPF sigma to process monochrome (e.g.LWIR) during aberration correction");
		gd.addNumericField("LPF sigma for correlation, color",                                                          this.gpu_sigma_corr, 4, 6,"pix",
				"LPF sigma to apply to the composite 2D correlation for RGB images");
		gd.addNumericField("LPF sigma for correlation, mono",                                                           this.gpu_sigma_corr_m, 4, 6,"pix",
				"LPF sigma to apply to the composite 2D correlation for monochrome images");
		gd.addNumericField("Fat zero (absolute) for phase correlation of color images",                                 this.gpu_fatz, 4, 6,"",
				"Add squared fat zero to the sum of squared amplitudes, color images");
		gd.addNumericField("Fat zero (absolute) for phase correlation of monochrome images",                            this.gpu_fatz_m, 4, 6,"",
				"Add squared fat zero to the sum of squared amplitudes, monochrome images");

		gd.addTab         ("LWIR", "parameters for LWIR/EO 8-camera rig");
		this.lwir.dialogQuestions(gd);


		gd.addTab         ("Debug", "Other debug images");
		gd.addMessage     ("--- Other debug images ---");
		//	clt_parameters.debug_initial_discriminate, // final boolean    debug_initial_discriminate,
@@ -3190,8 +3263,6 @@ public class CLTParameters {
		gd.addMessage     ("Unity up vector in camera coordinate system (x - right, y - up, z - to camera): {"+
				this.vertical_xyz[0]+","+          this.vertical_xyz[1]+","+          this.vertical_xyz[2]+"}");

		gd.addTab         ("LWIR", "parameters for LWIR/EO 8-camera rig");
		this.lwir.dialogQuestions(gd);

		//  			gd.buildDialog();
		gd.showDialog();
@@ -3886,6 +3957,20 @@ public class CLTParameters {
		this.taEnFlaps=             gd.getNextBoolean();
		this.taEnMismatch=          gd.getNextBoolean();

		this.gpu_corr_rad =   (int) gd.getNextNumber();
		this.gpu_weight_r =         gd.getNextNumber();
		this.gpu_weight_b =         gd.getNextNumber();
		this.gpu_sigma_r =          gd.getNextNumber();
		this.gpu_sigma_b =          gd.getNextNumber();
		this.gpu_sigma_g =          gd.getNextNumber();
		this.gpu_sigma_m =          gd.getNextNumber();
		this.gpu_sigma_corr =       gd.getNextNumber();
		this.gpu_sigma_corr_m =     gd.getNextNumber();
		this.gpu_fatz =             gd.getNextNumber();
		this.gpu_fatz_m =           gd.getNextNumber();

		this.lwir.dialogAnswers(gd);

		this.debug_initial_discriminate= gd.getNextBoolean();
		this.dbg_migrate=                gd.getNextBoolean();

@@ -3911,8 +3996,6 @@ public class CLTParameters {
		this.show_first_clusters=   gd.getNextBoolean();
		this.show_planes=           gd.getNextBoolean();

		this.lwir.dialogAnswers(gd);

		return true;
	}

+4 −0
Original line number Diff line number Diff line
@@ -231,6 +231,7 @@ public class EyesisCorrectionParameters {
  			cp.zcorrect=  			    this.zcorrect;
  			cp.saveSettings=  		    this.saveSettings;
  			cp.sourceDirectory=    	    this.sourceDirectory;
  			cp.tile_processor_gpu =     this.tile_processor_gpu;
  			cp.use_set_dirs =           this.use_set_dirs;
//  			cp.sourcePrefix=    	    this.sourcePrefix;
//  			cp.sourceSuffix=    	    this.sourceSuffix;
@@ -388,6 +389,8 @@ public class EyesisCorrectionParameters {
  			properties.setProperty(prefix+"saveSettings",this.saveSettings+"");

    		properties.setProperty(prefix+"sourceDirectory",this.sourceDirectory);
    		properties.setProperty(prefix+"tile_processor_gpu",this.tile_processor_gpu);

    		properties.setProperty(prefix+"use_set_dirs",   this.use_set_dirs+"");

    		properties.setProperty(prefix+"sourcePrefix",this.sourcePrefix);
@@ -543,6 +546,7 @@ public class EyesisCorrectionParameters {
  		    if (properties.getProperty(prefix+"zcorrect")!=null) this.zcorrect=Boolean.parseBoolean(properties.getProperty(prefix+"zcorrect"));
  		    if (properties.getProperty(prefix+"saveSettings")!=null) this.saveSettings=Boolean.parseBoolean(properties.getProperty(prefix+"saveSettings"));
			if (properties.getProperty(prefix+"sourceDirectory")!=      null) this.sourceDirectory=properties.getProperty(prefix+"sourceDirectory");
			if (properties.getProperty(prefix+"tile_processor_gpu")!=      null) this.tile_processor_gpu=properties.getProperty(prefix+"tile_processor_gpu");
  		    if (properties.getProperty(prefix+"firstSubCamera")!=       null) this.firstSubCamera=Integer.parseInt(properties.getProperty(prefix+"firstSubCamera"));
  		    if (properties.getProperty(prefix+"firstSubCameraConfig")!= null) this.firstSubCameraConfig=Integer.parseInt(properties.getProperty(prefix+"firstSubCameraConfig"));
  		    if (properties.getProperty(prefix+"numSubCameras")!=        null) this.numSubCameras=Integer.parseInt(properties.getProperty(prefix+"numSubCameras"));
+1 −1
Original line number Diff line number Diff line
@@ -1220,7 +1220,7 @@ public class EyesisDCT {
		  }

		  if (this.correctionsParameters.deconvolve) { // process with DCT, otherwise use simple debayer
			  ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
			  ImageDtt image_dtt = new ImageDtt(dctParameters.dct_size, false, 1.0); // Bayer( not monochrome), scale correlation strengths
			  double [][][][] dct_data = image_dtt.mdctStack(
					  stack,
					  channel,
+17 −9
Original line number Diff line number Diff line
@@ -3075,7 +3075,7 @@ private Panel panel1,
           	}

           }
		  ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
		  ImageDtt image_dtt = new ImageDtt(DCT_PARAMETERS.dct_size, false, 1.0); // Bayer( not monochrome), scale correlation strengths
           double [][][][] dctdc_data = image_dtt.mdctScale(
           		DBG_IMP.getStack(),
           		DCT_PARAMETERS.kernel_chn,
@@ -3173,7 +3173,7 @@ private Panel panel1,
        	}

        }
        ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
        ImageDtt image_dtt = new ImageDtt(DCT_PARAMETERS.dct_size,false, 1.0); // Bayer( not monochrome), scale correlation strengths
        double [][][][] dctdc_data = image_dtt.mdctStack(
        		DBG_IMP.getStack(),
        		DCT_PARAMETERS.kernel_chn,
@@ -5723,6 +5723,7 @@ private Panel panel1,
		if (!prepareRigImages()) return false;
		String configPath=getSaveCongigPath();
		if (configPath.equals("ABORT")) return false;
//		if ((CORRECTION_PARAMETERS.tile_processor_gpu != null) &&

		if (DEBUG_LEVEL > -2){
			System.out.println("++++++++++++++ Calculating combined correlations ++++++++++++++");
@@ -5740,6 +5741,7 @@ private Panel panel1,

		try {
			TWO_QUAD_CLT.prepareFilesForGPUDebug(
					CORRECTION_PARAMETERS.tile_processor_gpu,//			String                                         save_prefix, // absolute path to the cuda project root
					QUAD_CLT, // QuadCLT quadCLT_main,
					QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
					CLT_PARAMETERS,  // EyesisCorrectionParameters.DCTParameters           dct_parameters,
@@ -7048,7 +7050,10 @@ private Panel panel1,
			}
		}

		ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
		ImageDtt image_dtt = new ImageDtt(
				CLT_PARAMETERS.transform_size,
				false,
				1.0); // Bayer( not monochrome), scale correlation strengths
		double [][][][][] clt_data = image_dtt.cltStack(
				DBG_IMP.getStack(),
				0, // CLT_PARAMETERS.kernel_chn,
@@ -7082,7 +7087,7 @@ private Panel panel1,
			for (int chn = 0; chn < clt_data.length; chn++) {
				clt_data[chn] = image_dtt.clt_shiftXY(
						clt_data[chn],                  // final double [][][][] dct_data,  // array [tilesY][tilesX][4][dct_size*dct_size]
						CLT_PARAMETERS.transform_size,  // final int             dct_size,
///						CLT_PARAMETERS.transform_size,  // final int             dct_size,
						CLT_PARAMETERS.shift_x,         // final double          shiftX,
						CLT_PARAMETERS.shift_y,         // final double          shiftY,
						(CLT_PARAMETERS.dbg_mode >> 2) & 3, // swap order hor/vert
@@ -7095,7 +7100,7 @@ private Panel panel1,
		for (int chn=0; chn<iclt_data.length;chn++){
			iclt_data[chn] = image_dtt.iclt_2d(
					clt_data[chn],                  // scanline representation of dcd data, organized as dct_size x dct_size tiles
					CLT_PARAMETERS.transform_size,  // final int
///					CLT_PARAMETERS.transform_size,  // final int
					CLT_PARAMETERS.clt_window,      //window_type
					CLT_PARAMETERS.iclt_mask,       //which of 4 to transform back
					CLT_PARAMETERS.dbg_mode,        //which of 4 to transform back
@@ -7178,7 +7183,10 @@ private Panel panel1,

        }
        String suffix = "-dx_"+(CLT_PARAMETERS.ishift_x+CLT_PARAMETERS.shift_x)+"_dy_"+(CLT_PARAMETERS.ishift_y+CLT_PARAMETERS.shift_y);
        ImageDtt image_dtt = new ImageDtt(COLOR_PROC_PARAMETERS.isMonochrome(), CLT_PARAMETERS.getScaleStrength(false)); // Bayer, not monochrome
        ImageDtt image_dtt = new ImageDtt(
        		CLT_PARAMETERS.transform_size,
        		COLOR_PROC_PARAMETERS.isMonochrome(),
        		CLT_PARAMETERS.getScaleStrength(false)); // Bayer, not monochrome
        String [] titles = {
        		"redCC",  "redSC",  "redCS",  "redSS",
        		"blueCC", "blueSC", "blueCS", "blueSS",
@@ -7235,7 +7243,7 @@ private Panel panel1,
            for (int chn = 0; chn < clt_data.length; chn++) {
        	clt_data2[chn] = image_dtt.clt_shiftXY(
        			clt_data2[chn],                 // final double [][][][] dct_data,  // array [tilesY][tilesX][4][dct_size*dct_size]
        			CLT_PARAMETERS.transform_size,  // final int             dct_size,
///        			CLT_PARAMETERS.transform_size,  // final int             dct_size,
        			CLT_PARAMETERS.shift_x,         // final double          shiftX,
        			CLT_PARAMETERS.shift_y,         // final double          shiftY,
        			(CLT_PARAMETERS.dbg_mode >> 2) & 3, // swap order hor/vert
@@ -7266,7 +7274,7 @@ private Panel panel1,
        	clt_corr[chn] = image_dtt.clt_correlate(
        			clt_data[chn],                  // final double [][][][] data1,  // array [tilesY][tilesX][4][dct_size*dct_size]
        			clt_data2[chn],                 // final double [][][][] data2,  // array [tilesY][tilesX][4][dct_size*dct_size]
        			CLT_PARAMETERS.transform_size,  // final int             dct_size,
///        			CLT_PARAMETERS.transform_size,  // final int             dct_size,
        			CLT_PARAMETERS.getFatZero(image_dtt.isMonochrome()),  // final double          fat_zero,    // add to denominator to modify phase correlation (same units as data1, data2)
            		CLT_PARAMETERS.tileX, //final int debug_tileX
            		CLT_PARAMETERS.tileY, //final int debug_tileY
@@ -7297,7 +7305,7 @@ private Panel panel1,
        		image_dtt.clt_lpf( // filter in-place
        				CLT_PARAMETERS.getCorrSigma(image_dtt.isMonochrome()),            // final double          sigma,
        				clt_corr[chn],                        // final double [][][][] clt_data,
        				CLT_PARAMETERS.transform_size,
///        				CLT_PARAMETERS.transform_size,
        				THREADS_MAX,                          // maximal number of threads to launch
        				DEBUG_LEVEL);                        // globalDebugLevel)
        	}
+286 −31

File changed.

Preview size limit exceeded, changes collapsed.

Loading