Commit 151ea276 authored by Andrey Filippov's avatar Andrey Filippov

Minor changes here and there during program use/debugging

parent 67ee5db2
...@@ -28,8 +28,8 @@ public class ThermalColor { ...@@ -28,8 +28,8 @@ public class ThermalColor {
double k = out_range/PALETTE_RANGE; double k = out_range/PALETTE_RANGE;
double value = (v-min)/(max-min) * (this.palette.length - 1); double value = (v-min)/(max-min) * (this.palette.length - 1);
int ivalue = (int) (value); int ivalue = (int) (value);
if (ivalue < 0) return this.palette[0]; if (value < 0) return this.palette[0];
if (ivalue >= (this.palette.length -1)) return this.palette[this.palette.length -1]; if (value >= (this.palette.length -1)) return this.palette[this.palette.length -1];
double a = (value-ivalue); // 0..1 double a = (value-ivalue); // 0..1
double [] rslt = { double [] rslt = {
k*((1 - a) * this.palette[ivalue][0] + a * this.palette[ivalue+1][0]), k*((1 - a) * this.palette[ivalue][0] + a * this.palette[ivalue+1][0]),
......
...@@ -116,7 +116,7 @@ public class IntersceneLmaParameters { ...@@ -116,7 +116,7 @@ public class IntersceneLmaParameters {
gd.addMessage("Interframe LMA parameters selection"); gd.addMessage("Interframe LMA parameters selection");
gd.addCheckbox ("3D mode (use disparity)", this.ilma_3d, gd.addCheckbox ("3D mode (use disparity)", this.ilma_3d,
"Use disparity for interscene matching (as for UAS imagery)" ); "Use disparity for interscene matching (as for UAS imagery)" );
gd.addNumericField("Disp[arity weight", this.ilma_disparity_weight, 6,8,"", gd.addNumericField("Disparity weight", this.ilma_disparity_weight, 6,8,"",
"Disparity component weight compared to dX and dY"); "Disparity component weight compared to dX and dY");
gd.addCheckbox ("LMA in 3D mode", this.ilma_3d_lma, gd.addCheckbox ("LMA in 3D mode", this.ilma_3d_lma,
"Use LMA disparity for interscene matching (as for UAS imagery)" ); "Use LMA disparity for interscene matching (as for UAS imagery)" );
......
...@@ -4538,6 +4538,10 @@ public class OpticalFlow { ...@@ -4538,6 +4538,10 @@ public class OpticalFlow {
int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it int min_num_scenes = clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it
int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series int max_num_scenes = clt_parameters.imp.max_num_scenes; // cut longer series
double boost_max_short = 2.0; //
double [] lma_rms = new double[2]; double [] lma_rms = new double[2];
double [] use_atr = null; double [] use_atr = null;
...@@ -4689,6 +4693,26 @@ public class OpticalFlow { ...@@ -4689,6 +4693,26 @@ public class OpticalFlow {
scenes_xyzatr[scene_index][1].clone()}; scenes_xyzatr[scene_index][1].clone()};
boolean rot_to_transl = after_spiral && clt_parameters.ilp.ilma_translation_priority; boolean rot_to_transl = after_spiral && clt_parameters.ilp.ilma_translation_priority;
double [] reg_weights = rot_to_transl? clt_parameters.ilp.ilma_regularization_weights0 : clt_parameters.ilp.ilma_regularization_weights; double [] reg_weights = rot_to_transl? clt_parameters.ilp.ilma_regularization_weights0 : clt_parameters.ilp.ilma_regularization_weights;
min_max[1] = max_offset;
if ((ref_index - scene_index) < min_num_scenes) {
min_max[1] = boost_max_short * max_offset;
if (debugLevel > -3) {
System.out.println("As the current series ("+(ref_index - scene_index)+
" scenes) is shorter than minimal ("+min_num_scenes+"), the maximal shift is scaled by "+
boost_max_short + " to " + (boost_max_short * max_offset)+
" pixels");
}
}
if ((scene_index - earliest_scene) < min_num_scenes) {
min_max[1] = boost_max_short * max_offset;
if (debugLevel > -3) {
System.out.println("As the remaining number of scenes to process ("+(scene_index - earliest_scene + 1)+
") is less than minimal ("+min_num_scenes+"), the maximal shift is scaled by "+
boost_max_short + " to " + (boost_max_short * max_offset)+
" pixels");
}
}
scenes_xyzatr[scene_index] = adjustPairsLMAInterscene( scenes_xyzatr[scene_index] = adjustPairsLMAInterscene(
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
use_lma_dsi, // clt_parameters.imp.use_lma_dsi, use_lma_dsi, // clt_parameters.imp.use_lma_dsi,
...@@ -5107,7 +5131,7 @@ public class OpticalFlow { ...@@ -5107,7 +5131,7 @@ public class OpticalFlow {
if (!force_initial_orientations) { if (!force_initial_orientations) {
if ((quadCLTs[ref_index].getNumOrient() == 0) ||(!quadCLTs[ref_index].propertiesContainString (".scenes_"))) { if ((quadCLTs[ref_index].getNumOrient() == 0) ||(!quadCLTs[ref_index].propertiesContainString (".scenes_"))) {
if (debugLevel >-2) { if (debugLevel >-3) {
System.out.println("Egomotion data for scene "+set_channels[ref_index].set_name+" does not exist, forcing its calculation."); System.out.println("Egomotion data for scene "+set_channels[ref_index].set_name+" does not exist, forcing its calculation.");
} }
force_initial_orientations = true; force_initial_orientations = true;
...@@ -5794,12 +5818,64 @@ public class OpticalFlow { ...@@ -5794,12 +5818,64 @@ public class OpticalFlow {
} // for (int ibase = 0; ibase < baselines.length; ibase++) { } // for (int ibase = 0; ibase < baselines.length; ibase++) {
}// for (int mode3d = 0; mode3d<generate_modes3d.length; mode3d++) if (generate_modes3d[mode3d]) { }// for (int mode3d = 0; mode3d<generate_modes3d.length; mode3d++) if (generate_modes3d[mode3d]) {
} // if (generate_mapped) { } // if (generate_mapped) {
if (export_dsi_image || show_dsi_image) {
if (combo_dsn_final == null) {
/// combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory(
/// "-INTER-INTRA-LMA", // String suffix,
/// 0, // int num_slices, // (0 - all)
/// null); // int [] wh);
combo_dsn_final =quadCLTs[ref_index].restoreComboDSI(true); // also sets quadCLTs[ref_index].dsi and blue sky
}
// re-load , should create quadCLTs[ref_index].dsi
double [][] dls = {
combo_dsn_final[COMBO_DSN_INDX_DISP],
combo_dsn_final[COMBO_DSN_INDX_LMA],
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]
};
int dbg_condition = debug_ranges ? Math.max(1, debugLevel) : debugLevel;
double [][] ds = conditionInitialDS( // Add debug szxy by providing debugLevel=1
true, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
dbg_condition); // int debug_level)
double [] disparity = ds[0];
double [] strength = ds[1];
double [][]szxy = getSceneSZXY(
quadCLTs[ref_index], // QuadCLT scene,
range_disparity_offset, // double disparity_offset,
range_min_strength, // double min_strength,
range_max, // double max_range,
disparity, // double [] disparity,
strength); // double [] strength)
String [] szxy_titles = {"strength", "Z(m)", "X(m)", "Y(m)"};
TileProcessor tp = quadCLTs[ref_index].getTileProcessor();
int tilesX = tp.getTilesX();
int tilesY = tp.getTilesY();
ImagePlus impSZXY = ShowDoubleFloatArrays.makeArrays(
szxy,
tilesX,
tilesY,
quadCLTs[ref_index].getImageName()+"_SZXY",
szxy_titles);
if (export_dsi_image) {
quadCLTs[ref_index].saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-BACKGROUND", // String suffix,
impSZXY); // ImagePlus imp)
}
if (show_dsi_image) {
impSZXY.show();
}
}
// debugging 3D model // debugging 3D model
int [] whs = new int[3]; int [] whs = new int[3];
double [] x0y0 = new double[2]; double [] x0y0 = new double[2];
if (export3d) { //combo_dsn_final had strength 1.0e-4 where it should not? Reset it? if (export3d) { //combo_dsn_final had strength 1.0e-4 where it should not? Reset it?
/* */ /*
boolean use_lma = true; // ; boolean use_lma = true; // ;
double discard_low = 0.01; // fraction of all pixels double discard_low = 0.01; // fraction of all pixels
double discard_high = 0.5; // fraction of all pixels double discard_high = 0.5; // fraction of all pixels
...@@ -5817,6 +5893,7 @@ public class OpticalFlow { ...@@ -5817,6 +5893,7 @@ public class OpticalFlow {
double [] hdr_x0y0 = new double[2]; double [] hdr_x0y0 = new double[2];
double [][] to_ground_xyxatr = quadCLTs[ref_index].getGround( double [][] to_ground_xyxatr = quadCLTs[ref_index].getGround(
use_lma, // boolean use_lma, use_lma, // boolean use_lma,
clt_parameters.imp.range_disparity_offset,// double range_disparity_offset
discard_low, // double discard_low, // fraction of all pixels discard_low, // double discard_low, // fraction of all pixels
discard_high, // double discard_high, // fraction of all pixels discard_high, // double discard_high, // fraction of all pixels
discard_adisp, // double discard_adisp, // discard above/below this fraction of average height discard_adisp, // double discard_adisp, // discard above/below this fraction of average height
...@@ -5827,7 +5904,7 @@ public class OpticalFlow { ...@@ -5827,7 +5904,7 @@ public class OpticalFlow {
hdr_whs, // int [] whs, // initialize to int[3] to return {width, height, scale reduction} hdr_whs, // int [] whs, // initialize to int[3] to return {width, height, scale reduction}
debugLevel); // int debug_level debugLevel); // int debug_level
/**/ */
boolean ok_3d = TexturedModel.output3d( // quadCLTs have same image name, and everything else boolean ok_3d = TexturedModel.output3d( // quadCLTs have same image name, and everything else
clt_parameters, // CLTParameters clt_parameters, clt_parameters, // CLTParameters clt_parameters,
...@@ -6085,58 +6162,6 @@ public class OpticalFlow { ...@@ -6085,58 +6162,6 @@ public class OpticalFlow {
} }
} }
if (export_dsi_image || show_dsi_image) {
if (combo_dsn_final == null) {
/// combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory(
/// "-INTER-INTRA-LMA", // String suffix,
/// 0, // int num_slices, // (0 - all)
/// null); // int [] wh);
combo_dsn_final =quadCLTs[ref_index].restoreComboDSI(true); // also sets quadCLTs[ref_index].dsi and blue sky
}
// re-load , should create quadCLTs[ref_index].dsi
double [][] dls = {
combo_dsn_final[COMBO_DSN_INDX_DISP],
combo_dsn_final[COMBO_DSN_INDX_LMA],
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]
};
int dbg_condition = debug_ranges ? Math.max(1, debugLevel) : debugLevel;
double [][] ds = conditionInitialDS( // Add debug szxy by providing debugLevel=1
true, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
quadCLTs[ref_index], // QuadCLT scene,
dbg_condition); // int debug_level)
double [] disparity = ds[0];
double [] strength = ds[1];
double [][]szxy = getSceneSZXY(
quadCLTs[ref_index], // QuadCLT scene,
range_disparity_offset, // double disparity_offset,
range_min_strength, // double min_strength,
range_max, // double max_range,
disparity, // double [] disparity,
strength); // double [] strength)
String [] szxy_titles = {"strength", "Z(m)", "X(m)", "Y(m)"};
TileProcessor tp = quadCLTs[ref_index].getTileProcessor();
int tilesX = tp.getTilesX();
int tilesY = tp.getTilesY();
ImagePlus impSZXY = ShowDoubleFloatArrays.makeArrays(
szxy,
tilesX,
tilesY,
quadCLTs[ref_index].getImageName()+"_SZXY",
szxy_titles);
if (export_dsi_image) {
quadCLTs[ref_index].saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-BACKGROUND", // String suffix,
impSZXY); // ImagePlus imp)
}
if (show_dsi_image) {
impSZXY.show();
}
}
if (export_ml_files) { if (export_ml_files) {
if (combo_dsn_final == null) { // always re-read? if (combo_dsn_final == null) { // always re-read?
...@@ -13112,11 +13137,22 @@ public class OpticalFlow { ...@@ -13112,11 +13137,22 @@ public class OpticalFlow {
} }
return null; return null;
} }
if (avg_offs > min_max[1]) {// NaN - do not check; if (avg_offs > min_max[1]) {// NaN - do not check;
if (fail_reason != null) { if (fail_reason != null) {
fail_reason[0]=FAIL_REASON_MAX; fail_reason[0]=FAIL_REASON_MAX;
} }
if (debug_level > -3){
System.out.println ("interCorrPair(): avg_offs = "+avg_offs+
" > "+min_max[1]+", sw = "+sw);
}
return null; return null;
} else {
if (debug_level > -3){
System.out.println ("interCorrPair(): avg_offs = "+avg_offs+
" <= "+min_max[1]+", sw = "+sw);
}
} }
} }
double half_disparity = near_important ? 0.0 : clt_parameters.imp.half_disparity; double half_disparity = near_important ? 0.0 : clt_parameters.imp.half_disparity;
...@@ -14242,6 +14278,7 @@ public class OpticalFlow { ...@@ -14242,6 +14278,7 @@ public class OpticalFlow {
// double mb_max_gain = clt_parameters.imp.mb_max_gain_inter; // 5.0; // motion blur maximal gain (if more - move second point more than a pixel // double mb_max_gain = clt_parameters.imp.mb_max_gain_inter; // 5.0; // motion blur maximal gain (if more - move second point more than a pixel
int margin = clt_parameters.imp.margin; int margin = clt_parameters.imp.margin;
double second_margin = 1.1; // allow slightly larger offset for readjsutments (to be limited by the first pass) double second_margin = 1.1; // allow slightly larger offset for readjsutments (to be limited by the first pass)
double boost_max_short = 5.0; // 2.0; // Some bug?
int earliest_scene = 0; int earliest_scene = 0;
boolean use_combo_dsi = clt_parameters.imp.use_combo_dsi; boolean use_combo_dsi = clt_parameters.imp.use_combo_dsi;
boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi; boolean use_lma_dsi = clt_parameters.imp.use_lma_dsi;
...@@ -14250,14 +14287,14 @@ public class OpticalFlow { ...@@ -14250,14 +14287,14 @@ public class OpticalFlow {
int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY(); int tilesY = quadCLTs[ref_index].getTileProcessor().getTilesY();
int tile_size = quadCLTs[ref_index].getTileProcessor().getTileSize(); int tile_size = quadCLTs[ref_index].getTileProcessor().getTileSize();
double min_offset = clt_parameters.imp.min_offset; double min_offset = clt_parameters.imp.min_offset;
double max_offset = second_margin*clt_parameters.imp.max_rel_offset * tilesX * tile_size; double max_offset = boost_max_short*second_margin*clt_parameters.imp.max_rel_offset * tilesX * tile_size;
double max_roll = second_margin*clt_parameters.imp.max_roll_deg*Math.PI/180.0; double max_roll = second_margin*clt_parameters.imp.max_roll_deg*Math.PI/180.0;
double max_zoom_diff = second_margin*clt_parameters.imp.max_zoom_diff; double max_zoom_diff = second_margin*clt_parameters.imp.max_zoom_diff;
boolean fpn_skip = clt_parameters.imp.fpn_skip; // if false - fail as before boolean fpn_skip = clt_parameters.imp.fpn_skip; // if false - fail as before
boolean fpn_rematch = clt_parameters.imp.fpn_rematch; // if false - keep previous boolean fpn_rematch = clt_parameters.imp.fpn_rematch; // if false - keep previous
double [] min_max = {min_offset, max_offset, 0.0} ; // {min, max, actual rms) double [] min_max = {min_offset, max_offset, 0.0} ; // {min, max, actual rms)
int [] fail_reason = new int[1]; // null or int[1]: 0 - OK, 2 - LMA, 3 - min, 4 - max int [] fail_reason = new int[1]; // null or int[1]: 0 - OK, 2 - LMA, 3 - min, 4 - max
System.out.println("reAdjustPairsLMAInterscene(): min_offset="+min_max[0]+", max_offset="+min_max[1]);
double [] disparity_raw = new double [tilesX * tilesY]; double [] disparity_raw = new double [tilesX * tilesY];
Arrays.fill(disparity_raw,clt_parameters.disparity); Arrays.fill(disparity_raw,clt_parameters.disparity);
/// double [][] combo_dsn_final = quadCLTs[ref_index].readDoubleArrayFromModelDirectory( /// double [][] combo_dsn_final = quadCLTs[ref_index].readDoubleArrayFromModelDirectory(
......
...@@ -223,6 +223,7 @@ public class QuadCLTCPU { ...@@ -223,6 +223,7 @@ public class QuadCLTCPU {
// cac // cac
public double [][] getGround( public double [][] getGround(
boolean use_lma, boolean use_lma,
double disparity_offset,
double discard_low, // fraction of all pixels double discard_low, // fraction of all pixels
double discard_high, // fraction of all pixels double discard_high, // fraction of all pixels
double discard_adisp, // discard above/below this fraction of average height double discard_adisp, // discard above/below this fraction of average height
...@@ -234,22 +235,24 @@ public class QuadCLTCPU { ...@@ -234,22 +235,24 @@ public class QuadCLTCPU {
int debug_level int debug_level
) { ) {
double [] z_tilts = null; double [] z_tilts = null;
final int tilesX=getTileProcessor().getTilesX(); double normal_damping = 0.001; // pull to horizontal if not enough data
final int tilesY=getTileProcessor().getTilesY(); // final int tilesX=getTileProcessor().getTilesX();
double hist_rlow = 0.4; // final int tilesY=getTileProcessor().getTilesY();
double hist_rlow = 0.5;
double hist_rhigh = 2.0; double hist_rhigh = 2.0;
int min_good = 20; //number of good tiles int min_good = 20; //number of good tiles
int min_good_quad = 20; // number of good tiles per quadrantto calculate tilts /// int min_good_quad = 20; // number of good tiles per quadrant to calculate tilts
int gap_frac2= 20; /// int gap_frac2= 20;
double rel_hight = 0.2; // when calculating scale, ignore objects far from plane double rel_hight = 0.2; // when calculating scale, ignore objects far from plane
int num_bins = 1000; int num_bins = 1000;
double [][] dls = getDLS(); double [][] dls = getDLS();
if (dls==null) { if (dls==null) {
return null; return null;
} }
double [][] ds = new double [][] {dls[use_lma?1:0], dls[2]}; double [][] ds = new double [][] {dls[use_lma?1:0].clone(), dls[2]};
double sw=0, swd=0; double sw=0, swd=0;
for (int i = 0; i < ds[0].length; i++) if (!Double.isNaN(ds[0][i])){ for (int i = 0; i < ds[0].length; i++) if (!Double.isNaN(ds[0][i])){
ds[0][i] -= disparity_offset;
sw += ds[1][i]; sw += ds[1][i];
swd += ds[0][i] * ds[1][i]; swd += ds[0][i] * ds[1][i];
} }
...@@ -318,7 +321,9 @@ public class QuadCLTCPU { ...@@ -318,7 +321,9 @@ public class QuadCLTCPU {
} }
return null; // too few good return null; // too few good
} }
double z_avg= getGeometryCorrection().getZFromDisparity(swd/sw);
// double z_avg= getGeometryCorrection().getZFromDisparity(swd/sw);
/*
int gap_x_0 = tilesX/2 - tilesX/gap_frac2; int gap_x_0 = tilesX/2 - tilesX/gap_frac2;
int gap_x_1 = tilesX/2 + tilesX/gap_frac2; int gap_x_1 = tilesX/2 + tilesX/gap_frac2;
int gap_y_0 = tilesY/2 - tilesY/gap_frac2; int gap_y_0 = tilesY/2 - tilesY/gap_frac2;
...@@ -348,9 +353,11 @@ public class QuadCLTCPU { ...@@ -348,9 +353,11 @@ public class QuadCLTCPU {
System.out.println("There are less than 3 quadrants ("+num_good_quads+") having more than "+min_good_quad+" tiles"); System.out.println("There are less than 3 quadrants ("+num_good_quads+") having more than "+min_good_quad+" tiles");
System.out.println("Using only level "+z_avg+", ignoring tilt."); System.out.println("Using only level "+z_avg+", ignoring tilt.");
} }
z_tilts = new double[] {z_avg, 0.0, 0.0}; // no tilts z_tilts = new double[] {-z_avg, 0.0, 0.0}; // no tilts
// return new double[] {z_avg, 0.0, 0.0}; // no tilts // return new double[] {z_avg, 0.0, 0.0}; // no tilts
} else { } else {
*/
// fit plane // fit plane
double [] ref_disparity = ds[0].clone(); double [] ref_disparity = ds[0].clone();
for (int i = 0; i < ref_disparity.length; i++) { for (int i = 0; i < ref_disparity.length; i++) {
...@@ -381,17 +388,18 @@ public class QuadCLTCPU { ...@@ -381,17 +388,18 @@ public class QuadCLTCPU {
mindx++; mindx++;
} }
PolynomialApproximation pa = new PolynomialApproximation(); PolynomialApproximation pa = new PolynomialApproximation();
double [] damping = new double [] {normal_damping, normal_damping};
double[][] approx2d = pa.quadraticApproximation( double[][] approx2d = pa.quadraticApproximation(
mdata, mdata,
true, // boolean forceLinear, // use linear approximation true, // boolean forceLinear, // use linear approximation
null, // double [] damping, null OK damping, // double [] damping, null OK
-1); // debug level -1); // debug level
z_tilts= new double [] { approx2d[0][2], approx2d[0][0], approx2d[0][1]}; z_tilts= new double [] { approx2d[0][2], approx2d[0][0], approx2d[0][1]};
if (debug_level > -3) { if (debug_level > -3) {
System.out.println("Found ground plane: level="+z_tilts[0]+", tiltX="+z_tilts[1]+", tiltY="+z_tilts[2]); System.out.println("Found ground plane: level="+z_tilts[0]+", tiltX="+z_tilts[1]+", tiltY="+z_tilts[2]);
} }
} /* } */
// ground - negative Z. picture right - positive X, picture up - positive Y // ground - negative Z. picture right - positive X, picture up - positive Y
// positive tiltX - to the right higher ground (lower altitude above it) or camera tilted left // positive tiltX - to the right higher ground (lower altitude above it) or camera tilted left
// positive tiltY - picture up - higher ground (or camera tilted back) // positive tiltY - picture up - higher ground (or camera tilted back)
...@@ -402,11 +410,16 @@ public class QuadCLTCPU { ...@@ -402,11 +410,16 @@ public class QuadCLTCPU {
// It is approximate for small angles. OK for now // It is approximate for small angles. OK for now
double [][] to_ground_xyxatr = ErsCorrection.invertXYZATR(ground_xyxatr); double [][] to_ground_xyxatr = ErsCorrection.invertXYZATR(ground_xyxatr);
// recalculate coordinates for all pixels including weak ones // recalculate coordinates for all pixels including weak ones
double [] ref_disparity = dls[0].clone(); // double []
ref_disparity = dls[0].clone();
for (int i = 0; i < ref_disparity.length; i++) { for (int i = 0; i < ref_disparity.length; i++) {
if (Double.isNaN(ref_disparity[i])) ref_disparity[i] = 0.0; if (Double.isNaN(ref_disparity[i])) ref_disparity[i] = 0.0;
else {
ref_disparity[i] -= disparity_offset;
}
} }
double [][] wxyz = OpticalFlow.transformToWorldXYZ( // double [][]
wxyz = OpticalFlow.transformToWorldXYZ(
ref_disparity, // final double [] disparity_ref, // invalid tiles - NaN in disparity ref_disparity, // final double [] disparity_ref, // invalid tiles - NaN in disparity
(QuadCLT) this, // final QuadCLT quadClt, // now - may be null - for testing if scene is rotated ref (QuadCLT) this, // final QuadCLT quadClt, // now - may be null - for testing if scene is rotated ref
THREADS_MAX); // int threadsMax) THREADS_MAX); // int threadsMax)
...@@ -432,8 +445,11 @@ public class QuadCLTCPU { ...@@ -432,8 +445,11 @@ public class QuadCLTCPU {
if (y < y_min_max[0]) y_min_max[0] = y; if (y < y_min_max[0]) y_min_max[0] = y;
else if (y > y_min_max[1]) y_min_max[1] = y; else if (y > y_min_max[1]) y_min_max[1] = y;
} }
if ((x_min_max == null) || (y_min_max == null)) {
return null; // no points at all?
}
if (x0y0!=null) { if (x0y0!=null) {
x0y0[0] = x_min_max[0]; x0y0[0] = x_min_max[0]; // null
x0y0[1] = y_min_max[0]; x0y0[1] = y_min_max[0];
} }
int scale = 0; int scale = 0;
...@@ -8387,6 +8403,9 @@ public class QuadCLTCPU { ...@@ -8387,6 +8403,9 @@ public class QuadCLTCPU {
double [][] rgba = new double [num_slices][]; double [][] rgba = new double [num_slices][];
for (int i = 0; i < 3; i++) rgba[i] = new double [texture_data[main_color_index].length]; for (int i = 0; i < 3; i++) rgba[i] = new double [texture_data[main_color_index].length];
for (int i = 0; i < rbg_in[main_color_index].length; i++) { for (int i = 0; i < rbg_in[main_color_index].length; i++) {
if (i==160000) {
System.out.println ("i="+i);
}
double [] rgb = tc.getRGB(texture_data[main_color_index][i]); double [] rgb = tc.getRGB(texture_data[main_color_index][i]);
rgba[0][i] = rgb[0]; // red rgba[0][i] = rgb[0]; // red
rgba[1][i] = rgb[1]; // green rgba[1][i] = rgb[1]; // green
...@@ -15421,6 +15440,7 @@ public class QuadCLTCPU { ...@@ -15421,6 +15440,7 @@ public class QuadCLTCPU {
public boolean writeLwirPreview( public boolean writeLwirPreview(
final CLTParameters clt_parameters, final CLTParameters clt_parameters,
double [] data, double [] data,
double [] minmax, // null for auto
QuadCLT scene, QuadCLT scene,
int tex_palette, int tex_palette,
String suffix, String suffix,
...@@ -15429,6 +15449,7 @@ public class QuadCLTCPU { ...@@ -15429,6 +15449,7 @@ public class QuadCLTCPU {
clt_parameters, clt_parameters,
data, data,
getTileProcessor().getTilesX() *getTileProcessor().getTileSize(), getTileProcessor().getTilesX() *getTileProcessor().getTileSize(),
minmax, // double [] minmax, // null for auto
scene, scene,
tex_palette, tex_palette,
suffix, suffix,
...@@ -15438,6 +15459,7 @@ public class QuadCLTCPU { ...@@ -15438,6 +15459,7 @@ public class QuadCLTCPU {
final CLTParameters clt_parameters, final CLTParameters clt_parameters,
double [] data, double [] data,
int width, int width,
double [] minmax, // null for auto
QuadCLT scene, QuadCLT scene,
int tex_palette, int tex_palette,
String suffix, String suffix,
...@@ -15449,7 +15471,15 @@ public class QuadCLTCPU { ...@@ -15449,7 +15471,15 @@ public class QuadCLTCPU {
for (int i = 0; i < rendered_texture[0].length; i++) { for (int i = 0; i < rendered_texture[0].length; i++) {
rendered_texture[1][i] = Double.isNaN(rendered_texture[0][i])? 0.0: 1.0; rendered_texture[1][i] = Double.isNaN(rendered_texture[0][i])? 0.0: 1.0;
} }
double [] minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene) // double [] minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene)
if (!suffix.equals("")) {
if (minmax == null) { // to replace standard preview file name
minmax = scene.getColdHot(); // used in linearStackToColor (from this current scene)
suffix +="-AUTORANGE";
} else {
suffix +="-RANGE"+(minmax[1]-minmax[0]);
}
}
// int width = getTileProcessor().getTilesX() *getTileProcessor().getTileSize(); // int width = getTileProcessor().getTilesX() *getTileProcessor().getTileSize();
int height = data.length/width; int height = data.length/width;
String set_name = getImageName(); String set_name = getImageName();
......
...@@ -2451,7 +2451,8 @@ public class TexturedModel { ...@@ -2451,7 +2451,8 @@ public class TexturedModel {
final boolean updateStatus, final boolean updateStatus,
final int debugLevel) final int debugLevel)
{ {
final boolean render_hdr = true; //false; // true; // generate textures w/o normalization to generate undistorted final boolean render_hdr = true; //false; // true; // generate textures w/o normalization to generate undistorted
final double range_disparity_offset = clt_parameters.imp.range_disparity_offset;// double range_disparity_offset
final boolean batch_mode = clt_parameters.multiseq_run; // batch_run; final boolean batch_mode = clt_parameters.multiseq_run; // batch_run;
final boolean gltf_emissive = clt_parameters.gltf_emissive; final boolean gltf_emissive = clt_parameters.gltf_emissive;
final boolean use_alpha_blend = clt_parameters.gltf_alpha_blend; final boolean use_alpha_blend = clt_parameters.gltf_alpha_blend;
...@@ -2495,6 +2496,9 @@ public class TexturedModel { ...@@ -2495,6 +2496,9 @@ public class TexturedModel {
// final int show_slice_bitmap = clt_parameters.lre_show_slice_bitmap; // final int show_slice_bitmap = clt_parameters.lre_show_slice_bitmap;
final int sky_layer = 0; // source disparity layer that contains "blue sky" final int sky_layer = 0; // source disparity layer that contains "blue sky"
final boolean tex_um_fixed = clt_parameters.tex_um_fixed; // imp.mono_fixed; // true; // normalize to fixed range when converting to 8 bits
final double tex_um_range = clt_parameters.tex_um_range; // imp.mono_range; // 500.0; // monochrome full-scale range (+/- half)
final int ref_index = scenes.length - 1; final int ref_index = scenes.length - 1;
final QuadCLT ref_scene = scenes[ref_index]; final QuadCLT ref_scene = scenes[ref_index];
final TileProcessor tp = ref_scene.getTileProcessor(); final TileProcessor tp = ref_scene.getTileProcessor();
...@@ -2986,10 +2990,12 @@ public class TexturedModel { ...@@ -2986,10 +2990,12 @@ public class TexturedModel {
double discard_adisp = 0.2; // discard above/below this fraction of average height double discard_adisp = 0.2; // discard above/below this fraction of average height
double discard_rdisp = 0.02; // discard above/below this fraction of average height double discard_rdisp = 0.02; // discard above/below this fraction of average height
double pix_size = 0.005; // hdr_x0y0, // in meters double pix_size = 0.005; // hdr_x0y0, // in meters
int max_image_width = 3200; // increase pixel size as a power of 2 until image fits int max_image_width = 4000; // 3200; // increase pixel size as a power of 2 until image fits
boolean crop_empty = true; boolean crop_empty = true;
int crop_extra = 20; int crop_extra = 20;
int [] tex_pals = {0,1,2}; int [] tex_pals = {0,1,2};
// boolean use_fixed_range = true;
// double fixed_range = 250.0;
int tex_palette_start = 0; int tex_palette_start = 0;
int tex_palette_end = 12; int tex_palette_end = 12;
...@@ -2997,6 +3003,7 @@ public class TexturedModel { ...@@ -2997,6 +3003,7 @@ public class TexturedModel {
double [] hdr_x0y0 = new double[2]; double [] hdr_x0y0 = new double[2];
double [][] to_ground_xyxatr = scenes[ref_index].getGround( double [][] to_ground_xyxatr = scenes[ref_index].getGround(
use_lma, // boolean use_lma, use_lma, // boolean use_lma,
range_disparity_offset,// double range_disparity_offset
discard_low, // double discard_low, // fraction of all pixels discard_low, // double discard_low, // fraction of all pixels
discard_high, // double discard_high, // fraction of all pixels discard_high, // double discard_high, // fraction of all pixels
discard_adisp, // double discard_adisp, // discard above/below this fraction of average height discard_adisp, // double discard_adisp, // discard above/below this fraction of average height
...@@ -3006,61 +3013,67 @@ public class TexturedModel { ...@@ -3006,61 +3013,67 @@ public class TexturedModel {
hdr_x0y0, // double [] x0y0, // initialize to double[2] to return width, height hdr_x0y0, // double [] x0y0, // initialize to double[2] to return width, height
hdr_whs, // int [] whs, // initialize to int[3] to return {width, height, scale reduction} hdr_whs, // int [] whs, // initialize to int[3] to return {width, height, scale reduction}
debugLevel); // int debug_level debugLevel); // int debug_level
if (to_ground_xyxatr == null) {
Render3D render3D = new Render3D ( System.out.println("***** Failed to detect flat ground surface, skipping rendering and output files generation *****");
//x3d_dir, // String x3d_dir, } else {
//ref_scene.correctionsParameters.getModelName(ref_scene.getImageName()), // String model_name, Render3D render3D = new Render3D (
scenes[ref_index], // QuadCLT ref_scene, // all coordinates relative to this scene //x3d_dir, // String x3d_dir,
to_ground_xyxatr, // double [][] plane_xyzatr, // projection plane center relative to reference scene //ref_scene.correctionsParameters.getModelName(ref_scene.getImageName()), // String model_name,
pix_size * hdr_whs[2], // double pixel_size, // in meters scenes[ref_index], // QuadCLT ref_scene, // all coordinates relative to this scene
hdr_x0y0, // double [] x0_y0, // usually negative - top-left point of the output render to_ground_xyxatr, // double [][] plane_xyzatr, // projection plane center relative to reference scene
hdr_whs[0], // int out_width, // output rendered image width in pixels pix_size * hdr_whs[2], // double pixel_size, // in meters
hdr_whs[1]); // int out_height); // output rendered image height in pixels hdr_x0y0, // double [] x0_y0, // usually negative - top-left point of the output render
boolean last_is_alpha = true; // last channel in textures slices is alpha hdr_whs[0], // int out_width, // output rendered image width in pixels
double [][] full_render =render3D.render3dPlane( hdr_whs[1]); // int out_height); // output rendered image height in pixels
tri_meshes, // final ArrayList<TriMesh> tri_meshes, boolean last_is_alpha = true; // last channel in textures slices is alpha
last_is_alpha, // final boolean last_is_alpha, double [][] full_render =render3D.render3dPlane(
scenes[ref_index], //final QuadCLT ref_scene, // all coordinates relative to this scene tri_meshes, // final ArrayList<TriMesh> tri_meshes,
debugLevel); //int debugLevel) last_is_alpha, // final boolean last_is_alpha,
// String model_name = ref_scene.correctionsParameters.getModelName(ref_scene.getImageName()); scenes[ref_index], //final QuadCLT ref_scene, // all coordinates relative to this scene
String suffix ="-RECT"; debugLevel); //int debugLevel)
if (clt_parameters.tex_um) { // String model_name = ref_scene.correctionsParameters.getModelName(ref_scene.getImageName());
suffix+="-UM"+(clt_parameters.tex_um_sigma)+"_"+(clt_parameters.tex_um_weight); String suffix ="-RECT";
} if (clt_parameters.tex_um) {
suffix +="-PIX"+pix_size * hdr_whs[2]; suffix+="-UM"+(clt_parameters.tex_um_sigma)+"_"+(clt_parameters.tex_um_weight);
scenes[ref_index].saveDoubleArrayInModelDirectory( }
suffix+"-FULL", // String suffix, suffix +="-PIX"+pix_size * hdr_whs[2];
null, // String [] labels, // or null
full_render, // double [][] data,
hdr_whs[0], // int width, // int tilesX,
hdr_whs[1]); // int height, // int tilesY,
if (crop_empty || (crop_extra > 0)) {
int [] wh = new int[2];
double [][] img_cropped = Render3D.cropRectified(
crop_empty, // boolean crop_empty,
last_is_alpha, // boolean last_is_alpha,
crop_extra, // int crop_extra,
hdr_whs[0], // int width,
wh, // int [] wh, // should be initialized to int [2]
full_render); // double [][] img_src)
scenes[ref_index].saveDoubleArrayInModelDirectory( scenes[ref_index].saveDoubleArrayInModelDirectory(
suffix+"-CROP", // String suffix, suffix+"-FULL", // String suffix,
null, // String [] labels, // or null null, // String [] labels, // or null
img_cropped, // double [][] data, full_render, // double [][] data,
wh[0], // int width, // int tilesX, hdr_whs[0], // int width, // int tilesX,
wh[1]); // int height, // int tilesY, hdr_whs[1]); // int height, // int tilesY,
// for (int tex_palette = tex_palette_start; tex_palette <= tex_palette_end; tex_palette++) { if (crop_empty || (crop_extra > 0)) {
for (int tex_palette: tex_pals) { int [] wh = new int[2];
scenes[ref_index].writeLwirPreview( double [][] img_cropped = Render3D.cropRectified(
clt_parameters, // final CLTParameters clt_parameters, crop_empty, // boolean crop_empty,
img_cropped[0], // double [] data, last_is_alpha, // boolean last_is_alpha,
wh[0], // int width, // int tilesX, crop_extra, // int crop_extra,
null, // QuadCLT scene, hdr_whs[0], // int width,
tex_palette, // int tex_palette, wh, // int [] wh, // should be initialized to int [2]
suffix+"-CROP"+"-PAL"+tex_palette, // +tex_palette, // String suffix, full_render); // double [][] img_src)
debugLevel); // int debugLevel) scenes[ref_index].saveDoubleArrayInModelDirectory(
suffix+"-CROP", // String suffix,
null, // String [] labels, // or null
img_cropped, // double [][] data,
wh[0], // int width, // int tilesX,
wh[1]); // int height, // int tilesY,
// for (int tex_palette = tex_palette_start; tex_palette <= tex_palette_end; tex_palette++) {
for (int tex_palette: tex_pals) {
// try with fixed range?
double [] minmax = tex_um_fixed ? (new double[] {-tex_um_range/2, tex_um_range/2}): null;
scenes[ref_index].writeLwirPreview(
clt_parameters, // final CLTParameters clt_parameters,
img_cropped[0], // double [] data,
wh[0], // int width, // int tilesX,
minmax, // double [] minmax, // null for auto
null, // QuadCLT scene,
tex_palette, // int tex_palette,
suffix+"-CROP"+"-PAL"+tex_palette, // +tex_palette, // String suffix,
debugLevel); // int debugLevel)
}
} }
} }
} }
if (dbg_mesh_imgs != null) { if (dbg_mesh_imgs != null) {
...@@ -7112,7 +7125,7 @@ public class TexturedModel { ...@@ -7112,7 +7125,7 @@ public class TexturedModel {
final double mb_max_gain = clt_parameters.imp.mb_max_gain; // 5.0; // motion blur maximal gain (if more - move second point more than a pixel final double mb_max_gain = clt_parameters.imp.mb_max_gain; // 5.0; // motion blur maximal gain (if more - move second point more than a pixel
final double max_distortion = clt_parameters.tex_distort; // 0.5; // Maximal texture distortion to accumulate multiple scenes (0 - any) final double max_distortion = clt_parameters.tex_distort; // 0.5; // Maximal texture distortion to accumulate multiple scenes (0 - any)
final double tex_mb = clt_parameters.tex_mb; // 1.0; // Reduce texture weight if motion blur exceeds this (as square of MB length) final double tex_mb = clt_parameters.imp.mb_en? clt_parameters.tex_mb: 0.0; // 1.0; // Reduce texture weight if motion blur exceeds this (as square of MB length)
final boolean is_lwir = ref_scene.isLwir(); final boolean is_lwir = ref_scene.isLwir();
final boolean tex_um = clt_parameters.tex_um; // imp.um_mono; // TODO: add own parameter final boolean tex_um = clt_parameters.tex_um; // imp.um_mono; // TODO: add own parameter
final double tex_um_sigma = clt_parameters.tex_um_sigma; // imp.um_sigma; final double tex_um_sigma = clt_parameters.tex_um_sigma; // imp.um_sigma;
...@@ -7129,6 +7142,7 @@ public class TexturedModel { ...@@ -7129,6 +7142,7 @@ public class TexturedModel {
final boolean save_um_texture0= clt_parameters.tex_save_um_texture0; final boolean save_um_texture0= clt_parameters.tex_save_um_texture0;
final boolean save_preview= clt_parameters.tex_save_preview; final boolean save_preview= clt_parameters.tex_save_preview;
// final boolean show_sky_textures = clt_parameters.lre_show_sky_textures && !clt_parameters.multiseq_run; // final boolean show_sky_textures = clt_parameters.lre_show_sky_textures && !clt_parameters.multiseq_run;
// final int show_slice_bitmap = clt_parameters.lre_show_slice_bitmap; // final int show_slice_bitmap = clt_parameters.lre_show_slice_bitmap;
// final int shrink_sky_tiles = 2 * (2 +clt_parameters.tex_sky_extra); // 4; // 2; sum of 2 +bg extend // final int shrink_sky_tiles = 2 * (2 +clt_parameters.tex_sky_extra); // 4; // 2; sum of 2 +bg extend
...@@ -7639,14 +7653,38 @@ public class TexturedModel { ...@@ -7639,14 +7653,38 @@ public class TexturedModel {
dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length); dbg_titles[i] = dbg_subtitles[i % dbg_subtitles.length] + "-" + (i / dbg_subtitles.length);
} }
if (save_preview) { if (save_preview) {
// final boolean tex_um_fixed = clt_parameters.tex_um_fixed; // imp.mono_fixed; // true; // normalize to fixed range when converting to 8 bits
// final double tex_um_range = clt_parameters.tex_um_range; // imp.mono_range; // 500.0; // monochrome full-scale range (+/- half)
double [] minmax = tex_um_fixed ? (new double[] {-tex_um_range/2, tex_um_range/2}): null;
/*
ref_scene.writePreview( // may move to different (earlier) stage of processing, (search for "-combined_textures") ref_scene.writePreview( // may move to different (earlier) stage of processing, (search for "-combined_textures")
dbg_textures[0], // double [] data, dbg_textures[0], // double [] data,
debugLevel); // int debugLevel debugLevel); // int debugLevel
*/
// Trying different palettes // Trying different palettes
int tex_palette = 2; // regular color int tex_palette = 0; // regular mono white-hot
ref_scene.writeLwirPreview(
clt_parameters, // final CLTParameters clt_parameters,
dbg_textures[0], // double [] data,
minmax, // double [] minmax, // null for auto
null, // QuadCLT scene,
tex_palette, // int tex_palette,
"", // +tex_palette, // String suffix,
debugLevel); // int debugLevel)
tex_palette = 1; // regular color
ref_scene.writeLwirPreview(
clt_parameters, // final CLTParameters clt_parameters,
dbg_textures[0], // double [] data,
minmax, // double [] minmax, // null for auto
null, // QuadCLT scene,
tex_palette, // int tex_palette,
"-black_hot", // +tex_palette, // String suffix,
debugLevel); // int debugLevel)
tex_palette = 2; // regular color
ref_scene.writeLwirPreview( ref_scene.writeLwirPreview(
clt_parameters, // final CLTParameters clt_parameters, clt_parameters, // final CLTParameters clt_parameters,
dbg_textures[0], // double [] data, dbg_textures[0], // double [] data,
minmax, // double [] minmax, // null for auto
null, // QuadCLT scene, null, // QuadCLT scene,
tex_palette, // int tex_palette, tex_palette, // int tex_palette,
"-color", // +tex_palette, // String suffix, "-color", // +tex_palette, // String suffix,
......
...@@ -69,7 +69,7 @@ public class Render3D { ...@@ -69,7 +69,7 @@ public class Render3D {
this.out_width = out_width; this.out_width = out_width;
this.out_height = out_height; this.out_height = out_height;
this.toground = toground; this.toground = toground;
this.tocam = ErsCorrection.invertXYZATR(this.toground); this.tocam = ErsCorrection.invertXYZATR(this.toground); // null
// double [][] test1 = ErsCorrection.invertXYZATR(this.tocam); //OK // double [][] test1 = ErsCorrection.invertXYZATR(this.tocam); //OK
// double [][] test2 = ErsCorrection.invertXYZATR(test1); // OK // double [][] test2 = ErsCorrection.invertXYZATR(test1); // OK
// ground plane x0, y0 in camera coordinates // ground plane x0, y0 in camera coordinates
......
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