Commit 91616de2 authored by Andrey Filippov's avatar Andrey Filippov

trying with actual kernels

parent be7e6c62
...@@ -1666,7 +1666,15 @@ public class EyesisCorrectionParameters { ...@@ -1666,7 +1666,15 @@ public class EyesisCorrectionParameters {
public double dbg_sigma =2.0; public double dbg_sigma =2.0;
public String dbg_mask = ".........:::::::::.........:::::::::......*..:::::*:::.........:::::::::........."; public String dbg_mask = ".........:::::::::.........:::::::::......*..:::::*:::.........:::::::::.........";
public int dbg_mode = 1; // 0 - old LMA, 1 - new LMA public int dbg_mode = 1; // 0 - old LMA, 1 - new LMA
public int dbg_window_mode = 2; // 0 - none, 1 - square, 2 - sin public int dbg_window_mode = 2; // 0 - none, 1 - square, 2 - sin 3 - sin^2
public boolean centerWindowToTarget = true;
// parameters to extract a kernel from the kernel image file
public int color_channel = 2; // green (<0 - use simulated kernel, also will use simulated if kernels are not set)
public int decimation = 2; // decimate original kernel this much in each direction
public double decimateSigma = 0.4; // what is the optimal value for each decimation?
public int tileX = 82; // number of kernel tile (0..163)
public int tileY = 62; // number of kernel tile (0..122)
public DCTParameters( public DCTParameters(
int dct_size, int dct_size,
...@@ -1697,7 +1705,6 @@ public class EyesisCorrectionParameters { ...@@ -1697,7 +1705,6 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"asym_tax_free", this.asym_tax_free+""); properties.setProperty(prefix+"asym_tax_free", this.asym_tax_free+"");
properties.setProperty(prefix+"seed_size", this.seed_size+""); properties.setProperty(prefix+"seed_size", this.seed_size+"");
properties.setProperty(prefix+"asym_random", this.asym_random+""); properties.setProperty(prefix+"asym_random", this.asym_random+"");
properties.setProperty(prefix+"LMA_steps", this.LMA_steps+""); properties.setProperty(prefix+"LMA_steps", this.LMA_steps+"");
properties.setProperty(prefix+"dbg_x", this.dbg_x+""); properties.setProperty(prefix+"dbg_x", this.dbg_x+"");
properties.setProperty(prefix+"dbg_y", this.dbg_y+""); properties.setProperty(prefix+"dbg_y", this.dbg_y+"");
...@@ -1707,6 +1714,12 @@ public class EyesisCorrectionParameters { ...@@ -1707,6 +1714,12 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"dbg_mask", this.dbg_mask+""); properties.setProperty(prefix+"dbg_mask", this.dbg_mask+"");
properties.setProperty(prefix+"dbg_mode", this.dbg_mode+""); properties.setProperty(prefix+"dbg_mode", this.dbg_mode+"");
properties.setProperty(prefix+"dbg_window_mode", this.dbg_window_mode+""); properties.setProperty(prefix+"dbg_window_mode", this.dbg_window_mode+"");
properties.setProperty(prefix+"centerWindowToTarget", this.centerWindowToTarget+"");
properties.setProperty(prefix+"color_channel", this.color_channel+"");
properties.setProperty(prefix+"decimation", this.dbg_window_mode+"");
properties.setProperty(prefix+"decimateSigma", this.decimateSigma+"");
properties.setProperty(prefix+"tileX", this.tileX+"");
properties.setProperty(prefix+"tileY", this.tileY+"");
} }
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
...@@ -1728,32 +1741,46 @@ public class EyesisCorrectionParameters { ...@@ -1728,32 +1741,46 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"dbg_sigma")!=null) this.dbg_sigma=Double.parseDouble(properties.getProperty(prefix+"dbg_sigma")); if (properties.getProperty(prefix+"dbg_sigma")!=null) this.dbg_sigma=Double.parseDouble(properties.getProperty(prefix+"dbg_sigma"));
if (properties.getProperty(prefix+"dbg_mask")!=null) this.dbg_mask=properties.getProperty(prefix+"dbg_mask"); if (properties.getProperty(prefix+"dbg_mask")!=null) this.dbg_mask=properties.getProperty(prefix+"dbg_mask");
if (properties.getProperty(prefix+"dbg_mode")!=null) this.dbg_mode=Integer.parseInt(properties.getProperty(prefix+"dbg_mode")); if (properties.getProperty(prefix+"dbg_mode")!=null) this.dbg_mode=Integer.parseInt(properties.getProperty(prefix+"dbg_mode"));
if (properties.getProperty(prefix+"tileY")!=null) this.tileY=Integer.parseInt(properties.getProperty(prefix+"tileY"));
if (properties.getProperty(prefix+"centerWindowToTarget")!=null) this.centerWindowToTarget=Boolean.parseBoolean(properties.getProperty(prefix+"centerWindowToTarget"));
if (properties.getProperty(prefix+"color_channel")!=null) this.color_channel=Integer.parseInt(properties.getProperty(prefix+"color_channel"));
if (properties.getProperty(prefix+"decimation")!=null) this.decimation=Integer.parseInt(properties.getProperty(prefix+"decimation"));
if (properties.getProperty(prefix+"decimateSigma")!=null) this.decimateSigma=Double.parseDouble(properties.getProperty(prefix+"decimateSigma"));
if (properties.getProperty(prefix+"tileX")!=null) this.tileX=Integer.parseInt(properties.getProperty(prefix+"tileX"));
if (properties.getProperty(prefix+"dbg_window_mode")!=null) this.dbg_window_mode=Integer.parseInt(properties.getProperty(prefix+"dbg_window_mode")); if (properties.getProperty(prefix+"dbg_window_mode")!=null) this.dbg_window_mode=Integer.parseInt(properties.getProperty(prefix+"dbg_window_mode"));
} }
public boolean showDialog() { public boolean showDialog() {
GenericDialog gd = new GenericDialog("Set DCT parameters"); GenericDialog gd = new GenericDialog("Set DCT parameters");
gd.addNumericField("DCT size", this.dct_size, 0); //32 gd.addNumericField("DCT size", this.dct_size, 0);
gd.addNumericField("Size of asymmetrical (non-DCT) kernel", this.asym_size, 0); //6 gd.addNumericField("Size of asymmetrical (non-DCT) kernel", this.asym_size, 0);
gd.addNumericField("Maximal number of non-zero pixels in direct convolution kernel", this.asym_pixels, 0); //6 gd.addNumericField("Maximal number of non-zero pixels in direct convolution kernel", this.asym_pixels, 0);
gd.addNumericField("How far to try a new asym kernel pixel from existing ones", this.asym_distance, 0); //6 gd.addNumericField("How far to try a new asym kernel pixel from existing ones", this.asym_distance, 0);
gd.addNumericField("MDCT window type (0,1,2)", this.dct_window, 0); //0..2 gd.addNumericField("MDCT window type (0,1,2)", this.dct_window, 0);
gd.addNumericField("LMA_steps", this.LMA_steps, 0); //0..2 gd.addNumericField("LMA_steps", this.LMA_steps, 0);
gd.addNumericField("Compactness (punish off-center asym_kernel pixels (proportional to r^2)", this.compactness, 2); //0..2 gd.addNumericField("Compactness (punish off-center asym_kernel pixels (proportional to r^2)", this.compactness,2);
gd.addNumericField("Factorization target precision (stop if achieved)", this.fact_precision, 4); //0..2 gd.addNumericField("Factorization target precision (stop if achieved)", this.fact_precision, 4);
gd.addNumericField("Do not punish pixels in the square around center", this.asym_tax_free, 0); //0..2 gd.addNumericField("Do not punish pixels in the square around center", this.asym_tax_free, 0);
gd.addNumericField("Start asym_kernel with this number of pixels (0 - single, 4n+0 (X between cells), 4*n+1 - x around center cell", this.seed_size, 0); //0..2 gd.addNumericField("Start asym_kernel with this number of pixels (0 - single, 4n+0 (X between cells), 4*n+1 - x around center cell", this.seed_size, 0); //0..2
gd.addNumericField("Initialize asym_kernel with random numbers (amplitude)", this.asym_random, 2); //0..2 gd.addNumericField("Initialize asym_kernel with random numbers (amplitude)", this.asym_random, 2);
gd.addNumericField("dbg_x", this.dbg_x, 2); //0..2 gd.addNumericField("dbg_x", this.dbg_x, 2);
gd.addNumericField("dbg_y", this.dbg_y, 2); //0..2 gd.addNumericField("dbg_y", this.dbg_y, 2);
gd.addNumericField("dbg_x1", this.dbg_x1, 2); //0..2 gd.addNumericField("dbg_x1", this.dbg_x1, 2);
gd.addNumericField("dbg_y1", this.dbg_y1, 2); //0..2 gd.addNumericField("dbg_y1", this.dbg_y1, 2);
gd.addNumericField("dbg_sigma", this.dbg_sigma, 3); //0..2 gd.addNumericField("dbg_sigma", this.dbg_sigma, 3);
gd.addStringField ("Debug mask (anything but * is false)", this.dbg_mask,100); gd.addStringField ("Debug mask (anything but * is false)", this.dbg_mask, 100);
gd.addNumericField("LMA implementation: 0 - old, 1 - new", this.dbg_mode, 0); //32 gd.addNumericField("LMA implementation: 0 - old, 1 - new", this.dbg_mode, 0);
gd.addNumericField("Convolution window: 0 - none, 1 - square, 2 - sin, 3 - sin^2", this.dbg_window_mode, 0); //32 gd.addNumericField("Convolution window: 0 - none, 1 - square, 2 - sin, 3 - sin^2", this.dbg_window_mode, 0);
gd.addCheckbox ("Center convolution window around target kernel center", this.centerWindowToTarget);
// gd.addNumericField("Debug Level:", MASTER_DEBUG_LEVEL, 0); gd.addNumericField("Color channel to extract kernel (<0 - use synthetic)", this.color_channel, 0);
gd.addNumericField("Convolution kernel decimation (original is normally 2x)", this.decimation, 0);
gd.addNumericField("Smooth convolution kernel before decimation", this.decimateSigma, 3);
gd.addNumericField("Tile X to extract (0..163)", this.tileX, 0);
gd.addNumericField("Tile Y to extract (0..122)", this.tileY, 0);
gd.showDialog(); gd.showDialog();
if (gd.wasCanceled()) return false; if (gd.wasCanceled()) return false;
this.dct_size= (int) gd.getNextNumber(); this.dct_size= (int) gd.getNextNumber();
this.asym_size= (int) gd.getNextNumber(); this.asym_size= (int) gd.getNextNumber();
...@@ -1774,6 +1801,12 @@ public class EyesisCorrectionParameters { ...@@ -1774,6 +1801,12 @@ public class EyesisCorrectionParameters {
this.dbg_mask= gd.getNextString(); this.dbg_mask= gd.getNextString();
this.dbg_mode= (int) gd.getNextNumber(); this.dbg_mode= (int) gd.getNextNumber();
this.dbg_window_mode= (int) gd.getNextNumber(); this.dbg_window_mode= (int) gd.getNextNumber();
this.centerWindowToTarget= gd.getNextBoolean();
this.color_channel= (int) gd.getNextNumber();
this.decimation= (int) gd.getNextNumber();
this.decimateSigma= gd.getNextNumber();
this.tileX= (int) gd.getNextNumber();
this.tileY= (int) gd.getNextNumber();
// MASTER_DEBUG_LEVEL= (int) gd.getNextNumber(); // MASTER_DEBUG_LEVEL= (int) gd.getNextNumber();
return true; return true;
......
This diff is collapsed.
This diff is collapsed.
...@@ -78,7 +78,7 @@ public class FactorConvKernel { ...@@ -78,7 +78,7 @@ public class FactorConvKernel {
public double currentRMS ; public double currentRMS ;
public double firstRMS; public double firstRMS;
public double nextRMS ; public double nextRMS ;
public double [] RMSes = {-1.0,-1.0};
public double currentRMSPure=-1.0; // calculated RMS for the currentVector->currentfX public double currentRMSPure=-1.0; // calculated RMS for the currentVector->currentfX
public double nextRMSPure= -1.0; // calculated RMS for the nextVector->nextfX public double nextRMSPure= -1.0; // calculated RMS for the nextVector->nextfX
public double firstRMSPure= -1.0; // RMS before current series of LMA started public double firstRMSPure= -1.0; // RMS before current series of LMA started
...@@ -98,7 +98,8 @@ public class FactorConvKernel { ...@@ -98,7 +98,8 @@ public class FactorConvKernel {
public double goal_rms_pure; public double goal_rms_pure;
public LMAData lMAData = null; public LMAData lMAData = null;
public int numLMARuns = 0; public int numLMARuns = 0;
public int target_window_mode = 2; // 0 - none, 1 - square, 2 - sin public int target_window_mode = 2; // 0 - none, 1 - square, 2 - sin, 3 - sin^2
public boolean centerWindowToTarget = true; // center convolution weights around target kernel center
public class LMAArrays { public class LMAArrays {
public double [][] jTByJ= null; // jacobian multiplied by Jacobian transposed public double [][] jTByJ= null; // jacobian multiplied by Jacobian transposed
...@@ -141,6 +142,7 @@ public class FactorConvKernel { ...@@ -141,6 +142,7 @@ public class FactorConvKernel {
public double [] saved_rmses = null; public double [] saved_rmses = null;
public double [] first_rmses = null; public double [] first_rmses = null;
public int target_window_mode = 2; // 0 - none, 1 - square, 2 - sin public int target_window_mode = 2; // 0 - none, 1 - square, 2 - sin
public boolean centerWindowToTarget = true; // center convolution weights around target kernel center
public LMAData(){ public LMAData(){
...@@ -148,8 +150,9 @@ public class FactorConvKernel { ...@@ -148,8 +150,9 @@ public class FactorConvKernel {
public LMAData( int debugLevel){ public LMAData( int debugLevel){
this.debugLevel = debugLevel; this.debugLevel = debugLevel;
} }
public void setTargetWindowMode(int mode){ public void setTargetWindowMode(int mode, boolean centerWindowToTarget){
target_window_mode = mode; this.target_window_mode = mode;
this.centerWindowToTarget = centerWindowToTarget;
} }
public void initLMAData(){ public void initLMAData(){
...@@ -390,20 +393,36 @@ public class FactorConvKernel { ...@@ -390,20 +393,36 @@ public class FactorConvKernel {
System.out.println("getWeight(), delete jacobian"); System.out.println("getWeight(), delete jacobian");
} }
if ((weights[0] == null) || (weights[0].length != target_kernel.length)){ if ((weights[0] == null) || (weights[0].length != target_kernel.length)){
if (debugLevel > 2){ int xc = 0;
System.out.println("Convolution weight is null/outdated, regenerating default (only center part)"); int yc = 0;
int conv_size = asym_size + 2*sym_radius-2;
int cc = conv_size/2;
if (this.centerWindowToTarget) {
double s0=0.0,sx=0.0,sy=0.0;
for (int i = 0; i < conv_size; i++){
for (int j = 0; j < conv_size; j++){
double d = target_kernel[conv_size*i+j];
d *= d;
s0 += d;
sx += d* (j - cc);
sy += d* (i - cc);
}
}
xc = (int) Math.round(sx/s0);
yc = (int) Math.round(sy/s0);
} }
double [] sins = new double [2*sym_radius-1]; double [] sins = new double [2*sym_radius-1];
for (int i = 1; i< 2*sym_radius; i++) sins[i-1] = Math.sin(Math.PI*i/(2.0 * sym_radius)); for (int i = 1; i< 2*sym_radius; i++) sins[i-1] = Math.sin(Math.PI*i/(2.0 * sym_radius));
weights[0] = new double [target_kernel.length]; weights[0] = new double [target_kernel.length];
int conv_size = asym_size + 2*sym_radius-2; int left_margin = ((asym_size-1)/2) +xc; // inclusive
int left_top_margin = ((asym_size-1)/2); // inclusive int top_margin = ((asym_size-1)/2) + yc; // inclusive
int right_bottom_margin = left_top_margin + (2 * sym_radius - 1); // exclusive int right_margin = left_margin + (2 * sym_radius - 1); // exclusive
int bottom_margin = top_margin + (2 * sym_radius - 1); // exclusive
for (int i = 0; i < conv_size; i++) { for (int i = 0; i < conv_size; i++) {
for (int j = 0; j < conv_size; j++){ for (int j = 0; j < conv_size; j++){
int cindx = i * conv_size + j; int cindx = i * conv_size + j;
if ((i >= left_top_margin) && (i < right_bottom_margin) && (j >= left_top_margin) && (j < right_bottom_margin)) { if ((i >= top_margin) && (i < bottom_margin) && (j >= left_margin) && (j < right_margin)) {
weights[0][cindx] = (target_window_mode>=2)?(sins[i-left_top_margin]*sins[j-left_top_margin]):1.0; weights[0][cindx] = (target_window_mode>=2)?(sins[i-top_margin]*sins[j-left_margin]):1.0;
if (target_window_mode == 3) { if (target_window_mode == 3) {
weights[0][cindx]*=weights[0][cindx]; weights[0][cindx]*=weights[0][cindx];
} }
...@@ -413,6 +432,8 @@ public class FactorConvKernel { ...@@ -413,6 +432,8 @@ public class FactorConvKernel {
} }
} }
} }
// public boolean centerWindowToTarget = true; // center convolution weights around target kernel center
//target_window_mode //target_window_mode
rebuildMapsPars(false); // only if it does not exist rebuildMapsPars(false); // only if it does not exist
double sw = 0.0; double sw = 0.0;
...@@ -749,6 +770,7 @@ public class FactorConvKernel { ...@@ -749,6 +770,7 @@ public class FactorConvKernel {
} // class LMAData } // class LMAData
public FactorConvKernel(){ public FactorConvKernel(){
this.new_mode =true;
} }
public FactorConvKernel(boolean new_mode){ public FactorConvKernel(boolean new_mode){
...@@ -760,8 +782,17 @@ public class FactorConvKernel { ...@@ -760,8 +782,17 @@ public class FactorConvKernel {
this.sym_radius = sym_radius; this.sym_radius = sym_radius;
} }
public void setTargetWindowMode(int mode){ public void setTargetWindowMode(int mode, boolean centerWindowToTarget){
target_window_mode = mode; target_window_mode = mode;
this.centerWindowToTarget = centerWindowToTarget;
}
public double[] getRMSes(){
return this.RMSes; // lMAData.getRMSes();
}
public double getTargetRMS(){
return lMAData.getTargetRMSW();
} }
public double [] generateAsymWeights( public double [] generateAsymWeights(
...@@ -844,7 +875,9 @@ public class FactorConvKernel { ...@@ -844,7 +875,9 @@ public class FactorConvKernel {
lMAData.setSymKernel(null, sym_mask_frozen); lMAData.setSymKernel(null, sym_mask_frozen);
levenbergMarquardt(); levenbergMarquardt();
lMAData.setSymKernel(null, sym_mask); lMAData.setSymKernel(null, sym_mask);
return levenbergMarquardt(); boolean OK = levenbergMarquardt();
this.RMSes = lMAData.getRMSes().clone();
return OK;
} else{ } else{
initLevenbergMarquardt_old(fact_precision, seed_size, asym_random); initLevenbergMarquardt_old(fact_precision, seed_size, asym_random);
if (mask != null){ if (mask != null){
...@@ -1116,6 +1149,7 @@ public class FactorConvKernel { ...@@ -1116,6 +1149,7 @@ public class FactorConvKernel {
System.out.println(); System.out.println();
} }
} }
this.RMSes = RMSes.clone();
return numAsym; return numAsym;
} }
...@@ -2148,16 +2182,7 @@ public class FactorConvKernel { ...@@ -2148,16 +2182,7 @@ public class FactorConvKernel {
private void initLevenbergMarquardt(double fact_precision, int seed_size, double asym_random){ private void initLevenbergMarquardt(double fact_precision, int seed_size, double asym_random){
lMAData = new LMAData(debugLevel); lMAData = new LMAData(debugLevel);
lMAData.setTarget(target_kernel); lMAData.setTarget(target_kernel);
lMAData.setTargetWindowMode(target_window_mode); lMAData.setTargetWindowMode(target_window_mode, centerWindowToTarget);
/* double s = 0.0;
for (int i = 0; i<target_kernel.length; i++){
s+= target_kernel[i]*target_kernel[i];
}
this.goal_rms_pure = Math.sqrt(s/target_kernel.length)*fact_precision;
*/
// this.currentVector = setInitialVector(target_kernel, null); // should be (asym_size + 2*sym_radius-1)**2
double [][]kernels = setInitialVector(target_kernel, seed_size, asym_random); // should be (asym_size + 2*sym_radius-1)**2 double [][]kernels = setInitialVector(target_kernel, seed_size, asym_random); // should be (asym_size + 2*sym_radius-1)**2
sym_kernel_scale = kernels[0][0]; sym_kernel_scale = kernels[0][0];
for (int i=0;i<kernels[0].length;i++) if (!Double.isNaN(kernels[0][i])) kernels[0][i] /=sym_kernel_scale; for (int i=0;i<kernels[0].length;i++) if (!Double.isNaN(kernels[0][i])) kernels[0][i] /=sym_kernel_scale;
...@@ -2166,13 +2191,9 @@ public class FactorConvKernel { ...@@ -2166,13 +2191,9 @@ public class FactorConvKernel {
lMAData.setAsymKernel(kernels[1]); lMAData.setAsymKernel(kernels[1]);
this.goal_rms_pure = lMAData.getTargetRMSW()*fact_precision; this.goal_rms_pure = lMAData.getTargetRMSW()*fact_precision;
this.target_rms = lMAData.getTargetRMSW(); //Math.sqrt(s/target_kernel.length); this.target_rms = lMAData.getTargetRMSW(); //Math.sqrt(s/target_kernel.length);
// lMAData.invalidateLMAArrays(); // should be in each run , not at init
resetLMARuns(); resetLMARuns();
// this.currentVector = setVectorFromKernels(kernels[0], kernels[1]);
} }
private boolean levenbergMarquardt(){ private boolean levenbergMarquardt(){
long startTime=System.nanoTime(); long startTime=System.nanoTime();
this.iterationStepNumber = 0; this.iterationStepNumber = 0;
......
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