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

updating before branching

parent a817f0c0
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -3335,6 +3335,7 @@ public class GpuQuad{ // quad camera description
	public TpTask[]  setInterTasks(
	public TpTask[]  setInterTasks(
			final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
			final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
			final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
			final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
			final boolean []          selection, // may be null, if not null do not  process unselected tiles
			final GeometryCorrection  geometryCorrection,
			final GeometryCorrection  geometryCorrection,
			final double              disparity_corr,
			final double              disparity_corr,
			final int                 margin,      // do not use tiles if their centers are closer to the edges
			final int                 margin,      // do not use tiles if their centers are closer to the edges
@@ -3346,6 +3347,7 @@ public class GpuQuad{ // quad camera description
				img_width,          // final int                 img_width,
				img_width,          // final int                 img_width,
				calcPortsCoordinatesAndDerivatives, // final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
				calcPortsCoordinatesAndDerivatives, // final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
				pXpYD,              // final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
				pXpYD,              // final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
				selection,          // final boolean []          selection, // may be null, if not null do not  process unselected tiles
				geometryCorrection, // final GeometryCorrection  geometryCorrection,
				geometryCorrection, // final GeometryCorrection  geometryCorrection,
				disparity_corr,     // final double              disparity_corr,
				disparity_corr,     // final double              disparity_corr,
				margin,             // final int                 margin,      // do not use tiles if their centers are closer to the edges
				margin,             // final int                 margin,      // do not use tiles if their centers are closer to the edges
@@ -3358,6 +3360,7 @@ public class GpuQuad{ // quad camera description
			final int                 img_width,
			final int                 img_width,
			final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
			final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
			final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
			final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
			final boolean []          selection, // may be null, if not null do not  process unselected tiles
			final GeometryCorrection  geometryCorrection,
			final GeometryCorrection  geometryCorrection,
			final double              disparity_corr,
			final double              disparity_corr,
			final int                 margin,      // do not use tiles if their centers are closer to the edges
			final int                 margin,      // do not use tiles if their centers are closer to the edges
@@ -3395,9 +3398,7 @@ public class GpuQuad{ // quad camera description
			threads[ithread] = new Thread() {
			threads[ithread] = new Thread() {
				@Override
				@Override
				public void run() {
				public void run() {
					//    					for (int indx = ai.getAndIncrement(); indx < tp_tasks.length; indx = ai.getAndIncrement()) {
					for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if ((pXpYD[nTile] != null) && ((selection == null) || selection[nTile])) {
					//   						int nTile = tile_indices[indx];
					for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if (pXpYD[nTile] != null) {
						int tileY = nTile / tilesX;
						int tileY = nTile / tilesX;
						int tileX = nTile % tilesX;
						int tileX = nTile % tilesX;
						TpTask tp_task = new TpTask(num_cams, tileX, tileY);
						TpTask tp_task = new TpTask(num_cams, tileX, tileY);
+39 −113
Original line number Original line Diff line number Diff line
@@ -107,6 +107,8 @@ public class Corr2dLMA {
	private double []         values;
	private double []         values;


	// next values are only updated after success
	// next values are only updated after success
	private int iter =        0; // to be able to read number of used iterations 

	private double []         last_rms =        null; // {rms, rms_pure}, matching this.vector
	private double []         last_rms =        null; // {rms, rms_pure}, matching this.vector
	private double []         good_or_bad_rms = null; // just for diagnostics, to read last (failed) rms
	private double []         good_or_bad_rms = null; // just for diagnostics, to read last (failed) rms
	private double []         initial_rms =     null; // {rms, rms_pure}, first-calcualted rms
	private double []         initial_rms =     null; // {rms, rms_pure}, first-calcualted rms
@@ -153,6 +155,11 @@ public class Corr2dLMA {


    public int                bad_tile=-1;   // bad tile - exponent got infinite, remove the tile and start over again
    public int                bad_tile=-1;   // bad tile - exponent got infinite, remove the tile and start over again
                                             // happens in gaussian mode with the convex area around wrong maximum
                                             // happens in gaussian mode with the convex area around wrong maximum
    public int getNumIter() {
    	return iter;
    }
//	private int iter =        0; // to be able to read number of used iterations 



	public class Sample{ // USED in lwir
	public class Sample{ // USED in lwir
		int    tile;   // tile in a cluster
		int    tile;   // tile in a cluster
@@ -207,33 +214,13 @@ public class Corr2dLMA {
		this.gaussian_mode = gaussian_mode;
		this.gaussian_mode = gaussian_mode;
		this.used_cams_map  =  new int[num_cams];
		this.used_cams_map  =  new int[num_cams];
		
		
		
		/*
		this.pindx =           new int [num_cams][num_cams];
		for (int f = 0; f < num_cams; f++) {
			pindx[f][f]=-1;
			for (int s = f+1; s < num_cams; s++) {
				pindx[f][s] = getPairIndex(f,s);
				pindx[s][f] = pindx[f][s];
			}
		}
		*/
		
		
		this.numTiles = numTiles;
		this.numTiles = numTiles;
		ddisp_index = this.numTiles * this.tile_params; // ;
		ddisp_index = this.numTiles * this.tile_params; // ;
		ndisp_index =  ddisp_index + num_cams;  // disparity offset per camera - none should be disable
		ndisp_index =  ddisp_index + num_cams;  // disparity offset per camera - none should be disable
		num_all_pars = ndisp_index+ num_cams; // maximal number of parameters
		num_all_pars = ndisp_index+ num_cams; // maximal number of parameters

//		boolean sq = true; // false;
		this.transform_size = ts;
		this.transform_size = ts;
	    this.corr_wnd = corr_wnd;
	    this.corr_wnd = corr_wnd;
	}
	}
/*
	public static double [][] getCorrWnd(int transform_size){
		return getCorrWnd(transform_size, true);// false);
	}
*/
	public static double [][] getCorrWnd(int transform_size, double pwr){ // sq = false
	public static double [][] getCorrWnd(int transform_size, double pwr){ // sq = false
//		double pwr = 1.3;
//		double pwr = 1.3;
		double [][] corr_wnd = new double[2 * transform_size - 1][2 * transform_size - 1];
		double [][] corr_wnd = new double[2 * transform_size - 1][2 * transform_size - 1];
@@ -264,32 +251,13 @@ public class Corr2dLMA {
		}
		}
		return corr_wnd;
		return corr_wnd;
	}
	}

//	public double[][] getCorrWnd() {
//		return this.corr_wnd;
//	}
/*
	public void addSample( // x = 0, y=0 - center
			int    tile,
			int    fcam,   // first  camera index
			int    scam,   // second camera index
			int    x,      // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
			int    y,      // y coordinate (0 - disparity axis)
			double v,      // correlation value at that point
			double w) {    // sample weight
		if ((w > 0) && !Double.isNaN(v)) samples.add(new Sample(tile,fcam,scam,x,y,v,w));
	}
*/
	public void addSample( // x = 0, y=0 - center
	public void addSample( // x = 0, y=0 - center
			int    tile,
			int    tile,
			int    pair,
			int    pair,
//			int    fcam,   // first  camera index
//			int    scam,   // second camera index
			int    x,      // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
			int    x,      // x coordinate on the common scale (corresponding to the largest baseline), along the disparity axis
			int    y,      // y coordinate (0 - disparity axis)
			int    y,      // y coordinate (0 - disparity axis)
			double v,      // correlation value at that point
			double v,      // correlation value at that point
			double w) {    // sample weight
			double w) {    // sample weight
//		if ((w > 0) && !Double.isNaN(v)) samples.add(new Sample(tile,fcam,scam,x,y,v,w));
		if ((w > 0) && !Double.isNaN(v)) samples.add(new Sample(tile,pair,x,y,v,w));
		if ((w > 0) && !Double.isNaN(v)) samples.add(new Sample(tile,pair,x,y,v,w));
	}
	}
	
	
@@ -307,7 +275,7 @@ public class Corr2dLMA {
		return samples;
		return samples;
	}
	}


	// maybe in the future - just remove a pad pair?
	// maybe in the future - just remove a bad pair?
	private void removeBadTile(
	private void removeBadTile(
			int ntile,
			int ntile,
			int fcam,   // not yet used, maybe try removing just a pair, not all tile?
			int fcam,   // not yet used, maybe try removing just a pair, not all tile?
@@ -338,9 +306,6 @@ public class Corr2dLMA {
	}
	}


	public double [][][] dbgGetSamples(double [][] ds, int mode){
	public double [][][] dbgGetSamples(double [][] ds, int mode){
//		int [][] comb_map = getCombMap();
//		int numPairs = comb_map[0][0];
//		comb_map[0][0] = -1;
		int numPairs = getNumAllTilesUsedPairs();
		int numPairs = getNumAllTilesUsedPairs();
		int size = 2* transform_size -1;
		int size = 2* transform_size -1;
		int size2 = size*size;
		int size2 = size*size;
@@ -366,8 +331,6 @@ public class Corr2dLMA {
			if      (mode == 0) d = s.v;
			if      (mode == 0) d = s.v;
			else if (mode == 1) d = s.w;
			else if (mode == 1) d = s.w;
			else if (mode == 2) d = fx[ns];
			else if (mode == 2) d = fx[ns];
//			int np = comb_map[s.fcam][s.scam]; ////////////////////
//			int np = s.pair; ////////////////////
			int inp = used_pairs_map[s.tile][s.pair];
			int inp = used_pairs_map[s.tile][s.pair];
			rslt[s.tile][inp][s.iy*size + s.ix] = d;
			rslt[s.tile][inp][s.iy*size + s.ix] = d;
		}
		}
@@ -378,7 +341,6 @@ public class Corr2dLMA {
	public String [] dbgGetSliceTitles() {
	public String [] dbgGetSliceTitles() {
		int [] comb_map = getCombMap();
		int [] comb_map = getCombMap();
		int np = getNumAllTilesUsedPairs(); // comb_map[0][0];
		int np = getNumAllTilesUsedPairs(); // comb_map[0][0];
//		comb_map[0][0] = -1;
		String [] srslt = new String [np];
		String [] srslt = new String [np];
		for (int npair = 0; npair < comb_map.length; npair++) {
		for (int npair = 0; npair < comb_map.length; npair++) {
			if (comb_map[npair] >= 0) {
			if (comb_map[npair] >= 0) {
@@ -389,27 +351,6 @@ public class Corr2dLMA {
		return srslt;
		return srslt;
	}
	}
	
	
	/*
	@Deprecated
	public int [][] getCombMap(){
		boolean [][]  comb_pairs = new boolean[num_cams][num_cams];

		for (int t = 0; t < numTiles; t++) {
			for (int f = 0; f < num_cams; f++) for (int s = 0; s < num_cams; s++) {
				comb_pairs[f][s] |= used_pairs_map[t][f][s] >= 0;
			}
		}
		int np = 0;
		int [][] comb_map = new int [num_cams][num_cams];
		for (int f = 0; f < num_cams; f++) for (int s = 0; s < num_cams; s++) {
			if  (comb_pairs[f][s]) comb_map[f][s] = np++;
			else comb_map[f][s] = -1;
		}
		comb_map[0][0] = np;
		return comb_map;

	}
   */
	public int [] getCombMap(){
	public int [] getCombMap(){
		int []comb_map = new int [num_pairs];
		int []comb_map = new int [num_pairs];
		Arrays.fill(comb_map, -1);
		Arrays.fill(comb_map, -1);
@@ -625,8 +566,6 @@ public class Corr2dLMA {
			boolean adjust_lazyeye_par,   // adjust disparity corrections parallel to disparities                    lma_adjust_wxy
			boolean adjust_lazyeye_par,   // adjust disparity corrections parallel to disparities                    lma_adjust_wxy
			boolean adjust_lazyeye_ortho, // obsolete - make == adjust_lazyeye_par adjust disparity corrections orthogonal to disparities                  lma_adjust_ly1
			boolean adjust_lazyeye_ortho, // obsolete - make == adjust_lazyeye_par adjust disparity corrections orthogonal to disparities                  lma_adjust_ly1
			double [][] disp_str,         // initial value of disparity
			double [][] disp_str,         // initial value of disparity
//			double [][] ly_offsets_pairs, // common for all tiles: initial per sensor x,y LY offsets (or null)  
//			double [][] ly_offsets_pairs, // common for all tiles: initial per pair x,y LY offsets (or null)  
			double  half_width,           // A=1/(half_widh)^2                                                       lma_half_width
			double  half_width,           // A=1/(half_widh)^2                                                       lma_half_width
			double  cost_lazyeye_par,     // cost for each of the non-zero disparity corrections                     lma_cost_wy
			double  cost_lazyeye_par,     // cost for each of the non-zero disparity corrections                     lma_cost_wy
			double  cost_lazyeye_odtho    // cost for each of the non-zero ortho disparity corrections               lma_cost_wxy
			double  cost_lazyeye_odtho    // cost for each of the non-zero ortho disparity corrections               lma_cost_wxy
@@ -634,18 +573,13 @@ public class Corr2dLMA {
		adjust_lazyeye_ortho = adjust_lazyeye_par; // simplify relations for the calculated/dependent parameters
		adjust_lazyeye_ortho = adjust_lazyeye_par; // simplify relations for the calculated/dependent parameters
		lazy_eye = adjust_lazyeye_par | adjust_lazyeye_ortho;
		lazy_eye = adjust_lazyeye_par | adjust_lazyeye_ortho;
		bad_tile = -1;
		bad_tile = -1;
//		used_pairs_map = new int [numTiles][num_cams][num_cams];
		used_cameras = new boolean[num_cams];
		used_cameras = new boolean[num_cams];
		boolean [][] used_pairs = new boolean[numTiles][num_pairs];
		boolean [][] used_pairs = new boolean[numTiles][num_pairs];
		// 0-weight values and NaN-s should be filtered on input!
		// 0-weight values and NaN-s should be filtered on input!
//		for (int t = 0; t < numTiles; t++) for (int f = 0; f < num_cams; f++) for (int s = 0; s < num_cams; s++) {
//			used_pairs_map[t][f][s] = -1;
//		}
		used_pairs_map = new int [numTiles][num_pairs];
		used_pairs_map = new int [numTiles][num_pairs];
		for (int t = 0; t < numTiles; t++) {
		for (int t = 0; t < numTiles; t++) {
			Arrays.fill(used_pairs_map[t], -1);
			Arrays.fill(used_pairs_map[t], -1);
		}
		}
//		boolean [][][] used_pairs_dir = new boolean [numTiles][num_cams][num_cams];
		used_tiles = new boolean[numTiles];
		used_tiles = new boolean[numTiles];
		for (Sample s:samples) { // ignore zero-weight samples
		for (Sample s:samples) { // ignore zero-weight samples
			int pair = s.pair;
			int pair = s.pair;
@@ -654,8 +588,6 @@ public class Corr2dLMA {
			used_cameras[fscam[1]]=true;
			used_cameras[fscam[1]]=true;
			used_tiles[s.tile] = true;
			used_tiles[s.tile] = true;
			used_pairs[s.tile][pair]=true; // throws < 0 - wrong pair, f==s
			used_pairs[s.tile][pair]=true; // throws < 0 - wrong pair, f==s
//			used_pairs_dir[s.tile][s.fcam][s.scam] = true;
//			used_pairs_dir[s.tile][fscam[0]][fscam[1]] = true;
		}
		}
		ncam_used = 0;
		ncam_used = 0;
		npairs =new int [numTiles];  // pairs in each tile
		npairs =new int [numTiles];  // pairs in each tile
@@ -686,22 +618,8 @@ public class Corr2dLMA {
				upmam[i] = npairs[nTile];
				upmam[i] = npairs[nTile];
				if (used_pairs[nTile][i])  npairs[nTile]++;
				if (used_pairs[nTile][i])  npairs[nTile]++;
			}
			}
			/*
			for (int f = 0; f < num_cams; f++) {
				for (int s = f+1; s < num_cams; s++) {
					int npair = upmam[pindx[f][s]];
					if      (used_pairs_dir[nTile][f][s]) used_pairs_map[nTile][f][s] = npair;  // either or, can not be f,s and s,f pairs
					else if (used_pairs_dir[nTile][s][f]) used_pairs_map[nTile][s][f] = npair;
				}
			}
			*/
			for (int pair = 0; pair < num_pairs; pair++) {
			for (int pair = 0; pair < num_pairs; pair++) {
				int npair = upmam[pair];
				int npair = upmam[pair];
//				int [] fs = correlation2d.getPair(pair);
//				if      (used_pairs_dir[nTile][fs[0]][fs[1]]) used_pairs_map[nTile][fs[0]][fs[1]] = npair;  // either or, can not be f,s and s,f pairs
//				else if (used_pairs_dir[nTile][fs[1]][fs[0]]) used_pairs_map[nTile][fs[1]][fs[0]] = npair;
//				if      (used_pairs_dir[nTile][fs[0]][fs[1]]) used_pairs_map[nTile][pair] = npair;  // either or, can not be f,s and s,f pairs
//				else if (used_pairs_dir[nTile][fs[1]][fs[0]]) used_pairs_map[nTile][pair] = npair;
				if      (used_pairs[nTile][pair]) used_pairs_map[nTile][pair] = npair;
				if      (used_pairs[nTile][pair]) used_pairs_map[nTile][pair] = npair;
			}
			}
		}
		}
@@ -752,7 +670,6 @@ public class Corr2dLMA {
			total_weight += s.w;
			total_weight += s.w;
			values[i] =  s.v;
			values[i] =  s.v;
			sw += weights[i];
			sw += weights[i];
//			int indx = G0_INDEX + pindx[s.fcam][s.scam] + s.tile * tile_params;
			int indx = G0_INDEX + s.pair + s.tile * tile_params;
			int indx = G0_INDEX + s.pair + s.tile * tile_params;
			double d = s.v;
			double d = s.v;
			if (this.corr_wnd !=null) {
			if (this.corr_wnd !=null) {
@@ -794,14 +711,11 @@ public class Corr2dLMA {




	public void initMatrices() { // should be called after initVector and after setMatrices
	public void initMatrices() { // should be called after initVector and after setMatrices
//		m_pairs = new Matrix[used_pairs_map.length][num_cams][num_cams];
//		m_pairs_inv = new Matrix[used_pairs_map.length][num_cams][num_cams];
		m_pairs = new Matrix[used_pairs_map.length][num_pairs];
		m_pairs = new Matrix[used_pairs_map.length][num_pairs];
		m_pairs_inv = new Matrix[used_pairs_map.length][num_pairs];
		m_pairs_inv = new Matrix[used_pairs_map.length][num_pairs];
		for (int nTile = 0; nTile < used_pairs_map.length; nTile++) if (used_tiles[nTile]){
		for (int nTile = 0; nTile < used_pairs_map.length; nTile++) if (used_tiles[nTile]){
			for (int npair = 0; npair < num_pairs; npair++) {
			for (int npair = 0; npair < num_pairs; npair++) {
				int [] fs = correlation2d.getPair(npair); // TODO: change used_pairs_map?
				int [] fs = correlation2d.getPair(npair); // TODO: change used_pairs_map?
//				if (used_pairs_map[nTile][fs[0]][fs[1]] >= 0) {
				if (used_pairs_map[nTile][npair] >= 0) {
				if (used_pairs_map[nTile][npair] >= 0) {
					m_pairs[nTile][npair] =     m_disp[nTile][fs[0]].minus(m_disp[nTile][fs[1]]);
					m_pairs[nTile][npair] =     m_disp[nTile][fs[0]].minus(m_disp[nTile][fs[1]]);
					m_pairs_inv[nTile][npair] = m_pairs[nTile][npair].inverse();
					m_pairs_inv[nTile][npair] = m_pairs[nTile][npair].inverse();
@@ -812,13 +726,11 @@ public class Corr2dLMA {




	public void initInvertMatrices() { // should be called after initMatrices only if m_pairs_inv are needed
	public void initInvertMatrices() { // should be called after initMatrices only if m_pairs_inv are needed
//		m_pairs_inv = new Matrix[used_pairs_map.length][num_cams][num_cams];
		m_pairs_inv = new Matrix[used_pairs_map.length][num_pairs];
		m_pairs_inv = new Matrix[used_pairs_map.length][num_pairs];


		for (int nTile = 0; nTile < used_pairs_map.length; nTile++)  if (used_tiles[nTile]){
		for (int nTile = 0; nTile < used_pairs_map.length; nTile++)  if (used_tiles[nTile]){
			for (int npair = 0; npair < num_pairs; npair++) {
			for (int npair = 0; npair < num_pairs; npair++) {
				int [] fs = correlation2d.getPair(npair); // TODO: change used_pairs_map?
				int [] fs = correlation2d.getPair(npair); // TODO: change used_pairs_map?
//				if (used_pairs_map[nTile][fs[0]][fs[1]] >= 0) {
				if (used_pairs_map[nTile][npair] >= 0) {
				if (used_pairs_map[nTile][npair] >= 0) {
					m_pairs_inv[nTile][npair] = m_pairs[nTile][npair].inverse();
					m_pairs_inv[nTile][npair] = m_pairs[nTile][npair].inverse();
				}
				}
@@ -850,7 +762,6 @@ public class Corr2dLMA {
    		} else {
    		} else {
        		bv = s.v / corr_wnd[s.iy][s.ix];
        		bv = s.v / corr_wnd[s.iy][s.ix];
    		}
    		}
//    		bv /=this.all_pars[G0_INDEX + pindx[s.fcam][s.scam] + s.tile * tile_params];
    		bv /=this.all_pars[G0_INDEX + s.pair + s.tile * tile_params];
    		bv /=this.all_pars[G0_INDEX + s.pair + s.tile * tile_params];
    		//corr_wnd
    		//corr_wnd
    		int indx = 2 * ns;
    		int indx = 2 * ns;
@@ -863,7 +774,6 @@ public class Corr2dLMA {


    	    double [] aXY = {s.ix - center, s.iy - center};
    	    double [] aXY = {s.ix - center, s.iy - center};
    	    Matrix mXY = new Matrix(aXY,2);
    	    Matrix mXY = new Matrix(aXY,2);
//    	    Matrix mDDND = m_pairs_inv[s.tile][s.fcam][s.scam].times(mXY);
    	    Matrix mDDND = m_pairs_inv[s.tile][s.pair].times(mXY);
    	    Matrix mDDND = m_pairs_inv[s.tile][s.pair].times(mXY);


    	    mdata[indx  ][0][0] =  mDDND.get(0, 0); // dd
    	    mdata[indx  ][0][0] =  mDDND.get(0, 0); // dd
@@ -1532,9 +1442,9 @@ public class Corr2dLMA {
		double [] BT = new double [numTiles]; // av[B_INDEX];
		double [] BT = new double [numTiles]; // av[B_INDEX];
		double [] CT = new double [numTiles]; // A + av[CMA_INDEX];
		double [] CT = new double [numTiles]; // A + av[CMA_INDEX];
		for (int nTile = 0; nTile < numTiles; nTile++)  if (used_tiles[nTile]){
		for (int nTile = 0; nTile < numTiles; nTile++)  if (used_tiles[nTile]){
			for (int i = 0; i < num_cams; i++) if (used_cameras[i]) {
			for (int ncam = 0; ncam < num_cams; ncam++) if (used_cameras[ncam]) {
				double [] add_dnd = {av[DISP_INDEX+ nTile * tile_params]+ av[ddisp_index + i],  av[ndisp_index + i]};
				double [] add_dnd = {av[DISP_INDEX+ nTile * tile_params]+ av[ddisp_index + ncam],  av[ndisp_index + ncam]};
				xcam_ycam[nTile][i] = m_disp[nTile][i].times(new Matrix(add_dnd,2));
				xcam_ycam[nTile][ncam] = m_disp[nTile][ncam].times(new Matrix(add_dnd,2));
			}
			}
			for (int f = 0; f < num_cams; f++) if (used_cameras[f]) {
			for (int f = 0; f < num_cams; f++) if (used_cameras[f]) {
				for (int s = 0; s < num_cams; s++) if (used_cameras[s]) {
				for (int s = 0; s < num_cams; s++) if (used_cameras[s]) {
@@ -1590,7 +1500,7 @@ public class Corr2dLMA {
			if (s.tile > 0) {
			if (s.tile > 0) {
				System.out.print("");
				System.out.print("");
			}
			}
			if (jt != null) {
			if (jt != null) { // Need derivatives too, no just Fx
				if (par_map[DISP_INDEX + s.tile*tile_params] >= 0)  jt[par_map[DISP_INDEX + s.tile*tile_params]][ns] = 2 * WGpexp *
				if (par_map[DISP_INDEX + s.tile*tile_params] >= 0)  jt[par_map[DISP_INDEX + s.tile*tile_params]][ns] = 2 * WGpexp *
						((A * xmxp + B * ymyp) * m_pairs[s.tile][s.pair].get(0, 0)+
						((A * xmxp + B * ymyp) * m_pairs[s.tile][s.pair].get(0, 0)+
								(B * xmxp + C * ymyp) * m_pairs[s.tile][s.pair].get(1, 0));
								(B * xmxp + C * ymyp) * m_pairs[s.tile][s.pair].get(1, 0));
@@ -1698,6 +1608,33 @@ public class Corr2dLMA {
		return fx;
		return fx;
	}
	}


	/**
	 * Calculate each defined pair x,y expected offset, assuming only disparity, not lazy eye   
	 * @param corrs - pairs 2D correlations (each in scanline order) - just to determine null/non-null
	 * @param disparity - expected disparity (e.g. from CM)
	 * @param disp_dist - per camera disparity matrix as a 1d (linescan order))
	 * @return per pair x,y expected center offset in 2D correlations or nulls for undefined pairs (or null if already set)
	 */
	public double [][] getPairsOffsets(
			double [][]       corrs,
			boolean []        pair_mask,
			double            disparity,
			double [][]       disp_dist){ // 
		double [][] xy_offsets = new double [corrs.length][];
		if (disp_dist != null) {
			setMatrices(disp_dist);
		}
		for (int pair = 0; pair < xy_offsets.length; pair++) if ((pair < correlation2d.getNumPairs()) && (corrs[pair] != null) && ((pair_mask == null) || pair_mask[pair])){ // OK to calculate for each
 			int [] fscam = correlation2d.getPair(pair); // returns [first_cam, second_cam]
			Matrix mdd_dnd = new Matrix(new double[] {-disparity,  0.0},2);
			Matrix xcam_ycam_f = m_disp[0][fscam[0]].times(mdd_dnd);
			Matrix xcam_ycam_s = m_disp[0][fscam[1]].times(mdd_dnd);
			xy_offsets[pair] = xcam_ycam_f.minus(xcam_ycam_s).getColumnPackedCopy();	
		}
		return xy_offsets;
	}
	
	


	public void printParams() { // not used in lwir
	public void printParams() { // not used in lwir
		// to make sure it is updated
		// to make sure it is updated
@@ -1872,7 +1809,6 @@ public class Corr2dLMA {


	public void updateFromVector() { // USED in lwir
	public void updateFromVector() { // USED in lwir
		int np = 0;
		int np = 0;
//		all_pars = fromVector(vector);//


		for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) all_pars[i] = vector[np++];
		for (int i = 0; i < par_mask.length; i++) if (par_mask[i]) all_pars[i] = vector[np++];
		// just for reporting
		// just for reporting
@@ -1885,9 +1821,6 @@ public class Corr2dLMA {
		}
		}
		Matrix m5 = new Matrix(a5,a5.length); // single column, normally 5 rows
		Matrix m5 = new Matrix(a5,a5.length); // single column, normally 5 rows
		Matrix m3 = mddnd.times(m5);
		Matrix m3 = mddnd.times(m5);
//		all_pars[ddisp_index + used_cams_rmap[pre_last_cam]] = m3.get(0, 0);
//		all_pars[ddisp_index + used_cams_rmap[last_cam]] =     m3.get(1, 0);
//		all_pars[ndisp_index + used_cams_rmap[last_cam]] =     m3.get(2, 0);
		all_pars[ddisp_index + pre_last_cam] = m3.get(0, 0);
		all_pars[ddisp_index + pre_last_cam] = m3.get(0, 0);
		all_pars[ddisp_index + last_cam] =     m3.get(1, 0);
		all_pars[ddisp_index + last_cam] =     m3.get(1, 0);
		all_pars[ndisp_index + last_cam] =     m3.get(2, 0);
		all_pars[ndisp_index + last_cam] =     m3.get(2, 0);
@@ -1910,9 +1843,6 @@ public class Corr2dLMA {
		}
		}
		Matrix m5 = new Matrix(a5,a5.length); // single column, normally 5 rows
		Matrix m5 = new Matrix(a5,a5.length); // single column, normally 5 rows
		Matrix m3 = mddnd.times(m5);
		Matrix m3 = mddnd.times(m5);
//		ap[ddisp_index + used_cams_rmap[pre_last_cam]] = m3.get(0, 0);
//		ap[ddisp_index + used_cams_rmap[last_cam]] =     m3.get(1, 0);
//		ap[ndisp_index + used_cams_rmap[last_cam]] =     m3.get(2, 0);
		ap[ddisp_index + pre_last_cam] = m3.get(0, 0);
		ap[ddisp_index + pre_last_cam] = m3.get(0, 0);
		ap[ddisp_index + last_cam] =     m3.get(1, 0);
		ap[ddisp_index + last_cam] =     m3.get(1, 0);
		ap[ndisp_index + last_cam] =     m3.get(2, 0);
		ap[ndisp_index + last_cam] =     m3.get(2, 0);
@@ -2426,9 +2356,6 @@ public class Corr2dLMA {
	public double [][] getABCTile(){
	public double [][] getABCTile(){
		double [][] abc = new double[numTiles][3];
		double [][] abc = new double[numTiles][3];
		for (int tile = 0; tile < numTiles; tile++) {
		for (int tile = 0; tile < numTiles; tile++) {
//			abc[tile][0] =  (par_mask[A_INDEX+ tile * tile_params])? all_pars[A_INDEX+ tile * tile_params] :Double.NaN;
//			abc[tile][1] =  (par_mask[B_INDEX+ tile * tile_params])? all_pars[B_INDEX+ tile * tile_params] :Double.NaN;
//			abc[tile][2] = abc[tile][0] + ( (par_mask[CMA_INDEX+ tile * tile_params])? all_pars[CMA_INDEX+ tile * tile_params] :Double.NaN);
			abc[tile][0] =  all_pars[A_INDEX+ tile * tile_params];
			abc[tile][0] =  all_pars[A_INDEX+ tile * tile_params];
			abc[tile][1] =  all_pars[B_INDEX+ tile * tile_params];
			abc[tile][1] =  all_pars[B_INDEX+ tile * tile_params];
			abc[tile][2] =  abc[tile][0] + all_pars[CMA_INDEX+ tile * tile_params];
			abc[tile][2] =  abc[tile][0] + all_pars[CMA_INDEX+ tile * tile_params];
@@ -2461,7 +2388,6 @@ public class Corr2dLMA {
	{
	{
		boolean [] rslt = {false,false};
		boolean [] rslt = {false,false};
		this.last_rms = null;
		this.last_rms = null;
		int iter = 0;
		for (iter = 0; iter < num_iter; iter++) {
		for (iter = 0; iter < num_iter; iter++) {
			rslt =  lmaStep(
			rslt =  lmaStep(
					lambda,
					lambda,
+396 −77

File changed.

Preview size limit exceeded, changes collapsed.

+21 −22
Original line number Original line Diff line number Diff line
@@ -960,7 +960,6 @@ public class ErsCorrection extends GeometryCorrection {
		}
		}
		if (xyzw[2] > 0) {
		if (xyzw[2] > 0) {
			xyzw[2] = xyzw[2];
			xyzw[2] = xyzw[2];
///				return null; // can not match object behind the camera
		}
		}
		ErsCorrection ers_camera = this;
		ErsCorrection ers_camera = this;
		if (cameraQuadCLT != null) {
		if (cameraQuadCLT != null) {
+42 −6
Original line number Original line Diff line number Diff line
@@ -697,6 +697,7 @@ public class ImageDtt extends ImageDttCPU {
       	TpTask[] tp_tasks =  gpuQuad.setInterTasks(
       	TpTask[] tp_tasks =  gpuQuad.setInterTasks(
       			false, // final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
       			false, // final boolean             calcPortsCoordinatesAndDerivatives, // GPU can calculate them centreXY
       			pXpYD,              // final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
       			pXpYD,              // final double [][]         pXpYD, // per-tile array of pX,pY,disparity triplets (or nulls)
				null,               // final boolean []          selection, // may be null, if not null do not  process unselected tiles
       			geometryCorrection, // final GeometryCorrection  geometryCorrection,
       			geometryCorrection, // final GeometryCorrection  geometryCorrection,
       			disparity_corr,     // final double              disparity_corr,
       			disparity_corr,     // final double              disparity_corr,
       			margin,             // final int                 margin,      // do not use tiles if their centers are closer to the edges
       			margin,             // final int                 margin,      // do not use tiles if their centers are closer to the edges
@@ -2308,6 +2309,7 @@ public class ImageDtt extends ImageDttCPU {
			return;
			return;
		}
		}


		
		final double [][] debug_offsets = new double[getNumSensors()][2];  
		final double [][] debug_offsets = new double[getNumSensors()][2];  
		for (int i = 0; i < imgdtt_params.lma_dbg_offset.length; i++) for (int j = 0; j < debug_offsets[i].length; j++) {
		for (int i = 0; i < imgdtt_params.lma_dbg_offset.length; i++) for (int j = 0; j < debug_offsets[i].length; j++) {
			debug_offsets[i][j] = imgdtt_params.lma_dbg_offset[i][j]*imgdtt_params.lma_dbg_scale;
			debug_offsets[i][j] = imgdtt_params.lma_dbg_offset[i][j]*imgdtt_params.lma_dbg_scale;
@@ -2322,6 +2324,13 @@ public class ImageDtt extends ImageDttCPU {
		
		
		final int corr_size = transform_size * 2 - 1;
		final int corr_size = transform_size * 2 - 1;


		final double [][]         debug_lma = imgdtt_params.lmamask_dbg? (new double [6][tilesX*tilesY]):null;
		if (debug_lma != null) {
			for (int i = 0; i < debug_lma.length; i++) {
				Arrays.fill(debug_lma[i], Double.NaN);
			}
		}
		


		// reducing weight of on-axis correlation values to enhance detection of vertical/horizontal lines
		// reducing weight of on-axis correlation values to enhance detection of vertical/horizontal lines
		// multiply correlation results inside the horizontal center strip  2*enhortho_width - 1 wide by enhortho_scale
		// multiply correlation results inside the horizontal center strip  2*enhortho_width - 1 wide by enhortho_scale
@@ -2422,7 +2431,7 @@ public class ImageDtt extends ImageDttCPU {
			}
			}


			if (combine_corrs) {
			if (combine_corrs) {
				correlation2d.generateResample( // should be called before
				correlation2d.generateResample( // should be called before *** This can be done in CPU, table(s) copied to GPU 
						mcorr_comb_width,  // combined correlation tile width
						mcorr_comb_width,  // combined correlation tile width
						mcorr_comb_height, // combined correlation tile full height
						mcorr_comb_height, // combined correlation tile full height
						mcorr_comb_offset, // combined correlation tile height offset: 0 - centered (-height/2 to height/2), height/2 - only positive (0 to height)
						mcorr_comb_offset, // combined correlation tile height offset: 0 - centered (-height/2 to height/2), height/2 - only positive (0 to height)
@@ -2499,7 +2508,7 @@ public class ImageDtt extends ImageDttCPU {
								}
								}
							}
							}
							// get CM disparity/strength
							// get CM disparity/strength
							double [] disp_str = {0.0, 0.0}; // dispaprity = 0 will be initial approximation for LMA if no averaging
							double [] disp_str = {0.0, 0.0}; // disparity = 0 will be initial approximation for LMA if no averaging
							if (combine_corrs) {
							if (combine_corrs) {
								double [] corr_combo_tile = correlation2d.accumulateInit(); // combine all available pairs
								double [] corr_combo_tile = correlation2d.accumulateInit(); // combine all available pairs
								double sumw = 0.0;
								double sumw = 0.0;
@@ -2592,6 +2601,13 @@ public class ImageDtt extends ImageDttCPU {
									System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
									System.out.println("Will run new LMA for tileX="+tileX+", tileY="+tileY);
								}
								}
								double [] poly_disp = {Double.NaN, 0.0};
								double [] poly_disp = {Double.NaN, 0.0};
								double [] debug_lma_tile = (debug_lma != null) ? (new double [debug_lma.length]):null;
								if (debug_lma_tile != null) {
									for (int i = 0; i < debug_lma.length; i++) {
										debug_lma_tile[i] = debug_lma[i][nTile];
									}
								}
								
								Corr2dLMA lma2 = correlation2d.corrLMA2Single( // null pointer
								Corr2dLMA lma2 = correlation2d.corrLMA2Single( // null pointer
										imgdtt_params,                // ImageDttParameters  imgdtt_params,
										imgdtt_params,                // ImageDttParameters  imgdtt_params,
										imgdtt_params.lmas_LY_single, // false,    // boolean             adjust_ly, // adjust Lazy Eye
										imgdtt_params.lmas_LY_single, // false,    // boolean             adjust_ly, // adjust Lazy Eye
@@ -2605,9 +2621,12 @@ public class ImageDtt extends ImageDttCPU {
										disp_str,  //corr_stat[0],                 // double    xcenter,   // preliminary center x in pixels for largest baseline
										disp_str,  //corr_stat[0],                 // double    xcenter,   // preliminary center x in pixels for largest baseline
										poly_disp,                    // double[]            poly_ds,    // null or pair of disparity/strength
										poly_disp,                    // double[]            poly_ds,    // null or pair of disparity/strength
										imgdtt_params.ortho_vasw_pwr, // double    vasw_pwr,  // value as weight to this power,
										imgdtt_params.ortho_vasw_pwr, // double    vasw_pwr,  // value as weight to this power,
										-2, //0,                            // tile_lma_debug_level, // +2,         // int                 debug_level,
										debug_lma_tile,               // double []           debug_lma_tile,
										(debugTile0 ? 1: -2),         // int                 debug_level,
//										-2, //0,                            // tile_lma_debug_level, // +2,         // int                 debug_level,
										tileX,                        // int                 tileX, // just for debug output
										tileX,                        // int                 tileX, // just for debug output
										tileY );                      // int                 tileY
										tileY ); 
								// int                 tileY
								if (debugTile0) { // should be debugTile
								if (debugTile0) { // should be debugTile
									System.out.println("Ran LMA for tileX="+tileX+", tileY="+tileY);
									System.out.println("Ran LMA for tileX="+tileX+", tileY="+tileY);
								}
								}
@@ -2659,14 +2678,31 @@ public class ImageDtt extends ImageDttCPU {
										}
										}
									}
									}
								}
								}
							}


								if (debug_lma_tile != null) {
									for (int i = 0; i < debug_lma.length; i++) {
										debug_lma[i][nTile] = debug_lma_tile[i];
									}
								}
							}
						}
						}
					}
					}
				};
				};
			}
			}
			startAndJoin(threads);
			startAndJoin(threads);
			if (debug_lma != null) {
	    		(new ShowDoubleFloatArrays()).showArrays(
	    				debug_lma,
	    				tilesX,
	    				tilesY,
	    				true,
	    				"lma_debug",
	    				new String[] {"disp_samples","num_cnvx_samples","num_comb_samples", "num_lmas","num_iters","rms"}
	    				);
				
			}			
			}			
		}
		
		return;
		return;
	}	
	}	
	
	
Loading