Commit 62655772 authored by Andrey Filippov's avatar Andrey Filippov

Added filtering, improved center DSI near margins

parent d15a47db
......@@ -9,7 +9,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.common.PolynomialApproximation;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.gpu.GPUTileProcessor;
import com.elphel.imagej.tileprocessor.ErsCorrection;
import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.OpticalFlow;
......@@ -456,6 +455,7 @@ public class Cuas {
double [] cuas_atr = new double [] { center_ATR[0][0], center_ATR[0][1], center_ATR[0][2]};
double [][] cuas_xyzatr = {cuas_xyz, cuas_atr};
String center_name = QuadCLT.getCenterDirName(quadCLTs[quadCLTs.length - 1].getImageName());
QuadCLT center_CLT = changeReference(
quadCLTs, // QuadCLT [] quadCLTs,
ref_scene, // QuadCLT ref_old,
......@@ -490,32 +490,75 @@ public class Cuas {
ds[0], // double [] ref_disparity,
ref_scene, // QuadCLT refCLT, // should be the same instance if one of quadCLTs
debugLevel); // int debugLevel)
//Filter ref_pXpYD from folds in pX, pY and other
boolean show_debug = false;
int discard_border = clt_parameters.imp.cuas_discard_border;
double max_fold = clt_parameters.imp.cuas_max_fold;
int min_in_row_col = clt_parameters.imp.cuas_min_in_row_col;
if (debugLevel > -3) {
System.out.println("createCenterClt(): filtering ref_pXpYD: discard_border="+discard_border+
" pix, max_fold="+max_fold+" pix, min_in_row_col="+min_in_row_col+" tiles");
}
int width = ref_scene.getTilesX()*ref_scene.getTileSize();
int height = ref_scene.getTilesY()*ref_scene.getTileSize();
boolean apply_window_filter = (discard_border > 0) || (max_fold > 0) || (min_in_row_col > 0);
final Rectangle window = apply_window_filter ? (new Rectangle(discard_border,discard_border,width-2*discard_border,height-2*discard_border)): null;
if (window != null) {
if (show_debug) {
String debug_suffix="-center-disparity-pre-filtered";
center_CLT.show_pXpYD(
ref_pXpYD, // double [][] pXpYD,
debug_suffix, // String suffix,
true);// boolean show)
}
ref_scene.windowPsPyD(
ref_pXpYD, // final double [][] pXpYD,
window, // final Rectangle window) // window in pixels!
max_fold, // final double max_fold)
min_in_row_col); // final int min_in_row_col, // Minimal number of defined tiles in a row/column
}
double [] disparity_center = new double [ref_pXpYD.length];
Arrays.fill(disparity_center, Double.NaN);
for (int i = 0; i < ref_pXpYD.length; i++) if (ref_pXpYD[i] != null) {
disparity_center[i] = ref_pXpYD[i][2];
}
// TODO: extrapolate, fill gaps in disparity_center
// TODO: extra/interpolate, fill gaps in disparity_center
int grow_width = Math.max(center_CLT.getTilesX(), center_CLT.getTilesY());
int num_passes = 20;
double [][] debug_disparity_center = show_debug? (new double [2][]): null;
if (debug_disparity_center != null) {
debug_disparity_center[0] = disparity_center.clone();
}
disparity_center = TileProcessor.fillNaNs(
disparity_center, // final double [] data,
null, // final boolean [] prohibit,
center_CLT.getTilesX(), // int width,
2 * grow_width, // 100, // 2*width, // 16, // final int grow,
0.7, // double diagonal_weight, // relative to ortho
num_passes, // int num_passes,
0.03); // final double max_rchange, // = 0.01 - does not need to be accurate
if (debug_disparity_center != null) {
debug_disparity_center[1] = disparity_center.clone();
}
if (show_debug) {
String debug_suffix="-center-disparity-filtered";
center_CLT.show_pXpYD(
ref_pXpYD, // double [][] pXpYD,
debug_suffix, // String suffix,
true);// boolean show)
ShowDoubleFloatArrays.showArrays(
debug_disparity_center,
center_CLT.getTilesX(),
center_CLT.getTilesY(),
true,
center_CLT.getImageName()+"-center-disparity-filtering",
new String[] {"before","after"});
}
boolean save_weights = true; // always
/*
float [][][] center_clt_w = getTDComboSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
ref_pXpYD, // double [][] ref_pXpYD,
save_weights, // boolean save_weights, // output corresponding weights for each data
true, // boolean merge_all,
sensor_mask, // int sensor_mask,
null, // Rectangle fov_tiles,
OpticalFlow.ZERO3, // double [] stereo_xyz, // offset reference camera {x,y,z}
cuas_atr, // double [] stereo_atr_in, // offset reference orientation (cuas)
null, // ds[0], // double [] ref_disparity, // may be null if ref_pXpYD != null
quadCLTs, // QuadCLT [] quadCLTs,
ref_scene, // QuadCLT refCLT, // should be the same instance if one of quadCLTs
debugLevel); // int debugLevel)
*/
float [][][] center_clt_w = getTDComboSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
null, // ref_pXpYD, // double [][] ref_pXpYD,
......@@ -529,17 +572,9 @@ public class Cuas {
quadCLTs, // QuadCLT [] quadCLTs,
center_CLT, // ref_scene, // QuadCLT refCLT, // should be the same instance if one of quadCLTs
debugLevel); // int debugLevel)
/*
String center_name = QuadCLT.getCenterDirName(last_clt.getImageName()); // make name from last timestamp, not reference
String ref_dir_path = ref_scene.getX3dDirectory(center_name);
File cdir = new File(ref_dir_path);
QuadCLT center_CLT = new QuadCLT(ref_scene, center_name); //null
cdir.mkdirs();
center_CLT.setImagePath(cdir.getPath());
*/
center_CLT.setCenterClt( // only for merged sensors
center_clt_w[0][0], // float [] clt,
center_clt_w[1][0]); // int [] clt_num, // Index 1 out of bounds for length 1
center_clt_w[0][0], // float [] clt, // per CLT sample (4x pixels)
center_clt_w[1][0]); // float [] clt_weights // per tile
final int transform_size = ref_scene.getTileSize();
final int tilesX = ref_scene.getTilesX();
......@@ -550,109 +585,69 @@ public class Cuas {
transform_size, // final int transform_size,
tilesX, // final int tilesX,
tilesY); //final int tilesY);
int [] slices_to_fill = {
OpticalFlow.COMBO_DSN_INDX_DISP,
OpticalFlow.COMBO_DSN_INDX_STRENGTH
// OpticalFlow.COMBO_DSN_INDX_LMA, // keep as is
// OpticalFlow.COMBO_DSN_INDX_CHANGE, // may just relace nan with 0
/// OpticalFlow.COMBO_DSN_INDX_DISP_FG,
/// OpticalFlow.COMBO_DSN_INDX_DISP_BG_ALL
};
fillNanDsi(
ref_pXpYD, // double [][] ref_pXpYD,
center_combo_dsi, // double [][] dsi,
center_CLT, // QuadCLT ref_clt, // just for dimensions
slices_to_fill, // int [] slices)
debugLevel); // int debugLevel)
center_CLT.setDSIFromCombo(center_combo_dsi); // reformat
// center_CLT.setDSI(center_combo_dsi); // WRONG!
String rslt_suffix = "-INTER-INTRA";
rslt_suffix += (clt_parameters.correlate_lma?"-LMA":"-NOLMA");
/*
// fixing NaN in strengths. It is uses to return RMS in Not needed - NaN was from Arrays.fill(combo_dsn_final[i], Double.NaN);
// OpticalFlow:10348
for (int slice: OpticalFlow.COMBO_DSN_NONNAN) { // new int[] {COMBO_DSN_INDX_STRENGTH,COMBO_DSN_INDX_STRENGTH_BG}) {
if (center_combo_dsi[slice] != null) {
for (int i = 0; i <center_combo_dsi[slice].length; i++) {
if (Double.isNaN(center_combo_dsi[slice][i])) {
center_combo_dsi[slice][i] = 0.0;
}
}
}
}
*/
center_CLT.saveDoubleArrayInModelDirectory( // error
rslt_suffix, // String suffix,
OpticalFlow.COMBO_DSN_TITLES, // combo_dsn_titles_full, // null, // String [] labels, // or null
center_combo_dsi, // dbg_data, // double [][] data,
tilesX, // int width,
tilesY); // int height)
// center_CLT.saveDSI();
center_CLT.saveCenterClt();
/*
boolean save_clt = true;
boolean save_dsi = true;
boolean save_in_ref = true;
boolean save_in_last = true;
if (save_clt) {
final int height_clt = combo_seq_clt[0].length/width_clt;
String [] clt_titles = new String [combo_seq_clt_w.length];
for (int i = 0; i < combo_seq_clt.length; i++) {
clt_titles[i] = "chn-"+i;
if (save_weights) {
clt_titles[i+combo_seq_clt.length] = "weight-"+i;
}
}
String suffix_clt = "-clt_combo";
if (save_weights) {
suffix_clt+="_weights";
}
if (save_in_ref) {
ref_clt.saveFloatArrayInModelDirectory( // error
suffix_clt, // String suffix,
clt_titles, // combo_dsn_titles_full, // null, // String [] labels, // or null
combo_seq_clt_w, // dbg_data, // float [][] data,
width_clt, // int width,
height_clt); // int height)
return center_CLT;
}
if (save_in_last) {
quadCLTs[quadCLTs.length - 1].saveFloatArrayInModelDirectory( // error
suffix_clt, // String suffix,
clt_titles, // combo_dsn_titles_full, // null, // String [] labels, // or null
combo_seq_clt_w, // dbg_data, // float [][] data,
width_clt, // int width,
height_clt); // int height)
public static void fillNanDsi(
double [][] ref_pXpYD,
double [][] dsi,
QuadCLT ref_clt, // just for dimensions
int [] slices,
int debugLevel) {
int grow_width = Math.max(ref_clt.getTilesX(), ref_clt.getTilesY());
int num_passes = 20;
for (int slice:slices) {
double [] data = dsi[slice]; // .clone(); // not needed to clone
for (int i = 0; i < ref_pXpYD.length; i++) {
if (ref_pXpYD[i] == null) {
data[i] = Double.NaN; // for strength layers that are 0-s
}
}
if (save_dsi) {
// final double [][] combo_dsi_cli = ref_clt.restoreComboDSI (true);
TileProcessor tp = quadCLTs[quadCLTs.length - 1].getTileProcessor();
final int transform_size = tp.getTileSize();
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
final double [][] center_dsi = interpolateDSI(
ref_pXpYD, // final double [][] ref_pXpYD,
ref_dsi, // combo_dsi_cli, // final double [][] dsi_in,
transform_size, // final int transform_size,
tilesX, // final int tilesX,
tilesY); //final int tilesY);
String rslt_suffix = "-CENTER-INTER-INTRA";
// use quadCLTs[quadCLTs.length - 1].restoreComboDSI ("-CENTER",true); to restore
rslt_suffix += (clt_parameters.correlate_lma?"-LMA":"-NOLMA");
if (save_in_ref) {
ref_clt.saveDoubleArrayInModelDirectory( // error
rslt_suffix, // String suffix,
OpticalFlow.COMBO_DSN_TITLES, // combo_dsn_titles_full, // null, // String [] labels, // or null
center_dsi, // dbg_data, // double [][] data,
tilesX, // int width,
tilesY); // int height)
if (debugLevel > -3) {
System.out.println("fillNanDsi(); starting for slice "+slice+" ("+OpticalFlow.COMBO_DSN_TITLES[slice]+")");
}
if (save_in_last) {
quadCLTs[quadCLTs.length - 1].saveDoubleArrayInModelDirectory( // error
rslt_suffix, // String suffix,
OpticalFlow.COMBO_DSN_TITLES, // combo_dsn_titles_full, // null, // String [] labels, // or null
center_dsi, // dbg_data, // double [][] data,
tilesX, // int width,
tilesY); // int height)
dsi[slice] = TileProcessor.fillNaNs(
data, // final double [] data,
null, // final boolean [] prohibit,
ref_clt.getTilesX(), // int width,
2 * grow_width, // 100, // 2*width, // 16, // final int grow,
0.7, // double diagonal_weight, // relative to ortho
num_passes, // int num_passes,
0.03); // final double max_rchange, // = 0.01 - does not need to be accurate
if (debugLevel > -3) {
System.out.println("fillNanDsi(); done for slice "+slice+" ("+OpticalFlow.COMBO_DSN_TITLES[slice]+")");
}
}
*/
return center_CLT;
return;
}
public static double [][] interpolateDSI( // uses combo_dsi, not this.dsi
final double [][] ref_pXpYD,
final double [][] combo_dsi_in,
......
......@@ -5828,7 +5828,7 @@ public class OpticalFlow {
}
}
// just for verification
boolean show_clt = false;// true;
boolean show_clt = true; // false;// true;
if (show_clt) {
center_CLT.showCenterClt(
clt_parameters); // CLTParameters clt_parameters,
......@@ -15495,6 +15495,7 @@ public class OpticalFlow {
return mb_vectors;
}
// Use TileProcessor.fillNaNs
public static double[] fillGapsDouble(
double [] data,
boolean [] mask_in, // do not process if false (may be null)
......
......@@ -1689,7 +1689,8 @@ public class QuadCLT extends QuadCLTCPU {
int width=ref_scene.getTilesX()*ref_scene.getTileSize();
int height=ref_scene.getTilesY()*ref_scene.getTileSize();
// window in pixels!
final Rectangle window = (discard_border > 0)? (new Rectangle(discard_border,discard_border,width-2*discard_border,height-2*discard_border)): null;
boolean apply_window_filter = (discard_border > 0) || (max_fold > 0) || (min_in_row_col > 0);
final Rectangle window = apply_window_filter ? (new Rectangle(discard_border,discard_border,width-2*discard_border,height-2*discard_border)): null;
if (ref_pXpYD != null) { // cuas mode, ref_pXpYD defines offset reference scene
pXpYD=OpticalFlow.transformToScenePxPyD(
ref_pXpYD, // final double [][] reference_pXpYD, // invalid tiles - NaN in disparity. Should be no nulls, no NaN disparity
......
......@@ -932,11 +932,7 @@ public class QuadCLTCPU {
}
}
}
return new double [] {coeffs[0][1],coeffs[1][1],coeffs[2][1]};
}
public static double [] getOmegaCorrections(
......@@ -13889,7 +13885,8 @@ public class QuadCLTCPU {
tp.getTilesX(),
tp.getTilesY(),
true,
"filtered_bgnd_disp_strength",dbg_titles);
"filtered_bgnd_disp_strength",
dbg_titles);
}
int num_bg = tp.clt_3d_passes.get(bg_scan).setTileOpDisparity( // other minimal strength?
bg_sel, // bg_use, // bg_sel, // bg_use, // boolean [] selection, measure all that can be bg
......
......@@ -8835,7 +8835,7 @@ ImageDtt.startAndJoin(threads);
}
/**
* Us this one when filling full frame and prohibit is not used. Faster as it first tries lower resolution, then full
* Use this one when filling full frame and prohibit is not used. Faster as it first tries lower resolution, then full
* @param data_in input data array
* @param width_full width of the input dtata
* @param decimate_step decimation step (such as 16)
......
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