...
 
Commits (5)
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -11,6 +11,9 @@ public class ColorProcParameters {
public boolean lwir_islwir = false;
public double lwir_low = 27000;
public double lwir_high = 31000;
public boolean lwir_autorange = true;
public double lwir_too_cold = 100.0; // discard this number of pixels too cold
public double lwir_too_hot = 3.0; // discard this number of pixels too hot
public int lwir_palette = 0; // 0 - white - hot, 1 - black - hot, 2+ - colored
public boolean lwir_subtract_dc = false;
public boolean lwir_eq_chn = true; // adjust average temperature between channels
......@@ -65,11 +68,23 @@ public class ColorProcParameters {
public boolean use8; // use 8 neighbors (false - only 4)
public boolean isMonochrome() {
return lwir_islwir; // for now it is the only reason to be monochrome
}
public boolean isLwir() {
return lwir_islwir;
}
private ColorProcParameters() {}
public ColorProcParameters(
boolean lwir_islwir, // false;
double lwir_low, // 27000;
double lwir_high, // 31000;
boolean lwir_autorange, // true;
double lwir_too_cold, // 100.0; // discard this number of pixels too cold
double lwir_too_hot, // 3.0; // discard this number of pixels too hot
int lwir_palette, // 0 - white - hot, 1 - black - hot, 2+ - colored
boolean lwir_subtract_dc, // = false;
boolean lwir_eq_chn, // true
......@@ -124,6 +139,11 @@ public class ColorProcParameters {
this.lwir_islwir = lwir_islwir;
this.lwir_low = lwir_low;
this.lwir_high = lwir_high;
this.lwir_autorange = lwir_autorange;
this.lwir_too_cold = lwir_too_cold;
this.lwir_too_hot = lwir_too_hot;
this.lwir_palette = lwir_palette;
this.lwir_subtract_dc = lwir_subtract_dc;
this.lwir_eq_chn =lwir_eq_chn;
......@@ -179,6 +199,11 @@ public class ColorProcParameters {
properties.setProperty(prefix+"lwir_islwir", this.lwir_islwir+"");
properties.setProperty(prefix+"lwir_low", this.lwir_low+"");
properties.setProperty(prefix+"lwir_high", this.lwir_high+"");
properties.setProperty(prefix+"lwir_autorange", this.lwir_autorange+"");
properties.setProperty(prefix+"lwir_too_cold", this.lwir_too_cold+"");
properties.setProperty(prefix+"lwir_too_hot", this.lwir_too_hot+"");
properties.setProperty(prefix+"lwir_palette", this.lwir_palette+"");
properties.setProperty(prefix+"lwir_subtract_dc", this.lwir_subtract_dc+"");
properties.setProperty(prefix+"lwir_eq_chn", this.lwir_eq_chn+"");
......@@ -240,9 +265,14 @@ public class ColorProcParameters {
}
public boolean getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"lwir_islwir")!=null) this.lwir_islwir=Boolean.parseBoolean(properties.getProperty(prefix+"lwir_islwir"));
if (properties.getProperty(prefix+"lwir_low")!=null) this.lwir_low=Double.parseDouble(properties.getProperty(prefix+"lwir_low"));
if (properties.getProperty(prefix+"lwir_high")!=null) this.lwir_high=Double.parseDouble(properties.getProperty(prefix+"lwir_high"));
if (properties.getProperty(prefix+"lwir_islwir")!=null) this.lwir_islwir=Boolean.parseBoolean(properties.getProperty(prefix+"lwir_islwir"));
if (properties.getProperty(prefix+"lwir_low")!=null) this.lwir_low=Double.parseDouble(properties.getProperty(prefix+"lwir_low"));
if (properties.getProperty(prefix+"lwir_high")!=null) this.lwir_high=Double.parseDouble(properties.getProperty(prefix+"lwir_high"));
if (properties.getProperty(prefix+"lwir_autorange")!=null) this.lwir_autorange=Boolean.parseBoolean(properties.getProperty(prefix+"lwir_autorange"));
if (properties.getProperty(prefix+"lwir_too_cold")!=null) this.lwir_too_cold=Double.parseDouble(properties.getProperty(prefix+"lwir_too_cold"));
if (properties.getProperty(prefix+"lwir_too_hot")!=null) this.lwir_too_hot=Double.parseDouble(properties.getProperty(prefix+"lwir_too_hot"));
if (properties.getProperty(prefix+"lwir_palette")!=null) this.lwir_palette=Integer.parseInt(properties.getProperty(prefix+"lwir_palette"));
if (properties.getProperty(prefix+"lwir_subtract_dc")!=null) this.lwir_subtract_dc=Boolean.parseBoolean(properties.getProperty(prefix+"lwir_subtract_dc"));
if (properties.getProperty(prefix+"lwir_eq_chn")!=null) this.lwir_eq_chn=Boolean.parseBoolean(properties.getProperty(prefix+"lwir_eq_chn"));
......@@ -312,8 +342,13 @@ public class ColorProcParameters {
}
gd.addMessage("--- Parameters related to thermal imaging ---");
gd.addCheckbox ("These sensors are thermal vision with absolute temperature", this.lwir_islwir);
gd.addNumericField("Lowest value (temperature) to display", this.lwir_low, 3); //0.53
gd.addNumericField("Highest value (temperature) to display", this.lwir_high, 3); //0.53
gd.addNumericField("Lowest value (temperature) to display", this.lwir_low, 6); //0.53
gd.addNumericField("Highest value (temperature) to display", this.lwir_high, 6); //0.53
gd.addCheckbox ("Autorange LWIR low/high temperatures (within limits above)", this.lwir_autorange); // true
gd.addNumericField("Number of too cold pixels/image to ignore during autorange", this.lwir_too_cold, 4); // 100.0
gd.addNumericField("Number of too hot pixels/image to ignore during autorange", this.lwir_too_hot, 4); // 0.53
gd.addNumericField("LWIR pallet (0-white hot, 1-black hot, 2+ - pseudo colors ", this.lwir_palette, 0);
gd.addCheckbox ("Subtract each image DC when conditioning", this.lwir_subtract_dc);
gd.addCheckbox ("Adjust average temperature between cameras", this.lwir_eq_chn);
......@@ -397,6 +432,11 @@ public class ColorProcParameters {
this.lwir_islwir= gd.getNextBoolean();
this.lwir_low= gd.getNextNumber();
this.lwir_high= gd.getNextNumber();
this.lwir_autorange = gd.getNextBoolean();
this.lwir_too_cold= gd.getNextNumber();
this.lwir_too_hot= gd.getNextNumber();
this.lwir_palette= (int) gd.getNextNumber();
this.lwir_subtract_dc= gd.getNextBoolean();
this.lwir_eq_chn= gd.getNextBoolean();
......@@ -458,6 +498,11 @@ public class ColorProcParameters {
cp.lwir_islwir = this.lwir_islwir;
cp.lwir_low = this.lwir_low;
cp.lwir_high = this.lwir_high;
cp.lwir_autorange = this.lwir_autorange;
cp.lwir_too_cold = this.lwir_too_cold;
cp.lwir_too_hot = this.lwir_too_hot;
cp.lwir_palette = this.lwir_palette;
cp.lwir_subtract_dc = this.lwir_subtract_dc;
cp.lwir_eq_chn = this.lwir_eq_chn;
......@@ -517,6 +562,11 @@ public class ColorProcParameters {
this.lwir_islwir = cp.lwir_islwir;
this.lwir_low = cp.lwir_low;
this.lwir_high = cp.lwir_high;
this.lwir_autorange = cp.lwir_autorange;
this.lwir_too_cold = cp.lwir_too_cold;
this.lwir_too_hot = cp.lwir_too_hot;
this.lwir_palette = cp.lwir_palette;
this.lwir_subtract_dc = cp.lwir_subtract_dc;
this.lwir_eq_chn = cp.lwir_eq_chn;
......
......@@ -1247,7 +1247,9 @@ public class EyesisCorrectionParameters {
String [] extensions = getSourceSuffixes();// ={this.sourceSuffix};
String [] prefixes = getSourcePrefixes();
int num_chn_files = numSubCameras + ((aux_camera != null)?aux_camera.numSubCameras : 0);
int num_chn_main = numSubCameras;
int num_chn_aux = ((aux_camera != null)?aux_camera.numSubCameras : 0);
int num_chn_files = num_chn_main + num_chn_aux;
extensions[0] = sourceSuffix;
prefixes[0] = sourcePrefix;
MultipleExtensionsFileFilter setFilter = new MultipleExtensionsFileFilter(prefixes,extensions,"Image sets");
......@@ -1281,7 +1283,10 @@ public class EyesisCorrectionParameters {
// String [] setChnFiles = files[nFile].list(setFilter);
File [] setChnFiles = files[nFile].listFiles(setFilter);
int num_match = setChnFiles.length;
if (num_match == num_chn_files) { // only use sets of exact number of files
if ( (num_match == num_chn_files) || // all files for main and aux
(num_match == num_chn_main) || // only main camera files
(num_match == num_chn_aux)) // only aux camera files
{ // only use sets of exact number of files
setDirList.add(files[nFile]);
for (File f: setChnFiles) {
setFilesList.add(f);
......
......@@ -26,11 +26,11 @@ public class ThermalColor {
public double [] getRGB(double v) { // Get R,G,B (0..255) triplet for input value in the range 0..1
double k = out_range/PALETTE_RANGE;
double value = (v-min)/(max-min);
int ivalue = (int) (value/(this.palette.length - 1));
double value = (v-min)/(max-min) * (this.palette.length - 1);
int ivalue = (int) (value);
if (ivalue < 0) return this.palette[0];
if (ivalue >= (this.palette.length -1)) return this.palette[this.palette.length -1];
double a = (value-ivalue)*(this.palette.length - 1); // 0..1
double a = (value-ivalue); // 0..1
double [] rslt = {
k*((1 - a) * this.palette[ivalue][0] + a * this.palette[ivalue+1][0]),
k*((1 - a) * this.palette[ivalue][1] + a * this.palette[ivalue+1][1]),
......@@ -97,7 +97,8 @@ public class ThermalColor {
0xfff285, 0xfff28a, 0xfff38e, 0xfff492, 0xfff496, 0xfff49a, 0xfff59e, 0xfff5a2,
0xfff5a6, 0xfff6aa, 0xfff6af, 0xfff7b3, 0xfff7b6, 0xfff8ba, 0xfff8bd, 0xfff8c1,
0xfff8c4, 0xfff9c7, 0xfff9ca, 0xfff9cd, 0xfffad1, 0xfffad4, 0xfffbd8, 0xfffcdb,
0xfffcdf, 0xfffde2, 0xfffde5, 0xfffde8, 0xfffeeb, 0xfffeee, 0xfffef1, 0xfffef4, 0xfffff};
0xfffcdf, 0xfffde2, 0xfffde5, 0xfffde8, 0xfffeeb, 0xfffeee, 0xfffef1, 0xfffef4,
0xffffff};
int [][] palettes = {white_hot_palette, black_hot_palette, iron_palette};
if (indx <0) indx = 0;
else if (indx >= palettes.length) indx = palettes.length - 1;
......
......@@ -1838,6 +1838,57 @@ public class EyesisCorrections {
return imp;
}
public static ImagePlus convertRGBAFloatToRGBA32(
ImageStack stackFloat, //r,g,b,a
String title,
double r_min,
double r_max,
double g_min,
double g_max,
double b_min,
double b_max,
double alpha_min,
double alpha_max){
double [] mins= {r_min,g_min,b_min,alpha_min};
double [] maxs= {r_max,g_max,b_max,alpha_max};
int i;
int length=stackFloat.getWidth()*stackFloat.getHeight();
int numSlices = stackFloat.getSize();
if (numSlices > 4) numSlices = 4;
float [][] fpixels=new float[numSlices][];
int [] sliceSeq = new int [numSlices];
for (int j = 0; j < numSlices; j++) sliceSeq[j] = (j + ((numSlices > 3)? 3:0)) % 4;
int [] pixels=new int[length];
int c,d;
double [] scale=new double[numSlices];
for (c = 0; c < numSlices; c++) {
scale[c]=256.0/(maxs[c]-mins[c]);
}
for (i = 0; i < numSlices; i++) {
fpixels[i]= (float[])stackFloat.getPixels(i+1);
}
for (i = 0; i < length; i++) {
pixels[i]=0;
for (int j=0; j < numSlices; j++) {
c = sliceSeq[j];
d=(int)((fpixels[c][i]-mins[c])*scale[c]);
if (d > 255) d=255;
else if (d < 0) d=0;
pixels[i]= d | (pixels[i] << 8);
}
}
ColorProcessor cp=new ColorProcessor(stackFloat.getWidth(),stackFloat.getHeight());
cp.setPixels(pixels);
ImagePlus imp=new ImagePlus(title,cp);
return imp;
}
public ImageStack convertRGB48toRGBA24Stack(
ImageStack stack16,
double [] dalpha, // alpha pixel array 0..1.0 or null
......
......@@ -1220,7 +1220,7 @@ public class EyesisDCT {
}
if (this.correctionsParameters.deconvolve) { // process with DCT, otherwise use simple debayer
ImageDtt image_dtt = new ImageDtt(false); // Bayer, not monochrome
ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
double [][][][] dct_data = image_dtt.mdctStack(
stack,
channel,
......
......@@ -245,7 +245,10 @@ private Panel panel1,
false, // boolean lwir_islwir, // false;
27000, // double lwir_low, // 27000;
31000, // double lwir_high, // 31000;
0, // int lwir_palette, // 0 - white - hot, 1 - black - hot, 2+ - colored
true, // boolean lwir_autorange, // true;
100.0, // double lwir_too_cold, // 100.0; // discard this number of pixels too cold
3.0, // double lwir_too_hot, // 3.0; // discard this number of pixels too hot
1, // int lwir_palette, // 0 - white - hot, 1 - black - hot, 2+ - pseudocolored
false, // boolean lwir_subtract_dc, // = false;
true, // boolean lwir_eq_chn = true; // adjust average temperature between channels
true, // boolean correct_vignetting, // = true;
......@@ -3061,7 +3064,7 @@ private Panel panel1,
}
}
ImageDtt image_dtt = new ImageDtt(false); // Bayer, not monochrome
ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
double [][][][] dctdc_data = image_dtt.mdctScale(
DBG_IMP.getStack(),
DCT_PARAMETERS.kernel_chn,
......@@ -3159,7 +3162,7 @@ private Panel panel1,
}
}
ImageDtt image_dtt = new ImageDtt(false); // Bayer, not monochrome
ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
double [][][][] dctdc_data = image_dtt.mdctStack(
DBG_IMP.getStack(),
DCT_PARAMETERS.kernel_chn,
......@@ -4452,17 +4455,17 @@ private Panel panel1,
int num_infinity_corr = infinity_corr? CLT_PARAMETERS.inf_repeat : 1;
if ( num_infinity_corr < 1) num_infinity_corr = 1;
for (int i_infinity_corr = 0; i_infinity_corr < num_infinity_corr; i_infinity_corr++) {
QUAD_CLT_AUX.processCLTQuadCorrs(
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS_AUX, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS_AUX, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
apply_corr,
infinity_corr, // calculate and apply geometry correction at infinity
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
QUAD_CLT_AUX.processCLTQuadCorrs(
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS_AUX, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS_AUX, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
apply_corr,
infinity_corr, // calculate and apply geometry correction at infinity
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
......@@ -4628,7 +4631,6 @@ private Panel panel1,
QUAD_CLT.cltDisparityScans(
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,
......@@ -4675,82 +4677,12 @@ private Panel panel1,
clt3d(adjust_extrinsics, adjust_poly, dry_run);
return;
} else if (label.equals("AUX extrinsics") || label.equals("AUX Poly corr")) {
} else if (label.equals("AUX 3D") || label.equals("AUX extrinsics") || label.equals("AUX Poly corr")) {
boolean adjust_extrinsics = label.equals("AUX extrinsics") || label.equals("AUX Poly corr");
boolean adjust_poly = label.equals("AUX Poly corr");
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
clt3d_aux(adjust_extrinsics, adjust_poly);
/*
if (QUAD_CLT_AUX == null){
if (EYESIS_CORRECTIONS_AUX == null) {
EYESIS_CORRECTIONS_AUX = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS.getAux());
}
QUAD_CLT_AUX = new QuadCLT (
QuadCLT.PREFIX_AUX,
PROPERTIES,
EYESIS_CORRECTIONS_AUX,
CORRECTION_PARAMETERS.getAux());
if (DEBUG_LEVEL > 0){
System.out.println("Created new QuadCLT instance for AUX camera, will need to read CLT kernels for aux camera");
}
}
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return;
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL);
int numChannelsAux=EYESIS_CORRECTIONS_AUX.getNumChannels();
CHANNEL_GAINS_PARAMETERS_AUX.modifyNumChannels(numChannelsAux);
if (!QUAD_CLT_AUX.CLTKernelsAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Reading AUX CLT kernels");
}
QUAD_CLT_AUX.readCLTKernels(
CLT_PARAMETERS,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
if (DEBUG_LEVEL > 1){
QUAD_CLT_AUX.showCLTKernels(
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
}
}
if (!QUAD_CLT_AUX.geometryCorrectionAvailable()){
if (DEBUG_LEVEL > 0){
System.out.println("Calculating geometryCorrection for AUX camera");
}
if (!QUAD_CLT_AUX.initGeometryCorrection(DEBUG_LEVEL+2)){
return;
}
}
QUAD_CLT_AUX.processCLTQuads3d(
adjust_extrinsics, // boolean adjust_extrinsics,
adjust_poly, // boolean adjust_poly,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS_AUX, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
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;
} else if (label.equals("CLT planes")) {
......@@ -5818,18 +5750,18 @@ private Panel panel1,
}
QUAD_CLT_AUX.processCLTQuads3d(
adjust_extrinsics, // boolean adjust_extrinsics,
adjust_poly, // boolean adjust_poly,
TWO_QUAD_CLT, // TwoQuadCLT twoQuadCLT, //maybe null in no-rig mode, otherwise may contain rig measurements to be used as infinity ground truth
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS_AUX, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL); //final int debugLevel);
adjust_extrinsics, // boolean adjust_extrinsics,
adjust_poly, // boolean adjust_poly,
TWO_QUAD_CLT, // TwoQuadCLT twoQuadCLT, //maybe null in no-rig mode, otherwise may contain rig measurements to be used as infinity ground truth
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, // EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS_AUX, // EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
CHANNEL_GAINS_PARAMETERS_AUX, // CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, // EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
THREADS_MAX, // final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, // final boolean updateStatus,
DEBUG_LEVEL); // final int debugLevel);
if (configPath!=null) {
......@@ -6837,7 +6769,7 @@ private Panel panel1,
}
}
ImageDtt image_dtt = new ImageDtt(false); // Bayer, not monochrome
ImageDtt image_dtt = new ImageDtt(false, 1.0); // Bayer( not monochrome), scale correlation strengths
double [][][][][] clt_data = image_dtt.cltStack(
DBG_IMP.getStack(),
0, // CLT_PARAMETERS.kernel_chn,
......@@ -6967,7 +6899,7 @@ private Panel panel1,
}
String suffix = "-dx_"+(CLT_PARAMETERS.ishift_x+CLT_PARAMETERS.shift_x)+"_dy_"+(CLT_PARAMETERS.ishift_y+CLT_PARAMETERS.shift_y);
ImageDtt image_dtt = new ImageDtt(false); // Bayer, not monochrome
ImageDtt image_dtt = new ImageDtt(COLOR_PROC_PARAMETERS.isMonochrome(), CLT_PARAMETERS.getScaleStrength(false)); // Bayer, not monochrome
String [] titles = {
"redCC", "redSC", "redCS", "redSS",
"blueCC", "blueSC", "blueCS", "blueSS",
......@@ -7056,7 +6988,7 @@ private Panel panel1,
clt_data[chn], // final double [][][][] data1, // array [tilesY][tilesX][4][dct_size*dct_size]
clt_data2[chn], // final double [][][][] data2, // array [tilesY][tilesX][4][dct_size*dct_size]
CLT_PARAMETERS.transform_size, // final int dct_size,
CLT_PARAMETERS.fat_zero, // final double fat_zero, // add to denominator to modify phase correlation (same units as data1, data2)
CLT_PARAMETERS.getFatZero(image_dtt.isMonochrome()), // final double fat_zero, // add to denominator to modify phase correlation (same units as data1, data2)
CLT_PARAMETERS.tileX, //final int debug_tileX
CLT_PARAMETERS.tileY, //final int debug_tileY
......@@ -7081,10 +7013,10 @@ private Panel panel1,
DBG_IMP.getTitle()+"-CORR+"+suffix, titles);
}
if (CLT_PARAMETERS.corr_sigma > 0.0){
if (CLT_PARAMETERS.getCorrSigma(image_dtt.isMonochrome()) > 0.0){
for (int chn = 0; chn < clt_data.length; chn++) {
image_dtt.clt_lpf( // filter in-place
CLT_PARAMETERS.corr_sigma, // final double sigma,
CLT_PARAMETERS.getCorrSigma(image_dtt.isMonochrome()), // final double sigma,
clt_corr[chn], // final double [][][][] clt_data,
CLT_PARAMETERS.transform_size,
THREADS_MAX, // maximal number of threads to launch
......
......@@ -1775,7 +1775,8 @@ B = |+dy0 -dy1 -2*dy3 |
final int hist_min_samples,
final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
final double inf_fraction, // fraction of the weight for the infinity tiles
CLTParameters clt_parameters,
final boolean right_left, // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
CLTParameters clt_parameters,
double [][] scans_14,
double [][] target_disparity, // null or programmed disparity (1 per each 14 entries of scans_14)
int tilesX,
......@@ -1878,7 +1879,8 @@ B = |+dy0 -dy1 -2*dy3 |
}
if (debugLevel > -2) {
System.out.println("lazyEyeCorrection() 1: removing tiles with residual disparity absoulte value > "+lazyEyeCompDiff);
System.out.println("lazyEyeCorrection().a 1: removing tiles with residual disparity absolute value > "+lazyEyeCompDiff);
// System.out.println("lazyEyeCorrection().a 1: removing tiles with residual disparity absolute value > "+(2*lazyEyeCompDiff));
}
double [][] combo_mismatch = new double [NUM_SLICES][num_tiles];
......@@ -1891,6 +1893,7 @@ B = |+dy0 -dy1 -2*dy3 |
double w = filtered_scans[ns * NUM_SLICES + 1][nTile];
if (w > 0.0){
double disp = filtered_scans[ns * NUM_SLICES + 0][nTile];
// if (Math.abs(disp) <= 2.0*lazyEyeCompDiff) {
if (Math.abs(disp) <= lazyEyeCompDiff) {
for (int i = 2; i < NUM_SLICES; i++) if (i != 1){
combo_mismatch[i][nTile] += filtered_scans[ns * NUM_SLICES + i][nTile] * w;
......@@ -2214,6 +2217,29 @@ B = |+dy0 -dy1 -2*dy3 |
System.out.println("lazyEyeCorrection(): number of all samples="+inf_samples_list.size()+", total weight = "+inf_weight);
}
if (right_left) {
System.out.println("Balancing right/left part of FoV weights, width = "+tilesX+" tiles");
double [] right_left_weights = {0.0, 0.0};
for (Sample s: inf_samples_list) {
int rl = (s.tile % tilesX) / (tilesX/2);
right_left_weights[rl] += s.weight;
}
System.out.println("Weights: left:"+ right_left_weights[0]+", right:"+ right_left_weights[1]);
for (Sample s: inf_samples_list) {
int rl = (s.tile % tilesX) / (tilesX/2);
s.weight *= right_left_weights[1 - rl];
}
// just verifying
right_left_weights[0] = 0.0;
right_left_weights[1] = 0.0;
for (Sample s: inf_samples_list) {
int rl = (s.tile % tilesX) / (tilesX/2);
right_left_weights[rl] += s.weight;
}
System.out.println("Weights after balancing: left:"+ right_left_weights[0]+", right:"+ right_left_weights[1]);
}
if (debugLevel > 0) {
String [] prefixes = {"disparity", "strength", "dx0", "dy0", "dx1", "dy1", "dx2", "dy2", "dx3", "dy3"};
......@@ -3369,6 +3395,11 @@ B = |+dy0 -dy1 -2*dy3 |
int dbg_height = qc.tp.getTilesY()*qc.tp.getTileSize();
int dbg_owidth = dbg_width/dbg_decimate;
int dbg_oheight = dbg_height/dbg_decimate;
while (dbg_owidth < 40) {
dbg_decimate /= 2;
dbg_owidth = dbg_width/dbg_decimate;
dbg_oheight = dbg_height/dbg_decimate;
}
int dbg_length = dbg_owidth*dbg_oheight;
String [] dbg_titles_sym= {"sym0","sym1","sym2","sym3","sym4","sym5","sroll0","sroll1","sroll2","sroll3", "zoom0", "zoom1", "zoom2"};
String [] dbg_titles_xy= {"dx0","dy0","dx1","dy1","dx2","dy2","dx3","y3"};
......
......@@ -244,6 +244,7 @@ public class Correlation2d {
* @param clt_data1 [3][4][transform_len] first operand data. First index - RBG color
* @param clt_data2 [3][4][transform_len] first operand data. First index - RBG color
* @param lpf optional [transform_len] LPF filter data
* @param scale_value scale correlation results to compensate for lpf changes and other factors
* @param col_weights [3] - color weights {R, B, G} - green is last, normalized to sum =1.0
* @param fat_zero fat zero for phase correlation (0 seems to be OK)
* @return correlation result [(2*transform_size-1) * (2*transform_size-1)]
......@@ -252,6 +253,7 @@ public class Correlation2d {
double [][][] clt_data1,
double [][][] clt_data2,
double [] lpf,
double scale_value, // scale correlation value
double [] col_weights_in, // should have the same dimension as clt_data1 and clt_data2
double fat_zero) {
......@@ -266,13 +268,18 @@ public class Correlation2d {
s+=col_weights[i];
}
for (int i = 0; i < col_weights.length; i++) {
if (col_weights[i] != 0.0) col_weights[i]/=s; // will have 1.0 for the single color
if (col_weights[i] != 0.0) col_weights[i] *= scale_value;
}
if (clt_data1.length == 1) { // monochrome
col_weights = new double[1];
col_weights[0] = 1.0;
}
for (int i = 0; i < col_weights.length; i++) {
if (col_weights[i] != 0.0) col_weights[i]/=s; // will have 1.0 for the single color
}
double [][][]tcorr = new double [clt_data1.length][4][transform_len];
int first_col = -1;
for (int col = 0; col < tcorr.length; col++) if (col_weights[col] > 0.0 ) {
......@@ -280,7 +287,7 @@ public class Correlation2d {
clt_data1[col],
clt_data2[col],
tcorr[col],
fat_zero);
fat_zero/scale_value);
if (first_col < 0) {// accummulate all channels in frst non-null color ( 0 for color, 2 for mono?)
first_col = col; // first non-empty color (2, green) or 0 for color images
......@@ -320,6 +327,7 @@ public class Correlation2d {
* @param tileY tile to extract Y index
* @param pairs_mask bimask of required pairs
* @param lpf optional low-pass filter
* @param scale_value scale correlation results to compensate for lpf changes and other factors
* @param col_weights RBG color weights
* @param fat_zero fat zero for phase correlations
* @return [pair][corr_index]
......@@ -330,6 +338,7 @@ public class Correlation2d {
int tileY,
int pairs_mask,
double [] lpf,
double scale_value, // scale correlation value
double [] col_weights,
double fat_zero) {
double [][][][] clt_data_tile = new double[clt_data.length][][][];
......@@ -343,6 +352,7 @@ public class Correlation2d {
clt_data_tile,
pairs_mask, // already decoded so bit 0 - pair 0
lpf,
scale_value,
col_weights,
fat_zero);
}
......@@ -352,6 +362,7 @@ public class Correlation2d {
* @param clt_data aberration-corrected FD CLT data for one tile [camera][color][quadrant][index]
* @param pairs_mask bimask of required pairs
* @param lpf optional low-pass filter
* @param scale_value scale correlation results to compensate for lpf changes and other factors
* @param col_weights RBG color weights
* @param fat_zero fat zero for phase correlations
* @return [pair][corr_index]
......@@ -360,6 +371,7 @@ public class Correlation2d {
double [][][][] clt_data_tile,
int pairs_mask, // already decoded so bit 0 - pair 0
double [] lpf,
double scale_value, // scale correlation value
double [] col_weights,
double fat_zero) {
if (clt_data_tile == null) return null;
......@@ -372,6 +384,7 @@ public class Correlation2d {
clt_data_tile[ncam1], // double [][][] clt_data1,
clt_data_tile[ncam2], // double [][][] clt_data2,
lpf, // double [] lpf,
scale_value,
col_weights, // double [] col_weights,
fat_zero); // double fat_zero)
}
......@@ -385,6 +398,7 @@ public class Correlation2d {
* @param clt_data_tile_main aberration-corrected FD CLT data for one tile of the main quad camera [sub-camera][color][quadrant][index]
* @param clt_data_tile_aux aberration-corrected FD CLT data for one tile of the auxiliary quad camera [sub-camera][color][quadrant][index]
* @param lpf optional low-pass filter
* @param scale_value scale correlation results to compensate for lpf changes and other factors
* @param col_weights RBG color weights
* @param fat_zero fat zero for phase correlations
* @return 2-d correlation array in line scan order
......@@ -393,6 +407,7 @@ public class Correlation2d {
double [][][][] clt_data_tile_main,
double [][][][] clt_data_tile_aux,
double [] lpf,
double scale_value, // scale correlation value
double [] col_weights,
double fat_zero) {
if ((clt_data_tile_main == null) || (clt_data_tile_aux == null)) return null;
......@@ -402,6 +417,7 @@ public class Correlation2d {
clt_mix_main, // double [][][] clt_data1,
clt_mix_aux, // double [][][] clt_data2,
lpf, // double [] lpf,
scale_value, // scale correlation value
col_weights, // double [] col_weights,
fat_zero); // double fat_zero)
return inter_cam_corr;
......
......@@ -1340,8 +1340,8 @@ public class GeometryCorrection {
sv[i] = sym_vect[i]*1000.0*distortionRadius/pixelSize; // zooms
}
s = String.format("tilt (up): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift of he image center)\n" , v[0], v[1], v[2], -(v[0] + v[1] + v[2]) );
s += String.format("azimuth (right): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift of he image center)\n" , v[3], v[4], v[5], -(v[3] + v[4] + v[5]) );
s = String.format("tilt (up): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift of the image center)\n" , v[0], v[1], v[2], -(v[0] + v[1] + v[2]) );
s += String.format("azimuth (right): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift of the image center)\n" , v[3], v[4], v[5], -(v[3] + v[4] + v[5]) );
s += String.format("roll (CW): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift at the image half-width from the center)\n" , v[6], v[7], v[8], v[9] );
s += String.format("diff zoom (in): %8.5fpx %8.5fpx %8.5fpx %8.5fpx (shift at the image half-width from the center)\n" , v[10], v[11], v[12], -(v[10] + v[11] + v[12]) );
s += "Symmetrical vector:\n";
......
......@@ -202,6 +202,7 @@ public class ImageDtt {
static String [] TCORR_TITLES = {"combo","sum","hor","vert"};
private final boolean monochrome;
private final double scale_strengths; // scale all correlation strengths (to compensate for LPF sigma changes)
public static int getImgMask (int data){ return (data & 0xf);} // which images to use
......@@ -213,8 +214,11 @@ public class ImageDtt {
public static boolean getOrthoLines (int data){return (data & 0x200) != 0;}
public static int setOrthoLines (int data, boolean force) {return (data & ~0x200) | (force?0x200:0);}
public ImageDtt(boolean mono){
monochrome = mono;
public ImageDtt(
boolean mono,
double scale_strengths){
this.monochrome = mono;
this.scale_strengths = scale_strengths;
}
public boolean isMonochrome() {
......@@ -2110,14 +2114,16 @@ public class ImageDtt {
// calculate all selected pairs correlations
int all_pairs = imgdtt_params.dbg_pair_mask; //TODO: use tile tasks
double [][] corrs = corr2d.correlateCompositeFD( // now works with nulls for some clt_data colors
clt_data, // double [][][][][][] clt_data,
tileX, // int tileX,
tileY, // int tileY,
all_pairs, // int pairs_mask,
filter, // double [] lpf,
col_weights, // double [] col_weights,
corr_fat_zero); // double fat_zero)
double [][] corrs = corr2d.correlateCompositeFD( // now works with nulls for some clt_data colors
clt_data, // double [][][][][][] clt_data,
tileX, // int tileX,
tileY, // int tileY,
all_pairs, // int pairs_mask,
filter, // double [] lpf,
scale_strengths, // double scale_value, // scale correlation value
col_weights, // double [] col_weights,
corr_fat_zero); // double fat_zero)
// calculate interpolated "strips" to match different scales and orientations (ortho/diagonal) on the
// fine (0.5 pix) grid. ortho for scale == 1 provide even/even samples (1/4 of all), diagonal ones -
......@@ -2233,8 +2239,8 @@ public class ImageDtt {
false, // boolean is_vert, // transpose X/Y
tile_lma_debug_level > 0); // boolean debug);
if (hor_pair1 != null) {
disparity_map[DISPARITY_INDEX_HOR][tIndex] = -hor_pair1[0];
disparity_map[DISPARITY_INDEX_HOR_STRENGTH][tIndex] = hor_pair1[1];
disparity_map[DISPARITY_INDEX_HOR][tIndex] = -hor_pair1[0];
disparity_map[DISPARITY_INDEX_HOR_STRENGTH][tIndex] = hor_pair1[1];
}
double [] vert_pair1 = corr2d.getMaxXSOrtho(
......@@ -6208,7 +6214,7 @@ public class ImageDtt {
// Create window to select center correlation strip using
// ortho_height - full width of non-zero elements
// ortho_eff_height - effective height (ration of the weighted column sum to the center value)
// ortho_eff_height - effective height (ratio of the weighted column sum to the center value)
int wcenter = transform_size - 1;
final double [] ortho_weights = new double [corr_size]; // [15]
for (int i = 0; i < corr_size; i++){
......@@ -7372,6 +7378,7 @@ public class ImageDtt {
clt_data_tile_main, // double [][][][] clt_data_tile_main,
clt_data_tile_aux, // double [][][][] clt_data_tile_aux,
filter, // double [] lpf,
scale_strengths,
col_weights, // double [] col_weights,
fatzero); // double fat_zero)
......@@ -7627,6 +7634,7 @@ public class ImageDtt {
clt_data, // double [][][][] clt_data, // aberration-corrected FD CLT data for one tile [camera][color][quadrant][index]
all_pairs, // int pairs_mask,
filter, // double [] lpf,
scale_strengths,
col_weights, // double [] col_weights,
fatzero); // double fat_zero)
......@@ -8063,13 +8071,13 @@ public class ImageDtt {
final double [] filter_direct= new double[transform_len];
if (clt_parameters.corr_sigma == 0) {
if (clt_parameters.getCorrSigma(isMonochrome()) == 0) {
filter_direct[0] = 1.0;
for (int i= 1; i<filter_direct.length;i++) filter_direct[i] =0;
} else {
for (int i = 0; i < clt_parameters.transform_size; i++){
for (int j = 0; j < clt_parameters.transform_size; j++){
filter_direct[i * clt_parameters.transform_size+j] = Math.exp(-(i*i+j*j)/(2*clt_parameters.corr_sigma)); // FIXME: should be sigma*sigma !
filter_direct[i * clt_parameters.transform_size+j] = Math.exp(-(i*i+j*j)/(2*clt_parameters.getCorrSigma(isMonochrome()))); // FIXME: should be sigma*sigma !
}
}
}
......@@ -8466,6 +8474,7 @@ public class ImageDtt {
clt_data_main, // double [][][][] clt_data_tile_main,
clt_data_aux, // double [][][][] clt_data_tile_aux,
filter, // double [] lpf,
scale_strengths,
col_weights, // double [] col_weights,
fatzero); // double fat_zero)
......@@ -8864,13 +8873,13 @@ public class ImageDtt {
final double [] filter_direct= new double[transform_len];
if (clt_parameters.corr_sigma == 0) {
if (clt_parameters.getCorrSigma(isMonochrome()) == 0) {
filter_direct[0] = 1.0;
for (int i= 1; i<filter_direct.length;i++) filter_direct[i] =0;
} else {
for (int i = 0; i < clt_parameters.transform_size; i++){
for (int j = 0; j < clt_parameters.transform_size; j++){
filter_direct[i * clt_parameters.transform_size+j] = Math.exp(-(i*i+j*j)/(2*clt_parameters.corr_sigma)); // FIXME: should be sigma*sigma !
filter_direct[i * clt_parameters.transform_size+j] = Math.exp(-(i*i+j*j)/(2*clt_parameters.getCorrSigma(isMonochrome()))); // FIXME: should be sigma*sigma !
}
}
}
......@@ -9242,6 +9251,7 @@ public class ImageDtt {
clt_data_main, // double [][][][] clt_data_tile_main,
clt_data_aux, // double [][][][] clt_data_tile_aux,
filter, // double [] lpf,
scale_strengths,
col_weights, // double [] col_weights,
fatzero); // double fat_zero)
......@@ -9594,13 +9604,13 @@ public class ImageDtt {
final double [] filter_direct= new double[transform_len];
if (clt_parameters.corr_sigma == 0) {
if (clt_parameters.getCorrSigma(isMonochrome()) == 0) {
filter_direct[0] = 1.0;
for (int i= 1; i<filter_direct.length;i++) filter_direct[i] =0;
} else {
for (int i = 0; i < clt_parameters.transform_size; i++){
for (int j = 0; j < clt_parameters.transform_size; j++){
filter_direct[i * clt_parameters.transform_size+j] = Math.exp(-(i*i+j*j)/(2*clt_parameters.corr_sigma)); // FIXME: should be sigma*sigma !
filter_direct[i * clt_parameters.transform_size+j] = Math.exp(-(i*i+j*j)/(2*clt_parameters.getCorrSigma(isMonochrome()))); // FIXME: should be sigma*sigma !
}
}
}
......@@ -9630,7 +9640,7 @@ public class ImageDtt {
System.out.println("max_corr_radius= "+clt_parameters.max_corr_radius);
System.out.println("max_search_radius= "+max_search_radius);
System.out.println("max_search_radius_poly="+max_search_radius_poly);
System.out.println("corr_fat_zero= "+clt_parameters.fat_zero);
System.out.println("corr_fat_zero= "+clt_parameters.getFatZero(isMonochrome()));
System.out.println("disparity_array[0][0]= "+disparity_array[0][0]);
......
......@@ -63,6 +63,7 @@ public class MacroCorrelation {
tileSize, // int tileSize,
tp.superTileSize, // int superTileSize,
tp.isMonochrome(),
tp.isAux(),
tp.getMagicScale(), // double scale,
trusted_correlation, // double trustedCorrelation,
0.0, // double maxOverexposure,
......@@ -305,7 +306,9 @@ public class MacroCorrelation {
// double [][][][] texture_tiles = save_textures ? new double [tilesY][tilesX][][] : null; // ["RGBA".length()][];
ImageDtt image_dtt = new ImageDtt(this.mtp.isMonochrome());
ImageDtt image_dtt = new ImageDtt(
this.mtp.isMonochrome(),
clt_parameters.getScaleStrength(this.mtp.isAux()));
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
8, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
......@@ -321,12 +324,12 @@ public class MacroCorrelation {
disparity_map, // [12][tp.tilesY * tp.tilesX]
null, // [tp.tilesY][tp.tilesX]["RGBA".length()][];
mTilesX * clt_parameters.transform_size, // imp_quad[0].getWidth(), // final int width,
clt_parameters.fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.getFatZero(image_dtt.isMonochrome()), // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_sym,
clt_parameters.corr_offset,
clt_parameters.corr_red,
clt_parameters.corr_blue,
clt_parameters.corr_sigma,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
clt_parameters.corr_normalize, // normalize correlation results by rms
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
......
......@@ -2723,7 +2723,7 @@ public class PoleProcessor {
disparity_array, // double [][] disparity_array,
null, // double [][] ml_data, // data for ML - 10 layers - 4 center areas (3x3, 5x5,..) per camera-per direction, 1 - composite, and 1 with just 1 data (target disparity)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_parameters.fat_zero, // double fatzero,
clt_parameters.getFatZero(quadCLT_main.isMonochrome()), // double fatzero,
notch_mode, // final boolean notch_mode, // use notch filter for inter-camera correlation to detect poles
lt_rad, // final int // low texture mode - inter-correlation is averaged between the neighbors before argmax-ing, using
true, // boolean no_int_x0, // do not offset window to integer maximum - used when averaging low textures to avoid "jumps" for very wide
......
......@@ -96,14 +96,31 @@ public class QuadCLT {
boolean is_mono = false; // Use clt_kernels?
double [] lwir_offsets = null; // per image subtracted values
double lwir_offset = Double.NaN; // average of lwir_offsets[]
// hot and cold are calculated during autoranging (when generating 4 images for restored (added lwir_offset)
// absolute temperatures to be used instead of colorProcParameters lwir_low and lwir_high if autoranging
// is enabled
double [] lwir_cold_hot = null;
// int [] woi_tops; // used to calculate scanline timing
// magic scale should be set before using TileProcessor (calculated disparities depend on it)
public boolean isMonochrome() {return is_mono;} // clt_kernels
public boolean isLwir() {return !Double.isNaN(lwir_offset);} // clt_kernels
public boolean isMonochrome() {return is_mono;}
public boolean isAux() {return is_aux;}
public boolean isLwir() {return !Double.isNaN(lwir_offset);} // clt_kernels
public double getLwirOffset() {return lwir_offset;}
public double [] getColdHot() {
return lwir_cold_hot;
}
public void setColdHot(double [] cold_hot) {
lwir_cold_hot = cold_hot;
}
public void setColdHot(double cold, double hot) {
lwir_cold_hot = new double[2];
lwir_cold_hot[0] = cold;
lwir_cold_hot[1] = hot;
}
public void resetGroundTruthByRig() {
tp.rig_disparity_strength = null;
}
......@@ -133,7 +150,8 @@ public class QuadCLT {
tilesY,
clt_parameters.transform_size,
clt_parameters.stSize,
this.is_mono,
isMonochrome(),
isAux(),
clt_parameters.corr_magic_scale,
clt_parameters.grow_disp_trust,
clt_parameters.max_overexposure, // double maxOverexposure,
......@@ -512,7 +530,7 @@ public class QuadCLT {
double [] kernel= new double[kernelSize*kernelSize];
int centered_len = (2*dtt_size-1) * (2*dtt_size-1);
double [] kernel_centered = new double [centered_len + extra_items];
ImageDtt image_dtt = new ImageDtt(isMonochrome());
ImageDtt image_dtt = new ImageDtt(isMonochrome(),clt_parameters.getScaleStrength(isAux()));
int chn,tileY,tileX;
DttRad2 dtt = new DttRad2(dtt_size);
ShowDoubleFloatArrays sdfa_instance = null;
......@@ -688,7 +706,7 @@ public class QuadCLT {
if (globalDebugLevel > 1) System.out.println("Threads done at "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
System.out.println("1.Threads done at "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
// Calculate differential offsets to interpolate for tiles between kernel centers
ImageDtt image_dtt = new ImageDtt(isMonochrome());
ImageDtt image_dtt = new ImageDtt(isMonochrome(),clt_parameters.getScaleStrength(isAux()));
image_dtt.clt_fill_coord_corr(
clt_parameters.kernel_step, // final int kern_step, // distance between kernel centers, in pixels.
clt_kernels, // final double [][][][] clt_data,
......@@ -1647,7 +1665,7 @@ public class QuadCLT {
sdfa_instance.showArrays(double_stack, imp_src.getWidth(), imp_src.getHeight(), true, "BEFORE_CLT_PROC", rbg_titles);
}
if (this.correctionsParameters.deconvolve) { // process with DCT, otherwise use simple debayer
ImageDtt image_dtt = new ImageDtt(isMonochrome());
ImageDtt image_dtt = new ImageDtt(isMonochrome(),clt_parameters.getScaleStrength(isAux()));
for (int i =0 ; i < double_stack[0].length; i++){
double_stack[2][i]*=0.5; // Scale blue twice to compensate less pixels than green
}
......@@ -1686,10 +1704,10 @@ public class QuadCLT {
debugLevel);
} else { // just LPF RGB
*/
if (clt_parameters.corr_sigma > 0){ // no filter at all
if (clt_parameters.getCorrSigma(image_dtt.isMonochrome()) > 0){ // no filter at all
for (int chn = 0; chn < clt_data.length; chn++) {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
clt_data[chn],
clt_parameters.transform_size,
threadsMax,
......@@ -2248,7 +2266,7 @@ public class QuadCLT {
sdfa_instance.showArrays(double_stack, imp_src.getWidth(), imp_src.getHeight(), true, "BEFORE_CLT_PROC", rbg_titles);
}
if (this.correctionsParameters.deconvolve) { // process with DCT, otherwise use simple debayer
ImageDtt image_dtt = new ImageDtt(isMonochrome());
ImageDtt image_dtt = new ImageDtt(isMonochrome(),clt_parameters.getScaleStrength(isAux()));
for (int i =0 ; i < double_stack[0].length; i++){
double_stack[2][i]*=0.5; // Scale blue twice to compensate less pixels than green
}
......@@ -2287,10 +2305,10 @@ public class QuadCLT {
debugLevel);
} else { // just LPF RGB
*/
if (clt_parameters.corr_sigma > 0){ // no filter at all
if (clt_parameters.getCorrSigma(image_dtt.isMonochrome()) > 0){ // no filter at all
for (int chn = 0; chn < clt_data.length; chn++) {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
clt_data[chn],
clt_parameters.transform_size,
threadsMax,
......@@ -2813,7 +2831,7 @@ public class QuadCLT {
// String [] rbg_titles = {"Red", "Blue", "Green"};
ImageStack stack;
// =================
ImageDtt image_dtt = new ImageDtt(isMonochrome());
ImageDtt image_dtt = new ImageDtt(isMonochrome(),clt_parameters.getScaleStrength(isAux()));
for (int i = 0; i < double_stacks.length; i++){
for (int j =0 ; j < double_stacks[i][0].length; j++){
double_stacks[i][2][j]*=0.5; // Scale green 0.5 to compensate more pixels than R,B
......@@ -2848,10 +2866,10 @@ public class QuadCLT {
String title=name+"-"+String.format("%02d", iQuad);
String titleFull=title+"-SPLIT";
if (clt_parameters.corr_sigma > 0){ // no filter at all
if (clt_parameters.getCorrSigma(image_dtt.isMonochrome()) > 0){ // no filter at all
for (int chn = 0; chn < clt_data[iQuad].length; chn++) {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
clt_data[iQuad][chn],
clt_parameters.transform_size,
threadsMax,
......@@ -3812,8 +3830,8 @@ public class QuadCLT {
boolean [][] saturation_imp, // (near) saturated pixels or null
CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters,
ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
// int convolveFFTSize, // 128 - fft size, kernel size should be size/2
double [] scaleExposures, // probably not needed here
......@@ -3846,7 +3864,7 @@ public class QuadCLT {
this.is_mono);
}
ImageDtt image_dtt = new ImageDtt(isMonochrome());
ImageDtt image_dtt = new ImageDtt(isMonochrome(),clt_parameters.getScaleStrength(isAux()));
for (int i = 0; i < double_stacks.length; i++){
if ( double_stacks[i].length > 2) {
for (int j =0 ; j < double_stacks[i][0].length; j++){
......@@ -3880,7 +3898,7 @@ public class QuadCLT {
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
if (clt_parameters.correlate){
if (clt_parameters.correlate){ // true
clt_corr_combo = new double [ImageDtt.TCORR_TITLES.length][tilesY][tilesX][];
texture_tiles = new double [tilesY][tilesX][][]; // ["RGBA".length()][];
for (int i = 0; i < tilesY; i++){
......@@ -3891,14 +3909,14 @@ public class QuadCLT {
texture_tiles[i][j] = null;
}
}
if (!infinity_corr && clt_parameters.corr_keep){
if (!infinity_corr && clt_parameters.corr_keep){ // true
clt_corr_partial = new double [tilesY][tilesX][][][];
for (int i = 0; i < tilesY; i++){
for (int j = 0; j < tilesX; j++){
clt_corr_partial[i][j] = null;
}
}
}
} // clt_parameters.corr_mismatch = false
if (clt_parameters.corr_mismatch || apply_corr || infinity_corr){ // added infinity_corr
clt_mismatch = new double [12][]; // What is 12?
}
......@@ -3936,12 +3954,12 @@ public class QuadCLT {
disparity_map, // [2][tp.tilesY * tp.tilesX]
texture_tiles, // [tp.tilesY][tp.tilesX]["RGBA".length()][];
imp_quad[0].getWidth(), // final int width,
clt_parameters.fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.getFatZero(isMonochrome()), // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_sym,
clt_parameters.corr_offset,
clt_parameters.corr_red,
clt_parameters.corr_blue,
clt_parameters.corr_sigma,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
// clt_parameters.corr_mask,
clt_parameters.corr_normalize, // normalize correlation results by rms
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
......@@ -4255,18 +4273,18 @@ public class QuadCLT {
}
}
}
double [][][] iclt_data = new double [clt_data.length][][];
if (!infinity_corr && (clt_parameters.gen_chn_img || clt_parameters.gen_4_img || clt_parameters.gen_chn_stacks)) {
ImagePlus [] imps_RGB = new ImagePlus[clt_data.length];
// ImagePlus [] imps_RGB = new ImagePlus[clt_data.length];
for (int iQuad = 0; iQuad < clt_data.length; iQuad++){
String title=name+"-"+String.format("%02d", iQuad);
// String title=name+"-"+String.format("%02d", iQuad);
// String titleFull=title+"-SPLIT-D"+clt_parameters.disparity;
if (clt_parameters.corr_sigma > 0){ // no filter at all
if (clt_parameters.getCorrSigma(image_dtt.isMonochrome()) > 0){ // no filter at all
for (int chn = 0; chn < clt_data[iQuad].length; chn++) if (clt_data[iQuad][chn] != null){
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
clt_data[iQuad][chn],
clt_parameters.transform_size,
threadsMax,
......@@ -4296,10 +4314,11 @@ public class QuadCLT {
results[iQuad].getTitle()+"-CLT-D"+clt_parameters.disparity);
}
}
double [][] iclt_data = new double [clt_data[iQuad].length][];
for (int chn=0; chn<iclt_data.length;chn++) if (clt_data[iQuad][chn] != null) {
iclt_data[chn] = image_dtt.iclt_2d(
clt_data[iQuad][chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
iclt_data[iQuad] = new double [clt_data[iQuad].length][];
for (int ncol=0; ncol<iclt_data[iQuad].length;ncol++) if (clt_data[iQuad][ncol] != null) {
iclt_data[iQuad][ncol] = image_dtt.iclt_2d(
clt_data[iQuad][ncol], // scanline representation of dcd data, organized as dct_size x dct_size tiles
clt_parameters.transform_size, // final int
clt_parameters.clt_window, // window_type
15, // clt_parameters.iclt_mask, //which of 4 to transform back
......@@ -4308,31 +4327,61 @@ public class QuadCLT {
debugLevel);
}
if (clt_parameters.gen_chn_stacks) sdfa_instance.showArrays(iclt_data,
if (clt_parameters.gen_chn_stacks) sdfa_instance.showArrays(
// if (clt_parameters.gen_chn_stacks || true) sdfa_instance.showArrays(
iclt_data[iQuad],
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
true,
results[iQuad].getTitle()+"-ICLT-RGB-D"+clt_parameters.disparity);
if (!clt_parameters.gen_chn_img) continue;
} // end of generating shifted channel images
// Use iclt_data here for LWIR autorange
if (colorProcParameters.isLwir() && colorProcParameters.lwir_autorange) {
double rel_low = colorProcParameters.lwir_low;
double rel_high = colorProcParameters.lwir_high;
if (!Double.isNaN(getLwirOffset())) {
rel_low -= getLwirOffset();
rel_high -= getLwirOffset();
}
double [] cold_hot = autorange(
iclt_data, // double [][][] iclt_data, // [iQuad][ncol][i] - normally only [][2][] is non-null
rel_low, // double hard_cold,// matches data, DC (this.lwir_offset) subtracted
rel_high, // double hard_hot, // matches data, DC (this.lwir_offset) subtracted
colorProcParameters.lwir_too_cold, // double too_cold, // pixels per image
colorProcParameters.lwir_too_hot, // double too_hot, // pixels per image
1024); // int num_bins)
if (cold_hot != null) {
if (!Double.isNaN(getLwirOffset())) {
cold_hot[0] += getLwirOffset();
cold_hot[1] += getLwirOffset();
}
}
setColdHot(cold_hot); // will be used for shifted images and for texture tiles
}
ImagePlus [] imps_RGB = new ImagePlus[clt_data.length];
for (int iQuad = 0; iQuad < clt_data.length; iQuad++){
if (!clt_parameters.gen_chn_img) continue;
String title=name+"-"+String.format("%02d", iQuad);
imps_RGB[iQuad] = linearStackToColor(
clt_parameters,
colorProcParameters,
rgbParameters,
title, // String name,
"-D"+clt_parameters.disparity, //String suffix, // such as disparity=...
toRGB,
!this.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
!batch_mode, // true, // boolean saveShowIntermediate, // save/show if set globally
false, // boolean saveShowFinal, // save/show result (color image?)
iclt_data[iQuad],
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
scaleExposures[iQuad], // double scaleExposure, // is it needed?
debugLevel );
}
imps_RGB[iQuad] = linearStackToColor(
clt_parameters,
colorProcParameters,
rgbParameters,
title, // String name,
"-D"+clt_parameters.disparity, //String suffix, // such as disparity=...
toRGB,
!this.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
!batch_mode, // true, // boolean saveShowIntermediate, // save/show if set globally
false, // boolean saveShowFinal, // save/show result (color image?)
iclt_data,
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
scaleExposures[iQuad], // double scaleExposure, // is it needed?
debugLevel );
} // end of generating shifted channel images
if (clt_parameters.gen_chn_img) {
// combine to a sliced color image
int [] slice_seq = {0,1,3,2}; //clockwise
......@@ -4420,6 +4469,112 @@ public class QuadCLT {
}
return rslt;
}
public int [] getLwirHistogram(
double [] data,
double hard_cold,
double hard_hot,
int num_bins) {
int [] hist = new int [num_bins];
double k = num_bins / (hard_hot - hard_cold);
for (double d:data) {
int bin = (int) ((d - hard_cold)*k);
if (bin < 0) bin = 0;
else if (bin >= num_bins) bin = (num_bins -1);
hist[bin]++;
}
return hist;
}
public int [] addHist(
int [] this_hist,
int [] other_hist) {
for (int i = 0; i < this_hist.length; i++) {
this_hist[i] += other_hist[i];
}
return this_hist;
}
// get low/high (soft min/max) from the histogram
// returns value between 0.0 (low histogram limit and 1.0 - high histgram limit
public double getMarginFromHist(
int [] hist, // histogram
double cumul_val, // cummulative number of items to be ignored
boolean high_marg) { // false - find low margin(output ~0.0) , true - find high margin (output ~1.0)
int n = 0;
int n_prev = 0;
int bin;
double s = 1.0 / hist.length;
double v;
if (high_marg) {
for (bin = hist.length -1; bin >= 0; bin--) {
n_prev = n;
n+= hist[bin];
if (n > cumul_val) break;
}
if (n <= cumul_val) {
v = 0.0; // cumul_val > total number of samples
} else {
v = s* (bin + 1 - (cumul_val - n_prev)/(n - n_prev));
}
} else {
for (bin = 0; bin < hist.length; bin++) {
n_prev = n;
n+= hist[bin];
if (n > cumul_val) break;
}
if (n <= cumul_val) {
v = 1.0; // cumul_val > total number of samples
} else {
v = s * (bin + (cumul_val - n_prev)/(n - n_prev));
}
}
return v;
}
public double [] autorange(
double [][][] iclt_data, // [iQuad][ncol][i] - normally only [][2][] is non-null
double hard_cold,// matches data, DC (this.lwir_offset) subtracted
double hard_hot, // matches data, DC (this.lwir_offset) subtracted
double too_cold, // pixels per image
double too_hot, // pixels per image
int num_bins) {
int ncol;
for (ncol = 0; ncol < iclt_data[0].length; ncol++) {
if (iclt_data[0][ncol] != null) break;
}
too_cold *= iclt_data.length;
too_hot *= iclt_data.length;
int [] hist = null;
for (int iQuad = 0; iQuad < iclt_data.length; iQuad++) {
int [] this_hist = getLwirHistogram(
iclt_data[iQuad][ncol], // double [] data,
hard_cold,
hard_hot,
num_bins);
if (hist == null) {
hist = this_hist;
} else {
addHist(
hist,
this_hist);
}
}
double [] rel_lim = {
getMarginFromHist(
hist, // histogram
too_cold, // double cumul_val, // cummulative number of items to be ignored
false), // boolean high_marg)
getMarginFromHist(
hist, // histogram
too_hot, // double cumul_val, // cummulative number of items to be ignored
true)}; // boolean high_marg)
double [] abs_lim = {
rel_lim[0] * (hard_hot - hard_cold) + hard_cold,
rel_lim[1] * (hard_hot - hard_cold) + hard_cold,
};
return abs_lim;
}
// float
public ImagePlus linearStackToColor(
......@@ -4471,6 +4626,8 @@ public class QuadCLT {
}
// double data
public ImagePlus linearStackToColor(
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
......@@ -4505,21 +4662,61 @@ public class QuadCLT {
}
}
if (isLwir()) {
String [] rgb_titles = {"red","green","blue"};
String [] rgba_titles = {"red","green","blue","alpha"};
String [] titles = (alpha == null) ? rgb_titles : rgba_titles;
int num_slices = (alpha == null) ? 3 : 4;
double mn = colorProcParameters.lwir_low;
double mx = colorProcParameters.lwir_high;
double [] cold_hot = getColdHot();
if (cold_hot != null) {
mn = cold_hot[0];
mx = cold_hot[1];
}
double offset = getLwirOffset();
double mn = colorProcParameters.lwir_low - offset;
double mx = colorProcParameters.lwir_high - offset;
if (!Double.isNaN(offset)) {
mn -= offset;
mx -= offset;
}
ThermalColor tc = new ThermalColor(
colorProcParameters.lwir_palette,
mn,
mx,
255.0);
rbg_in = new double [3][iclt_data[green_index].length];
for (int i = 0; i < rbg_in[0].length; i++) {
double [][] rgba = new double [num_slices][];
for (int i = 0; i < 3; i++) rgba[i] = new double [iclt_data[green_index].length];
for (int i = 0; i < rbg_in[green_index].length; i++) {
if (i == 700) {
System.out.println("linearStackToColor(): i="+i);
}
double [] rgb = tc.getRGB(iclt_data[green_index][i]);
rbg_in[0][i] = rgb[0]; // red
rbg_in[1][i] = rgb[2]; // blue
rbg_in[2][i] = rgb[1]; // green
}
rgba[0][i] = rgb[0]; // red
rgba[1][i] = rgb[1]; // green
rgba[2][i] = rgb[2]; // blue
}
if (alpha != null) {
rgba[3] = alpha; // 0..1
}
ImageStack stack = sdfa_instance.makeStack(
rgba, // iclt_data,
width, // (tilesX + 0) * clt_parameters.transform_size,
height, // (tilesY + 0) * clt_parameters.transform_size,
titles, // or use null to get chn-nn slice names
true); // replace NaN with 0.0
ImagePlus imp_rgba = EyesisCorrections.convertRGBAFloatToRGBA32(
stack, // ImageStack stackFloat, //r,g,b,a
name+"ARGB"+suffix, // String title,
0.0, // double r_min,
255.0, // double r_max,
0.0, // double g_min,
255.0, // double g_max,
0.0, // double b_min,
255.0, // double b_max,
0.0, // double alpha_min,
1.0); // double alpha_max)
return imp_rgba;
}
ImageStack stack = sdfa_instance.makeStack(
......@@ -4659,6 +4856,7 @@ public class QuadCLT {
titleFull=name+"-YPrPb"+suffix;
if (debugLevel > 1) System.out.println("Using full stack, including YPbPr");
}
if (alpha_pixels != null){
stack.addSlice("alpha",alpha_pixels);
}
......@@ -5050,11 +5248,9 @@ public class QuadCLT {
saturation_imp, // boolean [][] saturation_imp, // (near) saturated pixels or null
clt_parameters,
debayerParameters,
// nonlinParameters,
colorProcParameters,
channelGainParameters,
rgbParameters,
// convolveFFTSize, // 128 - fft size, kernel size should be size/2
scaleExposures,
threadsMax, // maximal number of threads to launch
updateStatus,
......@@ -5107,7 +5303,7 @@ public class QuadCLT {
this.is_mono);
}
// =================
ImageDtt image_dtt = new ImageDtt(isMonochrome());
ImageDtt image_dtt = new ImageDtt(isMonochrome(),clt_parameters.getScaleStrength(isAux()));
for (int i = 0; i < double_stacks.length; i++){
for (int j =0 ; j < double_stacks[i][0].length; j++){
double_stacks[i][2][j]*=0.5; // Scale green 0.5 to compensate more pixels than R,B
......@@ -5169,12 +5365,12 @@ public class QuadCLT {
disparity_maps[scan_step], // [2][tp.tilesY * tp.tilesX]
null, //texture_tiles, // [tp.tilesY][tp.tilesX]["RGBA".length()][];
imp_quad[0].getWidth(), // final int width,
clt_parameters.fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.getFatZero(isMonochrome()), // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_sym,
clt_parameters.corr_offset,
clt_parameters.corr_red,
clt_parameters.corr_blue,
clt_parameters.corr_sigma,
clt_parameters.getCorrSigma(image_dtt.isMonochrome()),
clt_parameters.corr_normalize, // normalize correlation results by rms
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
......@@ -5298,6 +5494,7 @@ public class QuadCLT {
clt_parameters.ih_min_samples, // 10, // final int hist_min_samples,
clt_parameters.ih_norm_center, // true, // final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
clt_parameters.ly_inf_frac, // 0.5, // final double inf_fraction, // fraction of the weight for the infinity tiles
clt_parameters.ly_right_left, // false // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disp_strength, // scans, // double [][] disp_strength,
null, // double [][] target_disparity, // null or programmed disparity (1 per each 14 entries of scans_14)
......@@ -5506,6 +5703,7 @@ public class QuadCLT {
clt_parameters.ih_min_samples, // 10, // final int hist_min_samples,
clt_parameters.ih_norm_center, // true, // final boolean hist_norm_center, // if there are more tiles that fit than min_samples, replace with
clt_parameters.ly_inf_frac, // 0.5, // final double inf_fraction, // fraction of the weight for the infinity tiles
clt_parameters.ly_right_left, // false // equalize weights of right/left FoV (use with horizon in both halves and gross infinity correction)
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
disp_strength, // scans, // double [][] disp_strength,
null, // double [][] target_disparity, // null or programmed disparity (1 per each 14 entries of scans_14)
......@@ -5689,18 +5887,18 @@ public class QuadCLT {
public void processCLTQuads3d(
boolean adjust_extrinsics,
boolean adjust_poly,
TwoQuadCLT twoQuadCLT, //maybe null in no-rig mode, otherwise may contain rig measurements to be used as infinity ground truth
CLTParameters clt_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
ColorProcParameters colorProcParameters,
CorrectionColorProc.ColorGainsParameters channelGainParameters,
boolean adjust_extrinsics,
boolean adjust_poly,