Commit c8348852 authored by Andrey Filippov's avatar Andrey Filippov

correcting extrinsics after being changed

parent 79689dc1
......@@ -55,7 +55,7 @@ public class EyesisCorrectionParameters {
public boolean blueProc = true;
public boolean toRGB = true;
public boolean rotate = true;
public boolean crop = true; // crop to the sennor size
public boolean crop = true; // crop to the sensor size
public int equirectangularFormat= 0; // 0 - 8 bit RGBA, 1 - 16 bit RGBA, 2 (32 int or 16 float!) ?, 3 - 32-bit FP RGBA. only 0, 1 and 3 currently supported
public double outputRangeInt= 0.25; // 1.0 intensity will be mapped to 65535*0.25
public double outputRangeFP= 255.0; // 1.0 intensity will be saved as 255.0 (in float 32-bit mode)
......@@ -2004,11 +2004,24 @@ public class EyesisCorrectionParameters {
public double fine_corr_x_3 = 0.0; // additionally shift image in port 3 in x direction
public double fine_corr_y_3 = 0.0; // additionally shift image in port 3 in y direction
public double fcorr_min_stength = 0.005; // minimal correlation strength to apply fine correction
public double fcorr_disp_diff = 3.0; // consider only tiles with absolute residual disparity lower than
public double fcorr_min_strength = 0.15 ; // 0.005 minimal correlation strength to apply fine correction
public double fcorr_disp_diff = 1.5; // consider only tiles with absolute residual disparity lower than
public boolean fcorr_quadratic = true; // Use quadratic polynomial for fine correction (false - only linear)
public boolean fcorr_ignore = false; // Ignore currently calculated fine correction
public double fcorr_inf_strength = 0.20 ; // Minimal correlation strength to use for infinity correction
public double fcorr_inf_diff = 0.2; // Disparity half-range for infinity
public boolean fcorr_inf_quad = true; // Use quadratic polynomial for infinity correction (false - only linear)
public boolean fcorr_inf_vert = false; // Correct infinity in vertical direction (false - only horizontal)
public int fcorr_sample_size = 32; // Use square this size side to detect outliers
public int fcorr_mintiles = 8; // Keep tiles only if there are more in each square
public double fcorr_reloutliers = 0.5; // Remove this fraction of tiles from each sample
public double fcorr_sigma = 20.0; // Gaussian blur channel mismatch data
public double corr_magic_scale = 0.85; // reported correlation offset vs. actual one (not yet understood)
// 3d reconstruction
......@@ -2366,6 +2379,9 @@ public class EyesisCorrectionParameters {
public double taDiffPwr = 0.25; // Strength power when calculating disparity error
public double taBestPwr = 0.0; // Strength power when calculating disparity error over best
public double taDiff9Pwr = 0.5; // Strength power when calculating disparity error for group of 9
public double taColSigma = 1.5; // Gaussian sigma to blur color difference between tiles along each direction
public double taColFraction = 0.3; // Relative amount of the blurred color difference in the mixture
public double taCostEmpty = 1.0; // Cost of a tile that is not assigned
public double taCostNoLink = 1.0; // Cost of a tile not having any neighbor in particular direction
......@@ -2499,11 +2515,21 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"fine_corr_x_3", this.fine_corr_x_3 +"");
properties.setProperty(prefix+"fine_corr_y_3", this.fine_corr_y_3 +"");
properties.setProperty(prefix+"fcorr_min_stength",this.fcorr_min_stength +"");
properties.setProperty(prefix+"fcorr_min_strength",this.fcorr_min_strength +"");
properties.setProperty(prefix+"fcorr_disp_diff", this.fcorr_disp_diff +"");
properties.setProperty(prefix+"fcorr_quadratic", this.fcorr_quadratic+"");
properties.setProperty(prefix+"fcorr_ignore", this.fcorr_ignore+"");
properties.setProperty(prefix+"fcorr_inf_strength",this.fcorr_inf_strength +"");
properties.setProperty(prefix+"fcorr_inf_diff", this.fcorr_inf_diff +"");
properties.setProperty(prefix+"fcorr_inf_quad", this.fcorr_inf_quad+"");
properties.setProperty(prefix+"fcorr_inf_vert", this.fcorr_inf_vert+"");
properties.setProperty(prefix+"fcorr_sample_size",this.fcorr_sample_size+"");
properties.setProperty(prefix+"fcorr_mintiles", this.fcorr_mintiles+"");
properties.setProperty(prefix+"fcorr_reloutliers",this.fcorr_reloutliers +"");
properties.setProperty(prefix+"fcorr_sigma", this.fcorr_sigma +"");
properties.setProperty(prefix+"corr_magic_scale", this.corr_magic_scale +"");
properties.setProperty(prefix+"show_textures", this.show_textures+"");
......@@ -2830,6 +2856,8 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"taDiffPwr", this.taDiffPwr +"");
properties.setProperty(prefix+"taBestPwr", this.taBestPwr +"");
properties.setProperty(prefix+"taDiff9Pwr", this.taDiff9Pwr +"");
properties.setProperty(prefix+"taColSigma", this.taColSigma +"");
properties.setProperty(prefix+"taColFraction", this.taColFraction +"");
properties.setProperty(prefix+"taCostEmpty", this.taCostEmpty +"");
properties.setProperty(prefix+"taCostNoLink", this.taCostNoLink +"");
......@@ -2957,10 +2985,21 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"fine_corr_x_3")!=null) this.fine_corr_x_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_x_3"));
if (properties.getProperty(prefix+"fine_corr_y_3")!=null) this.fine_corr_y_3=Double.parseDouble(properties.getProperty(prefix+"fine_corr_y_3"));
if (properties.getProperty(prefix+"fcorr_min_stength")!=null) this.fcorr_min_stength=Double.parseDouble(properties.getProperty(prefix+"fcorr_min_stength"));
if (properties.getProperty(prefix+"fcorr_min_strength")!=null) this.fcorr_min_strength=Double.parseDouble(properties.getProperty(prefix+"fcorr_min_strength"));
if (properties.getProperty(prefix+"fcorr_disp_diff")!=null) this.fcorr_disp_diff=Double.parseDouble(properties.getProperty(prefix+"fcorr_disp_diff"));
if (properties.getProperty(prefix+"fcorr_quadratic")!=null) this.fcorr_quadratic=Boolean.parseBoolean(properties.getProperty(prefix+"fcorr_quadratic"));
if (properties.getProperty(prefix+"fcorr_ignore")!=null) this.fcorr_ignore=Boolean.parseBoolean(properties.getProperty(prefix+"fcorr_ignore"));
if (properties.getProperty(prefix+"fcorr_inf_strength")!=null) this.fcorr_inf_strength=Double.parseDouble(properties.getProperty(prefix+"fcorr_inf_strength"));
if (properties.getProperty(prefix+"fcorr_inf_diff")!=null) this.fcorr_inf_diff=Double.parseDouble(properties.getProperty(prefix+"fcorr_inf_diff"));
if (properties.getProperty(prefix+"fcorr_inf_quad")!=null) this.fcorr_inf_quad=Boolean.parseBoolean(properties.getProperty(prefix+"fcorr_inf_quad"));
if (properties.getProperty(prefix+"fcorr_inf_vert")!=null) this.fcorr_inf_vert=Boolean.parseBoolean(properties.getProperty(prefix+"fcorr_inf_vert"));
if (properties.getProperty(prefix+"fcorr_sample_size")!=null) this.fcorr_sample_size=Integer.parseInt(properties.getProperty(prefix+"fcorr_sample_size"));
if (properties.getProperty(prefix+"fcorr_mintiles")!=null) this.fcorr_mintiles=Integer.parseInt(properties.getProperty(prefix+"fcorr_mintiles"));
if (properties.getProperty(prefix+"fcorr_reloutliers")!=null) this.fcorr_reloutliers=Double.parseDouble(properties.getProperty(prefix+"fcorr_reloutliers"));
if (properties.getProperty(prefix+"fcorr_sigma")!=null) this.fcorr_sigma=Double.parseDouble(properties.getProperty(prefix+"fcorr_sigma"));
if (properties.getProperty(prefix+"corr_magic_scale")!=null) this.corr_magic_scale=Double.parseDouble(properties.getProperty(prefix+"corr_magic_scale"));
if (properties.getProperty(prefix+"show_textures")!=null) this.show_textures=Boolean.parseBoolean(properties.getProperty(prefix+"show_textures"));
......@@ -3287,6 +3326,8 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"taDiffPwr")!=null) this.taDiffPwr=Double.parseDouble(properties.getProperty(prefix+"taDiffPwr"));
if (properties.getProperty(prefix+"taBestPwr")!=null) this.taBestPwr=Double.parseDouble(properties.getProperty(prefix+"taBestPwr"));
if (properties.getProperty(prefix+"taDiff9Pwr")!=null) this.taDiff9Pwr=Double.parseDouble(properties.getProperty(prefix+"taDiff9Pwr"));
if (properties.getProperty(prefix+"taColSigma")!=null) this.taDiff9Pwr=Double.parseDouble(properties.getProperty(prefix+"taColSigma"));
if (properties.getProperty(prefix+"taColFraction")!=null) this.taColFraction=Double.parseDouble(properties.getProperty(prefix+"taColFraction"));
if (properties.getProperty(prefix+"taCostEmpty")!=null) this.taCostEmpty=Double.parseDouble(properties.getProperty(prefix+"taCostEmpty"));
if (properties.getProperty(prefix+"taCostNoLink")!=null) this.taCostNoLink=Double.parseDouble(properties.getProperty(prefix+"taCostNoLink"));
......@@ -3429,10 +3470,21 @@ public class EyesisCorrectionParameters {
gd.addNumericField("X 3", this.fine_corr_x_3, 3);
gd.addNumericField("Y 4", this.fine_corr_y_3, 3);
gd.addNumericField("Minimal correlation strength to apply fine correction", this.fcorr_min_stength, 3);
gd.addNumericField("Minimal correlation strength to apply fine correction", this.fcorr_min_strength,3);
gd.addNumericField("Consider only tiles with absolute residual disparity lower than", this.fcorr_disp_diff, 3);
gd.addCheckbox ("Use quadratic polynomial for fine correction (false - only linear)", this.fcorr_quadratic);
gd.addCheckbox ("Ignore current calculated fine correction (use manual only)", this.fcorr_ignore);
gd.addNumericField("Minimal correlation strength to use for infinity correction", this.fcorr_inf_strength,3);
gd.addNumericField("Disparity half-range for infinity", this.fcorr_inf_diff, 3);
gd.addCheckbox ("Use quadratic polynomial for infinity correction (false - only linear)", this.fcorr_inf_quad);
gd.addCheckbox ("Correct infinity in vertical direction (false - only horizontal)", this.fcorr_inf_vert);
gd.addNumericField("Use square this size side to detect outliers", this.fcorr_sample_size, 0);
gd.addNumericField("Keep tiles only if there are more in each square", this.fcorr_mintiles, 0);
gd.addNumericField("Remove this fraction of tiles from each sample", this.fcorr_reloutliers, 3);
gd.addNumericField("Gaussian blur channel mismatch data", this.fcorr_sigma, 3);
gd.addNumericField("Calculated from correlation offset vs. actual one (not yet understood)", this.corr_magic_scale, 3);
gd.addMessage ("--- 3D reconstruction ---");
......@@ -3776,6 +3828,8 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Strength power when calculating disparity error", this.taDiffPwr, 6);
gd.addNumericField("Strength power when calculating disparity error over best", this.taBestPwr, 6);
gd.addNumericField("Strength power when calculating disparity error for group of 9", this.taDiff9Pwr, 6);
gd.addNumericField("Gaussian sigma to blur color difference between tiles along each direction", this.taColSigma, 6);
gd.addNumericField("Relative amount of the blurred color difference in the mixture", this.taColFraction, 6);
gd.addNumericField("Cost of a tile that is not assigned", this.taCostEmpty, 6);
gd.addNumericField("Cost of a tile not having any neighbor in particular direction", this.taCostNoLink, 6);
......@@ -3909,10 +3963,21 @@ public class EyesisCorrectionParameters {
this.fine_corr_x_3= gd.getNextNumber();
this.fine_corr_y_3= gd.getNextNumber();
this.fcorr_min_stength= gd.getNextNumber();
this.fcorr_min_strength= gd.getNextNumber();
this.fcorr_disp_diff= gd.getNextNumber();
this.fcorr_quadratic= gd.getNextBoolean();
this.fcorr_ignore= gd.getNextBoolean();
this.fcorr_inf_strength= gd.getNextNumber();
this.fcorr_inf_diff= gd.getNextNumber();
this.fcorr_inf_quad= gd.getNextBoolean();
this.fcorr_inf_vert= gd.getNextBoolean();
this.fcorr_sample_size= (int)gd.getNextNumber();
this.fcorr_mintiles= (int) gd.getNextNumber();
this.fcorr_reloutliers= gd.getNextNumber();
this.fcorr_sigma= gd.getNextNumber();
this.corr_magic_scale= gd.getNextNumber();
this.show_textures= gd.getNextBoolean();
......@@ -4240,6 +4305,9 @@ public class EyesisCorrectionParameters {
this.taDiffPwr= gd.getNextNumber();
this.taBestPwr= gd.getNextNumber();
this.taDiff9Pwr= gd.getNextNumber();
this.taColSigma= gd.getNextNumber();
this.taColFraction= gd.getNextNumber();
this.taCostEmpty= gd.getNextNumber();
this.taCostNoLink= gd.getNextNumber();
......@@ -4335,6 +4403,8 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Strength power when calculating disparity error", this.taDiffPwr, 6);
gd.addNumericField("Strength power when calculating disparity error over best", this.taBestPwr, 6);
gd.addNumericField("Strength power when calculating disparity error for group of 9", this.taDiff9Pwr, 6);
gd.addNumericField("Gaussian sigma to blur color difference between tiles along each direction", this.taColSigma, 6);
gd.addNumericField("Relative amount of the blurred color difference in the mixture", this.taColFraction, 6);
gd.addNumericField("Cost of a tile that is not assigned", this.taCostEmpty, 6);
gd.addNumericField("Cost of a tile not having any neighbor in particular direction", this.taCostNoLink, 6);
......@@ -4411,6 +4481,8 @@ public class EyesisCorrectionParameters {
this.taDiffPwr= gd.getNextNumber();
this.taBestPwr= gd.getNextNumber();
this.taDiff9Pwr= gd.getNextNumber();
this.taColSigma= gd.getNextNumber();
this.taColFraction= gd.getNextNumber();
this.taCostEmpty= gd.getNextNumber();
this.taCostNoLink= gd.getNextNumber();
......
......@@ -77,7 +77,9 @@ private Panel panel1,
panelPostProcessing2,
panelPostProcessing3,
panelDct1,
panelClt1;
panelClt1,
panelClt2
;
JP46_Reader_camera JP4_INSTANCE=null;
// private deBayerScissors debayer_instance;
......@@ -368,7 +370,7 @@ private Panel panel1,
instance = this;
addKeyListener(IJ.getInstance());
int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0) + (DCT_MODE?2:0);
int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0) + (DCT_MODE?3:0);
setLayout(new GridLayout(menuRows, 1));
panel6 = new Panel();
......@@ -488,7 +490,7 @@ private Panel panel1,
if (DCT_MODE) {
panelClt1 = new Panel();
panelClt1.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Setup CLT parameters", panelClt1, color_configure);
// addButton("Setup CLT parameters", panelClt1, color_configure);
addButton("Select CLT image", panelClt1, color_configure);
addButton("CLT stack", panelClt1, color_process);
addButton("Select second CLT image", panelClt1, color_configure);
......@@ -499,19 +501,48 @@ private Panel panel1,
addButton("CLT process files", panelClt1, color_process);
addButton("CLT process sets", panelClt1, color_process);
addButton("CLT process quads", panelClt1, color_process);
addButton("CLT process corr", panelClt1, color_conf_process);
addButton("CLT disparity scan", panelClt1, color_conf_process);
addButton("CLT reset fine corr", panelClt1, color_stop);
addButton("CLT show fine corr", panelClt1, color_configure);
addButton("CLT apply fine corr", panelClt1, color_process);
addButton("CLT reset 3D", panelClt1, color_stop);
addButton("CLT 3D", panelClt1, color_process);
addButton("CLT planes", panelClt1, color_conf_process);
addButton("CLT ASSIGN", panelClt1, color_process);
addButton("CLT OUT 3D", panelClt1, color_process);
// addButton("CLT process corr", panelClt1, color_conf_process);
// addButton("CLT disparity scan", panelClt1, color_conf_process);
// addButton("CLT reset fine corr", panelClt1, color_stop);
// addButton("CLT show fine corr", panelClt1, color_configure);
// addButton("CLT apply fine corr", panelClt1, color_process);
// addButton("CLT reset 3D", panelClt1, color_stop);
// addButton("CLT 3D", panelClt1, color_process);
// addButton("CLT planes", panelClt1, color_conf_process);
// addButton("CLT ASSIGN", panelClt1, color_process);
// addButton("CLT OUT 3D", panelClt1, color_process);
add(panelClt1);
}
if (DCT_MODE) {
panelClt2 = new Panel();
panelClt2.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Setup CLT parameters", panelClt2, color_configure);
// addButton("Select CLT image", panelClt2, color_configure);
// addButton("CLT stack", panelClt2, color_process);
// addButton("Select second CLT image", panelClt2, color_configure);
// addButton("CLT correlate", panelClt2, color_process);
// addButton("Create CLT kernels", panelClt2, color_process);
// addButton("Read CLT kernels", panelClt2, color_process);
// addButton("Reset CLT kernels", panelClt2, color_stop);
// addButton("CLT process files", panelClt2, color_process);
// addButton("CLT process sets", panelClt2, color_process);
// addButton("CLT process quads", panelClt2, color_process);
addButton("CLT process corr", panelClt2, color_conf_process);
addButton("CLT disparity scan", panelClt2, color_conf_process);
addButton("CLT reset fine corr", panelClt2, color_stop);
addButton("CLT show fine corr", panelClt2, color_configure);
addButton("CLT apply fine corr", panelClt2, color_process);
addButton("CLT test fine corr", panelClt2, color_process);
addButton("CLT process fine corr", panelClt2, color_conf_process);
addButton("CLT reset 3D", panelClt2, color_stop);
addButton("CLT 3D", panelClt2, color_process);
addButton("CLT planes", panelClt2, color_conf_process);
addButton("CLT ASSIGN", panelClt2, color_process);
addButton("CLT OUT 3D", panelClt2, color_process);
add(panelClt2);
}
pack();
GUI.center(this);
......@@ -2888,7 +2919,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -3490,7 +3521,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -3556,7 +3587,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -3606,7 +3637,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4082,7 +4113,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4132,7 +4163,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4187,7 +4218,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4273,7 +4304,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4368,7 +4399,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4465,7 +4496,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4562,6 +4593,24 @@ private Panel panel1,
QUAD_CLT.show_fine_corr();
return;
} else if (label.equals("CLT process fine corr") || label.equals("CLT test fine corr")) {
boolean dry_run = label.equals("CLT test fine corr");
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
PROPERTIES,
EYESIS_CORRECTIONS,
CORRECTION_PARAMETERS);
if (DEBUG_LEVEL > 0){
System.out.println("Created new QuadCLT instance, will need to read CLT kernels");
}
}
QUAD_CLT.process_fine_corr(
dry_run, // boolean dry_run
CLT_PARAMETERS,
DEBUG_LEVEL);
return;
} else if (label.equals("CLT disparity scan")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
......@@ -4585,7 +4634,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4697,7 +4746,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -4823,7 +4872,7 @@ private Panel panel1,
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"autoconfig";
configPath+=Prefs.getFileSeparator()+"autoconfig"+Prefs.getFileSeparator()+"autoconfig";
try {
saveTimestampedProperties(
configPath, // full path or null
......@@ -5396,9 +5445,21 @@ private Panel panel1,
try {
os = new FileOutputStream(path);
} catch (FileNotFoundException e1) {
// missing config directory
File dir = (new File(path)).getParentFile();
if (!dir.exists()){
dir.mkdirs();
try {
os = new FileOutputStream(path);
} catch (FileNotFoundException e2) {
IJ.showMessage("Error","Failed to create directory "+dir.getName()+" to save configuration file: "+path);
return;
}
} else {
IJ.showMessage("Error","Failed to open configuration file: "+path);
return;
}
}
if (useXML) {
try {
properties.storeToXML(os,
......
......@@ -1002,7 +1002,7 @@ public class ImageDtt {
final int window_type,
final double [][] shiftXY, // [port]{shiftX,shiftY}
final double [][][] fine_corr, // quadratic cofficients for fine correction (or null)
final double corr_magic_scale, // stil not understood coefficent that reduces reported disparity value. Seems to be around 8.5
final double corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
final double shiftX, // shift image horizontally (positive - right) - just for testing
final double shiftY, // shift image vertically (positive - down)
final int debug_tileX,
......@@ -1595,7 +1595,7 @@ public class ImageDtt {
clt_mismatch[3*pair + 1 ][tIndex] = Double.NaN;
clt_mismatch[3*pair + 2 ][tIndex] = Double.NaN;
} else {
double [] corr_max_XYmp = getMaxXYCm( // get fractiona center as a "center of mass" inside circle/square from the integer max
double [] corr_max_XYmp = getMaxXYCm( // get fractional center as a "center of mass" inside circle/square from the integer max
tcorr_partial[pair][numcol], // [data_size * data_size]
corr_size,
icorr_max, // integer center coordinates (relative to top left)
......
......@@ -2412,7 +2412,7 @@ public class LinkPlanes {
if (dl > 2){
System.out.println("weakForeground(): nsTile="+nsTile);
}
int n_planes = planes[nsTile].length;
//int n_planes = planes[nsTile].length;
weak_fgnd[nsTile] = new boolean [merge_candidates[nsTile].length];
for (int nPair = 0; nPair < merge_candidates[nsTile].length; nPair++) {
int [] pair = merge_candidates[nsTile][nPair];
......
......@@ -21,8 +21,12 @@
** -----------------------------------------------------------------------------**
**
*/
import java.awt.Polygon;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -31,6 +35,8 @@ import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.Prefs;
import ij.WindowManager;
import ij.gui.Roi;
import ij.io.FileSaver;
import ij.process.ColorProcessor;
import ij.process.ImageProcessor;
......@@ -3277,7 +3283,7 @@ public class QuadCLT {
clt_parameters.clt_window,
shiftXY, //
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // stil not understood coefficent that reduces reported disparity value. Seems to be around 8.5
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
......@@ -3402,7 +3408,7 @@ public class QuadCLT {
disparity_map,
clt_mismatch,
tilesX,
clt_parameters.corr_magic_scale, // stil not understood coefficent that reduces reported disparity value. Seems to be around 8.5
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
debugLevel); // int debugLevel)
apply_fine_corr(
new_corr,
......@@ -3777,7 +3783,7 @@ public class QuadCLT {
double [][] disparity_map,
double [][] clt_mismatch,
int tilesX,
double magic_coeff, // stil not understood coefficent that reduces reported disparity value. Seems to be around 8.5
double magic_coeff, // still not understood coefficent that reduces reported disparity value. Seems to be around 8.5
int debugLevel)
{
// TODO: update the following indices when format of the arrays will change (removed unneeded data)
......@@ -3789,13 +3795,13 @@ public class QuadCLT {
int numUsed = 0;
for (int i = 0; i < numTiles; i++) {
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_stength) &&
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_strength) &&
(Math.abs(disparity_map[index_disparity][i]) <= clt_parameters.fcorr_disp_diff)) numUsed ++;
}
double [][][] mdata = new double[numUsed][3][];
int indx = 0;
for (int i = 0; i < numTiles; i++) {
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_stength) &&
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_strength) &&
(Math.abs(disparity_map[index_disparity][i]) <= clt_parameters.fcorr_disp_diff)) {
int tileX = i % tilesX;
int tileY = i / tilesX;
......@@ -3860,7 +3866,7 @@ public class QuadCLT {
int len8 = tilesX8*tilesY8;
double [][] mismatch_8 = new double[11][len8];
for (int i = 0; i < numTiles; i++) {
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_stength) &&
if ((disparity_map[index_strength][i] >= clt_parameters.fcorr_min_strength) &&
(Math.abs(disparity_map[index_disparity][i]) <= clt_parameters.fcorr_disp_diff)) {
int tileX = i % tilesX;
int tileY = i / tilesX;
......@@ -3916,11 +3922,167 @@ public class QuadCLT {
"mismatch_8",
titles);
}
return coeff_full;
}
// new one, pre-calculated from the disparity scan
public double [][][] fine_geometry_correction(
EyesisCorrectionParameters.CLTParameters clt_parameters,
double [][] clt_mismatch,
int tilesX,
double magic_coeff, // still not understood coefficent that reduces reported disparity value. Seems to be around 8.5
int debugLevel)
{
// TODO: update the following indices when format of the arrays will change (removed unneeded data)
final int [] indices_mismatch = {1,4,6,9}; // "dy0", "dy1", "dx2", "dx3"
final int numTiles = clt_mismatch[0].length;
final int tilesY = numTiles/tilesX;
int numUsed = 0;
double [] strength = new double [numTiles];
for (int i = 0; i < numTiles; i++) {
boolean all_pairs = true;
for (int nPair = 0; nPair < 4; nPair++){
double w = clt_mismatch[3 * nPair + 2][i];
if (w == 0.0) {
all_pairs = false;
strength[i] = 0.0;
break;
}
strength[i] += w;
}
if (all_pairs) numUsed ++;
}
double [][][] mdata = new double[numUsed][3][];
int indx = 0;
for (int i = 0; i < numTiles; i++) {
if (strength[i] > 0) {
int tileX = i % tilesX;
int tileY = i / tilesX;
mdata[indx][0] = new double [2];
mdata[indx][0][0] = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0;
mdata[indx][0][1] = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
mdata[indx][1] = new double [indices_mismatch.length]; // 4
for (int ip = 0; ip < indices_mismatch.length; ip++) {
mdata[indx][1][ip] = clt_mismatch[indices_mismatch[ip]][i];
}
mdata[indx][2] = new double [1];
mdata[indx][2][0] = strength[i];
indx ++;
}
}
PolynomialApproximation pa = new PolynomialApproximation();
double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
/*
* returns array of vectors or null
* each vector (one per each z component) is either 6-element- (A,B,C,D,E,F) if quadratic is possible and enabled
* or 3-element - (D,E,F) if linear is possible and quadratic is not possible or disabled
* returns null if not enough data even for the linear approximation
*/
double [][] coeffs = pa.quadraticApproximation(
mdata,
!clt_parameters.fcorr_quadratic, // boolean forceLinear, // use linear approximation
thresholdLin, // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
thresholdQuad, // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
debugLevel);
for (int i = 0; i < coeffs.length; i++){
if (coeffs[i] == null){
coeffs[i] = new double [6];
for (int j = 0; j < coeffs[i].length; i++) coeffs[i][j] = 0.0;
} else if (coeffs[i].length < 6){
double [] short_coeffs = coeffs[i];
coeffs[i] = new double [6];
for (int j = 0; j < coeffs[i].length; j++) {
if (j < (coeffs[i].length - short_coeffs.length)) coeffs[i][j] = 0.0;
else coeffs[i][j] = short_coeffs[j - (coeffs[i].length - short_coeffs.length)];
}
}
}
// convert to 8 sets of coefficient for px0, py0, px1, py1, ... py3.
double [][][] coeff_full = new double [4][2][6];
double scale = 0.5/magic_coeff;
for (int j = 0; j<6; j++){
coeff_full[0][0][j] = -coeffs[2][j] * scale;
coeff_full[0][1][j] = -coeffs[0][j] * scale;
coeff_full[1][0][j] = -coeffs[3][j] * scale;
coeff_full[1][1][j] = coeffs[0][j] * scale;
coeff_full[2][0][j] = coeffs[2][j] * scale;
coeff_full[2][1][j] = -coeffs[1][j] * scale;
coeff_full[3][0][j] = coeffs[3][j] * scale;
coeff_full[3][1][j] = coeffs[1][j] * scale;
}
if (debugLevel > -1){
int tilesX8 = (tilesX - 1) / 8 + 1;
int tilesY8 = (tilesY - 1) / 8 + 1;
int len8 = tilesX8*tilesY8;
double [][] mismatch_8 = new double[11][len8];
for (int i = 0; i < numTiles; i++) {
if (strength[i] > 0) {
int tileX = i % tilesX;
int tileY = i / tilesX;
int tX8 = tileX/8;
int tY8 = tileY/8;
int indx8 = tY8*tilesX8+tX8;
double tX = (2.0 * tileX)/tilesX - 1.0; // -1.0 to +1.0;
double tY = (2.0 * tileY)/tilesY - 1.0; // -1.0 to +1.0
double w = strength[i];
for (int ip = 0; ip < 4; ip++) {
mismatch_8[ip][indx8] += w * clt_mismatch[indices_mismatch[ip]][i];
}
mismatch_8[8][indx8] += w * tX;
mismatch_8[9][indx8] += w * tY;
mismatch_8[10][indx8] += w;
}
}
for (int i = 0; i < len8; i++) {
if (mismatch_8[10][i] > 0){
for (int n = 0; n<4; n++){
mismatch_8[n][i] /= mismatch_8[10][i];
}
mismatch_8[8][i] /= mismatch_8[10][i];
mismatch_8[9][i] /= mismatch_8[10][i];
} else {
for (int n = 0; n<4; n++){
mismatch_8[n][i] = Double.NaN;
}
mismatch_8[8][i] = Double.NaN;
mismatch_8[9][i] = Double.NaN;
}
for (int n = 0; n<4; n++){
double tX = mismatch_8[8][i];
double tY = mismatch_8[9][i];
//f(x,y)=A*x^2+B*y^2+C*x*y+D*x+E*y+F
mismatch_8[4+n][i] = (
coeffs[n][0]*tX*tX+
coeffs[n][1]*tY*tY+
coeffs[n][2]*tX*tY+
coeffs[n][3]*tX+
coeffs[n][4]*tY+
coeffs[n][5]);
}
}
String [] titles = {"dy0","dy1","dx2","dx3","cy0","cy1","cx2","cx3","tx","ty","w"};
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(
mismatch_8,
tilesX8,
tilesY8,
true,
"mismatch_8",
titles);
}
return coeff_full;
}
public void apply_fine_corr(
double [][][] corr,
int debugLevel)
......@@ -3969,6 +4131,7 @@ public class QuadCLT {
}
}
public void reset_fine_corr()
{
this.fine_corr = new double [4][2][6]; // reset all coefficients to 0
......@@ -4262,7 +4425,7 @@ public class QuadCLT {
double min_corr_selected = clt_parameters.min_corr;
double [][][] disparity_maps = new double [clt_parameters.disp_scan_count][ImageDtt.DISPARITY_TITLES.length][]; //[0] -residual disparity, [1] - orthogonal (just for debugging)
double [][][] clt_mismatches = new double [clt_parameters.disp_scan_count][12][];
for (int scan_step = 0; scan_step < clt_parameters.disp_scan_count; scan_step++) {
double disparity = clt_parameters.disp_scan_start + scan_step * clt_parameters.disp_scan_step;
double [][] disparity_array = tp.setSameDisparity(disparity); // [tp.tilesY][tp.tilesX] - individual per-tile expected disparity
......@@ -4280,7 +4443,8 @@ public class QuadCLT {
// correlation results - final and partial
clt_corr_combo, // [tp.tilesY][tp.tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
null, // clt_corr_partial, // [tp.tilesY][tp.tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
null, // [tp.tilesY][tp.tilesX][pair]{dx,dy,weight}[(2*transform_size-1)*(2*transform_size-1)] // transpose unapplied. null - do not calculate
clt_mismatches[scan_step], // null, [12][tilesY * tilesX] // transpose unapplied. null - do not calculate
// Use it with disparity_maps[scan_step]? clt_mismatch, // [tp.tilesY][tp.tilesX][pair]{dx,dy,weight}[(2*transform_size-1)*(2*transform_size-1)] // transpose unapplied. null - do not calculate
disparity_maps[scan_step], // [2][tp.tilesY * tp.tilesX]
null, //texture_tiles, // [tp.tilesY][tp.tilesX]["RGBA".length()][];
......@@ -4314,7 +4478,7 @@ public class QuadCLT {
clt_parameters.clt_window,
shiftXY, //
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // stil not understood coefficent that reduces reported disparity value. Seems to be around 8.5
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileX, // final int debug_tileX,
......@@ -4325,6 +4489,48 @@ public class QuadCLT {
threadsMax,
debugLevel);
}
double [][] clt_mismatch = new double [12][tilesX*tilesY];
for (int pair = 0; pair < 4; pair++){
for (int scan_step = 0; scan_step < clt_parameters.disp_scan_count; scan_step++){
for (int i = 0; i < tilesX * tilesY; i++){
double w = clt_mismatches[scan_step][3 * pair + 2][i];
clt_mismatch[3 * pair + 0][i] += clt_mismatches[scan_step][3 * pair + 0][i] * w;
clt_mismatch[3 * pair + 1][i] += clt_mismatches[scan_step][3 * pair + 1][i] * w;
clt_mismatch[3 * pair + 2][i] += w;
}
}
}
for (int pair = 0; pair < 4; pair++){
for (int i = 0; i < tilesX * tilesY; i++){
double w = clt_mismatch[3 * pair + 2][i];
if (w != 0.0){
clt_mismatch[3 * pair + 0][i] /= w;
clt_mismatch[3 * pair + 1][i] /= w;
}
}
}
if (debugLevel > -1) {
showCltMismatches(
"clt_mismatches", // String title,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_mismatches, // double [][][] clt_mismatches)
disparity_maps,// double [][][] disparities,
ImageDtt.DISPARITY_INDEX_CM,
ImageDtt.DISPARITY_STRENGTH_INDEX,
tp.getTilesX(),
tp.getTilesY());
showCltMismatch(
"clt_mismatch", // String title,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_mismatch, // double [][][] clt_mismatch)
tp.getTilesX(),
tp.getTilesY());
}
int [] disp_indices = {
ImageDtt.DISPARITY_INDEX_INT,
ImageDtt.DISPARITY_INDEX_CM,
......@@ -4380,6 +4586,393 @@ public class QuadCLT {
return results;
}
public void showCltMismatches(
String title,
EyesisCorrectionParameters.CLTParameters clt_parameters,
double [][][] clt_mismatches,
double [][][] disparity_maps,
int disparity_index,
int strength_index,
int tilesX,
int tilesY)
{
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
int n = clt_mismatches.length;
String [] titles = new String [n * 14];
double [][] dbg_clt_mismatch= new double [clt_parameters.disp_scan_count * 14][];
for (int pair = 0; pair < 4; pair++){
for (int i = 0; i < n; i++){
double disparity = clt_parameters.disp_scan_start + i * clt_parameters.disp_scan_step;
titles[(2 * pair + 0) * n + i] = "dx_"+pair+"_"+disparity;
titles[(2 * pair + 1) * n + i] = "dy_"+pair+"_"+disparity;
titles[(2 * 4 + pair) * n + i] = "strength_"+pair+"_"+disparity;
dbg_clt_mismatch[(2 * pair + 0) * n + i] = clt_mismatches[i][3 * pair + 0];
dbg_clt_mismatch[(2 * pair + 1) * n + i] = clt_mismatches[i][3 * pair + 1];
dbg_clt_mismatch[(2 * 4 + pair) * n + i] = clt_mismatches[i][3 * pair + 2];
}
}
for (int i = 0; i < n; i++){
double disparity = clt_parameters.disp_scan_start + i * clt_parameters.disp_scan_step;
titles[ 12 * n + i] = "disp_"+disparity;
titles[ 13 * n + i] = "strength_"+disparity;
dbg_clt_mismatch[12 * n + i] = disparity_maps[i][disparity_index];
dbg_clt_mismatch[13 * n + i] = disparity_maps[i][strength_index];
}
sdfa_instance.showArrays(dbg_clt_mismatch, tilesX,tilesY, true, title, titles);
}
public void showCltMismatch(
String title,
EyesisCorrectionParameters.CLTParameters clt_parameters,
double [][] clt_mismatch,
int tilesX,
int tilesY)
{
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays();
String [] titles = new String [12];
double [][] dbg_clt_mismatch= new double [12][];
for (int pair = 0; pair < 4; pair++){
titles[2 * pair + 0] = "dx_"+pair;
titles[2 * pair + 1] = "dy_"+pair;
titles[2 * 4 + pair] = "strength_"+pair;
dbg_clt_mismatch[(2 * pair + 0)] = clt_mismatch[3 * pair + 0].clone();
dbg_clt_mismatch[(2 * pair + 1)] = clt_mismatch[3 * pair + 1].clone();
dbg_clt_mismatch[(2 * 4 + pair)] = clt_mismatch[3 * pair + 2];
for (int i = 0; i < dbg_clt_mismatch[(2 * 4 + pair)].length; i++ ){
if (dbg_clt_mismatch[(2 * 4 + pair)][i] == 0.0){
dbg_clt_mismatch[(2 * pair + 0)][i] = Double.NaN;
dbg_clt_mismatch[(2 * pair + 1)][i] = Double.NaN;
}
}
}
sdfa_instance.showArrays(dbg_clt_mismatch, tilesX, tilesY, true, title, titles);
}
public double [][] calcMismatchFromScan(
final EyesisCorrectionParameters.CLTParameters clt_parameters,
final double [][][] clt_mismatches,
final double [][][] disparity_maps,
final int disparity_index,
final int strength_index,
final int tilesX,
final int tilesY,
final int debugLevel)
{
final int dbg_tile = 46519; // 40926;
final int dbg_pair = 3; // 0;
double [][] combo_mismatch = new double [12][tilesX*tilesY];
for (int pair = 0; pair < 4; pair++){
final int f_pair = pair;
for (int scan_step = 0; scan_step < clt_mismatches.length ; scan_step++){
final int f_scan_step = scan_step;
for (int ty = 0; ty < tilesY -clt_parameters.fcorr_sample_size/2 ; ty += clt_parameters.fcorr_sample_size){
int ty_lim = ty + scan_step;
if (ty_lim >= tilesY -clt_parameters.fcorr_sample_size/2) {
ty_lim = tilesY;
}
for (int tx = 0; tx < tilesX - clt_parameters.fcorr_sample_size/2 ; tx += clt_parameters.fcorr_sample_size){
int tx_lim = tx + scan_step;
if (tx_lim >= tilesX - clt_parameters.fcorr_sample_size/2) {
tx_lim = tilesX;
}
ArrayList<Integer> samples_dx_list = new ArrayList<Integer>();
ArrayList<Integer> samples_dy_list = new ArrayList<Integer>();
boolean dbg = false;
for (int y = ty; y < ty_lim; y++){
for (int x = tx; x < tx_lim; x++){
int indx = y * tilesX + x;
if ((disparity_maps[scan_step][strength_index][indx] >= clt_parameters.fcorr_min_strength) &&
(Math.abs(disparity_maps[scan_step][disparity_index][indx]) <= clt_parameters.fcorr_disp_diff)){
samples_dx_list.add(indx);
samples_dy_list.add(indx);
// if ((indx == 43345) && (pair == 0)) {
if ((debugLevel > 0) && (indx == dbg_tile) && (pair == dbg_pair)) {
System.out.println("process_fine_corr(): scan = "+ scan_step+" pair = "+pair+" indx = "+indx+" tx="+tx+" ty="+ty+" x="+x+" y="+y);
dbg = true;
}
}
}
}
// Now sort according to mismatches (consider both dy and dx
Collections.sort(samples_dx_list, new Comparator<Integer>() {
@Override
public int compare(Integer lhs, Integer rhs) {
// -1 - less than, 1 - greater than, 0 - equal, all inverted for descending
double [] arr = clt_mismatches[f_scan_step][3 * f_pair + 0]; // dx
return (arr[lhs] > arr[rhs]) ? -1 : (arr[lhs] < arr[rhs] ) ? 1 : 0;
}
});
Collections.sort(samples_dy_list, new Comparator<Integer>() {
@Override
public int compare(Integer lhs, Integer rhs) {
// -1 - less than, 1 - greater than, 0 - equal, all inverted for descending
double [] arr = clt_mismatches[f_scan_step][3 * f_pair + 1]; // dy
return (arr[lhs] > arr[rhs]) ? -1 : (arr[lhs] < arr[rhs] ) ? 1 : 0;
}
});
if (dbg ){
for (int i = 0; i < samples_dx_list.size(); i++){
System.out.println (i+ ": samples_dx_list["+i+"]="+samples_dx_list.get(i)+" -> "+clt_mismatches[scan_step][3 * pair + 0][samples_dx_list.get(i)]+
" samples_dy_list["+i+"]="+samples_dy_list.get(i)+" -> "+clt_mismatches[scan_step][3 * pair + 1][samples_dy_list.get(i)]);
}
System.out.println();
}
int n_remove = (int) (samples_dx_list.size() * clt_parameters.fcorr_reloutliers);
if (n_remove > (samples_dx_list.size() - clt_parameters.fcorr_mintiles)) {
continue; // too small sample, remove completely
}
int remove_end = 0;
HashSet<Integer> outlier_set = new HashSet<Integer>();
// TODO: remove real outliers by updating weighted averages after each removal and finding which of the ends is the worst
// Or half and half ? First remove from some each end, then worst?
while (outlier_set.size() < n_remove){
switch (remove_end){
case 0:
outlier_set.add(samples_dx_list.remove(0)); // remove first
break;
case 1:
outlier_set.add(samples_dx_list.remove(samples_dx_list.size() - 1)); // remove last
break;
case 2:
outlier_set.add(samples_dy_list.remove(0)); // remove first
break;
case 3:
outlier_set.add(samples_dy_list.remove(samples_dy_list.size() - 1)); // remove last
break;
}
remove_end = (remove_end + 1) & 3;
if (dbg ){
System.out.println ("Removing : remove_end="+remove_end+" outlier_set.sizde()="+outlier_set.size()+
", samples_dx_list.size()="+samples_dx_list.size()+", samples_dy_list.size()="+samples_dy_list.size());
System.out.println();
}
}
if (dbg ){
for (int i = 0; i < samples_dx_list.size(); i++){
System.out.println (i+ ": samples_dx_list["+i+"]="+samples_dx_list.get(i)+" -> "+clt_mismatches[scan_step][3 * pair + 0][samples_dx_list.get(i)]);
}
System.out.println();
}
if (dbg ){
for (int i = 0; i < samples_dy_list.size(); i++){
System.out.println (i+ ": samples_dy_list["+i+"]="+samples_dy_list.get(i)+" -> "+clt_mismatches[scan_step][3 * pair + 1][samples_dy_list.get(i)]);
}
System.out.println();
}
// int n_remove = clt_parameters.fcorr_mintiles;
HashSet<Integer> remaining_set = new HashSet<Integer>();
remaining_set.addAll(samples_dx_list);
remaining_set.removeAll(outlier_set);
for (Integer nTile: remaining_set){
// using mismatch str5ength. How is it different from the disparity strength used in pre-selection?
double w = clt_mismatches[scan_step][3 * pair + 2][nTile];
combo_mismatch[3 * pair + 0][nTile] += clt_mismatches[scan_step][3 * pair + 0][nTile] * w;
combo_mismatch[3 * pair + 1][nTile] += clt_mismatches[scan_step][3 * pair + 1][nTile] * w;
combo_mismatch[3 * pair + 2][nTile] += w;
if (dbg ){
System.out.println (nTile+ " -> "+clt_mismatches[scan_step][3 * pair + 0][nTile]+
", "+clt_mismatches[scan_step][3 * pair + 1][nTile]+", w="+w+
", combo_mismatch["+(3 * pair + 0)+"]["+nTile+"]="+combo_mismatch[3 * pair + 0][nTile]+
", combo_mismatch["+(3 * pair + 1)+"]["+nTile+"]="+combo_mismatch[3 * pair + 1][nTile]+
", combo_mismatch["+(3 * pair + 2)+"]["+nTile+"]="+combo_mismatch[2 * pair + 1][nTile]);
System.out.println();
}
}
}
}
}
}
for (int pair = 0; pair < 4; pair++){
for (int i = 0; i < tilesX * tilesY; i++){
double w = combo_mismatch[3 * pair + 2][i];
if ((debugLevel > 0) && (i == dbg_tile) && (pair == dbg_pair)) {
System.out.println("process_fine_corr(): before norm: pair = "+pair+" i = "+i+" w="+w+
", combo_mismatch["+(3 * pair + 0)+"]["+i+"] = "+combo_mismatch[3 * pair + 0][i]+
", combo_mismatch["+(3 * pair + 1)+"]["+i+"] = "+combo_mismatch[3 * pair + 1][i]);
}
if (w != 0.0){
combo_mismatch[3 * pair + 0][i] /= w;
combo_mismatch[3 * pair + 1][i] /= w;
}
if ((debugLevel > 0) && (i == dbg_tile) && (pair == dbg_pair)) {
System.out.println("process_fine_corr(): before norm: pair = "+pair+" i = "+i+" w="+w+
", combo_mismatch["+(3 * pair + 0)+"]["+i+"] = "+combo_mismatch[3 * pair + 0][i]+
", combo_mismatch["+(3 * pair + 1)+"]["+i+"] = "+combo_mismatch[3 * pair + 1][i]);
}
}
}
return combo_mismatch;
}
public void process_fine_corr(
boolean dry_run,
EyesisCorrectionParameters.CLTParameters clt_parameters,
int debugLevel
) {
ImagePlus imp_src = WindowManager.getCurrentImage();
if (imp_src==null){
IJ.showMessage("Error","12*n-layer file clt_mismatches is required");
return;
}
// final double pre_disp_diff = clt_parameters.fcorr_disp_diff* 2; // allow wider initially
ImageStack clt_mismatches_stack= imp_src.getStack();
final int tilesX = clt_mismatches_stack.getWidth(); // tp.getTilesX();
final int tilesY = clt_mismatches_stack.getHeight(); // tp.getTilesY();
final int nTiles =tilesX * tilesY;
final int num_scans = clt_mismatches_stack.getSize()/14;
final double [][][] clt_mismatches = new double [num_scans][12][nTiles];
final double [][][] disparity_maps = new double [num_scans][2][nTiles];
// final int dbg_tile = 46519; // 40926;
// final int dbg_pair = 3; // 0;
for (int ns = 0; ns < num_scans; ns++){
for (int pair = 0; pair <4; pair++){
float [][] fset = new float [3][];
fset[0] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 0) * num_scans + ns +1);
fset[1] = (float[]) clt_mismatches_stack.getPixels((2 * pair + 1) * num_scans + ns +1); //
fset[2] = (float[]) clt_mismatches_stack.getPixels((8 + pair ) * num_scans + ns +1);
for (int i = 0; i < nTiles; i++){
clt_mismatches[ns][pair * 3 + 0][i] = fset[0][i];
clt_mismatches[ns][pair * 3 + 1][i] = fset[1][i];
clt_mismatches[ns][pair * 3 + 2][i] = fset[2][i];
}
}
float [][] fset = new float [2][];
fset[0] = (float[]) clt_mismatches_stack.getPixels(12 * num_scans + ns +1);
fset[1] = (float[]) clt_mismatches_stack.getPixels(13 * num_scans + ns +1); //
for (int i = 0; i < nTiles; i++){
disparity_maps[ns][0][i] = fset[0][i];
disparity_maps[ns][1][i] = fset[1][i];
}
}
double [][] clt_mismatch = new double [12][tilesX*tilesY];
for (int pair = 0; pair < 4; pair++){
for (int scan_step = 0; scan_step < clt_parameters.disp_scan_count; scan_step++){
for (int i = 0; i < tilesX * tilesY; i++){
double w = clt_mismatches[scan_step][3 * pair + 2][i];
clt_mismatch[3 * pair + 0][i] += clt_mismatches[scan_step][3 * pair + 0][i] * w;
clt_mismatch[3 * pair + 1][i] += clt_mismatches[scan_step][3 * pair + 1][i] * w;
clt_mismatch[3 * pair + 2][i] += w;
}
}
}
for (int pair = 0; pair < 4; pair++){
for (int i = 0; i < tilesX * tilesY; i++){
double w = clt_mismatch[3 * pair + 2][i];
if (w != 0.0){
clt_mismatch[3 * pair + 0][i] /= w;
clt_mismatch[3 * pair + 1][i] /= w;
}
}
}
if (debugLevel > -1) {
showCltMismatches(
"clt_mismatches_in", // String title,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_mismatches, // double [][][] clt_mismatches)
disparity_maps, // double [][][] disparity_maps,
0, // int disparity_index,
1, // int strength_index,
tilesX,
tilesY);
showCltMismatch(
"clt_mismatch_in", // String title,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_mismatch, // double [][][] clt_mismatch)
tilesX,
tilesY);
}
// TODO: Add/use composite disparity calculation from the multi-scan data and use it to filter?
Roi roi = imp_src.getRoi();
Polygon p = roi.getPolygon();
for (int i = 0; i < p.npoints; i++){
System.out.println(i+": "+p.xpoints[i]+"/"+p.ypoints[i]);
}
double [][] combo_mismatch = calcMismatchFromScan(
clt_parameters, // final EyesisCorrectionParameters.CLTParameters clt_parameters,
clt_mismatches, // final double [][][] clt_mismatches,
disparity_maps, // final double [][][] disparity_maps,
0, // final int disparity_index,
1, // final int strength_index,
tilesX, // final int tilesX,
tilesY, // final int tilesY,
debugLevel); // final int debugLevel)
showCltMismatch(
"combo_mismatch", // String title,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
combo_mismatch, // double [][][] clt_mismatch)
tilesX,
tilesY);
// Before applying smooth:
if (!dry_run) {
double [][][] new_corr = fine_geometry_correction(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
combo_mismatch, // double [][] clt_mismatch,
tilesX, // int tilesX,
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
debugLevel); // int debugLevel)
apply_fine_corr(
new_corr,
debugLevel + 2);
}
// Calculate smooth versions
if (clt_parameters.fcorr_sigma > 0.0){
for (int pair = 0; pair < 4; pair++){
for (int i = 0; i < tilesX * tilesY; i++){
double w = combo_mismatch[3 * pair + 2][i];
// if (w != 0.0){
combo_mismatch[3 * pair + 0][i] *= w;
combo_mismatch[3 * pair + 1][i] *= w;
}
// }
}
DoubleGaussianBlur gb = new DoubleGaussianBlur();
for (int n = 0; n < combo_mismatch.length; n++){
gb.blurDouble(combo_mismatch[n], tilesX, tilesY, clt_parameters.fcorr_sigma, clt_parameters.fcorr_sigma, 0.01);
}
}
for (int pair = 0; pair < 4; pair++){
for (int i = 0; i < tilesX * tilesY; i++){
double w = combo_mismatch[3 * pair + 2][i];
if (w != 0.0){
combo_mismatch[3 * pair + 0][i] /= w;
combo_mismatch[3 * pair + 1][i] /= w;
}
}
}
showCltMismatch(
"blured_mismatch", // String title,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
combo_mismatch, // double [][][] clt_mismatch)
tilesX,
tilesY);
}
public double [][] process_disparity_scan(
double [][] disparities_maps,
double disp_step,
......@@ -5968,7 +6561,7 @@ public class QuadCLT {
clt_parameters.clt_window,
shiftXY, //
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // stil not understood coefficent that reduces reported disparity value. Seems to be around 8.5
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileX, // final int debug_tileX,
......@@ -6067,7 +6660,7 @@ public class QuadCLT {
clt_parameters.clt_window,
shiftXY, //
(clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // stil not understood coefficent that reduces reported disparity value. Seems to be around 8.5
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileX, // final int debug_tileX,
......
......@@ -60,6 +60,9 @@ public class TileAssignment {
private double strengthDiffPwr; // = 0.25; // Strength power when calculating disparity error
private double strengthBestPwr; // = 0.0; // Strength power when calculating disparity error over best
private double strengthDiff9Pwr; // = 0.5; // Strength power when calculating disparity error for group of 9
private double taColSigma; // = 1.5; // Gaussian sigma to blur color difference between tiles along each direction
private double taColFraction; // = 0.3; // Relative amount of the blurred color difference in the mixture
private double shrinkWeakFgnd = 0.5; // 0.5; //reduce cost of multiple weak_fgnd links of the same tile
private double shrinkColor = 0.5; // 0.0; //reduce cost of surface transitions w/o color change
......@@ -91,11 +94,11 @@ public class TileAssignment {
this.empty = 1.0/0.35833; // 0.71715;
this.nolink = 1.0/0.83739; // 0.95952; // 1.50705;
this.swtch = 1.0/0.07604; // 0.05172; // 0.59474;
this.color = 1.0/3.34968; // 0.21458; // 0.19294; // 2.25763;
this.color = 1.0/6.69936; // 3.34968; // 0.21458; // 0.19294; // 2.25763;
this.diff = 1.0/0.11879; // 0.11039; // 1.94213;
this.diff_best = 1.0/0.02831; // 0.00628; // 0.06731;
this.diff9 = 1.0/0.04064; // 0.01350; // 1.09087;
this.weak_fgnd = 1.0/1.177746; // 0.02172; // 0.01726; // 0.22250;
this.weak_fgnd = 1.0/2.355492; // 1.177746; // 0.02172; // 0.01726; // 0.22250;
this.flaps = 1.0/0.1; // 0.00056; // 0.07229;
this.ml_mismatch = 1.0;
// ml_mismatch not yet implemented - is it needed - maybe some see-through data appears on one layer only
......@@ -281,12 +284,12 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
this.strengthBestPwr = clt_parameters.taBestPwr;
this.strengthDiff9Pwr = clt_parameters.taDiff9Pwr;
this.taColSigma = clt_parameters.taColSigma;
this.taColFraction = clt_parameters.taColFraction;
this.cost_coeff = new TACosts (clt_parameters);
this.cost_coeff.mul(new TACosts (0)); // make average ~=1.0 for each used component
}
public void setDispStrength(
double [][][] ds)
......@@ -352,7 +355,81 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
ImageDtt.startAndJoin(threads);
}
public void showToneDiffWeights3(){
public void blurMixTones(
final boolean use_sqrt,
final boolean weighted) // blur weighted
{
this.tone_diff_weight = blurMixTones(
this.tone_diff_weight, // final double [][][] tone_diffs,
this.taColSigma, // final double sigma,
this.taColFraction, // final double fraction,
use_sqrt,
weighted); // final boolean weighted)
}
public double [][][] blurMixTones(
final double [][][] tone_diffs,
final double sigma,
final double fraction,
final boolean use_sqrt,
final boolean weighted) // blur weighted
{
final int num_tiles = surfTilesX * surfTilesY;
final double [][] dir_blur = new double [4][num_tiles];
final double [][] dir_weight = new double [4][num_tiles];
final Thread[] threads = ImageDtt.newThreadArray(ts.getThreadsMax());
final AtomicInteger ai = new AtomicInteger(0);
final double [][][] mixed_diff_weight = new double [surfTilesX * surfTilesY][8][2];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int dir = ai.getAndIncrement(); dir < 4; dir = ai.getAndIncrement()) {
for (int nSurfTile = 0; nSurfTile < num_tiles; nSurfTile++){
double w = tone_diffs[nSurfTile][dir][1];
double dw = tone_diffs[nSurfTile][dir][0] ;
if (use_sqrt) dw = Math.sqrt(dw);
if (weighted) dw *= w;
dir_blur[dir][nSurfTile] = dw;
dir_weight[dir][nSurfTile] = w;
}
DoubleGaussianBlur gb =new DoubleGaussianBlur();
gb.blurDouble(dir_blur[dir], surfTilesX, surfTilesY, sigma, sigma, 0.01);
gb.blurDouble(dir_weight[dir], surfTilesX, surfTilesY, sigma, sigma, 0.01);
if (weighted){
for (int nSurfTile = 0; nSurfTile < num_tiles; nSurfTile++){
if (dir_weight[dir][nSurfTile] != 0.0) dir_blur[dir][nSurfTile] /= dir_weight[dir][nSurfTile];
}
}
int rdir = (dir + 4) % 8;
double rfract = 1.0 - fraction;
for (int nSurfTile = 0; nSurfTile < num_tiles; nSurfTile++){
int nSurfTile1 = tnSurface.getNeibIndex(nSurfTile, dir);
if (nSurfTile1 >= 0){
double d;
if (use_sqrt){
d = rfract * Math.sqrt(tone_diffs[nSurfTile][dir][0]) + fraction * dir_blur[dir][nSurfTile];
d *= d;
} else {
d =rfract * tone_diffs[nSurfTile][dir][0] + fraction * dir_blur[dir][nSurfTile];
}
mixed_diff_weight[nSurfTile][dir][0] = d;
mixed_diff_weight[nSurfTile][dir][1] = rfract * tone_diffs[nSurfTile][dir][1] + fraction * dir_weight[dir][nSurfTile];
mixed_diff_weight[nSurfTile1][rdir][0] = mixed_diff_weight[nSurfTile][dir][0];
mixed_diff_weight[nSurfTile1][rdir][1] = mixed_diff_weight[nSurfTile][dir][1];
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return mixed_diff_weight;
}
public void showToneDiffWeights3(String prefix){
String [] titles = {"diffs","sqrt","centers","weights"};
double [][] img_data = new double[titles.length][9 * surfTilesX * surfTilesY];
TileNeibs tnSurface3 = new TileNeibs( 3 * surfTilesX, 3 * surfTilesY);
......@@ -382,10 +459,10 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
img_data[2][nSurfTile3] = sdw;
img_data[3][nSurfTile3] = sw;
}
(new showDoubleFloatArrays()).showArrays(img_data, 3 * surfTilesX, 3 * surfTilesY, true, "Tone_diffs3", titles);
(new showDoubleFloatArrays()).showArrays(img_data, 3 * surfTilesX, 3 * surfTilesY, true, prefix+"tone_diffs3", titles);
}
public void showToneDiffWeights1(){
public void showToneDiffWeights1(String prefix){
double [][] img_data = new double[2][surfTilesX * surfTilesY];
for (int nSurfTile = 0; nSurfTile < tone_diff_weight.length; nSurfTile++){
double sdw = 0.0, sw = 0.0;
......@@ -405,7 +482,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
img_data[1][nSurfTile] = sw;
}
String [] titles = {"diffs","weights"};
(new showDoubleFloatArrays()).showArrays(img_data, surfTilesX, surfTilesY, true, "Tone_diffs1", titles);
(new showDoubleFloatArrays()).showArrays(img_data, surfTilesX, surfTilesY, true, prefix+"tone_diffs1", titles);
}
......@@ -830,12 +907,13 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
} //for (int ml = 0; ml < around.length; ml++) if ((around[ml] != null) && (around[ml][8] > 0))
// using /4.0 to maintain same value (==1.0) for half neighbors (straight edge)
if ((num_weak_fgnd > 0) && (shrinkWeakFgnd > 0.0)){
costs.weak_fgnd /= Math.pow(num_weak_fgnd, shrinkWeakFgnd);
costs.weak_fgnd /= Math.pow(num_weak_fgnd/4.0, shrinkWeakFgnd);
}
if ((num_color_sep > 0) && (shrinkColor > 0.0)){
costs.color /= Math.pow(num_color_sep, shrinkColor);
costs.color /= Math.pow(num_color_sep/4.0, shrinkColor);
}
double disp_diff_lpf = 0.0, disp_diff_weight = 0.0; // calculate LPF of the disparity signed error over all ML and 9 cells
......@@ -874,10 +952,15 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
}
// now diff is for the center, weight needs to be re-calculated
if (strengthDiffPwr > 0.0) {
weight = dispStrength[ml][nSurfTile][1];
if ((dispStrength[ml] == null) || (dispStrength[ml][nSurfTile] == null)){
System.out.println("getTileCosts() nSurfTile = "+nSurfTile+" ml = "+ml+" BUG - null pointer");
weight = 1.0;
} else {
weight = dispStrength[ml][nSurfTile][1]; // null pointer
if (strengthDiffPwr != 1.0) {
weight = Math.pow(weight, strengthDiffPwr);
}
}
} else {
weight = 1.0;
}
......
......@@ -3252,9 +3252,13 @@ public class TileProcessor {
Double.NaN, // double kB,
Double.NaN); // double fatZero)
ta.showToneDiffWeights3();
ta.showToneDiffWeights1();
ta.showToneDiffWeights3("Raw_");
ta.showToneDiffWeights1("Raw_");
ta.blurMixTones(
false, // final boolean use_sqrt,
true); //final boolean weighted) // blur weighted
ta.showToneDiffWeights3("Mixed_");
ta.showToneDiffWeights1("Mixed_");
// }
......
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