Commit d3b2b2c6 authored by Andrey Filippov's avatar Andrey Filippov

debugging

parent 43fae5db
...@@ -302,6 +302,7 @@ public class Aberration_Calibration extends PlugInFrame implements ActionListene ...@@ -302,6 +302,7 @@ public class Aberration_Calibration extends PlugInFrame implements ActionListene
public static MatchSimulatedPattern.DistortionParameters DISTORTION =new MatchSimulatedPattern.DistortionParameters( public static MatchSimulatedPattern.DistortionParameters DISTORTION =new MatchSimulatedPattern.DistortionParameters(
64, //32, // use 64 for less artifacts, // correlationSize 64, //32, // use 64 for less artifacts, // correlationSize
64, // Maximal correlation size
0.75,// reduce to 0.5 when correlationSize==64 // correlationGaussWidth 0.75,// reduce to 0.5 when correlationSize==64 // correlationGaussWidth
false, // boolean absoluteCorrelationGaussWidth=false; // do not scale correlationGaussWidth when the FFT size is increased false, // boolean absoluteCorrelationGaussWidth=false; // do not scale correlationGaussWidth when the FFT size is increased
0, //zeros - // leave this number of zeros on the margins of the window (toatal from both sides). If correlationGaussWidth>0 will 0, //zeros - // leave this number of zeros on the margins of the window (toatal from both sides). If correlationGaussWidth>0 will
...@@ -19190,6 +19191,8 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica ...@@ -19190,6 +19191,8 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica
gd.addNumericField("FFTSize (Initial pattern detection only):", distortionParameters.FFTSize, 0); // 128 gd.addNumericField("FFTSize (Initial pattern detection only):", distortionParameters.FFTSize, 0); // 128
gd.addNumericField("FFT Gaussian width (relative):", distortionParameters.fftGaussWidth, 3); gd.addNumericField("FFT Gaussian width (relative):", distortionParameters.fftGaussWidth, 3);
gd.addNumericField("Correlation size:", distortionParameters.correlationSize, 0); // 64 gd.addNumericField("Correlation size:", distortionParameters.correlationSize, 0); // 64
gd.addNumericField("Maximal correlation size:", distortionParameters.maximalCorrelationSize, 0); // 64
gd.addNumericField("Correlation Gauss width (relative):", distortionParameters.correlationGaussWidth, 3); gd.addNumericField("Correlation Gauss width (relative):", distortionParameters.correlationGaussWidth, 3);
gd.addCheckbox("Keep Gaussian width absolute when increasing FFT size",distortionParameters.absoluteCorrelationGaussWidth); gd.addCheckbox("Keep Gaussian width absolute when increasing FFT size",distortionParameters.absoluteCorrelationGaussWidth);
// /phaseCorrelationFraction // /phaseCorrelationFraction
...@@ -19268,6 +19271,8 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica ...@@ -19268,6 +19271,8 @@ use the result to create a rejectiobn mask - if the energy was high, (multiplica
distortionParameters.fftGaussWidth= gd.getNextNumber(); distortionParameters.fftGaussWidth= gd.getNextNumber();
distortionParameters.correlationSize=1; distortionParameters.correlationSize=1;
for (i=(int) gd.getNextNumber(); i >1; i>>=1) distortionParameters.correlationSize <<=1; /* make it to be power of 2 */ for (i=(int) gd.getNextNumber(); i >1; i>>=1) distortionParameters.correlationSize <<=1; /* make it to be power of 2 */
distortionParameters.maximalCorrelationSize=1;
for (i=(int) gd.getNextNumber(); i >1; i>>=1) distortionParameters.maximalCorrelationSize <<=1; /* make it to be power of 2 */
distortionParameters.correlationGaussWidth= gd.getNextNumber(); distortionParameters.correlationGaussWidth= gd.getNextNumber();
distortionParameters.absoluteCorrelationGaussWidth=gd.getNextBoolean(); distortionParameters.absoluteCorrelationGaussWidth=gd.getNextBoolean();
distortionParameters.zeros= (int) gd.getNextNumber(); distortionParameters.zeros= (int) gd.getNextNumber();
......
...@@ -975,7 +975,7 @@ public class MatchSimulatedPattern { ...@@ -975,7 +975,7 @@ public class MatchSimulatedPattern {
title, // title base for optional plots names title, // title base for optional plots names
this.debugLevel); this.debugLevel);
} }
public double correlationContrast ( double [] pixels, // square pixel array public double correlationContrastOld ( double [] pixels, // square pixel array
double [][] wVectors, // wave vectors (same units as the pixels array) double [][] wVectors, // wave vectors (same units as the pixels array)
double ringWidth, // ring (around r=0.5 dist to opposite corr) width double ringWidth, // ring (around r=0.5 dist to opposite corr) width
double x0, // center coordinates double x0, // center coordinates
...@@ -1060,6 +1060,70 @@ public class MatchSimulatedPattern { ...@@ -1060,6 +1060,70 @@ public class MatchSimulatedPattern {
} }
return contrast; return contrast;
} }
public double correlationContrast ( double [] pixels, // square pixel array
double [][] wVectors, // wave vectors (same units as the pixels array)
double ringWidth, // ring (around r=0.5 dist to opposite corr) width
double x0, // center coordinates
double y0,
String title, // title base for optional plots names
int debugLevel){
double sigma=0.1;
double sigma32=9*sigma*sigma;
double k=-0.5/(sigma*sigma);
double [][] sampleCentersXY={{0.0,0.0},{0.0,0.5},{0.5,0.0},{0.0,-0.5},{-0.5,0.0}};
int [] sampleTypes = {0,1,1,1,1};
int size=(int) Math.sqrt(pixels.length);
double [] xy= new double [2];
double [] uv;
double r2;
int i,j;
/* opposite sign correlation points in uv are at uv=(0,-0.5),(0,0.5), (-0.5,0) and (0.5,0), with radius of (1/2)
selecting center circle and a ring from 0.25 to 0.75 of the distance to opposite sign correlations */
double [] dbgMask= new double[size*size];
for (int n=0;n<dbgMask.length;n++) dbgMask[n]=0.0;
double [] s={0.0,0.0};
double [] w={0.0,0.0};
for (i=0;i<size;i++) {
xy[1]=i-size/2-y0;
for (j=0;j<size;j++) {
xy[0]=j-size/2-x0;
uv=matrix2x2_mul(wVectors,xy);
for (int np=0;np<sampleCentersXY.length;np++){
double dx=uv[0]-sampleCentersXY[np][0];
double dy=uv[1]-sampleCentersXY[np][1];
r2=dx*dx+dy*dy;
if (r2<sigma32){
double m=Math.exp(k*r2);
dbgMask[i*size+j]+=m;
w[sampleTypes[np]]+=m;
s[sampleTypes[np]]+=m*pixels[i*size+j];
}
}
}
}
if ((w[0]==0.0) || (w[1]==0.0)) {
if (debugLevel>1) System.out.println("Not enough data for correlation contrast: center - w[0]="+w[0]+" opposite - w[1]="+w[1]);
return -1.0;
}
double contrast=Math.sqrt((s[0]/w[0])/(s[1]/w[1]));
if (debugLevel>2) {
System.out.println("Correlation contrast is "+contrast);
double [][] dbgPixels={pixels,dbgMask};
String [] titles={"all","mask"};
(new showDoubleFloatArrays()).showArrays(
dbgPixels,
size,
size,
true,
title+"_CORR_MASK",
titles);
}
return contrast;
}
/* ======================================================================== */ /* ======================================================================== */
public double[] correlateWithModel (double [] imagePixels, // measured pixel array public double[] correlateWithModel (double [] imagePixels, // measured pixel array
double [] modelPixels, // simulated (model) pixel array) double [] modelPixels, // simulated (model) pixel array)
...@@ -7174,11 +7238,17 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1]) ...@@ -7174,11 +7238,17 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
double [] thisWindow=window; double [] thisWindow=window;
double uv_threshold=distortionParameters.minUVSpan*0.25*Math.sqrt(2.0); double uv_threshold=distortionParameters.minUVSpan*0.25*Math.sqrt(2.0);
if ((min_span<uv_threshold) && (window2!=null)) { // trying to increase only twice if (
(min_span<uv_threshold) &&
(window2!=null) &&
(thisCorrelationSize<distortionParameters.maximalCorrelationSize)) { // trying to increase only twice
thisCorrelationSize*=2; thisCorrelationSize*=2;
min_span*=2; min_span*=2;
thisWindow=window2; thisWindow=window2;
if ((min_span<uv_threshold) && (window4!=null)) { if (
(min_span<uv_threshold) &&
(window4!=null) &&
(thisCorrelationSize<distortionParameters.maximalCorrelationSize)) {
thisCorrelationSize*=2; thisCorrelationSize*=2;
min_span*=2; min_span*=2;
thisWindow=window4; thisWindow=window4;
...@@ -7427,6 +7497,23 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1]) ...@@ -7427,6 +7497,23 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
double [] thisWindow=window; double [] thisWindow=window;
double uv_threshold=distortionParameters.minUVSpan*0.25*Math.sqrt(2.0); double uv_threshold=distortionParameters.minUVSpan*0.25*Math.sqrt(2.0);
if (
(min_span<uv_threshold) &&
(window2!=null) &&
(thisCorrelationSize<distortionParameters.maximalCorrelationSize)) { // trying to increase only twice
thisCorrelationSize*=2;
min_span*=2;
thisWindow=window2;
if (
(min_span<uv_threshold) &&
(window4!=null) &&
(thisCorrelationSize<distortionParameters.maximalCorrelationSize)) {
thisCorrelationSize*=2;
min_span*=2;
thisWindow=window4;
}
}
/*
if ((min_span<uv_threshold) && (window2!=null)) { // trying to increase only twice if ((min_span<uv_threshold) && (window2!=null)) { // trying to increase only twice
thisCorrelationSize*=2; thisCorrelationSize*=2;
min_span*=2; min_span*=2;
...@@ -7437,6 +7524,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1]) ...@@ -7437,6 +7524,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
thisWindow=window4; thisWindow=window4;
} }
} }
*/
setCorrelationSizesUsed(thisCorrelationSize); setCorrelationSizesUsed(thisCorrelationSize);
if ((debug_level>0)&&(thisCorrelationSize>distortionParameters.correlationSize)) System.out.println("**** u/v span too small, increasing FFT size to "+thisCorrelationSize); if ((debug_level>0)&&(thisCorrelationSize>distortionParameters.correlationSize)) System.out.println("**** u/v span too small, increasing FFT size to "+thisCorrelationSize);
Rectangle centerCross=correlationSelection( Rectangle centerCross=correlationSelection(
...@@ -7499,6 +7587,10 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1]) ...@@ -7499,6 +7587,10 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
thisCorrelationSize, // number of Bayer cells in width of the square selection (half number of pixels) thisCorrelationSize, // number of Bayer cells in width of the square selection (half number of pixels)
0, 0,
0); 0);
if (sim_pix==null){
System.out.println("***** BUG: extractSimulPatterns() FAILED *****");
return null;
}
simGreensCentered= normalizeAndWindow (sim_pix[4], thisWindow); simGreensCentered= normalizeAndWindow (sim_pix[4], thisWindow);
...@@ -8966,6 +9058,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) ) ...@@ -8966,6 +9058,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) )
public static class DistortionParameters { public static class DistortionParameters {
public int correlationSize; public int correlationSize;
public int maximalCorrelationSize;
public double correlationGaussWidth; // 0 - no window, <0 - use Hamming public double correlationGaussWidth; // 0 - no window, <0 - use Hamming
public boolean absoluteCorrelationGaussWidth=false; // do not scale correlationGaussWidth when the FFT size is increased public boolean absoluteCorrelationGaussWidth=false; // do not scale correlationGaussWidth when the FFT size is increased
public int zeros; // leave this number of zeros on the margins of the window (toatal from both sides). If correlationGaussWidth>0 will public int zeros; // leave this number of zeros on the margins of the window (toatal from both sides). If correlationGaussWidth>0 will
...@@ -9027,6 +9120,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) ) ...@@ -9027,6 +9120,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) )
public DistortionParameters( public DistortionParameters(
int correlationSize, int correlationSize,
int maximalCorrelationSize,
double correlationGaussWidth, double correlationGaussWidth,
boolean absoluteCorrelationGaussWidth, boolean absoluteCorrelationGaussWidth,
int zeros, int zeros,
...@@ -9082,6 +9176,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) ) ...@@ -9082,6 +9176,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) )
){ ){
this.correlationSize = correlationSize; this.correlationSize = correlationSize;
this.maximalCorrelationSize=maximalCorrelationSize;
this.correlationGaussWidth = correlationGaussWidth; this.correlationGaussWidth = correlationGaussWidth;
this.absoluteCorrelationGaussWidth=absoluteCorrelationGaussWidth; this.absoluteCorrelationGaussWidth=absoluteCorrelationGaussWidth;
this.zeros=zeros; this.zeros=zeros;
...@@ -9139,6 +9234,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) ) ...@@ -9139,6 +9234,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) )
public DistortionParameters clone() { public DistortionParameters clone() {
return new DistortionParameters( return new DistortionParameters(
this.correlationSize, this.correlationSize,
this.maximalCorrelationSize,
this.correlationGaussWidth, this.correlationGaussWidth,
this.absoluteCorrelationGaussWidth, this.absoluteCorrelationGaussWidth,
this.zeros, this.zeros,
...@@ -9196,6 +9292,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) ) ...@@ -9196,6 +9292,7 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) )
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"correlationSize",this.correlationSize+""); properties.setProperty(prefix+"correlationSize",this.correlationSize+"");
properties.setProperty(prefix+"maximalCorrelationSize",this.maximalCorrelationSize+"");
properties.setProperty(prefix+"correlationGaussWidth",this.correlationGaussWidth+""); properties.setProperty(prefix+"correlationGaussWidth",this.correlationGaussWidth+"");
properties.setProperty(prefix+"absoluteCorrelationGaussWidth",this.absoluteCorrelationGaussWidth+""); properties.setProperty(prefix+"absoluteCorrelationGaussWidth",this.absoluteCorrelationGaussWidth+"");
properties.setProperty(prefix+"zeros",this.zeros+""); properties.setProperty(prefix+"zeros",this.zeros+"");
...@@ -9254,6 +9351,8 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) ) ...@@ -9254,6 +9351,8 @@ error=Sum(W(x,y)*(F^2 + 2*F*(A*x^2+B*y^2+C*x*y+D*x+E*y-Z(x,y)) +(...) )
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"correlationSize")!=null) if (properties.getProperty(prefix+"correlationSize")!=null)
this.correlationSize=Integer.parseInt(properties.getProperty(prefix+"correlationSize")); this.correlationSize=Integer.parseInt(properties.getProperty(prefix+"correlationSize"));
if (properties.getProperty(prefix+"maximalCorrelationSize")!=null)
this.maximalCorrelationSize=Integer.parseInt(properties.getProperty(prefix+"maximalCorrelationSize"));
if (properties.getProperty(prefix+"correlationGaussWidth")!=null) if (properties.getProperty(prefix+"correlationGaussWidth")!=null)
this.correlationGaussWidth=Double.parseDouble(properties.getProperty(prefix+"correlationGaussWidth")); this.correlationGaussWidth=Double.parseDouble(properties.getProperty(prefix+"correlationGaussWidth"));
if (properties.getProperty(prefix+"FFTSize")!=null) if (properties.getProperty(prefix+"FFTSize")!=null)
......
...@@ -877,7 +877,13 @@ Cv=(Cy*x-Cx*y)+(-Cy*Dx+Cx*Dy) ...@@ -877,7 +877,13 @@ Cv=(Cy*x-Cx*y)+(-Cy*Dx+Cx*Dy)
s=0.0; s=0.0;
for (py=iy0+sampLow;py<iy0+sampHigh;py++) for (px=ix0+sampLow;px<ix0+sampHigh;px++) { for (py=iy0+sampLow;py<iy0+sampHigh;py++) for (px=ix0+sampLow;px<ix0+sampHigh;px++) {
/// s+=this.barray[py][px]; /// s+=this.barray[py][px];
try {
s+=this.barray[py*fullSize+px]; s+=this.barray[py*fullSize+px];
} catch (Exception e){
System.out.println("Bug in extractSimulPatterns(): px="+px+" py="+py+" fullSize="+fullSize+" size="+size+" x0="+x0+" y0="+y0);
e.printStackTrace();
return null;
}
} }
simul_pixels[n][iy*size+ix]= (s-sampleAverage)/sampleAverage; simul_pixels[n][iy*size+ix]= (s-sampleAverage)/sampleAverage;
} }
......
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