Commit 9e7ad476 authored by Andrey Filippov's avatar Andrey Filippov

Added option to deconvolve patterns using projected (not extracted) grid

parent 825895a1
......@@ -2486,7 +2486,8 @@ For each point in the image
subCam,
goniometerTilt, // Tilt, goniometerHorizontal
goniometerAxial, // Axial,goniometerAxial
-1 // use camera parameters, not imageSet
-1, // use camera parameters, not imageSet
true // filter border
);
if (hintGrid==null){
String msg="Grid is not visible for subcamera="+subCam+", tilt="+goniometerTilt+", axial="+goniometerAxial;
......@@ -2664,7 +2665,8 @@ For each point in the image
dcd.gIP[numGridImage].channel,
goniometerTiltAxial[0], // Tilt, goniometerHorizontal
goniometerTiltAxial[1], // Axial,goniometerAxial
setNumber // -1 or specific image set
setNumber, // -1 or specific image set
true // filter border
);
if (global_debug_level>0){
System.out.println("\n**** applyHintedGrids(): processing grid image # "+numGridImage+", path="+dcd.gIP[numGridImage].path);
......@@ -2859,7 +2861,6 @@ For each point in the image
pixels[4][index]=1000.0;
}
(new showDoubleFloatArrays()).showArrays(pixels, width, height, true, "grid-"+numGridImage, titles);
}
public void showGridAndHint(){
GenericDialog gd=new GenericDialog("Show selected grid and/or hint grid");
......@@ -2903,8 +2904,9 @@ For each point in the image
fittingStrategy.distortionCalibrationData.gIP[numGridImage].channel,
goniometerTiltAxial[0], // Tilt, goniometerHorizontal
goniometerTiltAxial[1], // Axial,goniometerAxial
useSetData?fittingStrategy.distortionCalibrationData.gIP[numGridImage].setNumber:-1
);
(useSetData?fittingStrategy.distortionCalibrationData.gIP[numGridImage].setNumber:-1),
true // filter border
);
showHintGrid(hintGrid,"hint-"+numGridImage);
}
......@@ -3061,7 +3063,8 @@ For each point in the image
int subCamera,
double goniometerHorizontal, // Tilt
double goniometerAxial, // Axial
int imageSet){
int imageSet,
boolean filterBorder){
int debugThreshold=2;
// Get parameter vector (22) for the selected sensor, current Eyesisparameters and specified orientation angles
double [] parVector=fittingStrategy.distortionCalibrationData.eyesisCameraParameters.getParametersVector(stationNumber,subCamera);
......@@ -3139,21 +3142,22 @@ For each point in the image
}
}
}
// now filter border nodes
boolean [] mask= new boolean [patternGeometry.length*patternGeometry[0].length];
int index=0;
for (int v=0;v<result.length;v++) for (int u=0;u<result[v].length;u++){
mask [index++]=(result[v][u]!=null) &&
((v==0) || (result[v-1][u]!=null)) &&
((v==(result.length-1)) || (result[v+1][u]!=null)) &&
((u==0) || (result[v][u-1]!=null))&&
((u==(result[v].length-1)) || (result[v][u+1]!=null));
}
index=0;
for (int v=0;v<result.length;v++) for (int u=0;u<result[v].length;u++){
if (!mask[index++]) result[v][u]=null;
if (filterBorder){
// now filter border nodes
boolean [] mask= new boolean [patternGeometry.length*patternGeometry[0].length];
int index=0;
for (int v=0;v<result.length;v++) for (int u=0;u<result[v].length;u++){
mask [index++]=(result[v][u]!=null) &&
((v==0) || (result[v-1][u]!=null)) &&
((v==(result.length-1)) || (result[v+1][u]!=null)) &&
((u==0) || (result[v][u-1]!=null))&&
((u==(result[v].length-1)) || (result[v][u+1]!=null));
}
index=0;
for (int v=0;v<result.length;v++) for (int u=0;u<result[v].length;u++){
if (!mask[index++]) result[v][u]=null;
}
}
if (this.debugLevel>debugThreshold){
for (int v=0;v<result.length;v++) for (int u=0;u<result[v].length;u++){
int uv=u+v*result[v].length;
......@@ -1073,6 +1073,8 @@ public class EyesisAberrations {
int debugLevel
){
Distortions.DistortionCalibrationData distortionCalibrationData= distortions.fittingStrategy.distortionCalibrationData;
boolean partialToReprojected=this.aberrationParameters.partialToReprojected;
// this.distortions is set to top level LENS_DISTORTIONS
if (distortions==null){
String msg="Distortions instance does not exist, exiting";
IJ.showMessage("Error",msg);
......@@ -1212,7 +1214,7 @@ public class EyesisAberrations {
}
// reorder in the ascending channel number order
String [][] files=new String [numFiles][2]; // 0 - source, 1 - result
int [] fileIndices =new int [numFiles]; // needed to mark bad kernels
int [] fileIndices =new int [numFiles]; // needed to mark bad kernels (and also to reference grid parameters to replace extracted)
int numListedFiles=0;
int numChannel=0;
while (numListedFiles<numFiles) {
......@@ -1239,6 +1241,22 @@ public class EyesisAberrations {
int iRetry=0;
for (iRetry=0;iRetry<MaxRetries;iRetry++){ // is this retry needed?
try {
double [][][] projectedGrid=null;
double hintTolerance=0.0;
if (partialToReprojected){ // replace px, py with projected values form the grid
// this.distortions is set to the global LENS_DISTORTIONS
int numGridImage=fileIndices[imgNum];
projectedGrid=distortions.estimateGridOnSensor( // return grid array [v][u][0- x, 1 - y, 2 - u, 3 - v]
distortions.fittingStrategy.distortionCalibrationData.getImageStation(numGridImage), // station number,
distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].channel, // subCamera,
Double.NaN, // goniometerHorizontal, - not used
Double.NaN, // goniometerAxial, - not used
distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].getSetNumber(), //imageSet,
true); //filterBorder)
hintTolerance=5.0; // TODO:set from configurable parameter
}
int rslt=matchSimulatedPattern.calculateDistortions(
distortionParameters, //
patternDetectParameters,
......@@ -1247,9 +1265,8 @@ public class EyesisAberrations {
imp,
null, // LaserPointer laserPointer, // LaserPointer object or null
true, // don't care -removeOutOfGridPointers
null, // double [][][] hintGrid, // predicted grid array (or null)
0, // double hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
projectedGrid, // null, // double [][][] hintGrid, // predicted grid array (or null)
hintTolerance, // 0, // double hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
threadsMax,
updateStatus,
debugLevel,
......@@ -1259,6 +1276,11 @@ public class EyesisAberrations {
if (debugLevel>0) System.out.println("calculateDistortions failed, returned error code "+rslt+" iRetry="+iRetry+" (of "+MaxRetries+")");
continue;
}
// now replace extracted grid X,Y with projected:
if (projectedGrid!=null){
int numReplaced= matchSimulatedPattern.replaceGridXYWithProjected(projectedGrid);
if (debugLevel>0) System.out.println("Replaced extracted XY with projected ones for "+numReplaced+" nodes");
}
correlationSizesUsed=matchSimulatedPattern.getCorrelationSizesUsed();
simArray= (new SimulationPattern(simulParameters)).simulateGridAll (
imp.getWidth(),
......@@ -4428,6 +4450,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
public boolean autoReCalibrateIgnoreLaser=false; // "Ignore laser pointers on recalibrate"
public boolean noMessageBoxes=true;
public boolean overwriteResultFiles=false;
public boolean partialToReprojected=true; // Use reprojected grid for partial kernel calculation (false - use extracted)
public int seriesNumber=0;
public boolean allImages;
public String sourcePrefix="";
......@@ -4460,6 +4483,8 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
properties.setProperty(prefix+"autoReCalibrateIgnoreLaser",this.autoReCalibrateIgnoreLaser+"");
properties.setProperty(prefix+"noMessageBoxes",this.noMessageBoxes+"");
properties.setProperty(prefix+"overwriteResultFiles",this.overwriteResultFiles+"");
properties.setProperty(prefix+"partialToReprojected",this.partialToReprojected+"");
properties.setProperty(prefix+"seriesNumber",this.seriesNumber+"");
properties.setProperty(prefix+"allImages",this.allImages+"");
......@@ -4498,6 +4523,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
if (properties.getProperty(prefix+"autoReCalibrateIgnoreLaser")!=null) this.autoReCalibrateIgnoreLaser=Boolean.parseBoolean(properties.getProperty(prefix+"autoReCalibrateIgnoreLaser"));
if (properties.getProperty(prefix+"noMessageBoxes")!=null) this.noMessageBoxes=Boolean.parseBoolean(properties.getProperty(prefix+"noMessageBoxes"));
if (properties.getProperty(prefix+"overwriteResultFiles")!=null) this.overwriteResultFiles=Boolean.parseBoolean(properties.getProperty(prefix+"overwriteResultFiles"));
if (properties.getProperty(prefix+"partialToReprojected")!=null) this.partialToReprojected=Boolean.parseBoolean(properties.getProperty(prefix+"partialToReprojected"));
if (properties.getProperty(prefix+"seriesNumber")!=null) this.seriesNumber=Integer.parseInt(properties.getProperty(prefix+"seriesNumber"));
if (properties.getProperty(prefix+"allImages")!=null) this.allImages=Boolean.parseBoolean(properties.getProperty(prefix+"allImages"));
if (properties.getProperty(prefix+"sourcePrefix")!=null) this.sourcePrefix=properties.getProperty(prefix+"sourcePrefix");
......@@ -4629,6 +4655,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
gd.addCheckbox("Select aberrations kernels directory", false);
gd.addCheckbox("Supress non-essential message boxes", this.noMessageBoxes);
gd.addCheckbox("Overwrite result files if they exist", this.overwriteResultFiles);
gd.addCheckbox("Use reprojected grids for partial kernel calculation (false - extracted grids)", this.partialToReprojected);
gd.addNumericField("Fitting series number to use for image selection", this.seriesNumber,0);
gd.addCheckbox("Process all enabled image files (false - use selected fitting series)", this.allImages);
gd.addMessage("===== Autoload options (when restoring configuration) =====");
......@@ -4673,6 +4700,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
if (gd.getNextBoolean()) selectAberrationsKernelDirectory(false, this.aberrationsKernelDirectory, false);
this.noMessageBoxes= gd.getNextBoolean();
this.overwriteResultFiles= gd.getNextBoolean();
this.partialToReprojected= gd.getNextBoolean();
this.seriesNumber= (int) gd.getNextNumber();
this.allImages= gd.getNextBoolean();
this.autoRestore= gd.getNextBoolean();
......
......@@ -598,7 +598,8 @@ horizontal axis:
subCam,
goniometerTiltAxial[0], // Tilt, goniometerHorizontal
goniometerTiltAxial[1], // Axial,goniometerAxial
-1 // use camera parameters, not imageSet
-1, // use camera parameters, not imageSet
true // filter border
);
if (hintGrid==null){
String msg= "Target is not visible";
......
......@@ -6983,6 +6983,51 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
}
public int replaceGridXYWithProjected(double [][][] projectedGrid){
int minU=0,minV=0,maxU=0,maxV=0;
boolean notYetSet=true;
for (double [][]row:projectedGrid) for (double [] cell:row) if (cell!=null){
int u = (int) cell[2];
int v = (int) cell[3];
if (notYetSet){
minU=u;
maxU=u;
minV=v;
maxV=v;
notYetSet=false;
} else {
if (minU>u) minU=u;
if (maxU<u) maxU=u;
if (minV>v) minV=v;
if (maxV<v) maxV=v;
}
}
double [][][] grid=new double [maxV-minV+1][maxU-minU+1][];
// for (double [][]row:grid) for (double [] cell:row) cell=null; // See if this works with "enhanced for loop"
for (double [][]row:grid) for (int u=0;u<row.length;u++) row[u]=null; // See if this works with "enhanced for loop"
for (double [][] row:projectedGrid) for (double [] cell:row) if (cell!=null){
int u = (int) cell[2];
int v = (int) cell[3];
double [] xy={cell[0],cell[1]};
grid[v-minV][u-minU]=xy;
}
int numNewDefined=0;
for (int v=0;v<this.PATTERN_GRID.length;v++) for (int u=0;u<this.PATTERN_GRID[v].length;u++) {
double [][] cell=this.PATTERN_GRID[v][u];
if ((cell !=null) && (cell.length>0) &&(cell[0] !=null) && (cell[0].length>1)){
cell[0][0]=grid[this.targetUV[v][u][1]+minV][this.targetUV[v][u][0]+minU][0];
cell[0][1]=grid[this.targetUV[v][u][1]+minV][this.targetUV[v][u][0]+minU][1];
if (Double.isNaN(cell[0][0]) || Double.isNaN(cell[0][1])){
this.PATTERN_GRID[v][u]=null; // make it undefined
} else {
numNewDefined++;
}
}
}
return numNewDefined;
}
/* Get calibrated pattern as a 8-slice image (can be saved as TIFF)
* first slice - pixel X or -1 for undefined
* second slice - pixel Y or -1 for undefined
......
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