Commit a1118d6f authored by Andrey Filippov's avatar Andrey Filippov

debugging PSF generatin, fixing focusing mode

parent f7ad213d
......@@ -3839,7 +3839,9 @@ if (MORE_BUTTONS) {
// DEBUG_LEVEL);
DISTORTION.loop_debug_level);
if (numAbsolutePoints<=0) { // no pointers in this image
IJ.showMessage("Error","No laser pointers matched - they are needed for absolute grid positioning\nProcess canceled");
String msg="No laser pointers matched - they are needed for absolute grid positioning\nProcess canceled";
IJ.showMessage("Error",msg);
System.out.println("Error: "+msg);
return;
}
if (DEBUG_LEVEL>0) System.out.println("Matched "+numAbsolutePoints+" laser pointers, grid generated at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
......@@ -19720,7 +19722,6 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica
gd.addNumericField("Detection ring width (fraction):", distortionParameters.correlationRingWidth, 3);
gd.addNumericField("Correlation minimal contrast (normalized)", distortionParameters.correlationMinContrast, 3);
gd.addNumericField("Correlation minimal contrast for initial search (normalized)", distortionParameters.correlationMinInitialContrast, 3);
gd.addNumericField("Correlation minimal contrast (absolute)", distortionParameters.correlationMinAbsoluteContrast, 3);
gd.addNumericField("Correlation minimal contrast for initial search (absolute)", distortionParameters.correlationMinAbsoluteInitialContrast, 3);
......
......@@ -11,6 +11,7 @@ import ij.process.ImageProcessor;
import java.awt.Rectangle;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -1288,7 +1289,7 @@ public class EyesisAberrations {
}
// now replace extracted grid X,Y with projected (need to add sensor correction)
if (projectedGrid!=null){
int numReplaced= matchSimulatedPattern.replaceGridXYWithProjected(projectedGrid);
int numReplaced= matchSimulatedPattern.replaceGridXYWithProjected(projectedGrid,(debugLevel>1)?imp.getTitle():null);
if (debugLevel>0) System.out.println("Replaced extracted XY with projected ones for "+numReplaced+" nodes");
}
correlationSizesUsed=matchSimulatedPattern.getCorrelationSizesUsed();
......@@ -2232,6 +2233,7 @@ public class EyesisAberrations {
final int masterDebugLevel, // get rid of it? // ** NEW
final int globalDebugLevel,// ** NEW
final int debug_level){// debug level used inside loops
final boolean debugLateralShifts=(globalDebugLevel>1);
System.out.println("createPSFMap(): masterDebugLevel="+masterDebugLevel+" globalDebugLevel="+globalDebugLevel+" debug_level="+debug_level); // 2 2 0
final long startTime = System.nanoTime();
Runtime runtime = Runtime.getRuntime();
......@@ -2285,14 +2287,19 @@ public class EyesisAberrations {
pdfKernelMap[nTileY][nTileX]=new double[colorComponents.colorsToCorrect.length][];
} else pdfKernelMap[nTileY][nTileX]=null;
}
final double [][][][] debugLateral=new double [PSFBooleanMap.length][PSFBooleanMap[0].length][][];
for (nTileY=0;nTileY<debugLateral.length;nTileY++) for (nTileX=0;nTileX<debugLateral[0].length;nTileX++){
debugLateral[nTileY][nTileX]=null;
}
final Thread[] threads = newThreadArray(threadsMax);
if (globalDebugLevel>1) System.out.println("Starting "+threads.length+" threads: "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
if (globalDebugLevel>1) System.out.println("Starting "+threads.length+" threads: "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
final AtomicInteger ai = new AtomicInteger(0);
final int patternCells=numPatternCells;
// final double [] overexposedMap, // map of overexposed pixels in the image (may be null)
final double [] overexposed=(overexposedAllowed>0)?JP4_INSTANCE.overexposedMap (imp_sel):null;
final int mapWidth=imp_sel.getWidth();
final AtomicInteger tilesFinishedAtomic = new AtomicInteger(1); // first finished will be 1
final int debugNumColors=6;
for (int ithread = 0; ithread < threads.length; ithread++) {
// Concurrently run in as many threads as CPUs
threads[ithread] = new Thread() {
......@@ -2341,6 +2348,9 @@ public class EyesisAberrations {
pdfKernelMap[nTY][nTX]=null;
if (globalDebugLevel>0) System.out.println("Overexposed fraction of "+over+" at x0="+x0+" y0="+y0+" width"+(2*fft_size));
} else {
if (debugLateralShifts) {
debugLateral[nTY][nTX]= new double [debugNumColors][]; // X/Y shift of the PSF array, in Bayer component pixel coordinates (same as PSF arrays)
}
kernels=getPSFKernels(imp_sel,
simArray, //simulation image, scaled PSF_subpixel/2
2*fft_size, // size in pixels (twice fft_size)
......@@ -2360,7 +2370,8 @@ public class EyesisAberrations {
fht_instance, // provide DoubleFHT instance to save on initializations (or null)
debug_level,// ((x0<512)&& (y0<512))?3:debug_level DEBUG during "focusing"
masterDebugLevel, // get rid of it? // ** NEW
globalDebugLevel// ** NEW
globalDebugLevel,// ** NEW
debugLateralShifts?debugLateral[nTY][nTX]:null
);
if (kernels!=null) {
if (kernelLength(kernels)>(PSFKernelSize*PSFKernelSize)) kernels=resizeForFFT(kernels,PSFKernelSize); // shrink before normalizing
......@@ -2390,6 +2401,45 @@ public class EyesisAberrations {
startAndJoin(threads);
if (globalDebugLevel>1) System.out.println("Threads done at "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
// globalDebugLevel=saved_globalDebugLevel;
if (debugLateralShifts) {
boolean [] debugUsedColors=new boolean [debugNumColors];
Arrays.fill(debugUsedColors,false);
for (double [][][] dbgRow:debugLateral) for (double [][] dbgTile:dbgRow) if (dbgTile!=null) for (int c=0;c<dbgTile.length;c++){
if (dbgTile[c]!=null) debugUsedColors[c]=true;
}
int numUsedColors=0;
for (boolean b:debugUsedColors) if (b) numUsedColors++;
if (numUsedColors>0) {
int [] cIndex=new int [numUsedColors];
int index=0;
for (int i=0;i<debugUsedColors.length;i++) if (debugUsedColors[i]) cIndex[index++]=i;
String [] dbgComponets={"latChromX","latChromY","shftX","shftY","centX","centY"};
String [] debugTitles=new String[dbgComponets.length*numUsedColors];
index=0;
for (int i=0;i<dbgComponets.length;i++) for (int j=0;j<cIndex.length;j++){
debugTitles[index++]=dbgComponets[i]+"-"+cIndex[j];
}
double [][] dbgLat= new double [debugTitles.length][debugLateral.length*debugLateral[0].length];
int layer=0;
for (int i=0;i<dbgComponets.length;i++) for (int j=0;j<cIndex.length;j++){
Arrays.fill(dbgLat[layer],Double.NaN);
for (nTileY=0;nTileY<debugLateral.length;nTileY++) for (nTileX=0;nTileX<debugLateral[0].length;nTileX++) if (debugLateral[nTileY][nTileX]!=null){
if (debugLateral[nTileY][nTileX][cIndex[j]]!=null) dbgLat[layer][nTileY*debugLateral[0].length+nTileX]=debugLateral[nTileY][nTileX][cIndex[j]][i];
} layer++;
}
SDFA_INSTANCE.showArrays(dbgLat, debugLateral[0].length, debugLateral.length, true, "lateral"+imp_sel.getTitle(), debugTitles);
/*
debugLateralTile[i][0]=lateralChromatic[i][0];
debugLateralTile[i][1]=lateralChromatic[i][1];
debugLateralTile[i][2]=PSF_shifts[i][0];
debugLateralTile[i][3]=PSF_shifts[i][1];
debugLateralTile[i][4]=PSF_centroids[i][0];
debugLateralTile[i][5]=PSF_centroids[i][1];
sdfra_instance.showArrays(pointedBayer.clone(), halfWidth, halfHeight, true, title+"-bayer", subtitles);
*/
}
}
return pdfKernelMap;
}
/* Combine both greens as a checkerboard pattern (after oversampleFFTInput()) */
......@@ -2589,8 +2639,8 @@ public class EyesisAberrations {
DoubleFHT fht_instance, // provide DoubleFHT instance to save on initializations (or null)
int masterDebugLevel, // get rid of it? // ** NEW
int globalDebugLevel,// ** NEW
int debug
int debug,
double [][] debugLateralTile
){
boolean debugThis=false; //(y0==384) && ((x0==448) || (x0==512));
if (globalDebugLevel>1){
......@@ -2920,7 +2970,21 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
System.out.println("#!# "+x0+":"+y0+" "+"Lateral shift green from simulation "+IJ.d2s(lateralChromaticAbs[referenceComp],3)+"pix(sensor): ["+referenceComp+"][0]="+IJ.d2s(lateralChromatic[referenceComp][0],3)+
" ["+referenceComp+"][1]="+IJ.d2s(lateralChromatic[referenceComp][1],3));
}
if (debugLateralTile!=null) for (i=0;i<PSF_shifts.length;i++) {
if (colorComponents.colorsToCorrect[i]){
debugLateralTile[i]=new double [6];
debugLateralTile[i][0]=lateralChromatic[i][0];
debugLateralTile[i][1]=lateralChromatic[i][1];
debugLateralTile[i][2]=PSF_shifts[i][0];
debugLateralTile[i][3]=PSF_shifts[i][1];
debugLateralTile[i][4]=PSF_centroids[i][0];
debugLateralTile[i][5]=PSF_centroids[i][1];
} else {
debugLateralTile[i]=null;
}
}
if (debugThis && (kernels!=null)){
int debugSize=0;
for (int ii=0;ii<kernels.length;ii++) if (kernels[ii]!=null){
......
......@@ -71,6 +71,11 @@ public class LensAdjustment {
distortionParameters.flatFieldCorrection=focusMeasurementParameters.flatFieldCorrection;
distortionParameters.flatFieldExpand=focusMeasurementParameters.flatFieldExpand;
distortionParameters.correlationMinContrast=focusMeasurementParameters.correlationMinContrast;
distortionParameters.correlationMinInitialContrast=focusMeasurementParameters.correlationMinInitialContrast;
distortionParameters.correlationMinAbsoluteContrast=focusMeasurementParameters.correlationMinAbsoluteContrast;
distortionParameters.correlationMinAbsoluteInitialContrast=focusMeasurementParameters.correlationMinAbsoluteInitialContrast;
if (maskNonPSF) {
distortionParameters.numberExtrapolated=0; //1; //3; // measuring PSF - extrapolate
} else {
......@@ -364,6 +369,13 @@ public class LensAdjustment {
public int correlationSize=32;
public double correlationGaussWidth=0.75;
public double minUVSpan; // Minimal u/v span in correlation window that triggers increase of the correlation FFT size
public double correlationMinContrast=1.2; // minimal contrast for the pattern to pass
public double correlationMinInitialContrast=1.5; // minimal contrast for the pattern of the center (initial point)
public double correlationMinAbsoluteContrast=0.5; // minimal contrast for the pattern to pass, does not compensate for low ligt
public double correlationMinAbsoluteInitialContrast=0.5; // minimal contrast for the pattern of the center (initial point)
public boolean flatFieldCorrection=true;
public double flatFieldExpand=4.0;
......@@ -374,8 +386,10 @@ public class LensAdjustment {
public boolean configureCamera=false; // only valid after dialog
public int [] motorPos=null; // will point to
public double [] ampsSeconds={0.0,0.0,0.0,0.0}; // cumulative Amps*seconds (read only, but will be saved/restored)
public int manufacturingState=0;
public String [] manufacturingStateNames={
"New SFE",
"UV cured (not released)",
......@@ -579,6 +593,10 @@ public class LensAdjustment {
int correlationSize,
double correlationGaussWidth,
double minUVSpan, // Minimal u/v span in correlation window that triggers increase of the correlation FFT size
double correlationMinContrast, // minimal contrast for the pattern to pass
double correlationMinInitialContrast, // minimal contrast for the pattern of the center (initial point)
double correlationMinAbsoluteContrast, // minimal contrast for the pattern to pass, does not compensate for low ligt
double correlationMinAbsoluteInitialContrast, // minimal contrast for the pattern of the center (initial point)
boolean flatFieldCorrection,
double flatFieldExpand,
double thresholdFinish,// (copied from series) stop iterations if 2 last steps had less improvement (but not worsening )
......@@ -730,6 +748,10 @@ public class LensAdjustment {
this.correlationSize=correlationSize;
this.correlationGaussWidth=correlationGaussWidth;
this.minUVSpan=minUVSpan;
this.correlationMinContrast=correlationMinContrast; // minimal contrast for the pattern to pass
this.correlationMinInitialContrast=correlationMinInitialContrast; // minimal contrast for the pattern of the center (initial point)
this.correlationMinAbsoluteContrast=correlationMinAbsoluteContrast; // minimal contrast for the pattern to pass, does not compensate for low ligt
this.correlationMinAbsoluteInitialContrast=correlationMinAbsoluteInitialContrast; // minimal contrast for the pattern of the center (initial point)
this.flatFieldCorrection=flatFieldCorrection;
this.flatFieldExpand=flatFieldExpand;
this.thresholdFinish=thresholdFinish;// (copied from series) stop iterations if 2 last steps had less improvement (but not worsening )
......@@ -884,6 +906,10 @@ public class LensAdjustment {
this.correlationSize,
this.correlationGaussWidth,
this.minUVSpan,
this.correlationMinContrast,
this.correlationMinInitialContrast,
this.correlationMinAbsoluteContrast,
this.correlationMinAbsoluteInitialContrast,
this.flatFieldCorrection,
this.flatFieldExpand,
this.thresholdFinish,
......@@ -1047,6 +1073,12 @@ public class LensAdjustment {
properties.setProperty(prefix+"correlationSize",this.correlationSize+"");
properties.setProperty(prefix+"correlationGaussWidth",this.correlationGaussWidth+"");
properties.setProperty(prefix+"minUVSpan",this.minUVSpan+"");
properties.setProperty(prefix+"correlationMinContrast",this.correlationMinContrast+"");
properties.setProperty(prefix+"correlationMinInitialContrast",this.correlationMinInitialContrast+"");
properties.setProperty(prefix+"correlationMinAbsoluteContrast",this.correlationMinAbsoluteContrast+"");
properties.setProperty(prefix+"correlationMinAbsoluteInitialContrast",this.correlationMinAbsoluteInitialContrast+"");
properties.setProperty(prefix+"flatFieldCorrection",this.flatFieldCorrection+"");
properties.setProperty(prefix+"flatFieldExpand",this.flatFieldExpand+"");
properties.setProperty(prefix+"thresholdFinish",this.thresholdFinish+"");
......@@ -1365,6 +1397,14 @@ public class LensAdjustment {
this.correlationGaussWidth=Double.parseDouble(properties.getProperty(prefix+"correlationGaussWidth"));
if (properties.getProperty(prefix+"minUVSpan")!=null)
this.minUVSpan=Double.parseDouble(properties.getProperty(prefix+"minUVSpan"));
if (properties.getProperty(prefix+"correlationMinContrast")!=null)
this.correlationMinContrast=Double.parseDouble(properties.getProperty(prefix+"correlationMinContrast"));
if (properties.getProperty(prefix+"correlationMinInitialContrast")!=null)
this.correlationMinInitialContrast=Double.parseDouble(properties.getProperty(prefix+"correlationMinInitialContrast"));
if (properties.getProperty(prefix+"correlationMinAbsoluteContrast")!=null)
this.correlationMinAbsoluteContrast=Double.parseDouble(properties.getProperty(prefix+"correlationMinAbsoluteContrast"));
if (properties.getProperty(prefix+"correlationMinAbsoluteInitialContrast")!=null)
this.correlationMinAbsoluteInitialContrast=Double.parseDouble(properties.getProperty(prefix+"correlationMinAbsoluteInitialContrast"));
if (properties.getProperty(prefix+"flatFieldCorrection")!=null)
this.flatFieldCorrection=Boolean.parseBoolean(properties.getProperty(prefix+"flatFieldCorrection"));
if (properties.getProperty(prefix+"flatFieldExpand")!=null)
......@@ -1627,9 +1667,14 @@ public class LensAdjustment {
gd.addNumericField("Sigma for filling the OTF ", this.gaps_sigma, 3);
gd.addNumericField("Denoise mask ", this.mask_denoise, 3);
gd.addNumericField("Invert deconvolution if less than", this.deconvInvert, 3);
gd.addMessage( "--- Pattern correlation parameters ---");
gd.addNumericField("Correlation size:", this.correlationSize, 0); // 64
gd.addNumericField("Correlation Gauss width (relative):", this.correlationGaussWidth, 3);
gd.addNumericField("Minimal UV span in correlation window to trigger FFT size increase",this.minUVSpan, 3);
gd.addNumericField("Correlation minimal contrast (normalized)", this.correlationMinContrast, 3);
gd.addNumericField("Correlation minimal contrast for initial search (normalized)", this.correlationMinInitialContrast, 3);
gd.addNumericField("Correlation minimal contrast (absolute)", this.correlationMinAbsoluteContrast, 3);
gd.addNumericField("Correlation minimal contrast for initial search (absolute)", this.correlationMinAbsoluteInitialContrast, 3);
gd.addCheckbox ("Compensate uneven pattern intensity", this.flatFieldCorrection);
gd.addNumericField("Expand during extrapolation (relative to the average grid period)", this.flatFieldExpand, 3);
gd.addNumericField("Threshold RMS to exit LMA", this.thresholdFinish, 7,9,"pix");
......@@ -1816,6 +1861,10 @@ public class LensAdjustment {
this.correlationSize= (int) gd.getNextNumber();
this.correlationGaussWidth= gd.getNextNumber();
this.minUVSpan= gd.getNextNumber();
this.correlationMinContrast= gd.getNextNumber();
this.correlationMinInitialContrast= gd.getNextNumber();
this.correlationMinAbsoluteContrast= gd.getNextNumber();
this.correlationMinAbsoluteInitialContrast= gd.getNextNumber();
this.flatFieldCorrection= gd.getNextBoolean();
this.flatFieldExpand= gd.getNextNumber();
this.thresholdFinish= gd.getNextNumber();
......
......@@ -7217,7 +7217,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
}
public int replaceGridXYWithProjected(double [][][] projectedGrid){
public int replaceGridXYWithProjected(double [][][] projectedGrid, String debugTitle){
int minU=0,minV=0,maxU=0,maxV=0;
boolean notYetSet=true;
for (double [][]row:projectedGrid) for (double [] cell:row) if (cell!=null){
......@@ -7249,7 +7249,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
int numNewDefined=0;
// System.out.println("this.PATTERN_GRID.length="+this.PATTERN_GRID.length+"this.PATTERN_GRID[0.length="+this.PATTERN_GRID[0].length);
// System.out.println("this.targetUV.length="+this.targetUV.length+"this.targetUV[0.length="+this.targetUV[0].length);
if (this.debugLevel>1){
if ((debugTitle!=null) && (this.debugLevel>0)){
double [][] debugReplace=null;
String [] debugTiltes={"deltaX","deltaY","Contrast", "measX","measY", "targetU","targetV"};
debugReplace=new double[7][this.PATTERN_GRID.length*this.PATTERN_GRID[0].length];
......@@ -7271,7 +7271,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
}
}
}
SDFA_INSTANCE.showArrays(debugReplace, this.PATTERN_GRID[0].length, this.PATTERN_GRID.length, true, "replaceGridXYWithProjected", debugTiltes);
SDFA_INSTANCE.showArrays(debugReplace, this.PATTERN_GRID[0].length, this.PATTERN_GRID.length, true, "replaceGridXYWithProjected-"+debugTitle, debugTiltes);
}
for (int v=0;v<this.PATTERN_GRID.length;v++) for (int u=0;u<this.PATTERN_GRID[v].length;u++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment