Commit 6f8ae877 authored by Andrey Filippov's avatar Andrey Filippov

refactoring for ranging

parent 0d787dca
......@@ -108,25 +108,66 @@ public class CuasMotion {
private int tilesX;
private int tilesY;
private double [] sky_mask = null;
private int corr_offset;
private int corr_pairs;
private UasLogReader uasLogReader;
private String [] scene_titles = null;
private String [] slice_titles = null;
private double [][][] targets = null;
private boolean slow_targets = false;
public int getSeqLength() {
return clt_parameters.imp.cuas_corr_offset + clt_parameters.imp.cuas_corr_pairs;
}
public int getCorrInc() {
return clt_parameters.imp.cuas_half_step ? (clt_parameters.imp.cuas_corr_offset/2) : clt_parameters.imp.cuas_corr_offset;
}
public int getNumCorrSamples() {
return slice_titles.length;
}
public String [] getSceneTitles() {
return scene_titles;
}
public String [] getSliceTitles() {
return slice_titles;
}
public double [][][] getTargets(){
return targets;
}
public void setTargets(double [][][] targets) {
this.targets = targets;
}
public boolean slow_targets = false;
public CuasMotion (
CLTParameters clt_parameters,
String [] scene_titles,
QuadCLT parentCLT,
UasLogReader uasLogReader,
int debugLevel) {
this.debugLevel = debugLevel;
this.clt_parameters = clt_parameters;
this.parentCLT = parentCLT;
this.scene_titles = scene_titles;
final double max_01_diff = 1E-3;
System.out.println("Setting up GPU");
gpuTileProcessor = parentCLT.getGPUQuad().getGpuTileProcessor();
tilesX = parentCLT.getTilesX();
tilesY = parentCLT.getTilesY();
gpu_max_width = tilesX * GPUTileProcessor.DTT_SIZE;
gpu_max_height = tilesY * GPUTileProcessor.DTT_SIZE;
corr_offset = clt_parameters.imp.cuas_corr_offset;
corr_pairs = clt_parameters.imp.cuas_corr_pairs;
int start_frame = 0;
int num_corr_samples = (scene_titles.length - getSeqLength() - start_frame) / getCorrInc();
slice_titles = new String [num_corr_samples];
for (int nscan = 0; nscan < num_corr_samples; nscan++) {
int frame_cent = start_frame + getCorrInc() * nscan + getSeqLength()/2; // debug only
slice_titles[nscan] = scene_titles[frame_cent];
}
try {
gpuQuad = new GpuQuad(//single camera
gpuTileProcessor, // GPUTileProcessor gpuTileProcessor,
......@@ -140,6 +181,7 @@ public class CuasMotion {
e.printStackTrace();
return;
} // final int debugLevel);
this.uasLogReader = uasLogReader;
boolean is_aux = true;
boolean is_mono = true;
boolean is_lwir = true;
......@@ -268,7 +310,9 @@ public class CuasMotion {
CuasMotion cuasMotion = new CuasMotion (
clt_parameters, // CLTParameters clt_parameters,
null, // scene_titles, // String [] scene_titles,
parentCLT, // QuadCLT parentCLT,
null, // uasLogReader, // UasLogReader uasLogReader,
debugLevel); // int debugLevel)
int num_slices = imp_sel.getStack().getSize();
......@@ -812,26 +856,18 @@ public class CuasMotion {
CuasMotion cuasMotion = new CuasMotion (
clt_parameters, // CLTParameters clt_parameters,
scene_titles, // String [] scene_titles,
parentCLT, // QuadCLT parentCLT,
null, // uasLogReader, // UasLogReader uasLogReader,
debugLevel); // int debugLevel)
// String suffix_param = "-offs"+corr_offset+"-pairs"+corr_pairs+"-rstr"+rstr+"-fz"+fat_zero+"-cr"+cent_radius+"-mr"+max_range +
// "-ms"+speed_min+"-sp"+speed_pref+"-sb"+speed_boost+"-tr"+target_radius+"-ts"+target_strength+
// "-tf"+IntersceneMatchParameters.double2dToString(target_frac);
String imp_name = imp_sel.getTitle();
imp_name = trimSuffix(imp_name,".tif");
imp_name = trimSuffix(imp_name,".tiff");
// String title_vf = imp_name+"-vector_field"+suffix_param; //
// final int frame0 = start_frame + seq_length/2;
data_dir= trimSuffix(data_dir,"/");
// String vf_extended_path = data_dir + "/" + vf_extended+".tiff";
// String vf_filtered_path = data_dir + "/" + title_vf_filtered+".tiff";
// String vf_path = data_dir + "/" + title_vf+".tiff";
// motion_scan_filtered = getVectorFieldHyper(vf_filtered_path); // String path)
boolean batch_mode = true;
if (test_lma) {
String path_vf = "/media/elphel/NVME/lwir16-proc/eagle_mountain/linked/movement/selected/25_r1.5/I-1747803449_165687-vector_field_good-offs20-pairs50-rstr0.01-fz300.0-cr3.0-mr1-ms0.0-sp0.0-sb1.0-tr2.0-ts0.8-tf0.0,0.12:2.5,0.15:5.0,0.25.tiff";
// String path_acc = "/media/elphel/NVME/lwir16-proc/eagle_mountain/linked/movement/selected/25_r1.5/I-1747803449_165687-accumulated-offs20-pairs50-rstr0.01-fz300.0-cr3.0-mr1-ms0.0-sp0.0-sb1.0-tr2.0-ts0.8-tf0.0,0.12:2.5,0.15:5.0,0.25-n20.tiff";
double [][][] vf_sequence = getVectorFieldHyper(path_vf); // String path)
if (vf_sequence == null) {
System.out.println("Failed to motion vectors from "+path_vf);
......@@ -4087,7 +4123,9 @@ public class CuasMotion {
CuasMotion cuasMotion = new CuasMotion (
clt_parameters, // CLTParameters clt_parameters,
scene_titles, // String [] scene_titles,
parentCLT, // QuadCLT parentCLT,
uasLogReader, // UasLogReader uasLogReader,
debugLevel); // int debugLevel)
int start_frame = 0;
......@@ -4177,7 +4215,7 @@ public class CuasMotion {
@Deprecated
public static double [][][] locateAndFreezeTargets(
CLTParameters clt_parameters,
final boolean batch_mode,
......@@ -4883,7 +4921,7 @@ public class CuasMotion {
return target_sequence; // contains all tiles, good or bad, their data and when they were defined
}
@Deprecated
final static public double [][][] resolveTargetsConflicts(
CLTParameters clt_parameters,
boolean batch_mode,
......@@ -5144,7 +5182,7 @@ public class CuasMotion {
return target_sequence; // non-overlap if consider marked stronger tiles
}
@Deprecated
public static void removeShortTargetSequences(
CLTParameters clt_parameters,
final boolean batch_mode,
......@@ -5154,8 +5192,6 @@ public class CuasMotion {
String [] slice_titles,
final int debugLevel) {
String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null);
final int corr_offset = clt_parameters.imp.cuas_corr_offset;
final boolean half_step = clt_parameters.imp.cuas_half_step; // true;
final int corr_inc = half_step ? (corr_offset/2) : corr_offset;
......@@ -5383,6 +5419,28 @@ public class CuasMotion {
public void generateExtractFilterMovingTargets( // move parameters to clt_parameters
final boolean video_pass, // if clt_parameters.cuas_clean_video=true, video_pass=0 - output TIFFS, but no video. If video_pass==1 - only video with no debug
final boolean batch_mode,
final float [][] fpixels,
double [][][] target_sequence, // non-overlap only if consider marked stronger tiles
final int debugLevel) {
generateExtractFilterMovingTargets( // move parameters to clt_parameters
clt_parameters, // CLTParameters clt_parameters,
video_pass, // final boolean video_pass, // if clt_parameters.cuas_clean_video=true, video_pass=0 - output TIFFS, but no video. If video_pass==1 - only video with no debug
batch_mode, // final boolean batch_mode,
parentCLT, //QuadCLT parentCLT, //
fpixels, // final float [][] fpixels,
target_sequence, // double [][][] target_sequence, // non-overlap only if consider marked stronger tiles
this, // CuasMotion cuasMotion,
uasLogReader, // UasLogReader uasLogReader,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
}
public static void generateExtractFilterMovingTargets( // move parameters to clt_parameters
CLTParameters clt_parameters,
final boolean video_pass, // if clt_parameters.cuas_clean_video=true, video_pass=0 - output TIFFS, but no video. If video_pass==1 - only video with no debug
......@@ -7365,6 +7423,22 @@ public class CuasMotion {
return imp;
}
public float [][] temporalUnsharpMask(
final boolean batch_mode,
float [][] fpixels,
final int debugLevel) {
return temporalUnsharpMask(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
fpixels, // float [][] fpixels,
this, // final CuasMotion cuasMotion,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
debugLevel); // final int debugLevel) {
}
public static float [][] temporalUnsharpMask(
CLTParameters clt_parameters,
final boolean batch_mode,
......@@ -7372,7 +7446,6 @@ public class CuasMotion {
float [][] fpixels,
final CuasMotion cuasMotion,
String [] scene_titles, // recreate slice_titles from scene titles?
// String [] slice_titles,
final int debugLevel) {
int temporal_um = clt_parameters.imp.cuas_temporal_um;
double tum_threshold = clt_parameters.imp.cuas_tum_threshold;// 0.003; // clt_parameters.imp.rln_sngl_rstr; // FIXME: ADD
......@@ -7497,11 +7570,28 @@ public class CuasMotion {
}
public double [][][] prepareMotionBasedSequence(
final boolean batch_mode,
float [][] fpixels_tum,
final int debugLevel) {
return prepareMotionBasedSequence(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
fpixels_tum, // float [][] fpixels_tum,
this, // final CuasMotion cuasMotion,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
}
public static double [][][] prepareMotionBasedSequence(
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
// float [][] fpixels,
float [][] fpixels_tum,
final CuasMotion cuasMotion,
String [] scene_titles, // recreate slice_titles from scene titles?
......@@ -7668,11 +7758,26 @@ public class CuasMotion {
return target_sequence;
}
public double [][][][] locateAndFreezeTargetsMulti(
final boolean batch_mode,
float [][] fpixels_tum,
double [][][] motion_sequence, // starts with just motion-based, then adds other fields (single target per tile)
final int debugLevel) {
return locateAndFreezeTargetsMulti(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
fpixels_tum, // float [][] fpixels_tum,
motion_sequence, // double [][][] motion_sequence, // starts with just motion-based, then adds other fields (single target per tile)
this, // final CuasMotion cuasMotion,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
}
public static double [][][][] locateAndFreezeTargetsMulti(
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
// float [][] fpixels,
float [][] fpixels_tum,
double [][][] motion_sequence, // starts with just motion-based, then adds other fields (single target per tile)
final CuasMotion cuasMotion,
......@@ -9189,6 +9294,7 @@ public class CuasMotion {
num_bad); // int [] num_bad)
}
@Deprecated
public static void processMovingTargetsMulti(
CLTParameters clt_parameters,
final boolean batch_mode,
......@@ -9199,7 +9305,9 @@ public class CuasMotion {
final int debugLevel) {
CuasMotion cuasMotion = new CuasMotion (
clt_parameters, // CLTParameters clt_parameters,
scene_titles, // String [] scene_titles,
parentCLT, // QuadCLT parentCLT,
uasLogReader, // UasLogReader uasLogReader,
debugLevel); // int debugLevel)
int start_frame = 0;
......@@ -9353,6 +9461,8 @@ public class CuasMotion {
}
}
cuasMotion.setTargets(targets_nonconflict);
generateExtractFilterMovingTargets( // move parameters to clt_parameters
clt_parameters, // CLTParameters clt_parameters,
false, // final boolean video_pass, // if clt_parameters.cuas_clean_video=true, video_pass=0 - output TIFFS, but no video. If video_pass==1 - only video with no debug
......@@ -9384,6 +9494,21 @@ public class CuasMotion {
}
final public double [][][] resolveTargetsConflictsMulti(
boolean batch_mode,
float [][] fpixels,
double [][][][] targets_multi, // targets_good, // all targets, including conflicting
int debugLevel){
return resolveTargetsConflictsMulti(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
fpixels, // float [][] fpixels,
this, // CuasMotion cuasMotion,
targets_multi, // double [][][][] targets_multi, // targets_good, // all targets, including conflicting
slice_titles, // String [] slice_titles,
debugLevel); // int debugLevel)
}
final static public double [][][] resolveTargetsConflictsMulti(
CLTParameters clt_parameters,
......@@ -9787,6 +9912,106 @@ public class CuasMotion {
return;
}
public void processMovingTargetsMulti(
final boolean batch_mode,
final float [][] fpixels,
final int debugLevel) {
int start_frame = 0;
boolean half_step = clt_parameters.imp.cuas_half_step; // true;
double slow_ra = clt_parameters.imp.cuas_slow_ra;
double slow_score = clt_parameters.imp.cuas_slow_score;
boolean clean_video = clt_parameters.imp.cuas_clean_video; //true;// save video without any debug information for targets, output in TIFF files. False - same output for video and TIFFs
boolean reuse_targets = clt_parameters.imp.cuas_reuse_targets; // true; // read previously calculated non-conflict (one per tile) targets
String reuse_path = clt_parameters.imp.cuas_reuse_path; // ""; // either suffix (all parameters the same) or the full path (contains "/")
double [][][] targets_nonconflict = null;
int seq_length = corr_offset + corr_pairs;
int corr_inc = half_step ? (corr_offset/2) : corr_offset;
int num_corr_samples = (fpixels.length - seq_length - start_frame) / corr_inc;
String [] slice_titles = new String [num_corr_samples];
for (int nscan = 0; nscan < num_corr_samples; nscan++) {
int frame_cent = start_frame + corr_inc * nscan + seq_length/2; // debug only
slice_titles[nscan] = scene_titles[frame_cent];
}
String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null);
if (reuse_targets && (reuse_path.length() > 0)) {
if (reuse_path.indexOf(Prefs.getFileSeparator()) < 0) {
String x3d_path = parentCLT.getX3dDirectory();
reuse_path = x3d_path + Prefs.getFileSeparator() + model_prefix + reuse_path+".tiff";
}
targets_nonconflict = getTargetsFromHyper(reuse_path);
if (targets_nonconflict == null) {
System.out.println("processMovingTargetsMulti(): failed to read target data from "+reuse_path);
} else {
System.out.println("processMovingTargetsMulti(): re-using target data from "+reuse_path);
}
}
if (targets_nonconflict == null){
// process fast targets
slow_targets = false; // just for filenames
float [][] fpixels_fast = temporalUnsharpMask( // all good targets
batch_mode, // final boolean batch_mode,
fpixels, // final float [][] fpixels,
debugLevel); // final int debugLevel)
double [][][] motion_sequence_fast = prepareMotionBasedSequence( // all good targets
batch_mode, // final boolean batch_mode,
fpixels_fast, // float [][] fpixels_tum,
debugLevel); // final int debugLevel)
double [][][][] targets_fast = locateAndFreezeTargetsMulti( // all good targets
batch_mode, // final boolean batch_mode,
fpixels_fast, // float [][] fpixels_tum,
motion_sequence_fast, // double [][][] target_sequence,
debugLevel); // final int debugLevel)
// process slow targets
this.slow_targets = true; // just for filenames
float [][] fpixels_slow = runningGaussian(
fpixels, // final float [][] fpixels,
slow_ra, // final double ra_length,
this.gpu_max_width); // final int width)
double [][][] motion_sequence_slow = prepareMotionBasedSequence( // all good targets
batch_mode, // final boolean batch_mode,
fpixels_slow, // float [][] fpixels_tum,
debugLevel); // final int debugLevel)
double [][][][] targets_slow = locateAndFreezeTargetsMulti( // all good targets
batch_mode, // final boolean batch_mode,
fpixels_slow, // float [][] fpixels_tum,
motion_sequence_slow,// double [][][] target_sequence,
debugLevel); // final int debugLevel)
double [][][][] targets_good_multi = combineFastSlow(
targets_fast, // final double [][][][] targets_fast, // will only process non-nulls here
targets_slow, // final double [][][][] targets_slow,
slow_score); // final double scale_slow){ // if >0, limit number of best results to add
sortMultiTargets(
targets_good_multi, // final double [][][][] target_multi,
true); // final boolean trim_nulls) { // trim null targets
targets_nonconflict = resolveTargetsConflictsMulti(
batch_mode, // boolean batch_mode,
fpixels, // float [][] fpixels,
targets_good_multi, // double [][][][] targets_good_multi, // all targets, including conflicting
debugLevel); // final int debugLevel)
}
setTargets(targets_nonconflict);
generateExtractFilterMovingTargets( // move parameters to clt_parameters
false, // final boolean video_pass, // if clt_parameters.cuas_clean_video=true, video_pass=0 - output TIFFS, but no video. If video_pass==1 - only video with no debug
batch_mode, // final boolean batch_mode,
fpixels, // final float [][] fpixels,
targets_nonconflict, // final double [][][] vf_sequence, // center tiles (not extended), null /non-null only
debugLevel); // final int debugLevel)
if (clean_video) {
generateExtractFilterMovingTargets( // move parameters to clt_parameters
true, // final boolean video_pass, // if clt_parameters.cuas_clean_video=true, video_pass=0 - output TIFFS, but no video. If video_pass==1 - only video with no debug
batch_mode, // final boolean batch_mode,
fpixels, // final float [][] fpixels,
targets_nonconflict, // final double [][][] vf_sequence, // center tiles (not extended), null /non-null only
debugLevel); // final int debugLevel)
}
return;
}
}
package com.elphel.imagej.cuas;
import com.elphel.imagej.cameras.CLTParameters;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.ims.UasLogReader;
import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.OpticalFlow;
import com.elphel.imagej.tileprocessor.QuadCLT;
import com.elphel.imagej.tileprocessor.TwoQuadCLT;
import ij.ImagePlus;
public class CuasRanging {
final QuadCLT center_CLT;
final QuadCLT [] scenes;
final CLTParameters clt_parameters;
public int debugLevel = 0;
public CuasRanging (
CLTParameters clt_parameters,
QuadCLT center_CLT,
QuadCLT [] scenes,
int debugLevel) {
this.clt_parameters = clt_parameters;
this.center_CLT = center_CLT;
this.scenes = scenes;
}
public CuasMotion detectTargets(
UasLogReader uasLogReader,
boolean batch_mode){
boolean save_linear_cuas = true;
boolean save_um_cuas = true;
// boolean um_mono = clt_parameters.imp.um_mono;
double um_sigma = clt_parameters.imp.um_sigma;
double um_weight = clt_parameters.imp.um_weight;
boolean mono_fixed = clt_parameters.imp.mono_fixed;
double mono_range = clt_parameters.imp.mono_range;
double [][]combo_dsi = center_CLT.comboFromMain();
double [][] dls = {
combo_dsi[OpticalFlow.COMBO_DSN_INDX_DISP], // **** null on second scene sequence
combo_dsi[OpticalFlow.COMBO_DSN_INDX_LMA],
combo_dsi[OpticalFlow.COMBO_DSN_INDX_STRENGTH]
};
double [][] ds = OpticalFlow.conditionInitialDS(
true, // boolean use_conf, // use configuration parameters, false - use following
clt_parameters, // CLTParameters clt_parameters,
dls, // double [][] dls
center_CLT, // quadCLTs[ref_index], // QuadCLT scene,
debugLevel-1);
double [] disparity_fg = ds[0]; // combo_dsn_final[COMBO_DSN_INDX_DISP_FG];
double [] strength_fg = ds[1];
if (strength_fg != null) { // for FG/BG only, fixing for transformCameraVew()
for (int i = 0; i < disparity_fg.length; i++) {
if (!Double.isNaN(disparity_fg[i]) && (strength_fg[i] == 0)) strength_fg[i] = 0.01; // transformCameraVew ignores strength= 0
}
}
double [] xyz_offset= {0,0,0};
double [][] ds_vantage = new double[][] {disparity_fg, strength_fg};
boolean debug_vantage = true;
double [][] dbg_vantage = debug_vantage ? (new double[7][]): null;
if (dbg_vantage != null) {
for (int i = 0; i < 3; i++) {
dbg_vantage[i] = dls[i].clone();
}
for (int i = 0; i < 2; i++) {
dbg_vantage[i+3] = ds_vantage[i].clone();
}
}
ds_vantage = OpticalFlow.transformCameraVew(
null, // (debug_ds_fg_virt?"transformCameraVew":null), // final String title,
ds_vantage, // final double [][] dsrbg_camera_in,
xyz_offset, // xyz_offset, // _inverse[0], // final double [] scene_xyz, // camera center in world coordinates
OpticalFlow.ZERO3, // _inverse[1], // final double [] scene_atr, // camera orientation relative to world frame
center_CLT, // quadCLTs[ref_index], // final QuadCLT scene_QuadClt,
center_CLT, // quadCLTs[ref_index], // final QuadCLT reference_QuadClt,
8); // iscale); // final int iscale);
if (dbg_vantage != null) {
for (int i = 0; i < 2; i++) {
dbg_vantage[i+5] = ds_vantage[i].clone();
}
ShowDoubleFloatArrays.showArrays(
dbg_vantage,
center_CLT.getTileProcessor().getTilesX(),
center_CLT.getTileProcessor().getTilesY(),
true,
center_CLT.getImageName()+"-ds_vantage", // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
new String[] {"disp0","lma0", "str0", "disp","str","virt_disp", "virt_str"});
}
// float [] average_pixels = (center_CLT.getCenterAverage() != null) ? ((float []) center_CLT.getCenterAverage().getProcessor().getPixels()):null;
float [] average_pixels = (float []) center_CLT.getCenterAverage().getProcessor().getPixels();
float [][] average_channels = new float [][] {average_pixels}; // for future color images
double [] cuas_atr = OpticalFlow.ZERO3;
/*
boolean extract_center_orientation = false; // clt_parameters.imp.extract_center_orientation; // true; // false; // true;
double [][] center_ATR = null; // {{center_A, center_T, average_R},{radius_A, radius_T}}
if (extract_center_orientation && clt_parameters.imp.lock_position) {
// cuas_atr will be use for rendering combo images, the individual coordinate will be already image-based, not ims-based
center_ATR = CuasCenterLma.getCenterATR(
scenes, // QuadCLT [] quadCLTs,
scenes[ref_index], // QuadCLT ref_scene,ref_index, //int ref_index,
new int [] {earliest_scene, last_index}, // int [] range,
true, // boolean disable_AT_omegas,
debugLevel); // int debugLevel);
cuas_atr = new double [] { center_ATR[0][0], center_ATR[0][1], center_ATR[0][2]};
// Check omegas here !
System.out.println ("Omegas ATR: "+center_ATR[2][0]+", "+center_ATR[2][1]+", "+center_ATR[2][2]);
}
*/
String scenes_suffix = center_CLT.getImageName()+"-CUAS"; // "1747829900_781803-SEQ-FG-MONO-FPN";
ImagePlus imp_targets= OpticalFlow.renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
true, // center_CLT.hasCenterClt(), // boolean mode_cuas,
false, // clt_parameters.imp.um_mono, // boolean um_mono,
clt_parameters.imp.calculate_average, // boolean insert_average, // then add new parameter, keep add average
average_channels, // average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // fov_tiles, // Rectangle fov_tiles,
1, // mode3d, // int mode3d,
false, // toRGB, // boolean toRGB,
xyz_offset, // double [] stereo_offset, // offset reference camera {x,y,z}
cuas_atr, // double [] stereo_atr, // offset reference orientation (cuas)
1, // sensor_mask, // int sensor_mask,
scenes_suffix, // String suffix,
ds_vantage[0], // selected_disparity, // double [] ref_disparity,
scenes, // QuadCLT [] quadCLTs,
center_CLT, // ref_index, // int ref_index,
ImageDtt.THREADS_MAX, // threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
if (save_linear_cuas) {
center_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_targets); // imp_scenes); // ImagePlus imp)
}
// always generating UM, even if not saving - needed for targets
String cuas_title = imp_targets.getTitle();
String um_suffix = "";
if (mono_fixed) {
um_suffix = String.format("-UM%.1f_%.3f_%.0f",um_sigma,um_weight,mono_range);
} else {
um_suffix = String.format("-UM%.1f_%.3f_A",um_sigma,um_weight);
}
imp_targets = OpticalFlow.applyUM ( // apply UM
cuas_title + um_suffix , // final String title, // should include -UM...
imp_targets, // final ImagePlus imp,
um_sigma, // final double um_sigma,
um_weight); // final double um_weight)
if (save_um_cuas) {
center_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_targets); // imp_scenes); // ImagePlus imp)
}
boolean insert_average = (center_CLT.getCenterAverage() != null) || clt_parameters.imp.calculate_average;
// boolean subtract_average = clt_parameters.imp.subtract_average && insert_average;
// if (subtract_average && clt_parameters.imp.cuas_targets && (mode3d > 0)) {
System.out.println("Will generate targets images/videos");
int first_corr = insert_average? 1:0; // skip average
int num_scenes = imp_targets.getStack().getSize()- first_corr; // includes average
float [][] fpixels = new float[num_scenes][];
String [] scene_titles = new String [num_scenes];
for (int nscene = 0; nscene < fpixels.length; nscene++) {
fpixels[nscene] = (float[]) imp_targets.getStack().getPixels(nscene+first_corr+1);
String s = imp_targets.getStack().getSliceLabel(nscene+first_corr+1);
if (s.indexOf("-0") >=0) {
s=s.substring(0, s.indexOf("-0"));
}
scene_titles[nscene] = s;// imp_targets.getStack().getSliceLabel(nscene+first_corr+1);
}
boolean skip_targets = false;// true;
if (skip_targets) {
return null;
}
CuasMotion cuasMotion = new CuasMotion (
clt_parameters, // CLTParameters clt_parameters,
scene_titles, // String [] scene_titles,
center_CLT, // QuadCLT parentCLT,
uasLogReader, // UasLogReader uasLogReader,
debugLevel); // int debugLevel)
cuasMotion.processMovingTargetsMulti(
batch_mode, // final boolean batch_mode,
fpixels, // final float [][] fpixels,
debugLevel); // final int debugLevel) {
double[][][] targets = cuasMotion.getTargets();
/*
// detectTargets
center_CLT.processMovingTargets(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
fpixels, // final float [][] fpixels,
uasLogReader, // UasLogReader uasLogReader,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
debugLevel); // final int debugLevel)
*/
return cuasMotion;
}
}
......@@ -57,6 +57,8 @@ import com.elphel.imagej.correction.CorrectionColorProc;
import com.elphel.imagej.cuas.CorrectionFPN;
import com.elphel.imagej.cuas.Cuas;
import com.elphel.imagej.cuas.CuasCenterLma;
import com.elphel.imagej.cuas.CuasMotion;
import com.elphel.imagej.cuas.CuasRanging;
import com.elphel.imagej.gpu.GPUTileProcessor;
import com.elphel.imagej.gpu.GpuQuad;
import com.elphel.imagej.gpu.TpTask;
......@@ -6221,6 +6223,20 @@ public class OpticalFlow {
// Moved to the very end, after 3D
boolean test_vegetation = true;
if (master_CLT.hasCenterClt()) { // cuas mode
CuasRanging cuasRanging = new CuasRanging (
clt_parameters, // CLTParameters clt_parameters,
master_CLT, // QuadCLT center_CLT,
quadCLTs, // QuadCLT [] scenes,
debugLevel); // int debugLevel) {
CuasMotion cuasMotion = cuasRanging.detectTargets(
uasLogReader, // UasLogReader uasLogReader,
batch_mode); // boolean batch_mode)
if (debugLevel > -4) {
System.out.println("Target detection DONE");
}
}
if (generate_mapped || reuse_video) { // modifies combo_dsn_final ?
int tilesX = master_CLT.getTileProcessor().getTilesX();
int tilesY = master_CLT.getTileProcessor().getTilesY();
......@@ -6394,6 +6410,23 @@ public class OpticalFlow {
if (generate_mapped) {
double [][] ds_vantage = new double[][] {selected_disparity,selected_strength};
if ((views[ibase][0] != 0) || (views[ibase][1] != 0) || (views[ibase][2] != 0) || (master_CLT.hasCenterClt()) && (mode3d > 0)) {
boolean debug_vantage = true;
//dls
double [][] dbg_vantage = debug_vantage ? (new double[7][]): null;
if (dbg_vantage != null) {
double [][] dls = {
combo_dsn_final[COMBO_DSN_INDX_DISP], // **** null on second scene sequence
combo_dsn_final[COMBO_DSN_INDX_LMA],
combo_dsn_final[COMBO_DSN_INDX_STRENGTH]
};
for (int i = 0; i < 3; i++) {
dbg_vantage[i] = dls[i].clone();
}
for (int i = 0; i < 2; i++) {
dbg_vantage[i+3] = ds_vantage[i].clone();
}
}
ds_vantage = transformCameraVew(
null, // (debug_ds_fg_virt?"transformCameraVew":null), // final String title,
ds_vantage, // final double [][] dsrbg_camera_in,
......@@ -6402,6 +6435,19 @@ public class OpticalFlow {
master_CLT, // quadCLTs[ref_index], // final QuadCLT scene_QuadClt,
master_CLT, // quadCLTs[ref_index], // final QuadCLT reference_QuadClt,
8); // iscale); // final int iscale);
if (dbg_vantage != null) {
for (int i = 0; i < 2; i++) {
dbg_vantage[i+5] = ds_vantage[i].clone();
}
ShowDoubleFloatArrays.showArrays(
dbg_vantage,
master_CLT.getTileProcessor().getTilesX(),
master_CLT.getTileProcessor().getTilesY(),
true,
center_CLT.getImageName()+"-ds_vantage-old", // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
new String[] {"disp0","lma0", "str0", "disp","str","virt_disp", "virt_str"});
}
}
if (master_CLT.getFPN() != null) {
scenes_suffix += "-FPN";
......@@ -6447,6 +6493,12 @@ public class OpticalFlow {
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_scenes_pair[nstereo]); // imp_scenes); // ImagePlus imp)
if (master_CLT.hasCenterClt()) { // cuas mode
boolean new_cuas_mode = (debugLevel < 1000);
if (new_cuas_mode) {
System.out.println("CuasMotion should be already calculated, disabling old mode below.");
} else {
System.out.println("Detecting targets in old mode.");
boolean insert_average = (master_CLT.getCenterAverage() != null) || clt_parameters.imp.calculate_average;
boolean subtract_average = clt_parameters.imp.subtract_average && insert_average;
if (subtract_average && clt_parameters.imp.cuas_targets && (mode3d > 0)) {
......@@ -6475,6 +6527,7 @@ public class OpticalFlow {
}
}
}
}
} else {
if (fov_tiles==null) {
fov_tiles = new Rectangle(0, 0, tilesX, tilesY);
......
......@@ -5994,7 +5994,7 @@ if (debugLevel < -100) {
debugLevel);
}
@Deprecated
public void processMovingTargets(
CLTParameters clt_parameters,
final boolean batch_mode,
......@@ -6010,16 +6010,6 @@ if (debugLevel < -100) {
uasLogReader, // UasLogReader uasLogReader,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
debugLevel); // final int debugLevel)
/*
CuasMotion.processMovingTargets(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
this, // QuadCLT parentCLT, //
fpixels, // final float [][] fpixels,
uasLogReader, // UasLogReader uasLogReader,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
debugLevel); // final int debugLevel)
*/
}
}
......@@ -3089,6 +3089,10 @@ public class QuadCLTCPU {
dls[5] = dsi[isAux()? TwoQuadCLT.DSI_TERRAIN_AUX : TwoQuadCLT.DSI_TERRAIN_MAIN];
return dls;
}
public double [][] comboFromMain(){
return comboFromMain(this.dsi);
}
public double [][] comboFromMain(double [][] dsi){
if (dsi == null) {
......
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