Commit 7d130db1 authored by Andrey Filippov's avatar Andrey Filippov

more trying

parent 71215e97
......@@ -1653,29 +1653,46 @@ public class EyesisCorrectionParameters {
public int dct_window = 1; // currently only 3 types of windows - 0 (none), 1 and 2
public int LMA_steps = 100;
public double compactness = 1.0;
public int dbg_x =0;
public int dbg_y =0;
public int dbg_x1 =0;
public int dbg_y1 =0;
public int asym_tax_free = 1; // "compactness" does not apply to pixels with |x|<=asym_tax_free and |y| <= asym_tax_free
public double dbg_x =0;
public double dbg_y =0;
public double dbg_x1 =0;
public double dbg_y1 =0;
public double dbg_sigma =2.0;
public DCTParameters(int dct_size, int asym_size, int dct_window, double compactness) {
public DCTParameters(int dct_size, int asym_size, int dct_window, double compactness, int asym_tax_free) {
this.dct_size = dct_size;
this.asym_size = asym_size;
this.dct_window = dct_window;
this.compactness = compactness;
this.asym_tax_free = asym_tax_free;
}
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"dct_size",this.dct_size+"");
properties.setProperty(prefix+"asym_size",this.asym_size+"");
properties.setProperty(prefix+"dct_window", this.dct_window+"");
properties.setProperty(prefix+"compactness", this.compactness+"");
properties.setProperty(prefix+"asym_tax_free", this.asym_tax_free+"");
properties.setProperty(prefix+"dbg_x", this.dbg_x+"");
properties.setProperty(prefix+"dbg_y", this.dbg_y+"");
properties.setProperty(prefix+"dbg_x1", this.dbg_x1+"");
properties.setProperty(prefix+"dbg_y1", this.dbg_y1+"");
properties.setProperty(prefix+"dbg_sigma", this.dbg_sigma+"");
}
public void getProperties(String prefix,Properties properties){
this.dct_size=Integer.parseInt(properties.getProperty(prefix+"dct_size"));
this.asym_size=Integer.parseInt(properties.getProperty(prefix+"asym_size"));
this.dct_window=Integer.parseInt(properties.getProperty(prefix+"dct_window"));
this.compactness=Integer.parseInt(properties.getProperty(prefix+"compactness"));
if (properties.getProperty(prefix+"dct_size")!=null) this.dct_size=Integer.parseInt(properties.getProperty(prefix+"dct_size"));
if (properties.getProperty(prefix+"asym_size")!=null) this.asym_size=Integer.parseInt(properties.getProperty(prefix+"asym_size"));
if (properties.getProperty(prefix+"dct_window")!=null) this.dct_window=Integer.parseInt(properties.getProperty(prefix+"dct_window"));
if (properties.getProperty(prefix+"compactness")!=null) this.compactness=Double.parseDouble(properties.getProperty(prefix+"compactness"));
if (properties.getProperty(prefix+"asym_tax_free")!=null) this.asym_tax_free=Integer.parseInt(properties.getProperty(prefix+"asym_tax_free"));
if (properties.getProperty(prefix+"dbg_x")!=null) this.dbg_x=Double.parseDouble(properties.getProperty(prefix+"dbg_x"));
if (properties.getProperty(prefix+"dbg_y")!=null) this.dbg_y=Double.parseDouble(properties.getProperty(prefix+"dbg_y"));
if (properties.getProperty(prefix+"dbg_x1")!=null) this.dbg_x1=Double.parseDouble(properties.getProperty(prefix+"dbg_x1"));
if (properties.getProperty(prefix+"dbg_y1")!=null) this.dbg_y1=Double.parseDouble(properties.getProperty(prefix+"dbg_y1"));
if (properties.getProperty(prefix+"dbg_sigma")!=null) this.dbg_sigma=Double.parseDouble(properties.getProperty(prefix+"dbg_sigma"));
}
public boolean showDialog() {
GenericDialog gd = new GenericDialog("Set DCT parameters");
......@@ -1683,12 +1700,13 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Size of asymmetrical (non-DCT) kernel", this.asym_size, 0); //6
gd.addNumericField("MDCT window type (0,1,2)", this.dct_window, 0); //0..2
gd.addNumericField("LMA_steps", this.LMA_steps, 0); //0..2
gd.addNumericField("compactness", this.compactness, 6); //0..2
gd.addNumericField("Compactness (punish off-center asym_kernel pixels (proportional to r^2)", this.compactness, 2); //0..2
gd.addNumericField("Do not punish pixels in the square around center", this.asym_tax_free, 0); //0..2
gd.addNumericField("dbg_x", this.dbg_x, 0); //0..2
gd.addNumericField("dbg_y", this.dbg_y, 0); //0..2
gd.addNumericField("dbg_x1", this.dbg_x1, 0); //0..2
gd.addNumericField("dbg_y1", this.dbg_y1, 0); //0..2
gd.addNumericField("dbg_x", this.dbg_x, 2); //0..2
gd.addNumericField("dbg_y", this.dbg_y, 2); //0..2
gd.addNumericField("dbg_x1", this.dbg_x1, 2); //0..2
gd.addNumericField("dbg_y1", this.dbg_y1, 2); //0..2
gd.addNumericField("dbg_sigma", this.dbg_sigma, 3); //0..2
// gd.addNumericField("Debug Level:", MASTER_DEBUG_LEVEL, 0);
gd.showDialog();
......@@ -1698,10 +1716,11 @@ public class EyesisCorrectionParameters {
this.dct_window= (int) gd.getNextNumber();
this.LMA_steps = (int) gd.getNextNumber();
this.compactness = gd.getNextNumber();
this.dbg_x= (int) gd.getNextNumber();
this.dbg_y= (int) gd.getNextNumber();
this.dbg_x1= (int) gd.getNextNumber();
this.dbg_y1= (int) gd.getNextNumber();
this.asym_tax_free = (int) gd.getNextNumber();
this.dbg_x= gd.getNextNumber();
this.dbg_y= gd.getNextNumber();
this.dbg_x1= gd.getNextNumber();
this.dbg_y1= gd.getNextNumber();
this.dbg_sigma= gd.getNextNumber();
// MASTER_DEBUG_LEVEL= (int) gd.getNextNumber();
return true;
......
......@@ -88,7 +88,8 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
32, // dct_size
6, // asym_size
1, // dct_window
1.0 // double compactness
1.0, // double compactness
1 // asym_tax_free);
);
public static EyesisDCT EYESIS_DCT = null;
......@@ -2834,19 +2835,25 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
FactorConvKernel factorConvKernel = new FactorConvKernel();
factorConvKernel.setDebugLevel(DEBUG_LEVEL);
factorConvKernel.numIterations = DCT_PARAMETERS.LMA_steps;
factorConvKernel.setCompactnessWeight(DCT_PARAMETERS.compactness);
//// int target_kernel_size = 2*DCT_PARAMETERS.dct_size + DCT_PARAMETERS.asym_size -1;
int target_kernel_size = 2*DCT_PARAMETERS.dct_size + DCT_PARAMETERS.asym_size -2;
factorConvKernel.setAsymCompactness(
DCT_PARAMETERS.compactness,
DCT_PARAMETERS.asym_tax_free);
int target_kernel_size = 2*DCT_PARAMETERS.dct_size - 1;
double [] target_kernel = new double [target_kernel_size * target_kernel_size];
for (int ii=0; ii < target_kernel.length; ii++) target_kernel[ii]=0.0;
// for (int ii = -2; ii<=2; ii++) {
double dist = Math.sqrt((DCT_PARAMETERS.dbg_x1-DCT_PARAMETERS.dbg_x)*(DCT_PARAMETERS.dbg_x1-DCT_PARAMETERS.dbg_x)+
(DCT_PARAMETERS.dbg_y1-DCT_PARAMETERS.dbg_y)*(DCT_PARAMETERS.dbg_y1-DCT_PARAMETERS.dbg_y));
int num_steps = (int) Math.round(dist+0.5);
dist = num_steps;
for (int ii = 0; ii<= num_steps; ii++) {
int dbg_x = (int) Math.round((DCT_PARAMETERS.dbg_x1-DCT_PARAMETERS.dbg_x)*ii/dist + DCT_PARAMETERS.dbg_x);
int dbg_y = (int) Math.round((DCT_PARAMETERS.dbg_y1-DCT_PARAMETERS.dbg_y)*ii/dist + DCT_PARAMETERS.dbg_y);
target_kernel[(target_kernel_size/2 + dbg_y)*target_kernel_size+(target_kernel_size/2 + dbg_x)] = 1.0;
if (MASTER_DEBUG_LEVEL >2) {
System.out.println(ii+": "+((DCT_PARAMETERS.dbg_x1-DCT_PARAMETERS.dbg_x)*ii/dist + DCT_PARAMETERS.dbg_x)+
" / "+ ((DCT_PARAMETERS.dbg_y1-DCT_PARAMETERS.dbg_y)*ii/dist + DCT_PARAMETERS.dbg_y)+" ("+dbg_x+":"+dbg_y+")");
}
}
......@@ -2856,22 +2863,33 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
if (blurSigma>0) gb.blurDouble(target_kernel, target_kernel_size, target_kernel_size, blurSigma, blurSigma, 0.01);
// SDFA_INSTANCE.showArrays(target_kernel, target_kernel_size, target_kernel_size, "target_kernel");
int target_expanded_size = 2*DCT_PARAMETERS.dct_size + DCT_PARAMETERS.asym_size -2;
double [] target_expanded = new double [target_expanded_size * target_expanded_size];
for (int ii=0; ii < target_expanded.length; ii++) target_expanded[ii]=0.0;
int left_top_margin = ((DCT_PARAMETERS.asym_size-1)/2);
for (int ii=0;ii < target_kernel_size; ii++){
for (int jj=0; jj < target_kernel_size; jj++){
target_expanded[(ii+left_top_margin)*target_expanded_size + (jj+left_top_margin)] =
target_kernel[ii*target_kernel_size + jj];
}
}
boolean result = factorConvKernel.calcKernels(
target_kernel,
target_expanded,
DCT_PARAMETERS.asym_size,
DCT_PARAMETERS.dct_size);
System.out.println("factorConvKernel.calcKernels() returned"+result);
double [] sym_kernel = factorConvKernel.getSymKernel();
double [] asym_kernel = factorConvKernel.getAsymKernel();
double [] convolved = factorConvKernel.getConvolved();
double [][] compare_kernels = {target_kernel, convolved};
double [][] compare_kernels = {target_expanded, convolved};
System.out.println("DCT_PARAMETERS.dct_size="+DCT_PARAMETERS.dct_size+" DCT_PARAMETERS.asym_size="+DCT_PARAMETERS.asym_size);
System.out.println("sym_kernel.length="+ sym_kernel.length);
System.out.println("asym_kernel.length="+asym_kernel.length);
System.out.println("convolved.length="+convolved.length);
SDFA_INSTANCE.showArrays(sym_kernel, DCT_PARAMETERS.dct_size, DCT_PARAMETERS.dct_size, "sym_kernel");
SDFA_INSTANCE.showArrays(asym_kernel, DCT_PARAMETERS.asym_size, DCT_PARAMETERS.asym_size, "asym_kernel");
SDFA_INSTANCE.showArrays(compare_kernels, target_kernel_size, target_kernel_size, true, "compare_kernels");
SDFA_INSTANCE.showArrays(compare_kernels, target_expanded_size, target_expanded_size, true, "compare_kernels");
// SDFA_INSTANCE.showArrays(convolved, target_kernel_size, target_kernel_size, "convolved");
return;
......@@ -3557,6 +3575,7 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
properties.setProperty("MASTER_DEBUG_LEVEL",MASTER_DEBUG_LEVEL+"");
properties.setProperty("UPDATE_STATUS", UPDATE_STATUS+ "");
SPLIT_PARAMETERS.setProperties("SPLIT_PARAMETERS.", properties);
DCT_PARAMETERS.setProperties("DCT_PARAMETERS.", properties);
DEBAYER_PARAMETERS.setProperties("DEBAYER_PARAMETERS.", properties);
NONLIN_PARAMETERS.setProperties("NONLIN_PARAMETERS.", properties);
COLOR_PROC_PARAMETERS.setProperties("COLOR_PROC_PARAMETERS.", properties);
......@@ -3578,6 +3597,7 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
MASTER_DEBUG_LEVEL = Integer.parseInt(properties.getProperty("MASTER_DEBUG_LEVEL"));
UPDATE_STATUS= Boolean.parseBoolean(properties.getProperty("UPDATE_STATUS"));
SPLIT_PARAMETERS.getProperties("SPLIT_PARAMETERS.", properties);
DCT_PARAMETERS.getProperties("DCT_PARAMETERS.", properties);
DEBAYER_PARAMETERS.getProperties("DEBAYER_PARAMETERS.", properties);
NONLIN_PARAMETERS.getProperties("NONLIN_PARAMETERS.", properties);
COLOR_PROC_PARAMETERS.getProperties("COLOR_PROC_PARAMETERS.", properties);
......
......@@ -37,6 +37,9 @@ public class FactorConvKernel {
public double init_lambda = 0.001;
public double compactness_weight = 1.0; // realtive "importance of asymmetrical kernel being compact"
public int asym_tax_free = 1; // do not apply compactness_weight for pixels close to the center
public double lambdaStepUp= 8.0; // multiply lambda by this if result is worse
public double lambdaStepDown= 0.5; // multiply lambda by this if result is better
public double thresholdFinish=0.001; // (copied from series) stop iterations if 2 last steps had less improvement (but not worsening )
......@@ -113,13 +116,17 @@ public class FactorConvKernel {
public double [] getConvolved(){ // check that it matches original
return this.currentfX;
}
public void setDebugLevel(int debugLevel){
this.debugLevel =debugLevel;
}
public void setCompactnessWeight(double compactness_weight){
this.compactness_weight =compactness_weight;
}
public void setAsymCompactness(
double compactness_weight,
int asym_tax_free){
this.compactness_weight = compactness_weight;
this.asym_tax_free = asym_tax_free;
}
private double [] getSymKernel(
double [] kvect,
......@@ -150,11 +157,12 @@ public class FactorConvKernel {
private double [] setInitialVector(
double [] target_kernel) // should be (asym_size + 2*sym_radius-1)**2
{
// int conv_size = asym_size + 2*sym_radius-1;
int conv_size = asym_size + 2*sym_radius-2;
int sym_rad_m1 = sym_radius - 1; // 7
// find center of the target kernel squared value
double s0=0.0,sx=0.0,sy=0.0;
double scx=0.0,scy=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];
......@@ -162,6 +170,8 @@ public class FactorConvKernel {
s0 += d;
sx += d*j;
sy += d*i;
scx += d*(j-sym_rad_m1-asym_size/2);
scy += d*(i-sym_rad_m1-asym_size/2);
}
}
// int async_center = asym_size / 2; // will be 2 for 5x5 and 3 for 6x6 - more room in negative
......@@ -170,9 +180,12 @@ public class FactorConvKernel {
int j0= (int) Math.round(sx/s0 - sym_rad_m1); // should be ~ async_center
int i0= (int) Math.round(sy/s0 - sym_rad_m1); // should be ~ async_center
if (debugLevel>1){
System.out.println("setInitialVector(): conv_size = "+conv_size+" fj0 = "+(sx/s0 - sym_radius));
System.out.println("setInitialVector(): fi0 = "+(sy/s0 - sym_radius)+" asym_size = "+asym_size+" sym_radius = "+sym_radius);
System.out.println("setInitialVector(): i0 = "+i0+" j0 = "+j0 + " asym_size="+asym_size);
System.out.println("setInitialVector(): scx="+(scx/s0) + " scy="+(scy/s0));
System.out.println("setInitialVector(): x="+(sx/s0) + " y="+(sy/s0));
System.out.println("setInitialVector(): conv_size = "+conv_size + " asym_size="+asym_size);
System.out.println("setInitialVector(): fj0 = "+(sx/s0 - sym_rad_m1)+" j0 = "+j0 );
System.out.println("setInitialVector(): fi0 = "+(sy/s0 - sym_rad_m1)+" i0 = "+i0 );
}
// fit i0,j0 to asym_kernel (it should be larger)
// i0 += asym_size/2;
......@@ -246,7 +259,6 @@ public class FactorConvKernel {
private double [] convKernels(
double [] kvect) // first - all elements of sym kernel but [0] (replaced by 1.0), then - asym ones
{
//// int conv_size = asym_size + 2*sym_radius-1;
int conv_size = asym_size + 2*sym_radius-2;
int asym_start= sym_radius * sym_radius - 1;
int sym_radius_m1 = sym_radius -1;
......@@ -295,11 +307,16 @@ public class FactorConvKernel {
for (int ia=0; ia <asym_size;ia++){
for (int ja=0;ja< asym_size;ja++){
int ir2 = (ia-center_i0)*(ia-center_i0)+(ja-center_j0)*(ja-center_j0);
if ((ia - center_i0 <= asym_tax_free) &&
(center_i0 - ia <= asym_tax_free) &&
(ja - center_j0 <= asym_tax_free) &&
(center_j0 - ja <= asym_tax_free)) ir2 = 0;
double d = kvect[indx++]*ir2;
rms += d * d;
}
}
return cw*Math.sqrt(rms)/(asym_size*asym_size); // square for area, another - to normalize by r^2
// return cw*Math.sqrt(rms)/(asym_size*asym_size); // square for area, another - to normalize by r^2
return cw*Math.sqrt(rms)/asym_size; // square for area, another - to normalize by r^2
}
/*
......@@ -314,13 +331,12 @@ public class FactorConvKernel {
*/
private double getCompactWeight(){
// return compactness_weight*sym_kernel_scale/(asym_size*asym_size); // use
return compactness_weight*sym_kernel_scale/(asym_size*asym_size*asym_size*asym_size); // use
return compactness_weight*sym_kernel_scale; // (asym_size*asym_size*asym_size*asym_size); // use
}
private double [][] getJacobian(
double [] kvect)
{
//// int conv_size = asym_size + 2*sym_radius-1;
int conv_size = asym_size + 2*sym_radius-2;
int asym_start= sym_radius * sym_radius - 1;
int sym_radius_m1 = sym_radius -1;
......@@ -347,6 +363,10 @@ public class FactorConvKernel {
for (int ja=0;ja< asym_size;ja++){
int async_index = asym_size*ia + ja;
int ir2 = (ia-center_i0)*(ia-center_i0)+(ja-center_j0)*(ja-center_j0);
if ((ia - center_i0 <= asym_tax_free) &&
(center_i0 - ia <= asym_tax_free) &&
(ja - center_j0 <= asym_tax_free) &&
(center_j0 - ja <= asym_tax_free)) ir2 = 0;
jacob[async_index + asym_start][async_index+asym_terms_start] = ir2 * cw;
}
}
......@@ -380,12 +400,10 @@ public class FactorConvKernel {
double [] jTByDiff = new double [jacob.length];
for (int i=0; i < jTByDiff.length; i++){
jTByDiff[i] = 0;
// for (int k=0; k< jacob[i].length; k++){
for (int k=0; k< target_kernel.length; k++){
jTByDiff[i] += jacob[i][k]*(target_kernel[k]-conv_data[k]);
}
}
//// int conv_size = asym_size + 2*sym_radius-1;
int conv_size = asym_size + 2*sym_radius-2;
int asym_start= sym_radius * sym_radius - 1;
int asym_terms_start= conv_size*conv_size;
......@@ -394,7 +412,10 @@ public class FactorConvKernel {
for (int ja=0;ja< asym_size;ja++){
int async_index = asym_size*ia + ja;
int ir2 = (ia-center_i0)*(ia-center_i0)+(ja-center_j0)*(ja-center_j0);
// jacob[async_index + asym_start][async_index+asym_terms_start] = ir2 * cw;
if ((ia - center_i0 <= asym_tax_free) &&
(center_i0 - ia <= asym_tax_free) &&
(ja - center_j0 <= asym_tax_free) &&
(center_j0 - ja <= asym_tax_free)) ir2 = 0;
jTByDiff[async_index + asym_start] += jacob[async_index + asym_start][async_index+asym_terms_start]*
ir2 * cw* kvect[asym_start + async_index];
}
......@@ -531,7 +552,10 @@ public class FactorConvKernel {
this.currentRMSPure= getRms(this.currentfX,this.target_kernel);
this.currentRMS= getCompactRms(this.currentVector) + this.currentRMSPure;
/// this.currentRMS= getCompactRms(this.currentVector) + this.currentRMSPure;
double compactRMS = getCompactRms(this.currentVector);
this.currentRMS= Math.sqrt((compactRMS * asym_size*asym_size +
(currentRMSPure)*(currentRMSPure)*target_kernel.length)/(asym_size*asym_size+target_kernel.length));
if (this.debugLevel>1) {
System.out.println("initial RMS="+IJ.d2s(this.currentRMS,8)+
......@@ -540,7 +564,11 @@ public class FactorConvKernel {
}
} else {
this.currentRMSPure= getRms(this.currentfX,this.target_kernel);
this.currentRMS= getCompactRms(this.currentVector) + this.currentRMSPure;
// this.currentRMS= getCompactRms(this.currentVector) + this.currentRMSPure;
double compactRMS = getCompactRms(this.currentVector);
this.currentRMS= Math.sqrt((compactRMS * asym_size*asym_size +
(currentRMSPure)*(currentRMSPure)*target_kernel.length)/(asym_size*asym_size+target_kernel.length));
}
// this.currentRMS= calcError(calcYminusFx(this.currentfX));
if (this.firstRMS<0) {
......@@ -597,11 +625,11 @@ public class FactorConvKernel {
this.nextRMSPure= getRms(this.nextfX,this.target_kernel);
this.nextRMS= getCompactRms(this.nextVector) + this.nextRMSPure;
// this.nextRMS= getCompactRms(this.nextVector) + this.nextRMSPure;
double nextCompactRMS = getCompactRms(this.currentVector);
this.nextRMS= Math.sqrt((nextCompactRMS * asym_size*asym_size +
(nextRMSPure)*(nextRMSPure)*target_kernel.length)/(asym_size*asym_size+target_kernel.length));
this.lastImprovements[1]=this.lastImprovements[0];
this.lastImprovements[0]=this.currentRMS-this.nextRMS;
......
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