Commit 40a59975 authored by Andrey Filippov's avatar Andrey Filippov

fixed for not color-corrected images - color balance should be before color conversion

parent a2ab98bb
...@@ -1795,13 +1795,19 @@ public class EyesisCorrectionParameters { ...@@ -1795,13 +1795,19 @@ public class EyesisCorrectionParameters {
public double decimateSigma = -1.0; // special mode for 2:1 deciamtion public double decimateSigma = -1.0; // special mode for 2:1 deciamtion
public int tileX = 82; // number of kernel tile (0..163) public int tileX = 82; // number of kernel tile (0..163)
public int tileY = 62; // number of kernel tile (0..122) public int tileY = 62; // number of kernel tile (0..122)
public boolean subtract_dc = false;//subtract/restore dc public boolean subtract_dc = false;// subtract/restore dc
public int kernel_chn = -1; // camera channel calibration to use for aberration correction ( < 0 - no correction) public int kernel_chn = -1; // camera channel calibration to use for aberration correction ( < 0 - no correction)
public boolean normalize = true; //normalize both sym and asym kernels (asym to have sum==1, sym to have sum = dct_size public boolean normalize = true; // normalize both sym and asym kernels (asym to have sum==1, sym to have sum = dct_size
public boolean normalize_sym = true; //normalize sym kernels separately public boolean normalize_sym = true; // normalize sym kernels separately
public boolean antiwindow = false; // divide symmetrical kernel by a window function
public boolean skip_sym = false; // do not apply symmetrical correction public boolean skip_sym = false; // do not apply symmetrical correction
public boolean convolve_direct = false; // do not apply symmetrical correction public boolean convolve_direct = false; // do not apply symmetrical correction
// colors should be balanced before DCT color conversion!
public double novignetting_r = 0.2644; // reg gain in the center of sensor calibration R (instead of vignetting)
public double novignetting_g = 0.3733; // green gain in the center of sensor calibration G
public double novignetting_b = 0.2034; // blue gain in the center of sensor calibration B
public double vignetting_max = 0.4; // value in vignetting data to correspond to 1x in the kernel public double vignetting_max = 0.4; // value in vignetting data to correspond to 1x in the kernel
public double vignetting_range = 5.0; // do not try to correct vignetting less than vignetting_max/vignetting_range public double vignetting_range = 5.0; // do not try to correct vignetting less than vignetting_max/vignetting_range
...@@ -1875,8 +1881,14 @@ public class EyesisCorrectionParameters { ...@@ -1875,8 +1881,14 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"kernel_chn", this.kernel_chn+""); properties.setProperty(prefix+"kernel_chn", this.kernel_chn+"");
properties.setProperty(prefix+"normalize", this.normalize+""); properties.setProperty(prefix+"normalize", this.normalize+"");
properties.setProperty(prefix+"normalize_sym", this.normalize_sym+""); properties.setProperty(prefix+"normalize_sym", this.normalize_sym+"");
properties.setProperty(prefix+"antiwindow", this.antiwindow+"");
properties.setProperty(prefix+"skip_sym", this.skip_sym+""); properties.setProperty(prefix+"skip_sym", this.skip_sym+"");
properties.setProperty(prefix+"convolve_direct", this.convolve_direct+""); properties.setProperty(prefix+"convolve_direct", this.convolve_direct+"");
properties.setProperty(prefix+"novignetting_r", this.novignetting_r+"");
properties.setProperty(prefix+"novignetting_g", this.novignetting_g+"");
properties.setProperty(prefix+"novignetting_b", this.novignetting_b+"");
properties.setProperty(prefix+"vignetting_max", this.vignetting_max+""); properties.setProperty(prefix+"vignetting_max", this.vignetting_max+"");
properties.setProperty(prefix+"vignetting_range", this.vignetting_range+""); properties.setProperty(prefix+"vignetting_range", this.vignetting_range+"");
properties.setProperty(prefix+"color_DCT", this.color_DCT+""); properties.setProperty(prefix+"color_DCT", this.color_DCT+"");
...@@ -1933,8 +1945,14 @@ public class EyesisCorrectionParameters { ...@@ -1933,8 +1945,14 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"kernel_chn")!=null) this.kernel_chn=Integer.parseInt(properties.getProperty(prefix+"kernel_chn")); if (properties.getProperty(prefix+"kernel_chn")!=null) this.kernel_chn=Integer.parseInt(properties.getProperty(prefix+"kernel_chn"));
if (properties.getProperty(prefix+"normalize")!=null) this.normalize=Boolean.parseBoolean(properties.getProperty(prefix+"normalize")); if (properties.getProperty(prefix+"normalize")!=null) this.normalize=Boolean.parseBoolean(properties.getProperty(prefix+"normalize"));
if (properties.getProperty(prefix+"normalize_sym")!=null) this.normalize_sym=Boolean.parseBoolean(properties.getProperty(prefix+"normalize_sym")); if (properties.getProperty(prefix+"normalize_sym")!=null) this.normalize_sym=Boolean.parseBoolean(properties.getProperty(prefix+"normalize_sym"));
if (properties.getProperty(prefix+"antiwindow")!=null) this.antiwindow=Boolean.parseBoolean(properties.getProperty(prefix+"antiwindow"));
if (properties.getProperty(prefix+"skip_sym")!=null) this.skip_sym=Boolean.parseBoolean(properties.getProperty(prefix+"skip_sym")); if (properties.getProperty(prefix+"skip_sym")!=null) this.skip_sym=Boolean.parseBoolean(properties.getProperty(prefix+"skip_sym"));
if (properties.getProperty(prefix+"convolve_direct")!=null) this.convolve_direct=Boolean.parseBoolean(properties.getProperty(prefix+"convolve_direct")); if (properties.getProperty(prefix+"convolve_direct")!=null) this.convolve_direct=Boolean.parseBoolean(properties.getProperty(prefix+"convolve_direct"));
if (properties.getProperty(prefix+"novignetting_r")!=null) this.novignetting_r=Double.parseDouble(properties.getProperty(prefix+"novignetting_r"));
if (properties.getProperty(prefix+"novignetting_g")!=null) this.novignetting_g=Double.parseDouble(properties.getProperty(prefix+"novignetting_g"));
if (properties.getProperty(prefix+"novignetting_b")!=null) this.novignetting_b=Double.parseDouble(properties.getProperty(prefix+"novignetting_b"));
if (properties.getProperty(prefix+"vignetting_max")!=null) this.vignetting_max=Double.parseDouble(properties.getProperty(prefix+"vignetting_max")); if (properties.getProperty(prefix+"vignetting_max")!=null) this.vignetting_max=Double.parseDouble(properties.getProperty(prefix+"vignetting_max"));
if (properties.getProperty(prefix+"vignetting_range")!=null) this.vignetting_range=Double.parseDouble(properties.getProperty(prefix+"vignetting_range")); if (properties.getProperty(prefix+"vignetting_range")!=null) this.vignetting_range=Double.parseDouble(properties.getProperty(prefix+"vignetting_range"));
if (properties.getProperty(prefix+"color_DCT")!=null) this.color_DCT=Boolean.parseBoolean(properties.getProperty(prefix+"color_DCT")); if (properties.getProperty(prefix+"color_DCT")!=null) this.color_DCT=Boolean.parseBoolean(properties.getProperty(prefix+"color_DCT"));
...@@ -1990,8 +2008,14 @@ public class EyesisCorrectionParameters { ...@@ -1990,8 +2008,14 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Calibration channel to use for aberration ( <0 - no correction)",this.kernel_chn, 0); gd.addNumericField("Calibration channel to use for aberration ( <0 - no correction)",this.kernel_chn, 0);
gd.addCheckbox ("Normalize both sym and asym kernels ", this.normalize); gd.addCheckbox ("Normalize both sym and asym kernels ", this.normalize);
gd.addCheckbox ("Normalize sym kernels separately", this.normalize_sym); gd.addCheckbox ("Normalize sym kernels separately", this.normalize_sym);
gd.addCheckbox ("Divide symmetrical kernel by a window function", this.antiwindow);
gd.addCheckbox ("Do not apply symmetrical (DCT) correction ", this.skip_sym); gd.addCheckbox ("Do not apply symmetrical (DCT) correction ", this.skip_sym);
gd.addCheckbox ("Convolve directly with symmetrical kernel (debug feature) ", this.convolve_direct); gd.addCheckbox ("Convolve directly with symmetrical kernel (debug feature) ", this.convolve_direct);
gd.addNumericField("Reg gain in the center of sensor calibration R (instead of vignetting)",this.novignetting_r, 4);
gd.addNumericField("Green gain in the center of sensor calibration G (instead of vignetting)",this.novignetting_g, 4);
gd.addNumericField("Blue gain in the center of sensor calibration B (instead of vignetting)",this.novignetting_b, 4);
gd.addNumericField("Value (max) in vignetting data to correspond to 1x in the kernel",this.vignetting_max, 3); gd.addNumericField("Value (max) in vignetting data to correspond to 1x in the kernel",this.vignetting_max, 3);
gd.addNumericField("Do not try to correct vignetting smaller than this fraction of max",this.vignetting_range, 3); gd.addNumericField("Do not try to correct vignetting smaller than this fraction of max",this.vignetting_range, 3);
gd.addCheckbox ("Use DCT-base color conversion", this.color_DCT ); gd.addCheckbox ("Use DCT-base color conversion", this.color_DCT );
...@@ -2047,8 +2071,12 @@ public class EyesisCorrectionParameters { ...@@ -2047,8 +2071,12 @@ public class EyesisCorrectionParameters {
this.kernel_chn= (int) gd.getNextNumber(); this.kernel_chn= (int) gd.getNextNumber();
this.normalize= gd.getNextBoolean(); this.normalize= gd.getNextBoolean();
this.normalize_sym= gd.getNextBoolean(); this.normalize_sym= gd.getNextBoolean();
this.antiwindow= gd.getNextBoolean();
this.skip_sym= gd.getNextBoolean(); this.skip_sym= gd.getNextBoolean();
this.convolve_direct= gd.getNextBoolean(); this.convolve_direct= gd.getNextBoolean();
this.novignetting_r= gd.getNextNumber();
this.novignetting_g= gd.getNextNumber();
this.novignetting_b= gd.getNextNumber();
this.vignetting_max= gd.getNextNumber(); this.vignetting_max= gd.getNextNumber();
this.vignetting_range= gd.getNextNumber(); this.vignetting_range= gd.getNextNumber();
this.color_DCT= gd.getNextBoolean(); this.color_DCT= gd.getNextBoolean();
......
...@@ -706,6 +706,13 @@ public class EyesisDCT { ...@@ -706,6 +706,13 @@ public class EyesisDCT {
norm_sym_weights[i*dct_size+j] = d; norm_sym_weights[i*dct_size+j] = d;
} }
} }
double [] inv_window = new double [dct_size*dct_size];
for (int i = 0; i < dct_size; i++){
for (int j = 0; j < dct_size; j++){
double d = 1.0 / (Math.cos(Math.PI*i/(2*dct_size))*Math.cos(Math.PI*j/(2*dct_size)));
inv_window[i*dct_size+j] = d;
}
}
if (debugLevel>0) { if (debugLevel>0) {
System.out.println("readDCTKernels() debugLevel = "+debugLevel+ System.out.println("readDCTKernels() debugLevel = "+debugLevel+
...@@ -778,6 +785,15 @@ public class EyesisDCT { ...@@ -778,6 +785,15 @@ public class EyesisDCT {
i * dct_size, i * dct_size,
dct_size); dct_size);
} }
// sym_kernel pre-compensation for window function
if (dct_parameters.antiwindow) {
for (int i=0; i < kernels[chn].st_kernels[nc][tileY][tileX].length;i++) {
kernels[chn].st_kernels[nc][tileY][tileX][i] *= inv_window[i];
}
}
if (scale_asym != 1.0){ if (scale_asym != 1.0){
for (int i=0; i < kernels[chn].st_kernels[nc][tileY][tileX].length;i++) { for (int i=0; i < kernels[chn].st_kernels[nc][tileY][tileX].length;i++) {
kernels[chn].st_kernels[nc][tileY][tileX][i] *= scale_asym; kernels[chn].st_kernels[nc][tileY][tileX][i] *= scale_asym;
...@@ -1123,7 +1139,23 @@ public class EyesisDCT { ...@@ -1123,7 +1139,23 @@ public class EyesisDCT {
if (d > max_vign_corr) d = max_vign_corr; if (d > max_vign_corr) d = max_vign_corr;
pixels[i]*=d; pixels[i]*=d;
} }
} else { // assuming GR/BG pattern
System.out.println("Applying fixed color gain correction parameters: Gr="+
dct_parameters.novignetting_r+", Gg="+dct_parameters.novignetting_g+", Gb="+dct_parameters.novignetting_b);
float [] pixels=(float []) imp_src.getProcessor().getPixels();
int width = imp_src.getWidth();
int height = imp_src.getHeight();
double kr = 1.0/dct_parameters.novignetting_r;
double kg = 1.0/dct_parameters.novignetting_g;
double kb = 1.0/dct_parameters.novignetting_b;
for (int y = 0; y < height-1; y+=2){
for (int x = 0; x < width-1; x+=2){
pixels[y*width+x ] *= kg;
pixels[y*width+x+width+1] *= kg;
pixels[y*width+x +1] *= kr;
pixels[y*width+x+width ] *= kb;
}
}
} }
String title=name+"-"+String.format("%02d", channel); String title=name+"-"+String.format("%02d", channel);
ImagePlus result=imp_src; ImagePlus result=imp_src;
...@@ -1183,6 +1215,9 @@ public class EyesisDCT { ...@@ -1183,6 +1215,9 @@ public class EyesisDCT {
threadsMax, threadsMax,
debugLevel); debugLevel);
} }
//TODO: Scale up 2x to match color processed (or scale up lpf?)
} }
int tilesY = stack.getHeight()/dct_parameters.dct_size - 1; int tilesY = stack.getHeight()/dct_parameters.dct_size - 1;
......
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