Commit 57bfb4d6 authored by Andrey Filippov's avatar Andrey Filippov

Implemented/tested full resolution interscene fitting

parent 3f61a6c8
...@@ -37,11 +37,13 @@ import java.util.Set; ...@@ -37,11 +37,13 @@ import java.util.Set;
import com.elphel.imagej.common.GenericJTabbedDialog; import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.common.WindowTools; import com.elphel.imagej.common.WindowTools;
import com.elphel.imagej.correction.CorrectionColorProc;
import com.elphel.imagej.lwir.LwirReaderParameters; import com.elphel.imagej.lwir.LwirReaderParameters;
import com.elphel.imagej.tileprocessor.BiQuadParameters; import com.elphel.imagej.tileprocessor.BiQuadParameters;
import com.elphel.imagej.tileprocessor.ImageDtt; import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.ImageDttParameters; import com.elphel.imagej.tileprocessor.ImageDttParameters;
import com.elphel.imagej.tileprocessor.IntersceneLmaParameters; import com.elphel.imagej.tileprocessor.IntersceneLmaParameters;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
import com.elphel.imagej.tileprocessor.MeasuredLayersFilterParameters; import com.elphel.imagej.tileprocessor.MeasuredLayersFilterParameters;
import com.elphel.imagej.tileprocessor.OpticalFlowParameters; import com.elphel.imagej.tileprocessor.OpticalFlowParameters;
import com.elphel.imagej.tileprocessor.PoleProcessorParameters; import com.elphel.imagej.tileprocessor.PoleProcessorParameters;
...@@ -884,8 +886,10 @@ public class CLTParameters { ...@@ -884,8 +886,10 @@ public class CLTParameters {
public double gpu_sigma_corr_m = 0.15; public double gpu_sigma_corr_m = 0.15;
public double gpu_sigma_log_corr = 3.0; // fill in after testing public double gpu_sigma_log_corr = 3.0; // fill in after testing
public double gpu_sigma_log_corr_m = 3.0; // fill in after testing public double gpu_sigma_log_corr_m = 3.0; // fill in after testing
public double gpu_fatz = 500.0; // was 30 public double gpu_fatz = 2000.0; // 500.0; // was 30
public double gpu_fatz_m = 500.0; // was 30 public double gpu_fatz_m = 2000.0; // 500.0; // was 30
public double gpu_fatz_inter = 10000.0; // There is some artifact (bug or float precision)
public double gpu_fatz_inter_m = 10000.0; //
public boolean gpu_woi = false; // if true - use gpu_woi_tx, ... public boolean gpu_woi = false; // if true - use gpu_woi_tx, ...
public int gpu_woi_tx = 0; public int gpu_woi_tx = 0;
...@@ -946,6 +950,7 @@ public class CLTParameters { ...@@ -946,6 +950,7 @@ public class CLTParameters {
public MeasuredLayersFilterParameters mlfp = new MeasuredLayersFilterParameters(); public MeasuredLayersFilterParameters mlfp = new MeasuredLayersFilterParameters();
public LwirReaderParameters lwir = new LwirReaderParameters(); public LwirReaderParameters lwir = new LwirReaderParameters();
public OpticalFlowParameters ofp = new OpticalFlowParameters(); public OpticalFlowParameters ofp = new OpticalFlowParameters();
public IntersceneMatchParameters imp = new IntersceneMatchParameters();
public IntersceneLmaParameters ilp = new IntersceneLmaParameters(); public IntersceneLmaParameters ilp = new IntersceneLmaParameters();
public InterNoiseParameters inp = new InterNoiseParameters(); public InterNoiseParameters inp = new InterNoiseParameters();
...@@ -953,9 +958,30 @@ public class CLTParameters { ...@@ -953,9 +958,30 @@ public class CLTParameters {
public HashMap<String,Double> infinity_distace_map = new HashMap<String,Double>(); //new one public HashMap<String,Double> infinity_distace_map = new HashMap<String,Double>(); //new one
public static String Z_CORR_PREFIX = "z_corr."; public static String Z_CORR_PREFIX = "z_corr.";
public static String INFINITY_DISTANCE_PREFIX = "infinity_distance."; public static String INFINITY_DISTANCE_PREFIX = "infinity_distance.";
public boolean batch_run = false; // turned on only while running in batch mode public boolean batch_run = false; // turned on only while running in batch mode
// Quick fix to pass these parameters
public ColorProcParameters colorProcParameters;
public ColorProcParameters colorProcParametersAux;
public EyesisCorrectionParameters.RGBParameters rgbParameters;
public void setColorProcParameters(ColorProcParameters colorProcParameters, boolean aux) {
if (aux) {
this.colorProcParametersAux = colorProcParameters;
}else {
this.colorProcParameters = colorProcParameters;
}
}
public void setRGBParameters (EyesisCorrectionParameters.RGBParameters rgbParameters) {
this.rgbParameters =rgbParameters;
}
public EyesisCorrectionParameters.RGBParameters getRGBParameters(){
return rgbParameters;
}
public ColorProcParameters getColorProcParameters(boolean aux) {
return aux? colorProcParametersAux:colorProcParameters;
}
public boolean useGPU() { public boolean useGPU() {
return useGPU(false) || useGPU(true); return useGPU(false) || useGPU(true);
...@@ -981,6 +1007,10 @@ public class CLTParameters { ...@@ -981,6 +1007,10 @@ public class CLTParameters {
return monochrome ? gpu_fatz_m : gpu_fatz; return monochrome ? gpu_fatz_m : gpu_fatz;
} }
public double getGpuFatZeroInter(boolean monochrome) {
return monochrome ? gpu_fatz_inter_m : gpu_fatz_inter;
}
public double getGpuCorrSigma(boolean monochrome) { public double getGpuCorrSigma(boolean monochrome) {
return monochrome ? gpu_sigma_corr_m : gpu_sigma_corr; return monochrome ? gpu_sigma_corr_m : gpu_sigma_corr;
} }
...@@ -1765,6 +1795,8 @@ public class CLTParameters { ...@@ -1765,6 +1795,8 @@ public class CLTParameters {
properties.setProperty(prefix+"gpu_sigma_log_corr_m", this.gpu_sigma_log_corr_m +""); properties.setProperty(prefix+"gpu_sigma_log_corr_m", this.gpu_sigma_log_corr_m +"");
properties.setProperty(prefix+"gpu_fatz", this.gpu_fatz +""); properties.setProperty(prefix+"gpu_fatz", this.gpu_fatz +"");
properties.setProperty(prefix+"gpu_fatz_m", this.gpu_fatz_m +""); properties.setProperty(prefix+"gpu_fatz_m", this.gpu_fatz_m +"");
properties.setProperty(prefix+"gpu_fatz_inter", this.gpu_fatz_inter +"");
properties.setProperty(prefix+"gpu_fatz_inter_m", this.gpu_fatz_inter_m +"");
properties.setProperty(prefix+"gpu_woi", this.gpu_woi +""); properties.setProperty(prefix+"gpu_woi", this.gpu_woi +"");
properties.setProperty(prefix+"gpu_woi_tx", this.gpu_woi_tx +""); properties.setProperty(prefix+"gpu_woi_tx", this.gpu_woi_tx +"");
...@@ -1836,6 +1868,7 @@ public class CLTParameters { ...@@ -1836,6 +1868,7 @@ public class CLTParameters {
poles.setProperties (prefix+"_poles", properties); poles.setProperties (prefix+"_poles", properties);
lwir.setProperties (prefix+"_lwir", properties); lwir.setProperties (prefix+"_lwir", properties);
ofp.setProperties (prefix+"_ofp_", properties); ofp.setProperties (prefix+"_ofp_", properties);
imp.setProperties (prefix+"_imp_", properties);
ilp.setProperties (prefix+"_ilp_", properties); ilp.setProperties (prefix+"_ilp_", properties);
inp.setProperties (prefix+"_inp_", properties); inp.setProperties (prefix+"_inp_", properties);
...@@ -2617,6 +2650,8 @@ public class CLTParameters { ...@@ -2617,6 +2650,8 @@ public class CLTParameters {
if (properties.getProperty(prefix+"gpu_sigma_log_corr_m")!=null) this.gpu_sigma_log_corr_m=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_log_corr_m")); if (properties.getProperty(prefix+"gpu_sigma_log_corr_m")!=null) this.gpu_sigma_log_corr_m=Double.parseDouble(properties.getProperty(prefix+"gpu_sigma_log_corr_m"));
if (properties.getProperty(prefix+"gpu_fatz")!=null) this.gpu_fatz=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz")); if (properties.getProperty(prefix+"gpu_fatz")!=null) this.gpu_fatz=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz"));
if (properties.getProperty(prefix+"gpu_fatz_m")!=null) this.gpu_fatz_m=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz_m")); if (properties.getProperty(prefix+"gpu_fatz_m")!=null) this.gpu_fatz_m=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz_m"));
if (properties.getProperty(prefix+"gpu_fatz_inter")!=null) this.gpu_fatz_inter=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz_inter"));
if (properties.getProperty(prefix+"gpu_fatz_inter_m")!=null) this.gpu_fatz_inter_m=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz_inter_m"));
if (properties.getProperty(prefix+"gpu_woi")!=null) this.gpu_woi=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_woi")); if (properties.getProperty(prefix+"gpu_woi")!=null) this.gpu_woi=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_woi"));
if (properties.getProperty(prefix+"gpu_woi_tx")!=null) this.gpu_woi_tx=Integer.parseInt(properties.getProperty(prefix+"gpu_woi_tx")); if (properties.getProperty(prefix+"gpu_woi_tx")!=null) this.gpu_woi_tx=Integer.parseInt(properties.getProperty(prefix+"gpu_woi_tx"));
...@@ -2692,6 +2727,7 @@ public class CLTParameters { ...@@ -2692,6 +2727,7 @@ public class CLTParameters {
poles.getProperties (prefix+"_poles", properties); poles.getProperties (prefix+"_poles", properties);
lwir.getProperties (prefix+"_lwir", properties); lwir.getProperties (prefix+"_lwir", properties);
ofp.getProperties (prefix+"_ofp_", properties); ofp.getProperties (prefix+"_ofp_", properties);
imp.getProperties (prefix+"_imp_", properties);
ilp.getProperties (prefix+"_ilp_", properties); ilp.getProperties (prefix+"_ilp_", properties);
inp.getProperties (prefix+"_inp_", properties); inp.getProperties (prefix+"_inp_", properties);
} }
...@@ -3695,10 +3731,14 @@ public class CLTParameters { ...@@ -3695,10 +3731,14 @@ public class CLTParameters {
gd.addNumericField("LoG sigma for correlation, mono", this.gpu_sigma_log_corr_m, 4, 6,"pix", gd.addNumericField("LoG sigma for correlation, mono", this.gpu_sigma_log_corr_m, 4, 6,"pix",
"Use LoG filter to reduce dynamic range of the correlation input to fit into float range"); "Use LoG filter to reduce dynamic range of the correlation input to fit into float range");
gd.addNumericField("Fat zero (absolute) for phase correlation of color images", this.gpu_fatz, 4, 6,"", gd.addNumericField("Fat zero (absolute) for intrascene phase correlation of color images", this.gpu_fatz, 4, 6,"",
"Add squared fat zero to the sum of squared amplitudes, color images"); "Add squared fat zero to the sum of squared amplitudes in intrascene mode, color images");
gd.addNumericField("Fat zero (absolute) for phase correlation of monochrome images", this.gpu_fatz_m, 4, 6,"", gd.addNumericField("Fat zero (absolute) for intrascene phase correlation of monochrome images", this.gpu_fatz_m, 4, 6,"",
"Add squared fat zero to the sum of squared amplitudes, monochrome images"); "Add squared fat zero to the sum of squared amplitudes in intrascene mode, monochrome images");
gd.addNumericField("Fat zero (absolute) for interscene phase correlation of color images", this.gpu_fatz_inter, 4, 6,"",
"Add squared fat zero to the sum of squared amplitudes in interscene mode, color images");
gd.addNumericField("Fat zero (absolute) for interscene phase correlation of monochrome images", this.gpu_fatz_inter_m, 4, 6,"",
"Add squared fat zero to the sum of squared amplitudes in interscene mode, monochrome images");
gd.addMessage ("--- GPU WOI selection ---"); gd.addMessage ("--- GPU WOI selection ---");
gd.addCheckbox ("Use following WOI for GPU processing (unchecked - ignore WOI dimensions)", this.gpu_woi); gd.addCheckbox ("Use following WOI for GPU processing (unchecked - ignore WOI dimensions)", this.gpu_woi);
...@@ -3734,6 +3774,9 @@ public class CLTParameters { ...@@ -3734,6 +3774,9 @@ public class CLTParameters {
gd.addTab ("O-Flow", "parameters for the interscene Optical FLow calculations"); gd.addTab ("O-Flow", "parameters for the interscene Optical FLow calculations");
this.ofp.dialogQuestions(gd); this.ofp.dialogQuestions(gd);
gd.addTab ("Inter-Match", "Parameters for full-resolution (no decimation/macrotiles) scene matching");
this.imp.dialogQuestions(gd);
gd.addTab ("Inter-LMA", "parameters for the interscene LMA fitting"); gd.addTab ("Inter-LMA", "parameters for the interscene LMA fitting");
this.ilp.dialogQuestions(gd); this.ilp.dialogQuestions(gd);
...@@ -4541,6 +4584,8 @@ public class CLTParameters { ...@@ -4541,6 +4584,8 @@ public class CLTParameters {
this.gpu_sigma_log_corr_m = gd.getNextNumber(); this.gpu_sigma_log_corr_m = gd.getNextNumber();
this.gpu_fatz = gd.getNextNumber(); this.gpu_fatz = gd.getNextNumber();
this.gpu_fatz_m = gd.getNextNumber(); this.gpu_fatz_m = gd.getNextNumber();
this.gpu_fatz_inter = gd.getNextNumber();
this.gpu_fatz_inter_m = gd.getNextNumber();
this.gpu_woi= gd.getNextBoolean(); this.gpu_woi= gd.getNextBoolean();
this.gpu_woi_tx = (int) gd.getNextNumber(); this.gpu_woi_tx = (int) gd.getNextNumber();
...@@ -4564,6 +4609,7 @@ public class CLTParameters { ...@@ -4564,6 +4609,7 @@ public class CLTParameters {
this.lwir.dialogAnswers(gd); this.lwir.dialogAnswers(gd);
this.ofp.dialogAnswers(gd); this.ofp.dialogAnswers(gd);
this.imp.dialogAnswers(gd);
this.ilp.dialogAnswers(gd); this.ilp.dialogAnswers(gd);
this.inp.dialogAnswers(gd); this.inp.dialogAnswers(gd);
......
...@@ -6621,6 +6621,9 @@ public class Eyesis_Correction implements PlugIn, ActionListener { ...@@ -6621,6 +6621,9 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
QUAD_CLT_AUX.setGPU(GPU_QUAD_AUX); QUAD_CLT_AUX.setGPU(GPU_QUAD_AUX);
} }
} }
CLT_PARAMETERS.setColorProcParameters(COLOR_PROC_PARAMETERS, false);
CLT_PARAMETERS.setColorProcParameters(COLOR_PROC_PARAMETERS_AUX, true);
CLT_PARAMETERS.setRGBParameters(RGB_PARAMETERS);
try { try {
TWO_QUAD_CLT.batchLwirRig(QUAD_CLT, // QuadCLT quadCLT_main, TWO_QUAD_CLT.batchLwirRig(QUAD_CLT, // QuadCLT quadCLT_main,
......
...@@ -85,6 +85,7 @@ public class GPUTileProcessor { ...@@ -85,6 +85,7 @@ public class GPUTileProcessor {
static String GPU_CONVERT_DIRECT_NAME = "convert_direct"; // name in C code static String GPU_CONVERT_DIRECT_NAME = "convert_direct"; // name in C code
static String GPU_IMCLT_ALL_NAME = "imclt_rbg_all"; static String GPU_IMCLT_ALL_NAME = "imclt_rbg_all";
static String GPU_CORRELATE2D_NAME = "correlate2D"; // name in C code static String GPU_CORRELATE2D_NAME = "correlate2D"; // name in C code
static String GPU_CORRELATE2D_INTER_NAME = "correlate2D_inter"; // name in C code
static String GPU_CORR2D_COMBINE_NAME = "corr2D_combine"; // name in C code static String GPU_CORR2D_COMBINE_NAME = "corr2D_combine"; // name in C code
static String GPU_CORR2D_NORMALIZE_NAME = "corr2D_normalize"; // name in C code static String GPU_CORR2D_NORMALIZE_NAME = "corr2D_normalize"; // name in C code
static String GPU_TEXTURES_NAME = "textures_nonoverlap"; // name in C code static String GPU_TEXTURES_NAME = "textures_nonoverlap"; // name in C code
...@@ -163,6 +164,7 @@ public class GPUTileProcessor { ...@@ -163,6 +164,7 @@ public class GPUTileProcessor {
CUfunction GPU_CONVERT_DIRECT_kernel = null; // "convert_direct" CUfunction GPU_CONVERT_DIRECT_kernel = null; // "convert_direct"
CUfunction GPU_IMCLT_ALL_kernel = null; // "imclt_rbg_all" CUfunction GPU_IMCLT_ALL_kernel = null; // "imclt_rbg_all"
CUfunction GPU_CORRELATE2D_kernel = null; // "correlate2D" CUfunction GPU_CORRELATE2D_kernel = null; // "correlate2D"
CUfunction GPU_CORRELATE2D_INTER_kernel = null; // "correlate2D_inter"
CUfunction GPU_CORR2D_COMBINE_kernel = null; // "corr2D_combine" CUfunction GPU_CORR2D_COMBINE_kernel = null; // "corr2D_combine"
CUfunction GPU_CORR2D_NORMALIZE_kernel = null; // "corr2D_normalize"; CUfunction GPU_CORR2D_NORMALIZE_kernel = null; // "corr2D_normalize";
CUfunction GPU_TEXTURES_kernel = null; // "textures_nonoverlap" CUfunction GPU_TEXTURES_kernel = null; // "textures_nonoverlap"
...@@ -314,6 +316,7 @@ public class GPUTileProcessor { ...@@ -314,6 +316,7 @@ public class GPUTileProcessor {
GPU_CONVERT_DIRECT_NAME, GPU_CONVERT_DIRECT_NAME,
GPU_IMCLT_ALL_NAME, GPU_IMCLT_ALL_NAME,
GPU_CORRELATE2D_NAME, GPU_CORRELATE2D_NAME,
GPU_CORRELATE2D_INTER_NAME,
GPU_CORR2D_COMBINE_NAME, GPU_CORR2D_COMBINE_NAME,
GPU_CORR2D_NORMALIZE_NAME, GPU_CORR2D_NORMALIZE_NAME,
GPU_TEXTURES_NAME, GPU_TEXTURES_NAME,
...@@ -337,27 +340,29 @@ public class GPUTileProcessor { ...@@ -337,27 +340,29 @@ public class GPUTileProcessor {
GPU_CONVERT_DIRECT_kernel = functions[0]; GPU_CONVERT_DIRECT_kernel = functions[0];
GPU_IMCLT_ALL_kernel = functions[1]; GPU_IMCLT_ALL_kernel = functions[1];
GPU_CORRELATE2D_kernel = functions[2]; GPU_CORRELATE2D_kernel = functions[2];
GPU_CORR2D_COMBINE_kernel = functions[3]; GPU_CORRELATE2D_INTER_kernel = functions[3];
GPU_CORR2D_NORMALIZE_kernel = functions[4]; GPU_CORR2D_COMBINE_kernel = functions[4];
GPU_TEXTURES_kernel= functions[5]; GPU_CORR2D_NORMALIZE_kernel = functions[5];
GPU_RBGA_kernel= functions[6]; GPU_TEXTURES_kernel= functions[6];
GPU_ROT_DERIV_kernel = functions[7]; GPU_RBGA_kernel= functions[7];
GPU_CALCULATE_TILES_OFFSETS_kernel = functions[8]; GPU_ROT_DERIV_kernel = functions[8];
GPU_CALC_REVERSE_DISTORTION_kernel = functions[9]; GPU_CALCULATE_TILES_OFFSETS_kernel = functions[9];
GPU_CALC_REVERSE_DISTORTION_kernel = functions[10];
// Kernels to use w/o Dynamic Parallelism // Kernels to use w/o Dynamic Parallelism
GPU_CLEAR_TEXTURE_LIST_kernel = functions[10]; GPU_CLEAR_TEXTURE_LIST_kernel = functions[11];
GPU_MARK_TEXTURE_LIST_kernel = functions[11]; GPU_MARK_TEXTURE_LIST_kernel = functions[12];
GPU_MARK_TEXTURE_NEIGHBOR_kernel = functions[12]; GPU_MARK_TEXTURE_NEIGHBOR_kernel = functions[13];
GPU_GEN_TEXTURE_LIST_kernel = functions[13]; GPU_GEN_TEXTURE_LIST_kernel = functions[14];
GPU_CLEAR_TEXTURE_RBGA_kernel = functions[14]; GPU_CLEAR_TEXTURE_RBGA_kernel = functions[15];
GPU_TEXTURES_ACCUMULATE_kernel = functions[15]; GPU_TEXTURES_ACCUMULATE_kernel = functions[16];
GPU_CREATE_NONOVERLAP_LIST_kernel = functions[16]; GPU_CREATE_NONOVERLAP_LIST_kernel = functions[17];
System.out.println("GPU kernel functions initialized"); System.out.println("GPU kernel functions initialized");
System.out.println(GPU_CONVERT_DIRECT_kernel.toString()); System.out.println(GPU_CONVERT_DIRECT_kernel.toString());
System.out.println(GPU_IMCLT_ALL_kernel.toString()); System.out.println(GPU_IMCLT_ALL_kernel.toString());
System.out.println(GPU_CORRELATE2D_kernel.toString()); System.out.println(GPU_CORRELATE2D_kernel.toString());
System.out.println(GPU_CORRELATE2D_INTER_kernel.toString());
System.out.println(GPU_CORR2D_COMBINE_kernel.toString()); System.out.println(GPU_CORR2D_COMBINE_kernel.toString());
System.out.println(GPU_CORR2D_NORMALIZE_kernel.toString()); System.out.println(GPU_CORR2D_NORMALIZE_kernel.toString());
System.out.println(GPU_TEXTURES_kernel.toString()); System.out.println(GPU_TEXTURES_kernel.toString());
......
...@@ -2384,7 +2384,7 @@ public class Correlation2d { ...@@ -2384,7 +2384,7 @@ public class Correlation2d {
* @return argmax() relative to the tile center * @return argmax() relative to the tile center
*/ */
public double [] getMaxXYCm( // not used in lwir public static double [] getMaxXYCm( // not used in lwir
double [] data, double [] data,
int data_width, // = 2 * transform_size - 1; int data_width, // = 2 * transform_size - 1;
int center_row, int center_row,
...@@ -2411,6 +2411,72 @@ public class Correlation2d { ...@@ -2411,6 +2411,72 @@ public class Correlation2d {
return rslt; return rslt;
} }
public static double [] getMaxXYCm(
double [] data,
int data_width, // = 2 * transform_size - 1;
double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad)
int refine, // re-center window around new maximum. 0 -no refines (single-pass)
boolean debug)
{
int data_height = data.length/data_width;
int center_xy = (data_width - 1)/2; // = transform_size - 1;
double x0 = center_xy, y0 = center_xy;
int imax= 0;
for (int i= 1; i < data.length;i++) {
if (data[i] > data[imax]) {
imax = i;
}
}
double mx = data[imax];
x0 = imax % data_width;
y0 = imax / data_width;
//calculate as "center of mass"
if (radius == 0) {
double s0 = 0, sx=0,sy = 0;
for (int iy = 0; iy < data_height; iy++) {
double y = iy - y0;
for (int ix = 0; ix < data_width; ix++) {
double x = ix - x0;
double d = data[iy * data_width + ix];
s0 += d;
sx += d * x;
sy += d * y;
}
}
x0 += sx / s0;
y0 += sy / s0;
} else {
double radius2 = radius*radius;
for (int nref = 0; nref <= refine; nref++) {
double s0 = 0, sx=0,sy = 0;
for (int iy = 0; iy < data_height; iy++) {
double y = iy - y0;
for (int ix = 0; ix < data_width; ix++) {
double x = ix - x0;
double r2= x*x + y*y;
if (r2 < radius2) {
double r = Math.sqrt(r2);
double d = data[iy * data_width + ix];
d *= Math.cos(0.5*Math.PI*r/radius);
s0 += d;
sx += d * x;
sy += d * y;
}
}
}
x0 += sx / s0;
y0 += sy / s0;
}
}
double [] rslt = {x0 - center_xy, y0 - center_xy, mx};
if (debug){
System.out.println("getMaxXYCm() -> "+rslt[0]+":"+rslt[1]);
}
return rslt;
}
/** /**
* Analyze 1d correlation (single centerline of the 3D phase correlation combined output * Analyze 1d correlation (single centerline of the 3D phase correlation combined output
* from all pairs or only diameters to detect double maximum (simultaneous FG+BG) * from all pairs or only diameters to detect double maximum (simultaneous FG+BG)
......
...@@ -89,33 +89,44 @@ public class IntersceneLma { ...@@ -89,33 +89,44 @@ public class IntersceneLma {
} }
public String [] printOldNew(boolean allvectors) { public String [] printOldNew(boolean allvectors) {
return printOldNew(allvectors, 8, 5); return printOldNew(allvectors, 9, 6);
} }
public String [] printOldNew(boolean allvectors, int w, int d) { public String [] printOldNew(boolean allvectors, int w, int d) {
String fmt1 = String.format("%%%d.%df", w,d); String fmt1 = String.format("%%%d.%df", w+2,d+2); // more for the differences
ArrayList<String> lines = new ArrayList<String>(); ArrayList<String> lines = new ArrayList<String>();
for (int n = ErsCorrection.DP_DVAZ; n < ErsCorrection.DP_NUM_PARS; n+=3) { for (int n = ErsCorrection.DP_DVAZ; n < ErsCorrection.DP_NUM_PARS; n+=3) {
boolean adj = false; boolean adj = false;
for (int i = 0; i <3; i++) adj |= par_mask[n+i]; for (int i = 0; i <3; i++) adj |= par_mask[n+i];
if (allvectors || adj) { if (allvectors || adj) {
String line = printNameV3(n, false, w,d)+" (was "+printNameV3(n, true, w,d)+")"; String line = printNameV3(n, false, w,d)+" (was "+printNameV3(n, true, w,d)+")";
line += ", diff="+String.format(fmt1, getV3Diff(n)); line += ", diff_last="+String.format(fmt1, getV3Diff(n)[0]);
line += ", diff_first="+String.format(fmt1, getV3Diff(n)[1]);
lines.add(line); lines.add(line);
} }
} }
return lines.toArray(new String[lines.size()]); return lines.toArray(new String[lines.size()]);
} }
public double getV3Diff(int indx) { /**
double [] v_new = new double[3], v_old = new double[3]; * Calculate L2 for 3-vector difference between the adjusted values, this LMA start values
* and "backup" parameters - snapshot before the first adjustment (first calculation of
* the motion vectors+LMA iteration
* @param indx offset to the first element of the 3-vector in the full parameters array
* @return a pair of L2 differences {diff_with_this_LMA_start, diff_with_first_lma_start}
*/
public double [] getV3Diff(int indx) {
double [] v_new = new double[3], v_backup = new double[3], v_start = new double[3];
System.arraycopy(getFullVector(parameters_vector), indx, v_new, 0, 3); System.arraycopy(getFullVector(parameters_vector), indx, v_new, 0, 3);
System.arraycopy(backup_parameters_full, indx, v_old, 0, 3); System.arraycopy(backup_parameters_full, indx, v_backup, 0, 3);
double l2 = 0; System.arraycopy(parameters_full, indx, v_start, 0, 3);
double l2_backup = 0;
double l2_start = 0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
l2 += (v_new[i]-v_old[i]) * (v_new[i]-v_old[i]); l2_backup += (v_new[i]-v_backup[i]) * (v_new[i]-v_backup[i]);
l2_start += (v_new[i]-v_start[i]) * (v_new[i]-v_start[i]);
} }
return Math.sqrt(l2); return new double [] {Math.sqrt(l2_start), Math.sqrt(l2_backup)};
} }
public String printNameV3(int indx, boolean initial, int w, int d) { public String printNameV3(int indx, boolean initial, int w, int d) {
...@@ -129,7 +140,7 @@ public class IntersceneLma { ...@@ -129,7 +140,7 @@ public class IntersceneLma {
} }
public static String printNameV3(String name, double[] vector) { public static String printNameV3(String name, double[] vector) {
return printNameV3(name, vector, 8, 5); return printNameV3(name, vector, 10, 6);
} }
public static String printNameV3(String name, double[] vector, int w, int d) { public static String printNameV3(String name, double[] vector, int w, int d) {
...@@ -296,15 +307,17 @@ public class IntersceneLma { ...@@ -296,15 +307,17 @@ public class IntersceneLma {
if (show_intermediate && (debug_level > 0)) { if (show_intermediate && (debug_level > 0)) {
System.out.println("LMA: full RMS="+last_rms[0]+" ("+initial_rms[0]+"), pure RMS="+last_rms[1]+" ("+initial_rms[1]+") + lambda="+lambda); System.out.println("LMA: full RMS="+last_rms[0]+" ("+initial_rms[0]+"), pure RMS="+last_rms[1]+" ("+initial_rms[1]+") + lambda="+lambda);
} }
String [] lines1 = printOldNew(false); // boolean allvectors) if (debug_level > 2){
System.out.print("iteration="+iter); String [] lines1 = printOldNew(false); // boolean allvectors)
for (String line : lines1) { System.out.println("iteration="+iter);
System.out.println(line); for (String line : lines1) {
System.out.println(line);
}
} }
if (debug_level > 0) { if (debug_level > 0) {
if ((debug_level > 1) || (iter == 1) || last_run) { if ((debug_level > 1) || last_run) { // (iter == 1) || last_run) {
if (!show_intermediate) { if (!show_intermediate) {
System.out.println("LMA: full RMS="+last_rms[0]+" ("+initial_rms[0]+"), pure RMS="+last_rms[1]+" ("+initial_rms[1]+") + lambda="+lambda); System.out.println("LMA: iter="+iter+", full RMS="+last_rms[0]+" ("+initial_rms[0]+"), pure RMS="+last_rms[1]+" ("+initial_rms[1]+") + lambda="+lambda);
} }
String [] lines = printOldNew(false); // boolean allvectors) String [] lines = printOldNew(false); // boolean allvectors)
for (String line : lines) { for (String line : lines) {
...@@ -676,7 +689,11 @@ public class IntersceneLma { ...@@ -676,7 +689,11 @@ public class IntersceneLma {
} }
/**
* Combine unmodified parameters with these ones, using parameters mask
* @param vector variable-length adjustable vector, corresponding to a parameter mask
* @return full parameters vector combining adjusted and fixed parameters
*/
private double [] getFullVector(double [] vector) { private double [] getFullVector(double [] vector) {
double [] full_vector = parameters_full.clone(); double [] full_vector = parameters_full.clone();
for (int i = 0; i < par_indices.length; i++) { for (int i = 0; i < par_indices.length; i++) {
......
...@@ -923,7 +923,7 @@ public class MultisceneLY { ...@@ -923,7 +923,7 @@ public class MultisceneLY {
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
tp_tasks_scenes[nscene], // *** will be updated inside from GPU-calculated geometry tp_tasks_scenes[nscene], // *** will be updated inside from GPU-calculated geometry
fcorr_td, // fcorrs_td[nscene], // [tilesY][tilesX][pair][4*64] transform domain representation of 6 corr pairs fcorr_td, // fcorrs_td[nscene], // [tilesY][tilesX][pair][4*64] transform domain representation of 6 corr pairs
scene_gc, // // scene_gc, //
clt_parameters.gpu_sigma_r, // 0.9, 1.1 clt_parameters.gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // 0.9, 1.1 clt_parameters.gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // 0.6, 0.7 clt_parameters.gpu_sigma_g, // 0.6, 0.7
...@@ -1045,7 +1045,7 @@ public class MultisceneLY { ...@@ -1045,7 +1045,7 @@ public class MultisceneLY {
clt_parameters.tileY, // final int debug_tileY, clt_parameters.tileY, // final int debug_tileY,
threadsMax, // final int threadsMax, // maximal number of threads to launch threadsMax, // final int threadsMax, // maximal number of threads to launch
debug_level + 2); // -1 ); // final int globalDebugLevel) debug_level + 2); // -1 ); // final int globalDebugLevel)
image_dtt.convertFcltCorr( ImageDtt.convertFcltCorr(
dcorr_tiles, // double [][][] dcorr_tiles,// [tile][sparse, correlation pair][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate dcorr_tiles, // double [][][] dcorr_tiles,// [tile][sparse, correlation pair][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
fclt_corr); // float [][][] fclt_corr) // new float [tilesX * tilesY][][] or null fclt_corr); // float [][][] fclt_corr) // new float [tilesX * tilesY][][] or null
......
...@@ -1869,6 +1869,89 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -1869,6 +1869,89 @@ public class QuadCLT extends QuadCLTCPU {
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")"); IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
} }
public ImagePlus renderFromTD (
CLTParameters clt_parameters,
ColorProcParameters colorProcParameters,
EyesisCorrectionParameters.RGBParameters rgbParameters,
boolean toRGB,
boolean use_reference
) {
gpuQuad.execImcltRbgAll(isMonochrome(), use_reference); // add ref
// get data back from GPU
float [][][] iclt_fimg = new float [getNumSensors()][][];
for (int ncam = 0; ncam < iclt_fimg.length; ncam++) {
iclt_fimg[ncam] = gpuQuad.getRBG(ncam);
}
int out_width = gpuQuad.getImageWidth();// + gpuQuad.getDttSize(); // 2022/05/12 removed margins from gpuQuad.getRBG(ncam);
int out_height = gpuQuad.getImageHeight(); // + gpuQuad.getDttSize(); // 2022/05/12 removed margins from gpuQuad.getRBG(ncam);
if (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_fimg, // 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
}
/* Prepare 4-channel images*/
ImagePlus [] imps_RGB = new ImagePlus[iclt_fimg.length];
for (int ncam = 0; ncam < iclt_fimg.length; ncam++) {
String title=String.format("%s%s-%02d",image_name, sAux(), ncam);
imps_RGB[ncam] = linearStackToColor( // probably no need to separate and process the second half with quadCLT_aux (!)
clt_parameters,
colorProcParameters,
rgbParameters,
title, // String name,
"-D"+clt_parameters.disparity, //String suffix, // such as disparity=...
toRGB,
!correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
false, // true, // boolean saveShowIntermediate, // save/show if set globally
false, // boolean saveShowFinal, // save/show result (color image?)
iclt_fimg[ncam],
out_width,
out_height,
1.0, // scaleExposures[iAux][iSubCam], // double scaleExposure, // is it needed?
-1); // debugLevel );
}
// combine to a sliced color image
int [] slice_seq = {0,1,3,2}; //clockwise
if (imps_RGB.length > 4) {
slice_seq = new int [imps_RGB.length];
for (int i = 0; i < slice_seq.length; i++) {
slice_seq[i] = i;
}
}
int width = imps_RGB[0].getWidth();
int height = imps_RGB[0].getHeight();
ImageStack array_stack=new ImageStack(width,height);
for (int i = 0; i<slice_seq.length; i++){
/// if (imps_RGB[slice_seq[i]] != null) {
array_stack.addSlice("port_"+slice_seq[i], imps_RGB[slice_seq[i]].getProcessor().getPixels());
/// } else {
/// array_stack.addSlice("port_"+slice_seq[i], results[slice_seq[i]].getProcessor().getPixels());
/// }
}
ImagePlus imp_stack = new ImagePlus(image_name+sAux()+"GPU-SHIFTED-D"+clt_parameters.disparity, array_stack);
imp_stack.getProcessor().resetMinAndMax();
return imp_stack;
}
public ImagePlus processCLTQuadCorrGPU( public ImagePlus processCLTQuadCorrGPU(
...@@ -2459,20 +2542,20 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -2459,20 +2542,20 @@ public class QuadCLT extends QuadCLTCPU {
}; };
quadCLT_main.getGPU().setLpfRbg( // constants memory - same for all cameras quadCLT_main.getGPU().setLpfRbg( // constants memory - same for all cameras
lpf_rgb, lpf_rgb,
debugLevel > -1); // -3 debugLevel > 2); // -3
float [] lpf_flat = image_dtt.floatGetCltLpfFd(clt_parameters.getGpuCorrSigma(is_mono)); float [] lpf_flat = image_dtt.floatGetCltLpfFd(clt_parameters.getGpuCorrSigma(is_mono));
quadCLT_main.getGPU().setLpfCorr(// constants memory - same for all cameras quadCLT_main.getGPU().setLpfCorr(// constants memory - same for all cameras
"lpf_corr", // String const_name, // "lpf_corr" "lpf_corr", // String const_name, // "lpf_corr"
lpf_flat, lpf_flat,
debugLevel > -1); // -3 debugLevel > 2); // -3
float [] lpf_rb_flat = image_dtt.floatGetCltLpfFd(clt_parameters.getGpuCorrRBSigma(is_mono)); float [] lpf_rb_flat = image_dtt.floatGetCltLpfFd(clt_parameters.getGpuCorrRBSigma(is_mono));
quadCLT_main.getGPU().setLpfCorr(// constants memory - same for all cameras quadCLT_main.getGPU().setLpfCorr(// constants memory - same for all cameras
"lpf_rb_corr", // String const_name, // "lpf_corr" "lpf_rb_corr", // String const_name, // "lpf_corr"
lpf_rb_flat, lpf_rb_flat,
debugLevel > -1); // -3 debugLevel > 2); // -3
final boolean use_aux = false; // currently GPU is configured for a single quad camera final boolean use_aux = false; // currently GPU is configured for a single quad camera
......
...@@ -6914,7 +6914,7 @@ public class QuadCLTCPU { ...@@ -6914,7 +6914,7 @@ public class QuadCLTCPU {
float [] alpha = null; // (0..1.0) float [] alpha = null; // (0..1.0)
if (iclt_data.length > 3) alpha = iclt_data[3]; if (iclt_data.length > 3) alpha = iclt_data[3];
if (isLwir()) { if (isLwir()) {
if (colorProcParameters.lwir_pseudocolor) { if (!colorProcParameters.lwir_pseudocolor) {
ImageProcessor ip= new FloatProcessor(width,height); ImageProcessor ip= new FloatProcessor(width,height);
ip.setPixels(iclt_data[0]); ip.setPixels(iclt_data[0]);
ip.resetMinAndMax(); ip.resetMinAndMax();
...@@ -7040,7 +7040,7 @@ public class QuadCLTCPU { ...@@ -7040,7 +7040,7 @@ public class QuadCLTCPU {
} }
} }
if (isLwir()) { if (isLwir()) {
if (colorProcParameters.lwir_pseudocolor) { if (!colorProcParameters.lwir_pseudocolor) {
ImageProcessor ip= new FloatProcessor(width,height); ImageProcessor ip= new FloatProcessor(width,height);
float [] pixels = new float [iclt_data[0].length]; float [] pixels = new float [iclt_data[0].length];
for (int i = 0; i < pixels.length; i++) { for (int i = 0; i < pixels.length; i++) {
...@@ -12938,7 +12938,6 @@ public class QuadCLTCPU { ...@@ -12938,7 +12938,6 @@ public class QuadCLTCPU {
int mcorr_sel = save_corr ? Correlation2d.corrSelEncode(clt_parameters.img_dtt, getNumSensors()) : 0; int mcorr_sel = save_corr ? Correlation2d.corrSelEncode(clt_parameters.img_dtt, getNumSensors()) : 0;
TpTask[] tp_tasks = GpuQuad.setTasks( // null on geometryCorrection TpTask[] tp_tasks = GpuQuad.setTasks( // null on geometryCorrection
num_sensors, // final int num_cams, num_sensors, // final int num_cams,
// image_dtt.getTransformSize(), // final int transform_size,
disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
disparity_corr, // final double disparity_corr, disparity_corr, // final double disparity_corr,
tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
...@@ -12953,7 +12952,7 @@ public class QuadCLTCPU { ...@@ -12953,7 +12952,7 @@ public class QuadCLTCPU {
double [][][][][] clt_data = null; double [][][][][] clt_data = null;
double [] tile_corr_weights = null; double [] tile_corr_weights = null;
double[][] dbg_tilts = null; double[][] dbg_tilts = null;
final double gpu_sigma_corr = clt_parameters.getGpuCorrSigma(isMonochrome()); final double gpu_sigma_corr = clt_parameters.getGpuCorrSigma(isMonochrome());
final double gpu_sigma_rb_corr = isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr; final double gpu_sigma_rb_corr = isMonochrome()? 1.0 : clt_parameters.gpu_sigma_rb_corr;
...@@ -12967,7 +12966,6 @@ public class QuadCLTCPU { ...@@ -12967,7 +12966,6 @@ public class QuadCLTCPU {
// set tasks for all non-NaN target disparities // set tasks for all non-NaN target disparities
TpTask [] tp_tasks_target = GpuQuad.setTasks( TpTask [] tp_tasks_target = GpuQuad.setTasks(
num_sensors, // final int num_cams, num_sensors, // final int num_cams,
// image_dtt.getTransformSize(), // final int transform_size,
disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity disparity_array, // final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
disparity_corr, // final double disparity_corr, disparity_corr, // final double disparity_corr,
null, // tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile null, // tile_op, // final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
...@@ -13025,7 +13023,7 @@ public class QuadCLTCPU { ...@@ -13025,7 +13023,7 @@ public class QuadCLTCPU {
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
tp_tasks, // *** will be updated inside from GPU-calculated geometry tp_tasks, // *** will be updated inside from GPU-calculated geometry
fcorr_td, // fcorrs_td[nscene], // [tilesY][tilesX][pair][4*64] transform domain representation of 6 corr pairs fcorr_td, // fcorrs_td[nscene], // [tilesY][tilesX][pair][4*64] transform domain representation of 6 corr pairs
geometryCorrection, // // geometryCorrection, //
clt_parameters.gpu_sigma_r, // 0.9, 1.1 clt_parameters.gpu_sigma_r, // 0.9, 1.1
clt_parameters.gpu_sigma_b, // 0.9, 1.1 clt_parameters.gpu_sigma_b, // 0.9, 1.1
clt_parameters.gpu_sigma_g, // 0.6, 0.7 clt_parameters.gpu_sigma_g, // 0.6, 0.7
...@@ -13208,7 +13206,7 @@ public class QuadCLTCPU { ...@@ -13208,7 +13206,7 @@ public class QuadCLTCPU {
new String[] {"tiltX","tiltY","center","weight"}); new String[] {"tiltX","tiltY","center","weight"});
} }
float [][][] fclt_corr = new float [dcorr_tiles.length][][]; // dcorr_tiles== null float [][][] fclt_corr = new float [dcorr_tiles.length][][]; // dcorr_tiles== null
image_dtt.convertFcltCorr( ImageDtt.convertFcltCorr(
dcorr_tiles, // double [][][] dcorr_tiles,// [tile][sparse, correlation pair][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate dcorr_tiles, // double [][][] dcorr_tiles,// [tile][sparse, correlation pair][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
fclt_corr); // float [][][] fclt_corr) // new float [tilesX * tilesY][][] or null fclt_corr); // float [][][] fclt_corr) // new float [tilesX * tilesY][][] or null
float [][] dbg_corr_rslt_partial = ImageDtt.corr_partial_dbg( // not used in lwir float [][] dbg_corr_rslt_partial = ImageDtt.corr_partial_dbg( // not used in lwir
...@@ -13222,7 +13220,6 @@ public class QuadCLTCPU { ...@@ -13222,7 +13220,6 @@ public class QuadCLTCPU {
threadsMax, // final int threadsMax, // maximal number of threads to launch threadsMax, // final int threadsMax, // maximal number of threads to launch
debugLevel); // final int globalDebugLevel) debugLevel); // final int globalDebugLevel)
// String [] titles_ind_corr = image_dtt.getCorrelation2d().getCorrTitles();
String [] titles = new String [dbg_corr_rslt_partial.length]; // dcorr_tiles[0].length]; String [] titles = new String [dbg_corr_rslt_partial.length]; // dcorr_tiles[0].length];
int ind_length = image_dtt.getCorrelation2d().getCorrTitles().length; int ind_length = image_dtt.getCorrelation2d().getCorrTitles().length;
......
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