Commit 7d08fe37 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Added absoulte center option, debugging missing of the grid

parent 93c3e515
Loading
Loading
Loading
Loading
+12 −4
Original line number Original line Diff line number Diff line
@@ -143,6 +143,7 @@ public class Aberration_Calibration extends PlugInFrame implements ActionListene
			true,  // useWindow   - multiply separated OTF instance by window function (Hamming or Gaussian)
			true,  // useWindow   - multiply separated OTF instance by window function (Hamming or Gaussian)
			false, // symm180     - force PSF center-symmetrical (around centroid that is defined by lateral chromatic aberration
			false, // symm180     - force PSF center-symmetrical (around centroid that is defined by lateral chromatic aberration
			false, // ignoreChromatic - ignore lateral chromatic aberration (center PSF to 0,0)
			false, // ignoreChromatic - ignore lateral chromatic aberration (center PSF to 0,0)
			true,  // absoluteCenter - do not remove green correlation shift (forces ignoreChromatic=false)
			0.2,   // smoothSeparate  - low pass filter width when separating individual PSF instances
			0.2,   // smoothSeparate  - low pass filter width when separating individual PSF instances
			0.75,  // topCenter - consider only points above this fraction of the peak to find the centroid
			0.75,  // topCenter - consider only points above this fraction of the peak to find the centroid
			0.0,   // sigmaToRadius - variable-sigma blurring to reduce high frequencies more for the pixels farther from the PSF center
			0.0,   // sigmaToRadius - variable-sigma blurring to reduce high frequencies more for the pixels farther from the PSF center
