Commit 8991226b authored by Andrey Filippov's avatar Andrey Filippov

Tweaking software to handle more precise disparity measurements

parent 957badd3
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -572,6 +572,7 @@ private Panel panel1,
addButton("Infinity offset", panelClt3, color_configure);
addButton("Setup CLT Batch parameters", panelClt3, color_configure);
addButton("CLT batch process", panelClt3, color_process);
addButton("CM Test", panelClt3, color_stop);
// addButton("JTabbed", panelClt3, color_stop);
// addButton("Demo", panelClt3, color_process);
......@@ -3752,7 +3753,7 @@ private Panel panel1,
/* ======================================================================== */
} else if (label.equals("Setup CLT parameters")) {
CLT_PARAMETERS.showDialog();
CLT_PARAMETERS.showJDialog();
return;
/* ======================================================================== */
} else if (label.equals("Setup CLT")) {
......@@ -3769,7 +3770,7 @@ private Panel panel1,
} else if (label.equals("Select CLT image")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
ImagePlus imp_src = WindowManager.getCurrentImage();
if (imp_src==null){
......@@ -3802,7 +3803,7 @@ private Panel panel1,
} else if (label.equals("Select second CLT image")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
ImagePlus imp_src = WindowManager.getCurrentImage();
if (imp_src==null){
......@@ -3837,7 +3838,7 @@ private Panel panel1,
} else if (label.equals("CLT stack")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
if (DBG_IMP == null) {
ImagePlus imp_src = WindowManager.getCurrentImage();
......@@ -3937,7 +3938,7 @@ private Panel panel1,
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
if (DBG_IMP == null) {
ImagePlus imp_src = WindowManager.getCurrentImage();
......@@ -4191,7 +4192,7 @@ private Panel panel1,
//==============================================================================
} else if (label.equals("Create CLT kernels")) {
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
PROPERTIES,
......@@ -4250,7 +4251,7 @@ private Panel panel1,
}
} else if (label.equals("Read CLT kernels")) {
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
PROPERTIES,
......@@ -5161,6 +5162,9 @@ private Panel panel1,
PROPERTIES);
}
return;
} else if (label.equals("CM Test")) {
cm_test();
return;
//JTabbedTest
// End of buttons code
......@@ -5185,7 +5189,136 @@ private Panel panel1,
return true;
}
public boolean cm_test() {
double hsize_x = 1.5;
double hsize_y = 1.5;
int steps = 20;
double sigma = 0.0;
boolean separable = true; // false;
double pwr = 1.0;
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set CLT parameters",400,300);
gd.addNumericField("Half size X", hsize_x, 6, 8, "pix",
"Correlation maximum half width in disparity direction");
gd.addNumericField("Half size Y", hsize_y, 6, 8, "pix",
"Correlation maximum half width in orthogonal direction");
gd.addNumericField("Number of steps", steps, 0, 6, "",
"Number of steps to subdivide [0,1) half-interval");
gd.addNumericField("Low pass sigma", sigma, 3, 6, "pix",
"Correlation maximum half width in orthogonal direction");
gd.addCheckbox ("X/Y separable", separable);
gd.addNumericField("Value power", pwr, 6, 8, "",
"Raise values to this power before calculating CM");
gd.showDialog();
if (gd.wasCanceled()) return false;
DoubleGaussianBlur gb=new DoubleGaussianBlur();
hsize_x = gd.getNextNumber();
hsize_y = gd.getNextNumber();
steps = (int) gd.getNextNumber();
sigma = gd.getNextNumber();
separable = gd.getNextBoolean();
pwr = gd.getNextNumber();
int size_x = 2*((int) Math.round(hsize_x+ 2*sigma+1)) + 1;
int size_y = 2*((int) Math.round(hsize_y+ 2*sigma+1)) + 1;
System.out.println("size_x="+size_x+", size_y="+size_y+" sigma = "+sigma+" separable "+separable+" pwr=" + pwr);
String [] titles = new String[steps];
double [][] data = new double [steps][size_x*size_y];
for (int i = 0;i<steps; i++) {
double dx = 1.0*i/steps;
titles[i] = IJ.d2s(dx,3);
for (int iy = 0; iy < size_y; iy++) {
double y = (iy - (size_y - 1)/2)/hsize_y;
if ((y >= -1.0) && (y <= 1.0)) {
double ay = separable ? (0.5*(Math.cos(y * Math.PI) + 1.0)):1.0;
for (int ix = 0; ix < size_x; ix++) {
double x = (ix - (size_x - 1)/2 - dx)/hsize_x;
double r = separable? Math.abs(x) : Math.sqrt(x*x+y*y);
// if ((r >= -hsize_x) && (x <= hsize_x)) {
if (r <= 1.0) {
double ax = 0.5*(Math.cos(r * Math.PI) + 1.0);
data[i][iy*size_x+ix] = ax*ay;
}
}
}
}
}
(new showDoubleFloatArrays()) .showArrays(data, size_x, size_y, true, "pre-gauss", titles);
if (sigma > 0.0) {
for (int i = 0; i < steps; i++) {
gb.blurDouble(
data[i],
size_x,
size_y,
sigma,
sigma,
0.01);
}
(new showDoubleFloatArrays()) .showArrays(data, size_x, size_y, true, "blured", titles);
}
double [] cm_x = new double [steps];
for (int i = 0;i<steps; i++) {
double s0=0,sx=0;
for (int iy = 0; iy < size_y; iy++ ) {
for (int ix = 0; ix < size_x; ix++ ) {
double d = Math.pow(data[i][iy*size_y+ix], pwr);
s0+=d;
sx+=ix*d;
}
}
cm_x[i] = sx/s0 - (size_x - 1)/2;
}
for (int i = 0;i <= steps/2; i++) {
double dx = 1.0*i/steps;
System.out.println(String.format("%3d %8.5f %8.5f %8.5f %8.5f %8.5f", i, dx, cm_x[i],cm_x[i]-dx, cm_x[i]/(dx+0.00000001), dx/(cm_x[i]+0.00000001)));
}
return true;
/*
double s0 = 0, sx=0,sy = 0;
for (int y = - iradius ; y <= iradius; y++){
int dataY = icenter[1] +y;
if ((dataY >= 0) && (dataY < data_size)){
int y2 = y*y;
for (int x = - iradius ; x <= iradius; x++){
int dataX = icenter[0] +x;
double r2 = y2 + x * x;
// if ((dataX >= 0) && (dataX < data_size) && (square || ((y2 + x * x) <= ir2))){
if ((dataX >= 0) && (dataX < data_size) && (square || (r2 <= ir2))){
// double w = max_corr_double? (1.0 - r2/ir2):1.0;
// double d = w* data[dataY * data_size + dataX];
double d = data[dataY * data_size + dataX];
s0 += d;
sx += d * dataX;
sy += d * dataY;
}
}
}
}
double [] rslt = {sx / s0, sy / s0};
*
* showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(double_stack, imp_src.getWidth(), imp_src.getHeight(), true, "BEFORE_CLT_PROC", rbg_titles);
*
gb.blurDouble(
results[indexVar],
size,
size,
blurVarianceSigma,
blurVarianceSigma,
0.01);
*/
}
private boolean loadCorrelations(){
String []patterns={".corr-tiff",".tiff",".tif"};
......
......@@ -5,6 +5,7 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
......@@ -109,7 +110,13 @@ public class GenericJTabbedDialog implements ActionListener {
}
if (tooltip != null) {
label.setToolTipText(tooltip);
if (component != null) component.setToolTipText(tooltip);
if (component != null) {
component.setToolTipText(tooltip);
Component [] comps = component.getComponents();
if ((comps != null) && (comps.length >0)) {
((JComponent) comps[0]).setToolTipText(tooltip);
}
}
}
labels.get(labels.size()-1).add(label);
components.get(components.size()-1).add(component);
......@@ -148,6 +155,7 @@ public class GenericJTabbedDialog implements ActionListener {
inp_units.putClientProperty("type", "String");
inp_units.setLayout(new FlowLayout(FlowLayout.LEFT));
addLine(label, inp_units, tooltip);
}
public void addNumericField(String label, double defaultValue, int digits) { // as in IJ
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -3572,7 +3572,7 @@ public class QuadCLT {
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// may use this.StartTime to report intermediate steps execution times
String name=(String) imp_quad[0].getProperty("name");
String name=this.correctionsParameters.getModelName((String) imp_quad[0].getProperty("name"));
// int channel= Integer.parseInt((String) imp_src.getProperty("channel"));
// int channel= (Integer) imp_quad[0].getProperty("channel");
String path= (String) imp_quad[0].getProperty("path");
......@@ -3666,6 +3666,7 @@ public class QuadCLT {
}
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
double [][][][][][] clt_data = image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // final double disparity,
......@@ -4740,6 +4741,7 @@ public class QuadCLT {
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......@@ -5632,13 +5634,13 @@ public class QuadCLT {
debugLevel);
tp.clt_3d_passes.add(bgnd_data);
// if (show_init_refine)
if (debugLevel > -1) {
if ((debugLevel > -2) && clt_parameters.show_first_bg) {
tp.showScan(
tp.clt_3d_passes.get(0), // CLTPass3d scan,
"bgnd_data-"+tp.clt_3d_passes.size());
}
//TODO: Move away form here?
//TODO: Move away from here?
ImagePlus imp_bgnd = getBackgroundImage(
clt_parameters,
colorProcParameters,
......@@ -5827,7 +5829,8 @@ public class QuadCLT {
tp.clt_3d_passes.add(refined);
/// if (debugLevel > 1)
if (debugLevel > 0)
// if (debugLevel > 0)
if ((debugLevel > -2) && clt_parameters.show_first_bg)
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"before_makeUnique-"+refine_pass);
......@@ -5973,8 +5976,9 @@ public class QuadCLT {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
if (debugLevel > -1){
System.out.println("CLTMeasure("+refine_pass+")");
// if (debugLevel > -1){
if (debugLevel > -2){
System.out.println("?.CLTMeasure("+refine_pass+")");
}
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
......@@ -7041,7 +7045,7 @@ public class QuadCLT {
"after_pass3-"+(next_pass-1)); //String title)
}
String x3d_path= correctionsParameters.selectX3dDirectory( // for x3d and obj
this.image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
true, // smart,
true); //newAllowed, // save
......@@ -7058,7 +7062,7 @@ public class QuadCLT {
try {
wfOutput = new WavefrontExport(
x3d_path,
this.image_name,
correctionsParameters.getModelName(this.image_name),
clt_parameters,
correctionsParameters,
geometryCorrection,
......@@ -7117,7 +7121,7 @@ public class QuadCLT {
clt_parameters,
colorProcParameters,
rgbParameters,
this.image_name+"-img_infinity", // +scanIndex,
correctionsParameters.getModelName(this.image_name)+"-img_infinity", // +scanIndex,
bgndIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
......@@ -7198,7 +7202,7 @@ public class QuadCLT {
clt_parameters,
colorProcParameters,
rgbParameters,
this.image_name+"-img"+scanIndex,
correctionsParameters.getModelName(this.image_name)+"-img"+scanIndex,
scanIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
......@@ -7275,9 +7279,9 @@ public class QuadCLT {
if ((x3d_path != null) && (x3dOutput != null)){
// x3d_path+=Prefs.getFileSeparator()+this.image_name+".x3d";
// x3d_path+=Prefs.getFileSeparator()+correctionsParameters.getModelName(this.image_name)+".x3d";
// x3dOutput.generateX3D(x3d_path);
x3dOutput.generateX3D(x3d_path+Prefs.getFileSeparator()+this.image_name+".x3d");
x3dOutput.generateX3D(x3d_path+Prefs.getFileSeparator()+correctionsParameters.getModelName(this.image_name)+".x3d");
}
if (wfOutput != null){
wfOutput.close();
......@@ -7562,7 +7566,7 @@ public class QuadCLT {
debugLevel);
String path= correctionsParameters.selectX3dDirectory(
//TODO: Which one to use - name or this.image_name ?
this.image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
// name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
true, // smart,
......@@ -7711,7 +7715,7 @@ public class QuadCLT {
String path= correctionsParameters.selectX3dDirectory(
//TODO: Which one to use - name or this.image_name ?
this.image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
// name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
true, // smart,
......@@ -7841,6 +7845,7 @@ public class QuadCLT {
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......@@ -8054,6 +8059,7 @@ public class QuadCLT {
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment