Commit 3e7f255e authored by Andrey Filippov's avatar Andrey Filippov

aberration correction with clt

parent 2e50bfb7
...@@ -1880,13 +1880,22 @@ public class EyesisCorrectionParameters { ...@@ -1880,13 +1880,22 @@ public class EyesisCorrectionParameters {
public int ishift_x = 0; // debug feature - shift source image by this pixels left public int ishift_x = 0; // debug feature - shift source image by this pixels left
public int ishift_y = 0; // debug feature - shift source image by this pixels down public int ishift_y = 0; // debug feature - shift source image by this pixels down
public double fat_zero = 0.0; // modify phase correlation to prevent division by very small numbers public double fat_zero = 0.0; // modify phase correlation to prevent division by very small numbers
public double corr_sigma =0.8; // LPF correlarion sigma public double corr_sigma = 0.8; // LPF correlarion sigma
public boolean norm_kern = true; // normalize kernels public boolean norm_kern = true; // normalize kernels
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 scale_r = 1.0; // extra gain correction after vignetting or nonvignetting, before other processing
public double scale_g = 1.0;
public double scale_b = 1.0;
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 int kernel_step = 16; // source kernels step in pixels (have 1 kernel margin on each side)
public CLTParameters(){} public CLTParameters(){}
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"transform_size",this.transform_size+""); properties.setProperty(prefix+"transform_size", this.transform_size+"");
properties.setProperty(prefix+"clt_window", this.clt_window+""); properties.setProperty(prefix+"clt_window", this.clt_window+"");
properties.setProperty(prefix+"shift_x", this.shift_x+""); properties.setProperty(prefix+"shift_x", this.shift_x+"");
properties.setProperty(prefix+"shift_y", this.shift_y+""); properties.setProperty(prefix+"shift_y", this.shift_y+"");
...@@ -1898,6 +1907,17 @@ public class EyesisCorrectionParameters { ...@@ -1898,6 +1907,17 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"ishift_y", this.ishift_y+""); properties.setProperty(prefix+"ishift_y", this.ishift_y+"");
properties.setProperty(prefix+"fat_zero", this.fat_zero+""); properties.setProperty(prefix+"fat_zero", this.fat_zero+"");
properties.setProperty(prefix+"corr_sigma", this.corr_sigma+""); properties.setProperty(prefix+"corr_sigma", this.corr_sigma+"");
properties.setProperty(prefix+"norm_kern", this.norm_kern+"");
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+"scale_r", this.scale_r+"");
properties.setProperty(prefix+"scale_g", this.scale_g+"");
properties.setProperty(prefix+"scale_b", this.scale_b+"");
properties.setProperty(prefix+"vignetting_max", this.vignetting_max+"");
properties.setProperty(prefix+"vignetting_range", this.vignetting_range+"");
properties.setProperty(prefix+"kernel_step", this.kernel_step+"");
} }
public void getProperties(String prefix,Properties properties){ public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"transform_size")!=null) this.transform_size=Integer.parseInt(properties.getProperty(prefix+"transform_size")); if (properties.getProperty(prefix+"transform_size")!=null) this.transform_size=Integer.parseInt(properties.getProperty(prefix+"transform_size"));
...@@ -1912,10 +1932,21 @@ public class EyesisCorrectionParameters { ...@@ -1912,10 +1932,21 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"ishift_y")!=null) this.ishift_y=Integer.parseInt(properties.getProperty(prefix+"ishift_y")); if (properties.getProperty(prefix+"ishift_y")!=null) this.ishift_y=Integer.parseInt(properties.getProperty(prefix+"ishift_y"));
if (properties.getProperty(prefix+"fat_zero")!=null) this.fat_zero=Double.parseDouble(properties.getProperty(prefix+"fat_zero")); if (properties.getProperty(prefix+"fat_zero")!=null) this.fat_zero=Double.parseDouble(properties.getProperty(prefix+"fat_zero"));
if (properties.getProperty(prefix+"corr_sigma")!=null) this.corr_sigma=Double.parseDouble(properties.getProperty(prefix+"corr_sigma")); if (properties.getProperty(prefix+"corr_sigma")!=null) this.corr_sigma=Double.parseDouble(properties.getProperty(prefix+"corr_sigma"));
if (properties.getProperty(prefix+"norm_kern")!=null) this.norm_kern=Boolean.parseBoolean(properties.getProperty(prefix+"norm_kern"));
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+"scale_r")!=null) this.scale_r=Double.parseDouble(properties.getProperty(prefix+"scale_r"));
if (properties.getProperty(prefix+"scale_g")!=null) this.scale_g=Double.parseDouble(properties.getProperty(prefix+"scale_g"));
if (properties.getProperty(prefix+"scale_b")!=null) this.scale_b=Double.parseDouble(properties.getProperty(prefix+"scale_b"));
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+"kernel_step")!=null) this.kernel_step=Integer.parseInt(properties.getProperty(prefix+"kernel_step"));
} }
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.transform_size, 0); gd.addNumericField("Transform size (default 8)", this.transform_size, 0);
gd.addNumericField("Lapped transform window type (0- rectangular, 1 - sinus)", this.clt_window, 0); gd.addNumericField("Lapped transform window type (0- rectangular, 1 - sinus)", this.clt_window, 0);
gd.addNumericField("shift_x", this.shift_x, 4); gd.addNumericField("shift_x", this.shift_x, 4);
gd.addNumericField("shift_y", this.shift_y, 4); gd.addNumericField("shift_y", this.shift_y, 4);
...@@ -1927,6 +1958,17 @@ public class EyesisCorrectionParameters { ...@@ -1927,6 +1958,17 @@ public class EyesisCorrectionParameters {
gd.addNumericField("ishift_y: shift source image by this pixels down", this.ishift_y, 0); gd.addNumericField("ishift_y: shift source image by this pixels down", this.ishift_y, 0);
gd.addNumericField("Modify phase correlation to prevent division by very small numbers", this.fat_zero, 4); gd.addNumericField("Modify phase correlation to prevent division by very small numbers", this.fat_zero, 4);
gd.addNumericField("LPF correlarion sigma ", this.corr_sigma, 3); gd.addNumericField("LPF correlarion sigma ", this.corr_sigma, 3);
gd.addCheckbox ("Normalize kernels ", this.norm_kern);
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("Extra red correction to compensate for light temperature", this.scale_r, 4);
gd.addNumericField("Extra green correction to compensate for light temperature", this.scale_g, 4);
gd.addNumericField("Extra blue correction to compensate for light temperature", this.scale_b, 4);
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("Kernel step in pixels (has 1 kernel margin on each side)", this.kernel_step, 0);
WindowTools.addScrollBars(gd); WindowTools.addScrollBars(gd);
gd.showDialog(); gd.showDialog();
...@@ -1943,6 +1985,17 @@ public class EyesisCorrectionParameters { ...@@ -1943,6 +1985,17 @@ public class EyesisCorrectionParameters {
this.ishift_y= (int) gd.getNextNumber(); this.ishift_y= (int) gd.getNextNumber();
this.fat_zero = gd.getNextNumber(); this.fat_zero = gd.getNextNumber();
this.corr_sigma = gd.getNextNumber(); this.corr_sigma = gd.getNextNumber();
this.norm_kern= gd.getNextBoolean();
this.novignetting_r= gd.getNextNumber();
this.novignetting_g= gd.getNextNumber();
this.novignetting_b= gd.getNextNumber();
this.scale_r= gd.getNextNumber();
this.scale_g= gd.getNextNumber();
this.scale_b= gd.getNextNumber();
this.vignetting_max= gd.getNextNumber();
this.vignetting_range= gd.getNextNumber();
this.kernel_step= (int) gd.getNextNumber();
return true; return true;
} }
} }
...@@ -2272,17 +2325,16 @@ public class EyesisCorrectionParameters { ...@@ -2272,17 +2325,16 @@ public class EyesisCorrectionParameters {
this.antiwindow= 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_r= gd.getNextNumber();
this.novignetting_g= gd.getNextNumber(); this.novignetting_g= gd.getNextNumber();
this.novignetting_b= gd.getNextNumber(); this.novignetting_b= gd.getNextNumber();
this.scale_r= gd.getNextNumber(); this.scale_r= gd.getNextNumber();
this.scale_g= gd.getNextNumber(); this.scale_g= gd.getNextNumber();
this.scale_b= gd.getNextNumber(); this.scale_b= gd.getNextNumber();
this.vignetting_max= gd.getNextNumber(); this.vignetting_max= gd.getNextNumber();
this.vignetting_range= gd.getNextNumber(); this.vignetting_range= gd.getNextNumber();
this.post_debayer= gd.getNextBoolean(); this.post_debayer= gd.getNextBoolean();
this.color_DCT= gd.getNextBoolean(); this.color_DCT= gd.getNextBoolean();
this.sigma_rb= gd.getNextNumber(); this.sigma_rb= gd.getNextNumber();
......
...@@ -2078,6 +2078,51 @@ public class EyesisCorrections { ...@@ -2078,6 +2078,51 @@ public class EyesisCorrections {
return outStack; return outStack;
} }
// return 2-d double array instead of the stack
public double [][]bayerToDoubleStack(ImagePlus imp, // source bayer image, linearized, 32-bit (float))
EyesisCorrectionParameters.SplitParameters splitParameters){ // if null - no margins, no oversample
if (imp==null) return null;
boolean adv = splitParameters != null;
int oversample = adv? splitParameters.oversample : 1;
int addTop= adv?splitParameters.addTop: 0;
int addLeft= adv?splitParameters.addLeft: 0;
int addBottom= adv?splitParameters.addBottom: 0;
int addRight= adv?splitParameters.addRight: 0;
String [] chnNames={"Red","Blue","Green"}; //Different sequence than RGB!!
int nChn=chnNames.length;
ImageProcessor ip=imp.getProcessor();
int inWidth=imp.getWidth();
int inHeight=imp.getHeight();
int outHeight=inHeight*oversample + addTop + addBottom;
int outWidth= inWidth* oversample + addLeft + addRight;
int outLength=outWidth*outHeight;
double [][] outPixels=new double[nChn][outLength];
float [] pixels = (float[]) ip.getPixels();
int chn,y,x,i,index;
int bayerPeriod=2*oversample;
int ovrWidth= inWidth * oversample;
int ovrHeight= inHeight * oversample;
for (chn=0;chn<nChn;chn++) for (i=0;i<outPixels[chn].length;i++) outPixels[chn][i]=0.0f;
/* Can be optimized - now it calculate input address for all those 0-es */
for (index=0; index<outLength; index++) {
y=(index / outWidth) - addTop;
x=(index % outWidth) - addLeft;
if (y<0) y= (bayerPeriod-((-y) % bayerPeriod))%bayerPeriod;
else if (y>=ovrHeight) y= ovrHeight-bayerPeriod +((y-ovrHeight) % bayerPeriod);
if (x<0) x= (bayerPeriod-((-x) % bayerPeriod))%bayerPeriod;
else if (x>=ovrWidth) x= ovrWidth-bayerPeriod +((x-ovrWidth) % bayerPeriod);
if (((y% oversample)==0) && ((x% oversample)==0)) {
x/=oversample;
y/=oversample;
chn=((x&1)==(y&1))?2:(((x&1)!=0)?0:1);
outPixels[chn][index]=pixels[y*inWidth+x];
}
}
return outPixels;
}
//double [] DENOISE_MASK=null; //double [] DENOISE_MASK=null;
......
This diff is collapsed.
...@@ -2890,16 +2890,7 @@ private Panel panel1, ...@@ -2890,16 +2890,7 @@ private Panel panel1,
int numChannels=EYESIS_CORRECTIONS.getNumChannels(); int numChannels=EYESIS_CORRECTIONS.getNumChannels();
NONLIN_PARAMETERS.modifyNumChannels(numChannels); NONLIN_PARAMETERS.modifyNumChannels(numChannels);
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels); CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
/*
if (CORRECTION_PARAMETERS.deconvolve && (NONLIN_PARAMETERS.noiseGainPower!=0)) {
EYESIS_CORRECTIONS.updateImageNoiseGains(
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
CONVOLVE_FFT_SIZE, //int fftSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, // int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, // boolean updateStatus,
DEBUG_LEVEL); //int globalDebugLevel){
}
*/
if (!EYESIS_DCT.DCTKernelsAvailable()){ if (!EYESIS_DCT.DCTKernelsAvailable()){
if (DEBUG_LEVEL > 0){ if (DEBUG_LEVEL > 0){
System.out.println("Reading/converting DCT kernels"); System.out.println("Reading/converting DCT kernels");
...@@ -2914,11 +2905,7 @@ private Panel panel1, ...@@ -2914,11 +2905,7 @@ private Panel panel1,
EYESIS_DCT.showKernels(); // show restored kernels EYESIS_DCT.showKernels(); // show restored kernels
} }
} }
// EYESIS_CORRECTIONS.processChannelImages(
EYESIS_DCT.processDCTChannelImages( EYESIS_DCT.processDCTChannelImages(
// SPLIT_PARAMETERS, // EyesisCorrectionParameters.SplitParameters splitParameters,
DCT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters, DCT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters, DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters, NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
...@@ -4096,6 +4083,7 @@ private Panel panel1, ...@@ -4096,6 +4083,7 @@ private Panel panel1,
if (EYESIS_DCT != null){ if (EYESIS_DCT != null){
EYESIS_DCT.resetCLTKernels(); EYESIS_DCT.resetCLTKernels();
} }
} else if (label.equals("Read CLT kernels")) { } else if (label.equals("Read CLT kernels")) {
if (!CLT_PARAMETERS.showDialog()) return; if (!CLT_PARAMETERS.showDialog()) return;
if (EYESIS_DCT == null){ if (EYESIS_DCT == null){
...@@ -4145,6 +4133,92 @@ private Panel panel1, ...@@ -4145,6 +4133,92 @@ private Panel panel1,
DEBUG_LEVEL); DEBUG_LEVEL);
} }
return;
} else if (label.equals("CLT process files")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
if (EYESIS_DCT == null){
EYESIS_DCT = new EyesisDCT (
EYESIS_CORRECTIONS,
CORRECTION_PARAMETERS,
DCT_PARAMETERS);
if (DEBUG_LEVEL > 0){
System.out.println("Created new EyesisDCT instance, will need to read CLT kernels");
}
}
String configPath=null;
if (EYESIS_CORRECTIONS.correctionsParameters.saveSettings) {
configPath=EYESIS_CORRECTIONS.correctionsParameters.selectResultsDirectory(
true,
true);
if (configPath==null){
String msg="No results directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
} catch (Exception e){
String msg="Failed to save configuration to "+configPath+", command aborted";
System.out.println("Error: "+msg);
IJ.showMessage("Error",msg);
return;
}
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
int numChannels=EYESIS_CORRECTIONS.getNumChannels();
NONLIN_PARAMETERS.modifyNumChannels(numChannels);
CHANNEL_GAINS_PARAMETERS.modifyNumChannels(numChannels);
if (!EYESIS_DCT.CLTKernelsAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Reading CLT kernels");
}
EYESIS_DCT.readCLTKernels(
CLT_PARAMETERS,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
if (DEBUG_LEVEL > 1){
EYESIS_DCT.showCLTKernels(
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
}
}
///========================================
EYESIS_DCT.processCLTChannelImages(
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
NONLIN_PARAMETERS, //EyesisCorrectionParameters.NonlinParameters nonlinParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
CONVOLVE_FFT_SIZE, //int convolveFFTSize, // 128 - fft size, kernel size should be size/2
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
return; return;
// End of buttons code // End of buttons code
......
This diff is collapsed.
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