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

textures in lwir

parent 436cf9c1
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -767,7 +767,7 @@ public class Correlation2d {
    	pair_start_end = new int [num_pairs][2];
    	pair_orient =    new int [num_pairs][num_pairs];
    	pair_length =    new int [num_pairs];
    	top_is_0 = numSensors > 4; // sensor 0 is straight up, false half-rotated 
    	top_is_0 = imgdtt_params.getTopIs0(numSensors); // sensor 0 is straight up, false half-rotated 
    	cor_titles =       new String[num_pairs];
    	cor_titles_combo = new String[CORR_TITLES_EXTRA.length];
    	setupPairs();
@@ -796,6 +796,7 @@ public class Correlation2d {
    	pair_orient =    new int [num_pairs][num_pairs];
    	pair_length =    new int [num_pairs];
    	top_is_0 = numSensors > 4; // sensor 0 is straight up, false half-rotated
//     	top_is_0 = imgdtt_params.getTopIs0(numSensors); // sensor 0 is straight up, false half-rotated 
    	cor_titles =       new String[num_pairs];
    	cor_titles_combo = new String[CORR_TITLES_EXTRA.length];
    	setupPairs();
+51 −13
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public class ImageDttCPU {
			{0,2,1},
			{1,3,1}};
	public static double[][] PORT_OFFSETS = {
	public static double[][] PORT_OFFSETS4 = {
			{-0.5, -0.5},
			{ 0.5, -0.5},
			{-0.5,  0.5},
@@ -268,6 +268,7 @@ public class ImageDttCPU {
	  public final int numSensors;
	  public Correlation2d correlation2d = null;
	  final ImageDttParameters imgdtt_params;
	  final double [][] port_offsets;
	  // Save correlation parameters to instantiate  Correlation2d when first needed (called getCorrelation2d(),
	  // do it before threads to prevent races
	  
@@ -285,6 +286,26 @@ public class ImageDttCPU {
     public static boolean getOrthoLines (int data){return (data & 0x200) != 0;} // not used in lwir
     public static int     setOrthoLines (int data, boolean force) {return (data & ~0x200) | (force?0x200:0);} // not used in lwir
     
     public int getNumSensors() {
    	 return numSensors;
     }
     // different scale for quad and multi: Multi - diameter == 1.0, quad - side = 1.0
     public static double [][]getPortOffsets(int num_sensors, boolean quad_sequence, boolean topis0) {
    	 if ((num_sensors==4) && quad_sequence) {
    		 return PORT_OFFSETS4;
    	 } else {
    		 double [][] port_offsets = new double [num_sensors][2];
    		 for (int i = 0; i < num_sensors; i++) {
    			 double alpha = 2 * Math.PI * (i + (topis0 ? 0 : 0.5))/num_sensors;
    			 port_offsets[i][0] =  0.5 * Math.sin((alpha));
    			 port_offsets[i][1] = -0.5 * Math.cos((alpha));
    		 }
        	 return port_offsets;
    	 }
     }
     
     
     public Correlation2d getCorrelation2d() {
    	 if (correlation2d == null) {
    		 // instantiate
@@ -312,6 +333,10 @@ public class ImageDttCPU {
		this.lwir =       lwir;
		this.scale_strengths = scale_strengths;
		this.imgdtt_params = imgdtt_params;
		this.port_offsets = getPortOffsets(
				numSensors, // int num_sensors,
				imgdtt_params.mcorr_quad_sequence, // boolean quad_sequence, 
				imgdtt_params.getTopIs0(numSensors));// boolean topis0
	}
	public double getScaleStrengths() {
@@ -2756,6 +2781,14 @@ public class ImageDttCPU {
						tIndex = tileY * tilesX + tileX;
						if (tile_op[tileY][tileX] == 0) continue; // nothing to do for this tile
						int                 img_mask =  getImgMask(tile_op[tileY][tileX]);         // which images to use
						if (numSensors > 4) {
							if (img_mask == 0xf) {
								for (int i = 0; i < numSensors; i++){
									img_mask |= 1 << i;
								}
							}
						}
						
						int                 corr_mask = getPairMask(tile_op[tileY][tileX]);       // which pairs to combine in the combo:  1 - top, 2 bottom, 4 - left, 8 - right
						// mask out pairs that use missing channels
						for (int i = 0; i< CORR_PAIRS.length; i++){
@@ -3722,8 +3755,8 @@ public class ImageDttCPU {
											fract_shift(    // fractional shift in transform domain. Currently uses sin/cos - change to tables with 2? rotations
													clt_data[i][ncol][tileY][tileX], // double  [][]  clt_tile,
//													transform_size,
													extra_disparity * PORT_OFFSETS[i][0] / corr_magic_scale,     // double        shiftX,
													extra_disparity * PORT_OFFSETS[i][1] / corr_magic_scale,     // double        shiftY,
													extra_disparity * port_offsets[i][0] / corr_magic_scale,     // double        shiftX,
													extra_disparity * port_offsets[i][1] / corr_magic_scale,     // double        shiftY,
													//									(globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)); // external tile compare
													((globalDebugLevel > 0) && (ncol==0) && (tileX >= debug_tileX - 2) && (tileX <= debug_tileX + 2) &&
															(tileY >= debug_tileY - 2) && (tileY <= debug_tileY+2)));
@@ -3839,7 +3872,7 @@ public class ImageDttCPU {
									ports_rgb, // double []     ports_rgb,      // average values of R,G,B for each camera (R0,R1,...,B2,B3)
									max_diff,        // maximal (weighted) deviation of each channel from the average
									lt_window2,      // [256]
									PORT_OFFSETS,    // [port]{x_off, y_off}
									port_offsets,    // [port]{x_off, y_off}
									img_mask,        // which port to use, 0xf - all 4 (will modify as local variable)
									diff_sigma,      // pixel value/pixel change
									diff_threshold,  // pixel value/pixel change
@@ -3950,8 +3983,13 @@ public class ImageDttCPU {
			}
		}
		int usedPorts = ((port_mask >> 0) & 1) + ((port_mask >> 1) & 1) + ((port_mask >> 2) & 1) + ((port_mask >> 3) & 1);
//		int usedPorts = ((port_mask >> 0) & 1) + ((port_mask >> 1) & 1) + ((port_mask >> 2) & 1) + ((port_mask >> 3) & 1);
		int usedPorts = 0;
		for (int i = port_mask; i != 0; i >>= 1) {
			if (( i & 1) !=0) {
				usedPorts++;
			}
		}
		double [][] port_weights = new double[ports][tile_len];
		double [][] color_avg =    new double[numcol][tile_len];
@@ -4001,7 +4039,7 @@ public class ImageDttCPU {
		double []  alpha = new double[tile_len];
		double threshold2 = diff_sigma * diff_threshold;
		threshold2 *= threshold2; // squared to compare with diff^2
		if (usedPorts > 1) {
		if (usedPorts > 1) { // lwir16:
			double [] pair_dist2r =  new double [ports*(ports-1)/2]; // reversed squared distance between images - to be used with gaussian. Can be calculated once !
			int [][]  pair_ports = new int [ports*(ports-1)/2][2];
			int indx = 0;
@@ -5154,7 +5192,7 @@ public class ImageDttCPU {
			}
		}
		final double [][] dpixels = new double["RGBA".length()+(has_weights? 8: 0)][width*height]; // assuming java initializes them to 0
		final double [][] dpixels = new double["RGBA".length()+(has_weights? (numSensors+4): 0)][width*height]; // assuming java initializes them to 0
		final Thread[] threads = newThreadArray(threadsMax);
		final AtomicInteger ai = new AtomicInteger(0);
		final AtomicInteger nser = new AtomicInteger(0);
@@ -11011,7 +11049,7 @@ public class ImageDttCPU {
									texture_tiles_main,    // final double [][][][]  texture_tiles,   // [tilesY][tilesX]["RGBA".length()][];  null - will skip images combining
									lpf_rgb, //null, // filter, //null               // final double []        filter,
									lt_window2,            // final double []        lt_window2,
									PORT_OFFSETS,          // final double[][]       port_offsets,
									port_offsets,          // final double[][]       port_offsets,
									col_weights,           // final double []        col_weights,
									dtt,                   // final DttRad2          dtt,
									tileX,                 // final int              tileX, // only used in debug output
@@ -11033,7 +11071,7 @@ public class ImageDttCPU {
									texture_tiles_aux,    // final double [][][][]  texture_tiles,   // [tilesY][tilesX]["RGBA".length()][];  null - will skip images combining
									lpf_rgb, //  null, // filter,                // final double []        filter,
									lt_window2,            // final double []        lt_window2,
									PORT_OFFSETS,          // final double[][]       port_offsets,
									port_offsets,          // final double[][]       port_offsets,
									col_weights,           // final double []        col_weights,
									dtt,                   // final DttRad2          dtt,
									tileX,                 // final int              tileX, // only used in debug output
@@ -13685,8 +13723,8 @@ public class ImageDttCPU {
											fract_shift(    // fractional shift in transform domain. Currently uses sin/cos - change to tables with 2? rotations
													clt_data[i][ncol][tileY][tileX], // double  [][]  clt_tile,
//													transform_size,
													extra_disparity * PORT_OFFSETS[i][0] / corr_magic_scale,     // double        shiftX,
													extra_disparity * PORT_OFFSETS[i][1] / corr_magic_scale,     // double        shiftY,
													extra_disparity * port_offsets[i][0] / corr_magic_scale,     // double        shiftX,
													extra_disparity * port_offsets[i][1] / corr_magic_scale,     // double        shiftY,
													//									(globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)); // external tile compare
													((globalDebugLevel > 0) && (ncol==0) && (tileX >= debug_tileX - 2) && (tileX <= debug_tileX + 2) &&
															(tileY >= debug_tileY - 2) && (tileY <= debug_tileY+2)));
@@ -13802,7 +13840,7 @@ public class ImageDttCPU {
									ports_rgb, // double []     ports_rgb,      // average values of R,G,B for each camera (R0,R1,...,B2,B3)
									max_diff,        // maximal (weighted) deviation of each channel from the average
									lt_window2,      // [256]
									PORT_OFFSETS,    // [port]{x_off, y_off}
									port_offsets,    // [port]{x_off, y_off}
									img_mask,        // which port to use, 0xf - all 4 (will modify as local variable)
									diff_sigma,      // pixel value/pixel change
									diff_threshold,  // pixel value/pixel change
+26 −0
Original line number Diff line number Diff line
@@ -86,6 +86,9 @@ public class ImageDttParameters {
	public int     cnvx_min_pairs =         5;     // minimal number 2D correlation pairs per tile

	public int     mcorr_multi =            4;     // apply *_multi if number of sensors >= mcorr_multi
	public boolean mcorr_quad_sequence =    true;  // use linescan (old) numeration for quad cameras
	public boolean mcorr_topis0 =           false; // sensor 0 is on top (false - zero and last have same height)
	public boolean mcorr_topis0_multi =     true;  // sensor 0 is on top (false - zero and last have same height)
	public boolean mcorr_all =              true;  // correlate all N*(N-1)/2 pairs
	public boolean mcorr_all_multi =        false; // correlate all N*(N-1)/2 pairs for multi
	public boolean mcorr_dia =              true;  // all diameters (2 pairs for quad, 8 - for lwir16)
@@ -239,6 +242,9 @@ public class ImageDttParameters {
		enhortho_scale = s;
	}
	
	public boolean getTopIs0(int numSens) {
		return (numSens > mcorr_multi) ? mcorr_topis0_multi : mcorr_topis0;
	}
	
	public boolean getMcorrAll(int numSens) {
		return (numSens > mcorr_multi) ? mcorr_all_multi : mcorr_all;
@@ -367,6 +373,14 @@ public class ImageDttParameters {
			gd.addNumericField("Min number of sensors for \"multi\"",                             this.mcorr_multi,  0, 3, "sensors",
					"Cameras with this or larger number of sensor will use a \"_multi\" version of parameters (when available)");

			gd.addCheckbox    ("Use linescan (old) numeration for quad cameras",               this.mcorr_quad_sequence,
					"if true, quadcam ports CW are 2,4,2,0, if false - 0, 1, 2, 3");
			
			gd.addCheckbox    ("Top is 0 for small cameras",               this.mcorr_topis0,
					"True if sensor 0 is strait up, false if it is rotated clockwise so it has the same height as the last sensor");
			gd.addCheckbox    ("Top is 0 for multi cameras",               this.mcorr_topis0_multi,
					"True if sensor 0 is strait up, false if it is rotated clockwise so it has the same height as the last sensor");
			
			gd.addCheckbox    ("Calculate all correlation pairs for small cameras",               this.mcorr_all,
					"N*(N-1)/2: 6 for quad, 120 for lwir16 ");
			gd.addCheckbox    ("Calculate all correlation pairs for multi cameras",               this.mcorr_all_multi,
@@ -687,6 +701,9 @@ public class ImageDttParameters {
  			this.cnvx_min_pairs=   (int) gd.getNextNumber();

  			this.mcorr_multi=      (int) gd.getNextNumber();
  			this.mcorr_quad_sequence =   gd.getNextBoolean();
  			this.mcorr_topis0 =          gd.getNextBoolean();
  			this.mcorr_topis0_multi =    gd.getNextBoolean();
  			this.mcorr_all =             gd.getNextBoolean();
  			this.mcorr_all_multi =       gd.getNextBoolean();
  			this.mcorr_dia =             gd.getNextBoolean();
@@ -868,6 +885,9 @@ public class ImageDttParameters {
		properties.setProperty(prefix+"cnvx_min_pairs",       this.cnvx_min_pairs +"");

		properties.setProperty(prefix+"mcorr_multi",          this.mcorr_multi +"");
		properties.setProperty(prefix+"mcorr_quad_sequence",  this.mcorr_quad_sequence +"");
		properties.setProperty(prefix+"mcorr_topis0",         this.mcorr_topis0 +"");
		properties.setProperty(prefix+"mcorr_topis0_multi",   this.mcorr_topis0_multi +"");
		properties.setProperty(prefix+"mcorr_all",            this.mcorr_all +"");
		properties.setProperty(prefix+"mcorr_all_multi",      this.mcorr_all_multi +"");
		properties.setProperty(prefix+"mcorr_dia",            this.mcorr_dia +"");
@@ -1053,6 +1073,9 @@ public class ImageDttParameters {
		if (properties.getProperty(prefix+"cnvx_min_pairs")!=null)       this.cnvx_min_pairs=Integer.parseInt(properties.getProperty(prefix+"cnvx_min_pairs"));
		
		if (properties.getProperty(prefix+"mcorr_multi")!=null)          this.mcorr_multi=Integer.parseInt(properties.getProperty(prefix+"mcorr_multi"));
		if (properties.getProperty(prefix+"mcorr_quad_sequence")!=null)  this.mcorr_quad_sequence=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_quad_sequence"));
		if (properties.getProperty(prefix+"mcorr_topis0")!=null)         this.mcorr_topis0=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_topis0"));
		if (properties.getProperty(prefix+"mcorr_topis0_multi")!=null)   this.mcorr_topis0_multi=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_topis0_multi"));
		if (properties.getProperty(prefix+"mcorr_all")!=null)            this.mcorr_all=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_all"));
		if (properties.getProperty(prefix+"mcorr_all_multi")!=null)      this.mcorr_all_multi=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_all_multi"));
		if (properties.getProperty(prefix+"mcorr_dia")!=null)            this.mcorr_dia=Boolean.parseBoolean(properties.getProperty(prefix+"mcorr_dia"));
@@ -1233,6 +1256,9 @@ public class ImageDttParameters {
		idp.cnvx_min_pairs=          this.cnvx_min_pairs;

		idp.mcorr_multi=             this.mcorr_multi;
		idp.mcorr_quad_sequence=     this.mcorr_quad_sequence;
		idp.mcorr_topis0=            this.mcorr_topis0;
		idp.mcorr_topis0_multi=      this.mcorr_topis0_multi;
		idp.mcorr_all=               this.mcorr_all;
		idp.mcorr_all_multi=         this.mcorr_all_multi;
		idp.mcorr_dia=               this.mcorr_dia;
+18 −3
Original line number Diff line number Diff line
@@ -4709,7 +4709,7 @@ public class QuadCLTCPU {
			  }
			  
		  }
		  if (debugLevel > -1000) texture_tiles = null; // FIXME: until texture generation for multi-cam is fixed
		  if (debugLevel > 1000) texture_tiles = null; // FIXME: until texture generation for multi-cam is fixed
		  
		  double [][][][][][] clt_data = image_dtt.clt_aberrations_quad_corr(
				  clt_parameters.img_dtt,       // final ImageDttParameters  imgdtt_params,   // Now just extra correlation parameters, later will include, most others
@@ -4781,7 +4781,21 @@ public class QuadCLTCPU {
		  double [][] texture_nonoverlap = null;
		  double [][] texture_overlap = null;
		  String [] rbga_titles = {"red","blue","green","alpha"};
		  String [] rbga_weights_titles = {"red","blue","green","alpha","port0","port1","port2","port3","r-rms","b-rms","g-rms","w-rms"};
//		  String [] rbga_weights_titles4 = {"red","blue","green","alpha","port0","port1","port2","port3","r-rms","b-rms","g-rms","w-rms"};
		  String [] rbga_weights_titles_pre =  {"red","blue","green","alpha"};
		  String [] rbga_weights_titles_post = {"r-rms","b-rms","g-rms","w-rms"};
		  String [] rbga_weights_titles = new String[rbga_weights_titles_pre.length + rbga_weights_titles_post.length + image_dtt.getNumSensors()];
		  int indx = 0;
		  for (int i = 0; i < rbga_weights_titles_pre.length; i++) {
			  rbga_weights_titles[indx++] = rbga_weights_titles_pre[i];
		  }
		  for (int i = 0; i < image_dtt.getNumSensors(); i++) {
			  rbga_weights_titles[indx++] = "port"+i;
		  }
		  for (int i = 0; i < rbga_weights_titles_post.length; i++) {
			  rbga_weights_titles[indx++] = rbga_weights_titles_post[i];
		  }	
		  
		  // In monochrome mode only G is used ImageDtt.MONO_CHN(==2), others are null
		  if (texture_tiles != null){
			  if (clt_parameters.show_nonoverlap){// not used in lwir
@@ -4832,7 +4846,7 @@ public class QuadCLTCPU {
					  // for now - use just RGB. Later add option for RGBA
					  double [][] texture_rgb = {texture_overlap[0],texture_overlap[1],texture_overlap[2]};
					  double [][] texture_rgba = {texture_overlap[0],texture_overlap[1],texture_overlap[2],texture_overlap[3]};
//					  ImagePlus img_texture =
					  ImagePlus img_texture =
					  linearStackToColor(
							  clt_parameters,
							  colorProcParameters,
@@ -4848,6 +4862,7 @@ public class QuadCLTCPU {
							  tilesY *  image_dtt.transform_size,
							  1.0,         // double scaleExposure, // is it needed?
							  debugLevel );
					  img_texture.show();
				  }
			  }
		  }