Commit 9a499c0a authored by Andrey Filippov's avatar Andrey Filippov

working version

parent b3ad74ea
......@@ -1598,7 +1598,7 @@ public class ErsCorrection extends GeometryCorrection {
}
}
@Deprecated
public void compareDSItoWorldDerivatives(
QuadCLT scene_QuadClt,
double max_inf_disparity, // absolute value
......
......@@ -557,6 +557,11 @@ min_str_neib_fpn 0.35
public boolean ref_need_lma_combo = true; // need LMA output for reliable tiles (when combo is available)
public double min_ref_str = 0.33; // 0.22; // For orientations: use only tiles of the reference scene DSI_MAIN is stronger
public double min_ref_frac = 0.2; // 0.22; if fraction number of reliable tiles is less than this, use best possible
public boolean ref_smooth = false; // smooth reference disparity for initial matching
public double ref_sigma = 2.0; // Gaussian sigma to smooth reference disparity for initial matching
public double ref_smooth_diff = 0.15; // discard smooth disparity if it differs by more from measured
// SfM-related filtering (remove tiles without SfM)
public boolean sfm_filter = true; // use SfM filtering if available
public double sfm_minmax = 3.0; // 10.0 // minimal value of the SfM gain maximum to consider available
......@@ -736,6 +741,7 @@ min_str_neib_fpn 0.35
public int terr_shrink_terrain= 20; // shrink accumulated terrain after cutting shrunk vegetation (added to terr_shrink_veget)
public double terr_vegetation_over = 35; // initial vegetation over (hotter) filled terrain
public int terr_filter_veget = 10; // shrink+grow shrunk vegetation to remove small clusters
public int terr_veget_grow = 2; // grow (fill NaN holes) vegetation when extracting from multi-scene sequences
public boolean terr_tile_woi = true; // if false - use woi50;
public Rectangle terr_woi_enclos = new Rectangle(80, 210, 210, 230); // will be tiled, using width/height from woi_step;
......@@ -1670,6 +1676,15 @@ min_str_neib_fpn 0.35
gd.addNumericField("DSI_MAIN minimal fraction", this.min_ref_frac, 5,7,"",
"If relative number of the reliable tiles is less than this - use this best fraction.");
gd.addMessage ("Smooth reference disparity for initial matching");
gd.addCheckbox ("Smooth reference disparity", this.ref_smooth,
"Smooth reference disparity for initial matching.");
gd.addNumericField("Reference disparity sigma", this.ref_sigma, 5,7,"pix",
"Gaussian sigma to smooth reference disparity for initial matching.");
gd.addNumericField("Max smooth offset", this.ref_smooth_diff, 5,7,"pix",
"Discard smooth disparity if it differs by more from measured.");
gd.addCheckbox ("Use SfM filtering if available", this.sfm_filter,
"Mask out tiles without sufficient SfM gain (if SfM data is available).");
gd.addNumericField("Min SfM gain maximum to consider", this.sfm_minmax, 5,7,"",
......@@ -2017,6 +2032,7 @@ min_str_neib_fpn 0.35
gd.addNumericField("Vegetation hotter", terr_vegetation_over, 5,7,"", "Initially consider to be vegetation if it is this hotter than filled in terrain holes.");
gd.addNumericField("Vegetation shrink+grow", terr_filter_veget, 0,3,"pix", "Shrink + grow hot enough vegetation to filter from small clusters - needed for initial alpha.");
gd.addNumericField("Grow vegetation extract", terr_veget_grow, 0,3,"pix", "Grow vegetation when extracting from the multi-scene sequences.");
gd.addMessage ("Scan WOI parameters");
gd.addCheckbox ("Tiled WOI", terr_tile_woi, "Process tiled WOI (False - a single one).");
......@@ -2532,6 +2548,9 @@ min_str_neib_fpn 0.35
this.ref_need_lma_combo = gd.getNextBoolean();
this.min_ref_str = gd.getNextNumber();
this.min_ref_frac = gd.getNextNumber();
this.ref_smooth = gd.getNextBoolean();
this.ref_sigma = gd.getNextNumber();
this.ref_smooth_diff = gd.getNextNumber();
this.sfm_filter = gd.getNextBoolean();
this.sfm_minmax = gd.getNextNumber();
this.sfm_fracmax = gd.getNextNumber();
......@@ -2740,6 +2759,8 @@ min_str_neib_fpn 0.35
terr_vegetation_over = gd.getNextNumber(); // double
terr_filter_veget = (int) gd.getNextNumber(); // int
terr_veget_grow = (int) gd.getNextNumber(); // int
terr_tile_woi = gd.getNextBoolean(); // boolean
terr_continue = gd.getNextBoolean(); // boolean
terr_woi_enclos = stringToRectangle(gd.getNextString());// Rectangle
......@@ -3255,6 +3276,10 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"min_ref_str", this.min_ref_str+""); // double
properties.setProperty(prefix+"min_ref_frac", this.min_ref_frac+""); // double
properties.setProperty(prefix+"ref_smooth", this.ref_smooth+""); // boolean
properties.setProperty(prefix+"ref_sigma", this.ref_sigma+""); // double
properties.setProperty(prefix+"ref_smooth_diff", this.ref_smooth_diff+""); // double
properties.setProperty(prefix+"sfm_filter", this.sfm_filter+""); // boolean
properties.setProperty(prefix+"sfm_minmax", this.sfm_minmax+""); // double
properties.setProperty(prefix+"sfm_fracmax", this.sfm_fracmax+""); // double
......@@ -3417,8 +3442,12 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"terr_nan_tolerance", terr_nan_tolerance+""); // double
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int
properties.setProperty(prefix+"terr_shrink_veget", terr_shrink_veget+""); // int
properties.setProperty(prefix+"terr_shrink_terrain", terr_shrink_terrain+""); // int
properties.setProperty(prefix+"terr_vegetation_over", terr_vegetation_over+""); // double
properties.setProperty(prefix+"terr_filter_veget", terr_filter_veget+""); // int
properties.setProperty(prefix+"terr_veget_grow", terr_veget_grow+""); // int
properties.setProperty(prefix+"terr_nan_tolerance", terr_nan_tolerance+""); // double
properties.setProperty(prefix+"terr_nan_grow", terr_nan_grow+""); // int
......@@ -3940,6 +3969,10 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"min_ref_str")!=null) this.min_ref_str=Double.parseDouble(properties.getProperty(prefix+"min_ref_str"));
if (properties.getProperty(prefix+"min_ref_frac")!=null) this.min_ref_frac=Double.parseDouble(properties.getProperty(prefix+"min_ref_frac"));
if (properties.getProperty(prefix+"ref_smooth")!=null) this.ref_smooth=Boolean.parseBoolean(properties.getProperty(prefix+"ref_smooth"));
if (properties.getProperty(prefix+"ref_sigma")!=null) this.ref_sigma=Double.parseDouble(properties.getProperty(prefix+"ref_sigma"));
if (properties.getProperty(prefix+"ref_smooth_diff")!=null) this.ref_smooth_diff=Double.parseDouble(properties.getProperty(prefix+"ref_smooth_diff"));
if (properties.getProperty(prefix+"sfm_filter")!=null) this.sfm_filter=Boolean.parseBoolean(properties.getProperty(prefix+"sfm_filter"));
if (properties.getProperty(prefix+"sfm_minmax")!=null) this.sfm_minmax=Double.parseDouble(properties.getProperty(prefix+"sfm_minmax"));
if (properties.getProperty(prefix+"sfm_fracmax")!=null) this.sfm_fracmax=Double.parseDouble(properties.getProperty(prefix+"sfm_fracmax"));
......@@ -4124,7 +4157,7 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"terr_shrink_terrain")!= null) terr_shrink_terrain=Integer.parseInt(properties.getProperty(prefix+"terr_shrink_terrain"));
if (properties.getProperty(prefix+"terr_vegetation_over")!= null) terr_vegetation_over=Double.parseDouble(properties.getProperty(prefix+"terr_vegetation_over"));
if (properties.getProperty(prefix+"terr_filter_veget")!= null) terr_filter_veget=Integer.parseInt(properties.getProperty(prefix+"terr_filter_veget"));
if (properties.getProperty(prefix+"terr_veget_grow")!= null) terr_veget_grow=Integer.parseInt(properties.getProperty(prefix+"terr_veget_grow"));
if (properties.getProperty(prefix+"terr_tile_woi")!= null) terr_tile_woi=Boolean.parseBoolean(properties.getProperty(prefix+"terr_tile_woi"));
if (properties.getProperty(prefix+"terr_continue")!= null) terr_continue=Boolean.parseBoolean(properties.getProperty(prefix+"terr_continue"));
if (properties.getProperty(prefix+"terr_woi_enclos")!= null) terr_woi_enclos=stringToRectangle((String) properties.getProperty(prefix+"terr_woi_enclos"));
......@@ -4633,6 +4666,10 @@ min_str_neib_fpn 0.35
imp.min_ref_str = this.min_ref_str;
imp.min_ref_frac = this.min_ref_frac;
imp.ref_smooth = this.ref_smooth;
imp.ref_sigma = this.ref_sigma;
imp.ref_smooth_diff = this.ref_smooth_diff;
imp.sfm_filter = this.sfm_filter;
imp.sfm_minmax = this.sfm_minmax;
imp.sfm_fracmax = this.sfm_fracmax;
......@@ -4796,6 +4833,8 @@ min_str_neib_fpn 0.35
imp.terr_vegetation_over = this.terr_vegetation_over;
imp.terr_filter_veget = this.terr_filter_veget;
imp.terr_veget_grow = this.terr_veget_grow;
imp.terr_tile_woi = this.terr_tile_woi;
imp.terr_continue = this.terr_continue;
imp.terr_woi_enclos = new Rectangle(this.terr_woi_enclos);
......
......@@ -13256,6 +13256,7 @@ public class OpticalFlow {
param_regweights, // final double [] param_regweights,
vector_XYS, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
reference_tiles_macro, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
(nlma == 0), // boolean first_run,
clt_parameters.ilp.ilma_debug_level); // final int debug_level)
......@@ -13392,6 +13393,7 @@ public class OpticalFlow {
null, // final double [] param_regweights,
null, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
ref_pXpYD, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
false, // boolean first_run,
debug_level); // final int debug_level)
final double [][] last_jt = intersceneLma. getLastJT(); // alternating x,y for each selected parameters
......@@ -13716,6 +13718,7 @@ public class OpticalFlow {
clt_parameters.ilp.ilma_regularization_weights, // final double [] param_regweights,
vector_XYS, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
reference_tiles_macro, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
(nlma == 0), // boolean first_run,
debug_level); // final int debug_level)
int lmaResult = intersceneLma.runLma(
......
......@@ -2630,6 +2630,62 @@ public class QuadCLTCPU {
}
public double [] smoothDisparity(
double [] disparity_in,
boolean [] reliable_ref, // optional
double sigma,
double max_diff,
boolean apply_nan) {
final int tilesX = tp.getTilesX();
double [] disparity = disparity_in.clone();
if (reliable_ref != null) {
for (int i = 0; i < reliable_ref.length; i++) {
if (!reliable_ref[i]) {
disparity[i] = Double.NaN;
}
}
}
boolean [] good_tiles = new boolean [disparity.length];
for (int i = 0; i < disparity.length; i++) {
good_tiles[i] = !Double.isNaN(disparity[i]);
}
double scale_sigma = 5.0; // non-NaN - 5 pixels from original NaN for each sigma
int grow = 2* Math.min((int) Math.ceil(sigma * scale_sigma), tilesX);
disparity = TileProcessor.fillNaNs(
disparity, // final double [] data,
null, // final boolean [] prohibit,
tilesX, // int width,
// CAREFUL ! Remaining NaN is grown by unsharp mask filter ************* !
grow, // 100, // 2*width, // 16, // final int grow,
0.7, // double diagonal_weight, // relative to ortho
100, // int num_passes,
0.03); // final double max_rchange, // = 0.01 - does not need to be accurate
(new DoubleGaussianBlur()).blurDouble(
disparity, //
tilesX,
disparity.length/tilesX,
sigma, // double sigmaX,
sigma, // double sigmaY,
0.01); // double accuracy)
if (max_diff > 0) {
for (int i = 0; i < disparity.length; i++) if (good_tiles[i]){
if (Math.abs(disparity[i] - disparity_in[i]) > max_diff) {
good_tiles[i] = false;
}
}
}
if (apply_nan) {
for (int i = 0; i < disparity.length; i++) if (!good_tiles[i]){
disparity[i] = Double.NaN;
}
}
if (reliable_ref != null) {
System.arraycopy(good_tiles, 0, reliable_ref, 0, disparity.length);
}
return disparity;
}
public double [][] getDLS(){ // get disparity, disparity_lma, strength, sfm_gain
......
......@@ -2278,6 +2278,7 @@ public class StructureFromMotion {
null, // final double [] param_regweights,
null, // final double [][] vector_XYS, // optical flow X,Y, confidence obtained from the correlate2DIterate()
ref_pXpYD, // final double [][] centers, // macrotile centers (in pixels and average disparities
false, // final boolean same_weights,
false, // boolean first_run,
debug_level); // final int debug_level)
last_jts[nscene] = intersceneLma. getLastJT(); // alternating x,y for each selected parameters
......
......@@ -487,6 +487,7 @@ public class VegetationLMA {
max_warp, // final double max_warp,
valid_pixels_in, // final boolean [] valid_pixels_in, // should be initialized to woi, normally set to all true
max_offset, // final int max_offset,
elev_radius, // final double [] elev_radius, // this.elevation_radius
max_sacrifice, // final int max_sacrifice,
valid_stats, // final int [] stats,
max_warp_scene_pix, // final int [] max_warp_scene_pix,
......@@ -5200,12 +5201,14 @@ public class VegetationLMA {
final double max_warp,
final boolean [] valid_pixels_in, // should be initialized to woi, normally set to all true
final int max_offset,
final double [] elev_radius, // this.elevation_radius
final int max_sacrifice,
final int [] stats,
final int [] max_warp_scene_pix,
final Rectangle woi,
final Rectangle woi_veg // should be initialized, will be modified
) {
final int dbg_pix = 801; // 918;
final int woi_length = woi.width*woi.height;
final boolean [] valid_pixels = (valid_pixels_in != null) ? valid_pixels_in : (new boolean [woi_length]);
if (valid_pixels_in == null) {
......@@ -5255,6 +5258,9 @@ public class VegetationLMA {
int y = indx / woi_ext.width + woi_ext.y;
int x = indx % woi_ext.width + woi_ext.x;
int npix = x + y * full.width;
double radius = elev_radius[npix];
double radius2 = radius*radius;
int iradius = (int) Math.ceil (radius);
double elevation = tvao[TVAO_ELEVATION][npix];
double vegetation = tvao[TVAO_VEGETATION][npix];
if (!Double.isNaN(elevation) && !Double.isNaN(vegetation)) {
......@@ -5267,6 +5273,37 @@ public class VegetationLMA {
if (scales != null) {
double dx = scales[0] * elevation;
double dy = scales[1] * elevation;
int ax0 = (int) Math.floor(x + dx - radius);
int ax1 = (int) Math.ceil (x + dx + radius);
int ay0 = (int) Math.floor(y + dy - radius);
int ay1 = (int) Math.ceil (y + dy + radius);
Rectangle ar = new Rectangle(ax0, ay0, ax1-ax0 +1, ay1-ay0 +1);
if (woi.intersects(ar)) {
boolean has_valid_dependent = false;
for (int ay = ay0; ay <= ay1; ay++) {
double ddy = ay - (y + dy);
double ddy2 = ddy*ddy;
for (int ax = ax0; ax <= ax1; ax++) {
if (woi.contains(ax,ay)) {
double ddx = ax - (x + dx);
double ddr2 = ddy2 + ddx*ddx;
if (ddr2 <= radius2) {
int wx = ax - woi.x;
int wy = ay - woi.y;
int wpix =wx + wy*woi.width;
if (valid_pixels[wpix]) {
has_veg_thread[nthread][nscene][wpix] = true;
has_valid_dependent = true;
}
}
}
}
}
if (has_valid_dependent) {
veg_scene_used_prefilter[indx] = true;
}
}
/*
int px05 = (int) Math.floor(x + dx); // TODO: check sign! // ELEV-SIGN
int py05 = (int) Math.floor(y + dy); // TODO: check sign! // ELEV-SIGN
if (woi_plus1.contains(px05,py05)) { // up to 1 pixel to the nearest
......@@ -5291,6 +5328,7 @@ public class VegetationLMA {
veg_scene_used_prefilter[indx] = true;
}
}
*/
}
}
}
......@@ -5338,6 +5376,9 @@ public class VegetationLMA {
threads[ithread] = new Thread() {
public void run() {
for (int wPix = ai.getAndIncrement(); wPix < woi_length; wPix = ai.getAndIncrement()) { // if (valid_pixels[wPix]){
if (wPix == dbg_pix) {
System.out.println ("getValidScenesPixels() 1 : wpix = "+wPix);
}
boolean has_offset_middle = true;
for (int nscene = first_scene + max_sacrifice; nscene <= last_scene-max_sacrifice; nscene++) if (valid_scenes[nscene]){
if (!has_veg[nscene][wPix]) {
......
......@@ -401,14 +401,15 @@ public class VegetationModel {
double min_above = 0.02; // 0.025; // .04;
int patch_neib = 4; // 5;
double neibs_pow = 0.5;
final int grow_vegetation = clt_parameters.imp.terr_veget_grow;
double [][] combo_dsn =quadCLTs[ref_index].restoreComboDSI(true);
double [][] terr_veg = getTerrainVegetation(
combo_dsn, // double [][] combo_dsn);
tilesX, // final int tilesX,
min_above, // final double min_above, // absolute disparity difference
patch_neib, // final int patch_neib){
neibs_pow); // final double neibs_pow);
neibs_pow, // final double neibs_pow);
grow_vegetation); // final int grow_vegetation);
if (show_debug) {
String [] titles_terr_veg = {"terrain","vegetation"};
......@@ -725,7 +726,8 @@ public class VegetationModel {
final int tilesX,
final double min_above, // absolute disparity difference
final int patch_neibs,
final double neibs_pow){ // raise strength to this power when averaging neighbors
final double neibs_pow, // raise strength to this power when averaging neighbors
final int grow_vegetation){
final double [] terrain = combo_dsn[OpticalFlow.COMBO_DSN_INDX_TERRAIN];
final double [] ground = combo_dsn[OpticalFlow.COMBO_DSN_INDX_GROUND];
final double [] disparity = combo_dsn[OpticalFlow.COMBO_DSN_INDX_LMA];
......@@ -733,7 +735,7 @@ public class VegetationModel {
final int num_pixels = disparity.length;
final double [] vegetation = new double [num_pixels];
Arrays.fill(vegetation, Double.NaN);
final int dbg_tile = -(22+17*80);
final int dbg_tile = (25+20*80);
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -771,7 +773,20 @@ public class VegetationModel {
};
}
ImageDtt.startAndJoin(threads);
return new double [][] {terrain,vegetation};
double [] veget=vegetation;
if (grow_vegetation > 0) {
veget= TileProcessor.fillNaNs(
vegetation, // final double [] data,
null, // final boolean [] prohibit,
tilesX, // int width,
// CAREFUL ! Remaining NaN is grown by unsharp mask filter ************* !
grow_vegetation, // 100, // 2*width, // 16, // final int grow,
0.7, // double diagonal_weight, // relative to ortho
100, // int num_passes,
0.03); // final double max_rchange, // = 0.01 - does not need to be accurate
}
return new double [][] {terrain,veget}; // ation};
}
......@@ -819,14 +834,15 @@ public class VegetationModel {
double min_above = 0.02; // 0.025; // .04;
int patch_neib = 4; // 5;
double neibs_pow = 0.5;
final int grow_vegetation = clt_parameters.imp.terr_veget_grow;
double [][] combo_dsn =quadCLTs[ref_index].restoreComboDSI(true);
double [][] terr_veg = getTerrainVegetation(
combo_dsn, // double [][] combo_dsn);
tilesX, // final int tilesX,
min_above, // final double min_above, // absolute disparity difference
patch_neib, // final int patch_neib){
neibs_pow); // final double neibs_pow);
neibs_pow, // final double neibs_pow);
grow_vegetation); // final int grow_vegetation);
String [] titles_terr_veg = {"terrain","vegetation"};
ShowDoubleFloatArrays.showArrays(
......@@ -2089,7 +2105,7 @@ public class VegetationModel {
lambda_scale_bad, // double lambda_scale_bad, // 8.0
lambda_max, // double lambda_max, // 100
rms_diff, // double rms_diff, // 0.001
15, // num_iter, //int num_iter, // 20
num_iter, // 15, // num_iter, //int num_iter, // 20
last_run, // boolean last_run,
null, // String dbg_prefix,
debugLevel); // int debug_level)
......
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