@@ -16998,7 +16999,7 @@ if (DEBUG_LEVEL>2)DEBUG_LEVEL=0; //*********************************************
		kernels[i]=combinePSF (inverted[i], // Square array of pixels with multiple repeated PSF (alternating sign)
		kernels[i]=combinePSF (inverted[i], // Square array of pixels with multiple repeated PSF (alternating sign)
				true, // master, force ignoreChromatic
				!psfParameters.absoluteCenter, //true, // master, force ignoreChromatic
				PSF_shifts[i],  // centerXY[] - will be modified inside combinePSF() if PSF_PARS.ignoreChromatic is true
				PSF_shifts[i],  // centerXY[] - will be modified inside combinePSF() if PSF_PARS.ignoreChromatic is true
				PSF_centroids[i], // will return array of XY coordinates of the result centroid
				PSF_centroids[i], // will return array of XY coordinates of the result centroid
				(i==4)?wVectors4:wVectors, // two wave vectors, lengths in cycles/pixel (pixels match pixel array)
				(i==4)?wVectors4:wVectors, // two wave vectors, lengths in cycles/pixel (pixels match pixel array)
@@ -17009,7 +17010,7 @@ if (DEBUG_LEVEL>2)DEBUG_LEVEL=0; //*********************************************
		if (DEBUG_LEVEL>2)     System.out.println("After-1: color Component "+i+"    PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts   [i][0],3)+"    PSF_shifts["+i+"][1]="+IJ.d2s(   PSF_shifts[i][1],3));
		if (DEBUG_LEVEL>2)     System.out.println("After-1: color Component "+i+"    PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts   [i][0],3)+"    PSF_shifts["+i+"][1]="+IJ.d2s(   PSF_shifts[i][1],3));
		if (DEBUG_LEVEL>2)     System.out.println("After-1: color Component "+i+" PSF_centroids["+i+"][0]="+IJ.d2s(PSF_centroids[i][0],3)+" PSF_centroids["+i+"][1]="+IJ.d2s(PSF_centroids[i][1],3));
		if (DEBUG_LEVEL>2)     System.out.println("After-1: color Component "+i+" PSF_centroids["+i+"][0]="+IJ.d2s(PSF_centroids[i][0],3)+" PSF_centroids["+i+"][1]="+IJ.d2s(PSF_centroids[i][1],3));
		if (!psfParameters.ignoreChromatic) { /* Recalculate center to pixels from greens (diagonal)) and supply it to other colors (lateral chromatic aberration correction) */
		if (!psfParameters.ignoreChromatic && !psfParameters.absoluteCenter) { /* Recalculate center to pixels from greens (diagonal)) and supply it to other colors (lateral chromatic aberration correction) */
			for (j=0;j<input_bayer.length;j++) if ((colorComponents.colorsToCorrect[j]) && (j!=referenceComp)) {
			for (j=0;j<input_bayer.length;j++) if ((colorComponents.colorsToCorrect[j]) && (j!=referenceComp)) {
				PSF_shifts[j]=shiftSensorToBayer (shiftBayerToSensor(PSF_shifts[referenceComp],referenceComp,subpixel),j,subpixel);
				PSF_shifts[j]=shiftSensorToBayer (shiftBayerToSensor(PSF_shifts[referenceComp],referenceComp,subpixel),j,subpixel);
				if (DEBUG_LEVEL>2)       System.out.println("After-2 (recalc): color Component "+j+" PSF_shifts["+j+"][0]="+IJ.d2s(PSF_shifts[j][0],3)+" PSF_shifts["+j+"][1]="+IJ.d2s(PSF_shifts[j][1],3));
				if (DEBUG_LEVEL>2)       System.out.println("After-2 (recalc): color Component "+j+" PSF_shifts["+j+"][0]="+IJ.d2s(PSF_shifts[j][0],3)+" PSF_shifts["+j+"][1]="+IJ.d2s(PSF_shifts[j][1],3));
@@ -17052,6 +17053,7 @@ if (DEBUG_LEVEL>2)DEBUG_LEVEL=0; //*********************************************
				if (DEBUG_LEVEL>2) { //2
				if (DEBUG_LEVEL>2) { //2
					System.out.println("Color Component "+i+" subpixel="+subpixel+
					System.out.println("Color Component "+i+" subpixel="+subpixel+
							" psfParameters.ignoreChromatic="+psfParameters.ignoreChromatic+
							" psfParameters.ignoreChromatic="+psfParameters.ignoreChromatic+
							" psfParameters.absoluteCenter="+psfParameters.absoluteCenter+
							" psfParameters.symm180="+psfParameters.symm180);
							" psfParameters.symm180="+psfParameters.symm180);
					System.out.println(                     " PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
					System.out.println(                     " PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
							" PSF_shifts["+i+"][1]="+IJ.d2s(PSF_shifts[i][1],3)+
							" PSF_shifts["+i+"][1]="+IJ.d2s(PSF_shifts[i][1],3)+
@@ -17458,7 +17460,7 @@ if (DEBUG_LEVEL>2)DEBUG_LEVEL=0; //*********************************************
				debug);
				debug);
		//                   true);
		//                   true);
		
		
		if (!master && !psfParameters.ignoreChromatic && psfParameters.centerPSF && (centerXY!=null)){
		if (!master && !psfParameters.ignoreChromatic && !psfParameters.absoluteCenter && psfParameters.centerPSF && (centerXY!=null)){
//			System.out.println("1:pixelsPSF.length="+pixelsPSF.length+" outSize+"+outSize);
//			System.out.println("1:pixelsPSF.length="+pixelsPSF.length+" outSize+"+outSize);
			// TODO: Shift +/- 0.5 Pix here {centerXY[0]-Math.round(centerXY[0]),centerXY[1]-Math.round(centerXY[1])}	
			// TODO: Shift +/- 0.5 Pix here {centerXY[0]-Math.round(centerXY[0]),centerXY[1]-Math.round(centerXY[1])}	
@@ -17515,7 +17517,7 @@ if (DEBUG_LEVEL>2)DEBUG_LEVEL=0; //*********************************************
		if (DEBUG_LEVEL>2) System.out.println("Centroid after first binPSF: x="+IJ.d2s(centroidXY[0],3)+" y="+IJ.d2s(centroidXY[1],3)+" center was at x="+IJ.d2s(centerXY[0],3)+" y="+IJ.d2s(centerXY[1],3));
		if (DEBUG_LEVEL>2) System.out.println("Centroid after first binPSF: x="+IJ.d2s(centroidXY[0],3)+" y="+IJ.d2s(centroidXY[1],3)+" center was at x="+IJ.d2s(centerXY[0],3)+" y="+IJ.d2s(centerXY[1],3));
/* Re-bin results with the new center if ignoreChromatic is true, update centerXY[](shift of the result PSF array) and centroidXY[] (center of the optionally shifted PDF array) */
/* Re-bin results with the new center if ignoreChromatic is true, update centerXY[](shift of the result PSF array) and centroidXY[] (center of the optionally shifted PDF array) */
		if (master || psfParameters.ignoreChromatic) {
		if (!psfParameters.absoluteCenter && (master || psfParameters.ignoreChromatic)) {
			if (centerXY!=null) {
			if (centerXY!=null) {
				centerXY[0]+=centroidXY[0];
				centerXY[0]+=centroidXY[0];
				centerXY[1]+=centroidXY[1];
				centerXY[1]+=centroidXY[1];
@@ -18936,6 +18938,9 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica
		gd.addCheckbox    ("Multiply PSF cell by Hamming window",                                psfParameters.useWindow); //  true;
		gd.addCheckbox    ("Multiply PSF cell by Hamming window",                                psfParameters.useWindow); //  true;
		gd.addCheckbox    ("Force PSF center- symmetrical (around centroid)",                    psfParameters.symm180); //  true; // make OTF center-symmetrical (around centroid that is defined by lateral chromatic aberration)
		gd.addCheckbox    ("Force PSF center- symmetrical (around centroid)",                    psfParameters.symm180); //  true; // make OTF center-symmetrical (around centroid that is defined by lateral chromatic aberration)
		gd.addCheckbox     ("Ignore lateral chromatic aberrations, center PSF",                  psfParameters.ignoreChromatic); // true; // ignore lateral chromatic aberration (center OTF to 0,0)
		gd.addCheckbox     ("Ignore lateral chromatic aberrations, center PSF",                  psfParameters.ignoreChromatic); // true; // ignore lateral chromatic aberration (center OTF to 0,0)
		gd.addCheckbox     ("Use absolute PSF center (no adjustment to green center)",           psfParameters.absoluteCenter); 
		
		
		gd.addNumericField("PSF separation: low-pass filter width (to PSF half-period) ",        psfParameters.smoothSeparate,  3); // 0.125 low pass filter width (relative to PSF pitch) when separation individual PSF
		gd.addNumericField("PSF separation: low-pass filter width (to PSF half-period) ",        psfParameters.smoothSeparate,  3); // 0.125 low pass filter width (relative to PSF pitch) when separation individual PSF
		gd.addNumericField("PSF separation: threshold to find the PSF maximum",                  psfParameters.topCenter,  3); // 0.75 consider only points above this fraction of the peak to find the centroid
		gd.addNumericField("PSF separation: threshold to find the PSF maximum",                  psfParameters.topCenter,  3); // 0.75 consider only points above this fraction of the peak to find the centroid
		gd.addNumericField("PSF variable Gauss blurring (farther from center, higher the sigma", psfParameters.sigmaToRadius,3); // 0.4 variable-sigma blurring to reduce high frequencies more for the pixels farther from the PSF center
		gd.addNumericField("PSF variable Gauss blurring (farther from center, higher the sigma", psfParameters.sigmaToRadius,3); // 0.4 variable-sigma blurring to reduce high frequencies more for the pixels farther from the PSF center
@@ -18958,6 +18963,7 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica
		psfParameters.useWindow=                 gd.getNextBoolean();
		psfParameters.useWindow=                 gd.getNextBoolean();
		psfParameters.symm180=                   gd.getNextBoolean();
		psfParameters.symm180=                   gd.getNextBoolean();
		psfParameters.ignoreChromatic=           gd.getNextBoolean();
		psfParameters.ignoreChromatic=           gd.getNextBoolean();
		psfParameters.absoluteCenter=            gd.getNextBoolean();
		psfParameters.smoothSeparate=            gd.getNextNumber();
		psfParameters.smoothSeparate=            gd.getNextNumber();
		psfParameters.topCenter=                 gd.getNextNumber();
		psfParameters.topCenter=                 gd.getNextNumber();
		psfParameters.sigmaToRadius=             gd.getNextNumber();
		psfParameters.sigmaToRadius=             gd.getNextNumber();
@@ -19680,6 +19686,7 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica
		gd.addNumericField("PSF wings energy (searching for ellipse approximation)",      psfParameters.wingsEnergy, 3); //  0.8 fraction of energy in the pixels to be used
		gd.addNumericField("PSF wings energy (searching for ellipse approximation)",      psfParameters.wingsEnergy, 3); //  0.8 fraction of energy in the pixels to be used
		gd.addNumericField("PSF wings ellipse scale (multiply PSF by elliptical gaussian)",psfParameters.wingsEllipseScale, 3);// 2.0 increase wings cutoff ellipse by this from one defined by the  cutoff energy
		gd.addNumericField("PSF wings ellipse scale (multiply PSF by elliptical gaussian)",psfParameters.wingsEllipseScale, 3);// 2.0 increase wings cutoff ellipse by this from one defined by the  cutoff energy
		gd.addCheckbox     ("Ignore lateral chromatic aberrations, center PSF",           psfParameters.ignoreChromatic); // true; // ignore lateral chromatic aberration (center OTF to 0,0)
		gd.addCheckbox     ("Ignore lateral chromatic aberrations, center PSF",           psfParameters.ignoreChromatic); // true; // ignore lateral chromatic aberration (center OTF to 0,0)
		gd.addCheckbox     ("Use absolute PSF center (no adjustment to green center)",    psfParameters.absoluteCenter); 
		gd.addNumericField("OTF cutoff energy (used to determine bounding ellipse)",      inverseParameters.otfCutoffEnergy, 3); //0.6; use frequency points that have inverseParameters.otfCutoffEnergy of the total to determine ellipse for limiting frequency responce
		gd.addNumericField("OTF cutoff energy (used to determine bounding ellipse)",      inverseParameters.otfCutoffEnergy, 3); //0.6; use frequency points that have inverseParameters.otfCutoffEnergy of the total to determine ellipse for limiting frequency responce
		gd.addNumericField("OTF size of elliptical window relative to cluster size",      inverseParameters.otfEllipseScale, 3); //1.5;  // size of elliptical window relative to the cluster defined by inverseParameters.otfCutoffEnergy
		gd.addNumericField("OTF size of elliptical window relative to cluster size",      inverseParameters.otfEllipseScale, 3); //1.5;  // size of elliptical window relative to the cluster defined by inverseParameters.otfCutoffEnergy
@@ -19713,6 +19720,7 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica
		psfParameters.wingsEnergy=               gd.getNextNumber();
		psfParameters.wingsEnergy=               gd.getNextNumber();
		psfParameters.wingsEllipseScale=         gd.getNextNumber();
		psfParameters.wingsEllipseScale=         gd.getNextNumber();
		psfParameters.ignoreChromatic=           gd.getNextBoolean();
		psfParameters.ignoreChromatic=           gd.getNextBoolean();
		psfParameters.absoluteCenter=            gd.getNextBoolean();
		inverseParameters.otfCutoffEnergy=       gd.getNextNumber();
		inverseParameters.otfCutoffEnergy=       gd.getNextNumber();
		inverseParameters.otfEllipseScale=       gd.getNextNumber();
		inverseParameters.otfEllipseScale=       gd.getNextNumber();
		inverseParameters.otfEllipseGauss=       gd.getNextBoolean();
		inverseParameters.otfEllipseGauss=       gd.getNextBoolean();
+2 −1
Original line number Original line Diff line number Diff line
@@ -3060,8 +3060,9 @@ For each point in the image
					cell[0], //double px,
					cell[0], //double px,
					cell[1]); //double py)
					cell[1]); //double py)
			cell[0]+=corrXYARGB[0]; // measured-> corrected : subtract, projected->simulated:add;
			cell[0]+=corrXYARGB[0]; // measured-> corrected : subtract, projected->simulated:add;
			cell[1]+=corrXYARGB[1];
			cell[1]+=corrXYARGB[1]+0.0; // Debugging by adding +1.0!!
		}
		}
//		System.out.println("================== Added +0.0 to pixel y for debugging purposes! =====================");
		return true;
		return true;
	}
	}
	
	
+30 −20
Original line number Original line Diff line number Diff line
@@ -1446,7 +1446,7 @@ public class EyesisAberrations {
			int                    globalDebugLevel
			int                    globalDebugLevel
	){	
	){	
		double [][][][] psfKernelMap; // will be lost - do we need it outside
		double [][][][] psfKernelMap; // will be lost - do we need it outside
		double [][][][][] kernelsElllipsePars = new double[filenames.length][][][][];
		double [][][][][] kernelsElllipsePars = new double[filenames.length][][][][]; //x0,y0,a,b,c,area
		if (thisDebugLevel>0){
		if (thisDebugLevel>0){
			System.out.println("combinePSFKernels(): filenames.length="+filenames.length);
			System.out.println("combinePSFKernels(): filenames.length="+filenames.length);
		}
		}
@@ -1503,15 +1503,15 @@ public class EyesisAberrations {
				//   			  System.out.println("nChn="+nChn+" nFile="+nFile+" tileY="+tileY+" tileX="+tileX);
				//   			  System.out.println("nChn="+nChn+" nFile="+nFile+" tileY="+tileY+" tileX="+tileX);
				if (kernelsElllipsePars[nFile][tileY][tileX][chn]!=null) {
				if (kernelsElllipsePars[nFile][tileY][tileX][chn]!=null) {
					channels[chn]=true;
					channels[chn]=true;
					c[0][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][0];
					c[0][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][0]; // x0
					c[1][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][1];
					c[1][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][1]; // y0
					c[2][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][2];
					c[2][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][2]; // a
					c[3][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][3];
					c[3][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][3]; // b
					c[4][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][4];
					c[4][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][4]; // c
					a=1/Math.sqrt(kernelsElllipsePars[nFile][tileY][tileX][chn][2]*kernelsElllipsePars[nFile][tileY][tileX][chn][3]-
					a=1/Math.sqrt(kernelsElllipsePars[nFile][tileY][tileX][chn][2]*kernelsElllipsePars[nFile][tileY][tileX][chn][3]-
							kernelsElllipsePars[nFile][tileY][tileX][chn][4]*kernelsElllipsePars[nFile][tileY][tileX][chn][4]/4);
							kernelsElllipsePars[nFile][tileY][tileX][chn][4]*kernelsElllipsePars[nFile][tileY][tileX][chn][4]/4);
					c[5][chn][nFile+1][tileY*kWidth+tileX]= Math.sqrt(a); // radius
					c[5][chn][nFile+1][tileY*kWidth+tileX]= Math.sqrt(a); // radius
					c[6][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][5];
					c[6][chn][nFile+1][tileY*kWidth+tileX]=kernelsElllipsePars[nFile][tileY][tileX][chn][5]; // area


				} else {
				} else {
					c[0][chn][nFile+1][tileY*kWidth+tileX]=Double.NaN;
					c[0][chn][nFile+1][tileY*kWidth+tileX]=Double.NaN;
@@ -2057,7 +2057,8 @@ public class EyesisAberrations {
					"",
					"",
					debugLevel);
					debugLevel);
					//				  ellipseCoeffs[tileY][tileX][chn]=findEllipseOnPSF(kernel,  selection,   "");
					//				  ellipseCoeffs[tileY][tileX][chn]=findEllipseOnPSF(kernel,  selection,   "");
					ec=findEllipseOnPSF(kernel,  selection,   "", debugLevel);
					ec=findEllipseOnPSF(kernel,  selection,   "", debugLevel); // x0,y0,a,b,c (r2= a* x^2*+b*y^2+c*x*y)

					l=ec.length;
					l=ec.length;
					ellipseCoeffs[tileY][tileX][chn]=new double[l+1];
					ellipseCoeffs[tileY][tileX][chn]=new double[l+1];
					for (i=0;i<ec.length;i++) ellipseCoeffs[tileY][tileX][chn][i]=ec[i];
					for (i=0;i<ec.length;i++) ellipseCoeffs[tileY][tileX][chn][i]=ec[i];
@@ -2776,6 +2777,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
					globalDebugLevel,
					globalDebugLevel,
					title+"-"+i);
					title+"-"+i);
		}
		}
		int debugThreshold=1;
		if (debugThis) SDFA_INSTANCE.showArrays(inverted, fft_size*subpixel, fft_size*subpixel, title+"_Combined-PSF");
		if (debugThis) SDFA_INSTANCE.showArrays(inverted, fft_size*subpixel, fft_size*subpixel, title+"_Combined-PSF");
/* correct composite greens */
/* correct composite greens */
/* Here we divide wave vectors by subpixel as the pixels are already added */
/* Here we divide wave vectors by subpixel as the pixels are already added */
@@ -2811,7 +2813,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
		//int [][]  clusterMask;
		//int [][]  clusterMask;
/* Start with referenceComp */
/* Start with referenceComp */
		i= referenceComp;
		i= referenceComp;
		if (globalDebugLevel>2) {
		if (globalDebugLevel>debugThreshold) {
			System.out.println(x0+":"+y0+"1-PSF_shifts.length= "+PSF_shifts.length+" i="+i+" input_bayer.length="+input_bayer.length);
			System.out.println(x0+":"+y0+"1-PSF_shifts.length= "+PSF_shifts.length+" i="+i+" input_bayer.length="+input_bayer.length);
			System.out.println("Before: color Component "+i+" PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
			System.out.println("Before: color Component "+i+" PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
					" PSF_shifts["+i+"][1]="+IJ.d2s(PSF_shifts[i][1],3));
					" PSF_shifts["+i+"][1]="+IJ.d2s(PSF_shifts[i][1],3));
@@ -2819,7 +2821,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************




		kernels[i]=combinePSF (inverted[i], // Square array of pixels with multiple repeated PSF (alternating sign)
		kernels[i]=combinePSF (inverted[i], // Square array of pixels with multiple repeated PSF (alternating sign)
				true, // master, force ignoreChromatic
				!psfParameters.absoluteCenter, //true, // master, force ignoreChromatic
				PSF_shifts[i],  // centerXY[] - will be modified inside combinePSF() if PSF_PARS.ignoreChromatic is true
				PSF_shifts[i],  // centerXY[] - will be modified inside combinePSF() if PSF_PARS.ignoreChromatic is true
				PSF_centroids[i], // will return array of XY coordinates of the result centroid
				PSF_centroids[i], // will return array of XY coordinates of the result centroid
				(i==4)?wVectors4:wVectors, // two wave vectors, lengths in cycles/pixel (pixels match pixel array)
				(i==4)?wVectors4:wVectors, // two wave vectors, lengths in cycles/pixel (pixels match pixel array)
@@ -2829,13 +2831,13 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
						(globalDebugLevel>4),
						(globalDebugLevel>4),
						globalDebugLevel
						globalDebugLevel
						);
						);
		if (globalDebugLevel>2)     System.out.println(x0+":"+y0+"After-1: color Component "+i+"    PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts   [i][0],3)+"    PSF_shifts["+i+"][1]="+IJ.d2s(   PSF_shifts[i][1],3));
		if (globalDebugLevel>debugThreshold)     System.out.println(x0+":"+y0+"After-1: color Component "+i+"    PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts   [i][0],3)+"    PSF_shifts["+i+"][1]="+IJ.d2s(   PSF_shifts[i][1],3));
		if (globalDebugLevel>2)     System.out.println(x0+":"+y0+"After-1: color Component "+i+" PSF_centroids["+i+"][0]="+IJ.d2s(PSF_centroids[i][0],3)+" PSF_centroids["+i+"][1]="+IJ.d2s(PSF_centroids[i][1],3));
		if (globalDebugLevel>debugThreshold)     System.out.println(x0+":"+y0+"After-1: color Component "+i+" PSF_centroids["+i+"][0]="+IJ.d2s(PSF_centroids[i][0],3)+" PSF_centroids["+i+"][1]="+IJ.d2s(PSF_centroids[i][1],3));


		if (!psfParameters.ignoreChromatic) { /* Recalculate center to pixels from greens (diagonal)) and supply it to other colors (lateral chromatic aberration correction) */
		if (!psfParameters.ignoreChromatic && !psfParameters.absoluteCenter) { /* Recalculate center to pixels from greens (diagonal)) and supply it to other colors (lateral chromatic aberration correction) */
			for (j=0;j<input_bayer.length;j++) if ((colorComponents.colorsToCorrect[j]) && (j!=referenceComp)) {
			for (j=0;j<input_bayer.length;j++) if ((colorComponents.colorsToCorrect[j]) && (j!=referenceComp)) {
				PSF_shifts[j]=shiftSensorToBayer (shiftBayerToSensor(PSF_shifts[referenceComp],referenceComp,subpixel),j,subpixel);
				PSF_shifts[j]=shiftSensorToBayer (shiftBayerToSensor(PSF_shifts[referenceComp],referenceComp,subpixel),j,subpixel);
				if (globalDebugLevel>2)       System.out.println(x0+":"+y0+"After-2 (recalc): color Component "+j+" PSF_shifts["+j+"][0]="+IJ.d2s(PSF_shifts[j][0],3)+" PSF_shifts["+j+"][1]="+IJ.d2s(PSF_shifts[j][1],3));
				if (globalDebugLevel>debugThreshold)       System.out.println(x0+":"+y0+"After-2 (recalc): color Component "+j+" PSF_shifts["+j+"][0]="+IJ.d2s(PSF_shifts[j][0],3)+" PSF_shifts["+j+"][1]="+IJ.d2s(PSF_shifts[j][1],3));
			}
			}
		}
		}


@@ -2846,7 +2848,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
		lateralChromaticAbs[i]=Math.sqrt(lateralChromatic[i][0]*lateralChromatic[i][0]+lateralChromatic[i][1]*lateralChromatic[i][1]);
		lateralChromaticAbs[i]=Math.sqrt(lateralChromatic[i][0]*lateralChromatic[i][0]+lateralChromatic[i][1]*lateralChromatic[i][1]);
/* Now process all the other components */
/* Now process all the other components */
		for (i=0; i<input_bayer.length;i++) if ((i!=referenceComp) && (colorComponents.colorsToCorrect[i])) {
		for (i=0; i<input_bayer.length;i++) if ((i!=referenceComp) && (colorComponents.colorsToCorrect[i])) {
			if (globalDebugLevel>2) {
			if (globalDebugLevel>debugThreshold) {
				System.out.println(x0+":"+y0+"2-PSF_shifts.length= "+PSF_shifts.length+" i="+i+" input_bayer.length="+input_bayer.length);
				System.out.println(x0+":"+y0+"2-PSF_shifts.length= "+PSF_shifts.length+" i="+i+" input_bayer.length="+input_bayer.length);


				System.out.println(x0+":"+y0+"Before: color Component "+i+" PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
				System.out.println(x0+":"+y0+"Before: color Component "+i+" PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
@@ -2862,8 +2864,8 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
							title+"_"+i,    // reduce the PSF cell size to this part of the area connecting first negative clones
							title+"_"+i,    // reduce the PSF cell size to this part of the area connecting first negative clones
							(globalDebugLevel>4),
							(globalDebugLevel>4),
							globalDebugLevel);
							globalDebugLevel);
			if (globalDebugLevel>2)     System.out.println(x0+":"+y0+"After-1: color Component "+i+"    PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts   [i][0],3)+"    PSF_shifts["+i+"][1]="+IJ.d2s(   PSF_shifts[i][1],3));
			if (globalDebugLevel>debugThreshold)     System.out.println(x0+":"+y0+"After-1: color Component "+i+"    PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts   [i][0],3)+"    PSF_shifts["+i+"][1]="+IJ.d2s(   PSF_shifts[i][1],3));
			if (globalDebugLevel>2)     System.out.println(x0+":"+y0+"After-1: color Component "+i+" PSF_centroids["+i+"][0]="+IJ.d2s(PSF_centroids[i][0],3)+" PSF_centroids["+i+"][1]="+IJ.d2s(PSF_centroids[i][1],3));
			if (globalDebugLevel>debugThreshold)     System.out.println(x0+":"+y0+"After-1: color Component "+i+" PSF_centroids["+i+"][0]="+IJ.d2s(PSF_centroids[i][0],3)+" PSF_centroids["+i+"][1]="+IJ.d2s(PSF_centroids[i][1],3));
			lateralChromatic[i]=shiftBayerToSensor ( PSF_shifts[i][0]+PSF_centroids[i][0],
			lateralChromatic[i]=shiftBayerToSensor ( PSF_shifts[i][0]+PSF_centroids[i][0],
					PSF_shifts[i][1]+PSF_centroids[i][1],
					PSF_shifts[i][1]+PSF_centroids[i][1],
					i,
					i,
@@ -2873,9 +2875,10 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
		}
		}
		if (globalDebugLevel>1) { //1
		if (globalDebugLevel>1) { //1
			for (i=0;i<PSF_shifts.length;i++) if (colorComponents.colorsToCorrect[i]){
			for (i=0;i<PSF_shifts.length;i++) if (colorComponents.colorsToCorrect[i]){
				if (globalDebugLevel>2) { //2
				if (globalDebugLevel>debugThreshold) { //2
					System.out.println(x0+":"+y0+" Color Component "+i+" subpixel="+subpixel+
					System.out.println(x0+":"+y0+" Color Component "+i+" subpixel="+subpixel+
							" psfParameters.ignoreChromatic="+psfParameters.ignoreChromatic+
							" psfParameters.ignoreChromatic="+psfParameters.ignoreChromatic+
							" psfParameters.absoluteCenter="+psfParameters.absoluteCenter+
							" psfParameters.symm180="+psfParameters.symm180);
							" psfParameters.symm180="+psfParameters.symm180);
					System.out.println(x0+":"+y0+                     " PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
					System.out.println(x0+":"+y0+                     " PSF_shifts["+i+"][0]="+IJ.d2s(PSF_shifts[i][0],3)+
							" PSF_shifts["+i+"][1]="+IJ.d2s(PSF_shifts[i][1],3)+
							" PSF_shifts["+i+"][1]="+IJ.d2s(PSF_shifts[i][1],3)+
@@ -3339,7 +3342,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
					debugLevel);
					debugLevel);
			//                   true);
			//                   true);
			
			
			if (!master && !psfParameters.ignoreChromatic && psfParameters.centerPSF && (centerXY!=null)){
			if (!master && !psfParameters.ignoreChromatic && !psfParameters.absoluteCenter && psfParameters.centerPSF && (centerXY!=null)){
//				System.out.println("1:pixelsPSF.length="+pixelsPSF.length+" outSize+"+outSize);
//				System.out.println("1:pixelsPSF.length="+pixelsPSF.length+" outSize+"+outSize);


				// TODO: Shift +/- 0.5 Pix here {centerXY[0]-Math.round(centerXY[0]),centerXY[1]-Math.round(centerXY[1])}	
				// TODO: Shift +/- 0.5 Pix here {centerXY[0]-Math.round(centerXY[0]),centerXY[1]-Math.round(centerXY[1])}	
@@ -3397,7 +3400,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
			if (debugLevel>2) System.out.println("Centroid after first binPSF: x="+IJ.d2s(centroidXY[0],3)+" y="+IJ.d2s(centroidXY[1],3)+" center was at x="+IJ.d2s(centerXY[0],3)+" y="+IJ.d2s(centerXY[1],3));
			if (debugLevel>2) System.out.println("Centroid after first binPSF: x="+IJ.d2s(centroidXY[0],3)+" y="+IJ.d2s(centroidXY[1],3)+" center was at x="+IJ.d2s(centerXY[0],3)+" y="+IJ.d2s(centerXY[1],3));


	/* Re-bin results with the new center if ignoreChromatic is true, update centerXY[](shift of the result PSF array) and centroidXY[] (center of the optionally shifted PDF array) */
	/* Re-bin results with the new center if ignoreChromatic is true, update centerXY[](shift of the result PSF array) and centroidXY[] (center of the optionally shifted PDF array) */
			if (master || psfParameters.ignoreChromatic) {
			if (!psfParameters.absoluteCenter && (master || psfParameters.ignoreChromatic)) {
				if (centerXY!=null) {
				if (centerXY!=null) {
					centerXY[0]+=centroidXY[0];
					centerXY[0]+=centroidXY[0];
					centerXY[1]+=centroidXY[1];
					centerXY[1]+=centroidXY[1];
@@ -4908,6 +4911,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
		public boolean useWindow;
		public boolean useWindow;
		public boolean symm180;
		public boolean symm180;
		public boolean ignoreChromatic;
		public boolean ignoreChromatic;
		public boolean absoluteCenter;
		public double smoothSeparate;
		public double smoothSeparate;
		public double topCenter;
		public double topCenter;
		public double sigmaToRadius;
		public double sigmaToRadius;
@@ -4927,6 +4931,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
				boolean useWindow,
				boolean useWindow,
				boolean symm180,
				boolean symm180,
				boolean ignoreChromatic,
				boolean ignoreChromatic,
				boolean absoluteCenter,
				double smoothSeparate,
				double smoothSeparate,
				double topCenter,
				double topCenter,
				double sigmaToRadius,
				double sigmaToRadius,
@@ -4946,6 +4951,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
			this.useWindow = useWindow;
			this.useWindow = useWindow;
			this.symm180 = symm180;
			this.symm180 = symm180;
			this.ignoreChromatic = ignoreChromatic;
			this.ignoreChromatic = ignoreChromatic;
			this.absoluteCenter=absoluteCenter;
			this.smoothSeparate = smoothSeparate;
			this.smoothSeparate = smoothSeparate;
			this.topCenter = topCenter;
			this.topCenter = topCenter;
			this.sigmaToRadius = sigmaToRadius;
			this.sigmaToRadius = sigmaToRadius;
@@ -4968,6 +4974,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
        			this.useWindow,
        			this.useWindow,
        			this.symm180,
        			this.symm180,
        			this.ignoreChromatic,
        			this.ignoreChromatic,
        			this.absoluteCenter,
        			this.smoothSeparate,
        			this.smoothSeparate,
        			this.topCenter,
        			this.topCenter,
        			this.sigmaToRadius,
        			this.sigmaToRadius,
@@ -4988,6 +4995,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
        	properties.setProperty(prefix+"useWindow",this.useWindow+"");
        	properties.setProperty(prefix+"useWindow",this.useWindow+"");
        	properties.setProperty(prefix+"symm180",this.symm180+"");
        	properties.setProperty(prefix+"symm180",this.symm180+"");
        	properties.setProperty(prefix+"ignoreChromatic",this.ignoreChromatic+"");
        	properties.setProperty(prefix+"ignoreChromatic",this.ignoreChromatic+"");
        	properties.setProperty(prefix+"absoluteCenter",this.absoluteCenter+"");
        	properties.setProperty(prefix+"smoothSeparate",this.smoothSeparate+"");
        	properties.setProperty(prefix+"smoothSeparate",this.smoothSeparate+"");
        	properties.setProperty(prefix+"topCenter",this.topCenter+"");
        	properties.setProperty(prefix+"topCenter",this.topCenter+"");
        	properties.setProperty(prefix+"sigmaToRadius",this.sigmaToRadius+"");
        	properties.setProperty(prefix+"sigmaToRadius",this.sigmaToRadius+"");
@@ -5007,6 +5015,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
        	properties.setProperty(prefix+"useWindow",this.useWindow+"");
        	properties.setProperty(prefix+"useWindow",this.useWindow+"");
        	properties.setProperty(prefix+"symm180",this.symm180+"");
        	properties.setProperty(prefix+"symm180",this.symm180+"");
        	properties.setProperty(prefix+"ignoreChromatic",this.ignoreChromatic+"");
        	properties.setProperty(prefix+"ignoreChromatic",this.ignoreChromatic+"");
        	properties.setProperty(prefix+"absoluteCenter",this.absoluteCenter+"");
        	properties.setProperty(prefix+"smoothSeparate",this.smoothSeparate+"");
        	properties.setProperty(prefix+"smoothSeparate",this.smoothSeparate+"");
        	properties.setProperty(prefix+"topCenter",this.topCenter+"");
        	properties.setProperty(prefix+"topCenter",this.topCenter+"");
        	properties.setProperty(prefix+"sigmaToRadius",this.sigmaToRadius+"");
        	properties.setProperty(prefix+"sigmaToRadius",this.sigmaToRadius+"");
@@ -5027,6 +5036,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
			if (properties.getProperty(prefix+"useWindow")!=null)         this.useWindow=Boolean.parseBoolean(properties.getProperty(prefix+"useWindow"));
			if (properties.getProperty(prefix+"useWindow")!=null)         this.useWindow=Boolean.parseBoolean(properties.getProperty(prefix+"useWindow"));
			if (properties.getProperty(prefix+"symm180")!=null)           this.symm180=Boolean.parseBoolean(properties.getProperty(prefix+"symm180"));
			if (properties.getProperty(prefix+"symm180")!=null)           this.symm180=Boolean.parseBoolean(properties.getProperty(prefix+"symm180"));
			if (properties.getProperty(prefix+"ignoreChromatic")!=null)   this.ignoreChromatic=Boolean.parseBoolean(properties.getProperty(prefix+"ignoreChromatic"));
			if (properties.getProperty(prefix+"ignoreChromatic")!=null)   this.ignoreChromatic=Boolean.parseBoolean(properties.getProperty(prefix+"ignoreChromatic"));
			if (properties.getProperty(prefix+"absoluteCenter")!=null)   this.absoluteCenter=Boolean.parseBoolean(properties.getProperty(prefix+"absoluteCenter"));
			if (properties.getProperty(prefix+"smoothSeparate")!=null)    this.smoothSeparate=Double.parseDouble(properties.getProperty(prefix+"smoothSeparate"));
			if (properties.getProperty(prefix+"smoothSeparate")!=null)    this.smoothSeparate=Double.parseDouble(properties.getProperty(prefix+"smoothSeparate"));
			if (properties.getProperty(prefix+"topCenter")!=null)         this.topCenter=Double.parseDouble(properties.getProperty(prefix+"topCenter"));
			if (properties.getProperty(prefix+"topCenter")!=null)         this.topCenter=Double.parseDouble(properties.getProperty(prefix+"topCenter"));
			if (properties.getProperty(prefix+"sigmaToRadius")!=null)     this.sigmaToRadius=Double.parseDouble(properties.getProperty(prefix+"sigmaToRadius"));
			if (properties.getProperty(prefix+"sigmaToRadius")!=null)     this.sigmaToRadius=Double.parseDouble(properties.getProperty(prefix+"sigmaToRadius"));
+6 −6
Original line number Original line Diff line number Diff line
@@ -3350,8 +3350,10 @@ public class MatchSimulatedPattern {
			   if (!updating){
			   if (!updating){
				   double [][] node=gn.getNode();
				   double [][] node=gn.getNode();
				   double [] centerXY=node[0];
				   double [] centerXY=node[0];
				   if (global_debug_level>1) {
				   if (global_debug_level>0) {
					   System.out.println("distortions: node X/Y are "+centerXY[0]+"/"+centerXY[1]);
//					   System.out.println("distortions: node X/Y are "+centerXY[0]+"/"+centerXY[1]);
					   System.out.println("distortions: nodeQueue has "+(debug_left--)+" candidates left (including this one) :node X/Y are "+centerXY[0]+"/"+centerXY[1]);
					   
				   }
				   }
				   //				   if (debugLevel>1) {
				   //				   if (debugLevel>1) {
				   if (global_debug_level>1) {
				   if (global_debug_level>1) {
@@ -3374,7 +3376,6 @@ public class MatchSimulatedPattern {
				   if (global_debug_level>1) {
				   if (global_debug_level>1) {
					   System.out.println("putInWaveList(waveFrontList, {"+centerUV[0]+","+centerUV[1]+"}, 0);");
					   System.out.println("putInWaveList(waveFrontList, {"+centerUV[0]+","+centerUV[1]+"}, 0);");
				   }
				   }
				   
			   }
			   }
			   // Each layer processing may be multi-threaded, they join before going to the next layer
			   // Each layer processing may be multi-threaded, they join before going to the next layer
@@ -3453,7 +3454,7 @@ public class MatchSimulatedPattern {
				   layer++;
				   layer++;
				   if (updateStatus) IJ.showStatus("Correlating patterns, layer "+layer+(cleanup.get()?"(cleanup)":"")+", length "+waveFrontList.size());
				   if (updateStatus) IJ.showStatus("Correlating patterns, layer "+layer+(cleanup.get()?"(cleanup)":"")+", length "+waveFrontList.size());
//				   if (debugLevel>1) System.out.println("Correlating patterns, layer "+layer+", length "+waveFrontList.size());
//				   if (debugLevel>1) System.out.println("Correlating patterns, layer "+layer+", length "+waveFrontList.size());
				   if (global_debug_level>1) System.out.println("Correlating patterns, layer "+layer+", length "+waveFrontList.size());
				   if (global_debug_level>2) System.out.println("Correlating patterns, layer "+layer+", length "+waveFrontList.size());
				   // starting layer
				   // starting layer
				   cellNum.set(0);
				   cellNum.set(0);
				   for (int ithread = 0; ithread < threads.length; ithread++) {
				   for (int ithread = 0; ithread < threads.length; ithread++) {
@@ -4077,11 +4078,10 @@ public class MatchSimulatedPattern {
							   );
							   );
							   if ((node!=null) && (node[0]!=null)) {
							   if ((node!=null) && (node[0]!=null)) {
								   nodeQueue.add(new GridNode(node));
								   nodeQueue.add(new GridNode(node));
								   if (debugLevel>1)  System.out.println("probing "+n);
								   if (debugLevel>1)  System.out.println("adding candidate "+n+" x0="+point[0]+" y0="+point[1]+" -> "+ node[0][0]+"/"+node[0][1]);
							   }
							   }
						   }
						   }
						   triedIndices[n]=true; // regardless - good or bad
						   triedIndices[n]=true; // regardless - good or bad
						   
					   }
					   }
				   }
				   }
			   };
			   };
+2 −0
Original line number Original line Diff line number Diff line
@@ -141,6 +141,8 @@ Panel panel1,panel2;
 public static double  OTF_deconvInvert =  0.007; // 0.015; // 0.01; // when FFT component is less than this fraction of the maximal value, replace 1/z with Z
 public static double  OTF_deconvInvert =  0.007; // 0.015; // 0.01; // when FFT component is less than this fraction of the maximal value, replace 1/z with Z
/* TODO: check why combined greens result in center at x=-0.532/2 , y= -.0272/2 */
/* TODO: check why combined greens result in center at x=-0.532/2 , y= -.0272/2 */
 public static boolean PSF_ignoreChromatic= false; // ignore lateral chromatic aberration (center OTF to 0,0)
 public static boolean PSF_ignoreChromatic= false; // ignore lateral chromatic aberration (center OTF to 0,0)
 
 
 public static boolean OTF_fold =          false; // fold high frequency to lower when downsampling pixels (before inverse FFT)
 public static boolean OTF_fold =          false; // fold high frequency to lower when downsampling pixels (before inverse FFT)
 public static double  PSF_cutoff_energy=0.9;  // Limit result kernel to proportional of the PSF, calculate initial cluster shape by this cutoff energy
 public static double  PSF_cutoff_energy=0.9;  // Limit result kernel to proportional of the PSF, calculate initial cluster shape by this cutoff energy