Commit 421e0704 authored by Andrey Filippov's avatar Andrey Filippov

Extracted filter parameters to a class, working on far objects

parent 8991226b
......@@ -896,22 +896,23 @@ public class CLTPass3d{
double step_threshold,
double min_disparity,
double max_disparity,
double strength_floor,
double strength_pow,
// double strength_floor,
// double strength_pow,
double stBlurSigma,
boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
double max_abs_tilt, // 2.0; // pix per tile
double max_rel_tilt, // 0.2; // (pix / disparity) per tile
double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
MeasuredLayersFilterParameters mlfp,
// int smplSide, // = 2; // Sample size (side of a square)
// int smplNum, // = 3; // Number after removing worst
// double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// boolean smplWnd, // use window functions for the samples
// double max_abs_tilt, // 2.0; // pix per tile
// double max_rel_tilt, // 0.2; // (pix / disparity) per tile
// double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
int measSel)
{
......@@ -922,21 +923,22 @@ public class CLTPass3d{
step_threshold,
min_disparity,
max_disparity,
strength_floor,
strength_pow,
// strength_floor,
// strength_pow,
stBlurSigma,
smplMode, // = true; // Use sample mode (false - regular tile mode)
smplSide, // = 2; // Sample size (side of a square)
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // final boolean smplWnd, // use window functions for the samples
max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
far_power, // 1.0; // Raise disparity to this power before averaging for far objects
mlfp,
// smplSide, // = 2; // Sample size (side of a square)
// smplNum, // = 3; // Number after removing worst
// smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// smplWnd, // final boolean smplWnd, // use window functions for the samples
// max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// far_power, // 1.0; // Raise disparity to this power before averaging for far objects
// true, // boolean null_if_none,
measSel);
return this.superTiles;
......@@ -946,18 +948,19 @@ public class CLTPass3d{
boolean [][] tile_sel, // null or per-measurement layer, per-tile selection. For each layer null - do not use, {} - use all
boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
double max_abs_tilt, // 2.0; // pix per tile
double max_rel_tilt, // 0.2; // (pix / disparity) per tile
double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
MeasuredLayersFilterParameters mlfp,
// int smplSide, // = 2; // Sample size (side of a square)
// int smplNum, // = 3; // Number after removing worst
// double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// boolean smplWnd, // use window functions for the samples
// double max_abs_tilt, // 2.0; // pix per tile
// double max_rel_tilt, // 0.2; // (pix / disparity) per tile
// double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
int measSel)
{
......@@ -969,18 +972,19 @@ public class CLTPass3d{
tile_sel, // null or per-measurement layer, per-tile selection. For each layer null - do not use, {} - use all
smplMode, // = true; // Use sample mode (false - regular tile mode)
smplSide, // = 2; // Sample size (side of a square)
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
far_power, // 1.0; // Raise disparity to this power before averaging for far objects
mlfp,
// smplSide, // = 2; // Sample size (side of a square)
// smplNum, // = 3; // Number after removing worst
// smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
// smplWnd, // use window functions for the samples
// max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
// max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
// damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
// min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
// transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
// far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
// far_power, // 1.0; // Raise disparity to this power before averaging for far objects
measSel);
}
......
......@@ -23,10 +23,6 @@
**
*/
import ij.IJ;
import ij.gui.GenericDialog;
import ij.text.TextWindow;
import java.awt.Point;
import java.io.BufferedWriter;
import java.io.File;
......@@ -46,18 +42,12 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
//import Distortions.LMAArrays; // may still reuse?
import Jama.LUDecomposition;
import Jama.Matrix;
import ij.IJ;
import ij.gui.GenericDialog;
import ij.text.TextWindow;
public class FocusingField {
......@@ -790,6 +780,7 @@ public class FocusingField {
public class LMAArrays { // reuse from Distortions?
public double [][] jTByJ= null; // jacobian multiplied by Jacobian transposed
public double [] jTByDiff=null; // jacobian multiplied difference vector
@Override
public LMAArrays clone() {
LMAArrays lma=new LMAArrays();
lma.jTByJ = this.jTByJ.clone();
......@@ -2159,6 +2150,7 @@ public double [] createFXandJacobianMulti(
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
int threadIndex=threadIndexAtomic.getAndIncrement();
fxList.get(threadIndex).clear(); // not needed
......@@ -3117,6 +3109,7 @@ d_s2/d_x0= 2*delta_x*delta_y^2/r2^2
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int line=lineAtomic.getAndIncrement(); line<numPars;line=lineAtomic.getAndIncrement()){
double [] sLine=jacobian[line];
......@@ -7919,7 +7912,8 @@ public boolean LevenbergMarquardt(
public int getNumPars(){return descriptions.length;}
public int getIndex(String parName){
for (int i=0;i<descriptions.length;i++) if (descriptions[i].equals(parName)) return i;
// for (int i=0;i<descriptions.length;i++) if (descriptions[i].equals(parName)) return i;
for (int i=0;i<descriptions.length;i++) if (descriptions[i][0].equals(parName)) return i;
return -1;
}
public int getIndex(MECH_PAR mech_par){
......
This diff is collapsed.
This diff is collapsed.
......@@ -246,8 +246,8 @@ public class MacroCorrelation {
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
// clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
// clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
clt_parameters.max_corr_double, // Double pass when masking center of mass to reduce preference for integer values
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
......
This diff is collapsed.
import java.util.Properties;
/**
**
** MeasuredLayersFilterParameters - parameters defining tile filters
**
** Copyright (C) 2018 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** ImageDtt.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
public class MeasuredLayersFilterParameters {
public double strength_sure = 0.25; // Do not filter disparity above this strength
public double strength_floor = 0.1; // Subtract from strength, discard negative
public double strength_pow = 1.0; // raise strength to this power
public int smplSide = 3; // Sample size (side of a square)
public int smplNum = 5; // Number after removing worst
public double smplRms = 0.3; // Maximal RMS of the remaining tiles in a sample
public boolean smplWnd = false; // Use window function for the samples (TODO: change default to true after testing)
public double max_abs_tilt = 2.0; // Maximal absolute tilt in pixels/tile
public double max_rel_tilt = 0.2; // Maximal relative tilt in pixels/tile/disparity
public double damp_tilt = 0.001; // Tilt cost for damping insufficient plane data
public double min_tilt_disp = 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
public double transition = 1.0; // Mode transition range (between tilted and maximal disparity)
public int far_mode = 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
public double far_power = 3.0; // Raise disparity to this power before averaging for far objects
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"strength_sure", this.strength_sure +"");
properties.setProperty(prefix+"strength_floor", this.strength_floor +"");
properties.setProperty(prefix+"strength_pow", this.strength_pow +"");
properties.setProperty(prefix+"smplSide", this.smplSide+"");
properties.setProperty(prefix+"smplNum", this.smplNum+"");
properties.setProperty(prefix+"smplRms", this.smplRms +"");
properties.setProperty(prefix+"smplWnd", this.smplWnd+"");
properties.setProperty(prefix+"max_abs_tilt", this.max_abs_tilt+"");
properties.setProperty(prefix+"max_rel_tilt", this.max_rel_tilt+"");
properties.setProperty(prefix+"damp_tilt", this.damp_tilt+"");
properties.setProperty(prefix+"min_tilt_disp", this.min_tilt_disp+"");
properties.setProperty(prefix+"transition", this.transition+"");
properties.setProperty(prefix+"far_mode", this.far_mode+"");
properties.setProperty(prefix+"far_power", this.far_power+"");
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"strength_sure")!=null) this.strength_sure=Double.parseDouble(properties.getProperty(prefix+"strength_sure"));
if (properties.getProperty(prefix+"strength_floor")!=null) this.strength_floor=Double.parseDouble(properties.getProperty(prefix+"strength_floor"));
if (properties.getProperty(prefix+"strength_pow")!=null) this.strength_pow=Double.parseDouble(properties.getProperty(prefix+"strength_pow"));
if (properties.getProperty(prefix+"smplSide")!=null) this.smplSide=Integer.parseInt(properties.getProperty(prefix+"smplSide"));
if (properties.getProperty(prefix+"smplNum")!=null) this.smplNum=Integer.parseInt(properties.getProperty(prefix+"smplNum"));
if (properties.getProperty(prefix+"smplRms")!=null) this.smplRms=Double.parseDouble(properties.getProperty(prefix+"smplRms"));
if (properties.getProperty(prefix+"smplWnd")!=null) this.smplWnd=Boolean.parseBoolean(properties.getProperty(prefix+"smplWnd"));
if (properties.getProperty(prefix+"max_abs_tilt")!=null) this.max_abs_tilt=Double.parseDouble(properties.getProperty(prefix+"max_abs_tilt"));
if (properties.getProperty(prefix+"max_rel_tilt")!=null) this.max_rel_tilt=Double.parseDouble(properties.getProperty(prefix+"max_rel_tilt"));
if (properties.getProperty(prefix+"damp_tilt")!=null) this.damp_tilt=Double.parseDouble(properties.getProperty(prefix+"damp_tilt"));
if (properties.getProperty(prefix+"min_tilt_disp")!=null) this.min_tilt_disp=Double.parseDouble(properties.getProperty(prefix+"min_tilt_disp"));
if (properties.getProperty(prefix+"transition")!=null) this.transition=Double.parseDouble(properties.getProperty(prefix+"transition"));
if (properties.getProperty(prefix+"far_mode")!=null) this.far_mode=Integer.parseInt(properties.getProperty(prefix+"far_mode"));
if (properties.getProperty(prefix+"far_power")!=null) this.far_power=Double.parseDouble(properties.getProperty(prefix+"far_power"));
}
@Override
public MeasuredLayersFilterParameters clone() {
MeasuredLayersFilterParameters mlfp = new MeasuredLayersFilterParameters();
mlfp.strength_sure = this.strength_sure;
mlfp.strength_floor = this.strength_floor;
mlfp.strength_pow = this.strength_pow;
mlfp.smplSide = this.smplSide;
mlfp.smplNum = this.smplNum;
mlfp.smplRms = this.smplRms;
mlfp.smplWnd = this.smplWnd;
mlfp.max_abs_tilt = this.max_abs_tilt;
mlfp.max_rel_tilt = this.max_rel_tilt;
mlfp.damp_tilt = this.damp_tilt;
mlfp.min_tilt_disp = this.min_tilt_disp;
mlfp.transition = this.transition;
mlfp.far_mode = this.far_mode;
mlfp.far_power = this.far_power;
return mlfp;
}
public boolean equals(MeasuredLayersFilterParameters mlfp) {
return
(mlfp.strength_sure == this.strength_sure ) &&
(mlfp.strength_floor == this.strength_floor ) &&
(mlfp.strength_pow == this.strength_pow ) &&
(mlfp.smplSide == this.smplSide ) &&
(mlfp.smplNum == this.smplNum ) &&
(mlfp.smplRms == this.smplRms ) &&
(mlfp.smplWnd == this.smplWnd ) &&
(mlfp.max_abs_tilt == this.max_abs_tilt ) &&
(mlfp.max_rel_tilt == this.max_rel_tilt ) &&
(mlfp.damp_tilt == this.damp_tilt ) &&
(mlfp.min_tilt_disp == this.min_tilt_disp ) &&
(mlfp.transition == this.transition ) &&
(mlfp.far_mode == this.far_mode ) &&
(mlfp.far_power == this.far_power);
}
}
......@@ -196,6 +196,31 @@ public class PolynomialApproximation {
return xy;
}
// returns maximum's coordinates, value, and coefficients for x2, y2 and xy
public double[] quadraticMaxV2dX2Y2XY (double [][][] data,double thresholdQuad, int debugLevel){
double [][] coeff=quadraticApproximation(data, false, 1.0E-20, thresholdQuad,debugLevel);
if (coeff==null) return null;
if (coeff[0].length<6) return null;
double [][] aM={
{2*coeff[0][0], coeff[0][2]}, // | 2A, C |
{ coeff[0][2],2*coeff[0][1]}}; // | C, 2B |
Matrix M=(new Matrix(aM));
double nmQ=normMatix(aM);
if (debugLevel>3) System.out.println("M.det()="+M.det()+" normMatix(aM)="+nmQ+" data.length="+data.length);
if ((nmQ==0.0) || (Math.abs(M.det())/normMatix(aM)<thresholdQuad)) {
if (debugLevel>3) System.out.println("quadraticMax2d() failed: M.det()="+M.det()+" normMatix(aM)="+normMatix(aM));
return null;
}
double [][] aB={
{-coeff[0][3]}, // | - D |
{-coeff[0][4]}}; // | - E |
double [] xy=M.solve(new Matrix(aB)).getColumnPackedCopy();
double vmax = coeff[0][0]*xy[0]*xy[0]+coeff[0][1]*xy[1]*xy[1]+coeff[0][2]*xy[0]*xy[1]+coeff[0][3]*xy[0]+coeff[0][4]*xy[1]+coeff[0][5];
double [] xyx2y2 = {xy[0],xy[1], vmax, coeff[0][0], coeff[0][1], coeff[0][2]};
return xyx2y2;
}
/* ======================================================================== */
/**
* See below, this version is for backward compatibility with no damping
......
......@@ -3690,8 +3690,8 @@ public class QuadCLT {
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
// clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
// clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
clt_parameters.max_corr_double, // Double pass when masking center of mass to reduce preference for integer values
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
......@@ -4766,8 +4766,8 @@ public class QuadCLT {
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
// clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
// clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
clt_parameters.max_corr_double, // Double pass when masking center of mass to reduce preference for integer values
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
......@@ -7869,8 +7869,8 @@ public class QuadCLT {
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
// clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
// clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
clt_parameters.max_corr_double, // Double pass when masking center of mass to reduce preference for integer values
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
......@@ -8083,8 +8083,8 @@ public class QuadCLT {
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
// clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
// clt_parameters.enhortho_scale, // 0.2; // multiply center correlation pixels (inside enhortho_width)
clt_parameters.max_corr_double, // Double pass when masking center of mass to reduce preference for integer values
clt_parameters.corr_mode, // Correlation mode: 0 - integer max, 1 - center of mass, 2 - polynomial
clt_parameters.min_shot, // 10.0; // Do not adjust for shot noise if lower than
......
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