Commit 17709f53 authored by Andrey Filippov's avatar Andrey Filippov

Cleaning up, creating a single method to do all target processing

parent dafb1ad3
......@@ -30,6 +30,7 @@ import com.elphel.imagej.tileprocessor.QuadCLT;
import com.elphel.imagej.tileprocessor.TDCorrTile;
import com.elphel.imagej.tileprocessor.TileNeibs;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.process.ByteProcessor;
......@@ -280,6 +281,7 @@ public class CuasMotion {
boolean smooth = clt_parameters.imp.cuas_smooth; // true;
boolean half_step = clt_parameters.imp.cuas_half_step; // true;
int max_range = clt_parameters.imp.cuas_max_range;
int num_cycles = clt_parameters.imp.cuas_num_cycles;
double target_radius = clt_parameters.imp.cuas_target_radius;
double target_strength = clt_parameters.imp.cuas_target_strength;
double [][] target_frac = new double [clt_parameters.imp.cuas_target_frac.length][2];
......@@ -319,15 +321,13 @@ public class CuasMotion {
boolean ra_background = clt_parameters.imp.cuas_ra_background; //true;
int iter_show = clt_parameters.imp.cuas_iter_show; //1; // Maximal enhancement iteration to show intermediate result (0 - none)
boolean corr2d_save_show = clt_parameters.imp.cuas_2d_save_show; //true;
boolean intermed_low = clt_parameters.imp.cuas_intermed_low; //true;
boolean intermed_high = clt_parameters.imp.cuas_intermed_high; //true;
boolean save_mono = clt_parameters.imp.cuas_save_mono; //true;
boolean save_color = clt_parameters.imp.cuas_save_color; //true;
boolean save_video = clt_parameters.imp.cuas_save_video; //true;
for (int i = 0; i < target_frac.length; i++) {
if (clt_parameters.imp.cuas_target_frac[i].length >= 2) {
......@@ -363,6 +363,8 @@ public class CuasMotion {
gd.addNumericField("Preferable speed", speed_pref, 5,8,"ppr", "Boost effective strength when speed is above this.");
gd.addNumericField("Maximal speed boost", speed_boost, 5,8,"", "Maximal speed-caused effective strength boost.");
gd.addNumericField("Local max range", max_range, 0,3,"", "While filtering local correlation maximums: 1 - 3x3 neighbors, 2 - 5x5 ones.");
gd.addNumericField("Number of enhancement cycles", num_cycles, 0,3,"","Number of cycles of testing and removing bad targets from compoetition with weaker neighbors.");
gd.addNumericField("Target radius", target_radius, 5,8,"pix","Target radius, also used to calculate fraction of totals inside (windowed) to all positive values.");
gd.addNumericField("Minimal target strength", target_strength, 5,8,"","Minimal value of the target image.");
......@@ -429,7 +431,11 @@ public class CuasMotion {
gd.addCheckbox ("Smooth background with runnong average", ra_background,
"Apply running average to the background of the moving targets (false - use high-noise no-averaged images.");
gd.addMessage("=== Saving intermediate and final images and video ===");
gd.addMessage("=== Saving intermediate and final images and video ===");
gd.addNumericField("Maximal iteration to save/show", iter_show, 0,3,"",
"Maximal enhancement iteration to show intermediate result (0 - none).");
gd.addCheckbox ("Save/show 2D correlations", corr2d_save_show,
"Save and optionally show 2D correlations.");
gd.addCheckbox ("Save tile-resolution intermediate images", intermed_low,
"Save intermediate vector fields and target coordinates from the LMA (80x64 layers).");
gd.addCheckbox ("Save pixel-resolution intermediate images",intermed_high,
......@@ -447,6 +453,8 @@ public class CuasMotion {
gd.addStringField("Data directory", data_dir,100,"Intermediate results directory (to bypass first stages during debugging).");
gd.addMessage("=== Currently some methods use clt_parameters directly, so without saving parameters they will not work! ===");
gd.addCheckbox ("Save_params", save_params, "Save edited parameters");
gd.addCheckbox ("Test LMA", test_lma, "Test LMA from known files instead of normal operation.");
......@@ -469,6 +477,7 @@ public class CuasMotion {
speed_boost = gd.getNextNumber();
max_range = (int) gd.getNextNumber();
num_cycles = (int) gd.getNextNumber();
target_radius = gd.getNextNumber();
target_strength = gd.getNextNumber();
......@@ -504,6 +513,8 @@ public class CuasMotion {
scale2x = gd.getNextBoolean();
ra_background = gd.getNextBoolean();
iter_show= (int) gd.getNextNumber();
corr2d_save_show = gd.getNextBoolean();
intermed_low = gd.getNextBoolean();
intermed_high = gd.getNextBoolean();
save_mono = gd.getNextBoolean();
......@@ -523,11 +534,15 @@ public class CuasMotion {
clt_parameters.imp.cuas_cent_radius = cent_radius;
clt_parameters.imp.cuas_n_recenter = n_recenter;
clt_parameters.imp.cuas_rstr = rstr;
clt_parameters.imp.cuas_speed_min = speed_min;
clt_parameters.imp.cuas_speed_pref = speed_pref;
clt_parameters.imp.cuas_speed_boost = speed_boost;
clt_parameters.imp.cuas_smooth = smooth;
clt_parameters.imp.cuas_max_range = max_range;
clt_parameters.imp.cuas_num_cycles = num_cycles;
clt_parameters.imp.cuas_half_step = half_step;
clt_parameters.imp.cuas_target_radius = target_radius;
clt_parameters.imp.cuas_target_strength = target_strength;
......@@ -569,7 +584,9 @@ public class CuasMotion {
clt_parameters.imp.cuas_target_type = target_type;
clt_parameters.imp.cuas_input_range = input_range;
clt_parameters.imp.cuas_scale2x = scale2x;
clt_parameters.imp.cuas_ra_background =ra_background;
clt_parameters.imp.cuas_ra_background =ra_background;
clt_parameters.imp.cuas_iter_show = iter_show;
clt_parameters.imp.cuas_2d_save_show = corr2d_save_show;
clt_parameters.imp.cuas_intermed_low = intermed_low;
clt_parameters.imp.cuas_intermed_high =intermed_high;
clt_parameters.imp.cuas_save_mono = save_mono;
......@@ -605,6 +622,7 @@ public class CuasMotion {
System.out.println("speed_boost= "+speed_boost);
System.out.println("fat_zero= "+fat_zero);
System.out.println("max_range= "+max_range);
System.out.println("num_cycles= "+num_cycles);
System.out.println("target_radius= "+target_radius);
System.out.println("target_strength= "+target_strength);
System.out.println("target_frac= "+IntersceneMatchParameters.double2dToString(target_frac));
......@@ -637,12 +655,8 @@ public class CuasMotion {
System.out.println("input_range= "+input_range);
System.out.println("scale2x= "+scale2x);
System.out.println("ra_background= "+ra_background);
System.out.println("intermed_low= "+intermed_low);
System.out.println("intermed_high= "+intermed_high);
System.out.println("save_mono= "+save_mono);
System.out.println("save_color= "+save_color);
System.out.println("save_video= "+save_video);
System.out.println("ra_background= "+ra_background);
System.out.println("iter_show= "+iter_show);
System.out.println("corr2d_save_show="+corr2d_save_show);
System.out.println("intermed_low= "+intermed_low);
System.out.println("intermed_high= "+intermed_high);
System.out.println("save_mono= "+save_mono);
......@@ -658,7 +672,7 @@ public class CuasMotion {
String [] slice_titles= new String [num_corr_samples];
for (int nscan = 0; nscan < num_corr_samples; nscan++) {
int frame_cent = start_frame + corr_step * nscan + seq_length/2; // debug only
slice_titles[nscan] = imp_sel.getStack().getSliceLabel(frame_cent+1);
slice_titles[nscan] = imp_sel.getStack().getSliceLabel(frame_cent+1+first_corr); // wrong! should be imp_sel.getStack().getSliceLabel(frame_cent+1+first_corr)
}
......@@ -666,797 +680,54 @@ public class CuasMotion {
clt_parameters, // CLTParameters clt_parameters,
parentCLT, // QuadCLT parentCLT,
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 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_cor2d = imp_name+"-corr2d"+suffix_param; // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
String title_vf_all = imp_name+"-vector_field_all"+suffix_param; //
String title_vf = imp_name+"-vector_field"+suffix_param; //
String title_vf_filtered = imp_name+"-vector_field_filtered"+suffix_param; //
String title_vf_extended = imp_name+"-vector_extended"+suffix_param; //
String title_targets_all = imp_name+"-targets_all"+suffix_param; //
String title_targets_filt = imp_name+"-targets_filt"+suffix_param; //
String title_accumulated = imp_name+"-accumulated"+suffix_param;
String title_rendered_hyper=imp_name+"-rendered_hyper"+suffix_param; //
String title_acc_targets = imp_name+"-accumulated_targets"+suffix_param;
String title_vf_good = imp_name+"-vector_field_good"+suffix_param; //
String title_extended_good =imp_name+"-vector_field_extended_good"+suffix_param; //
String title_targets_good = imp_name+"-targets_good"+suffix_param; //
final int frame0 = start_frame + seq_length/2;
final int half_accum_range = corr_pairs/2;
// final boolean smooth_accum = true;
double [][][] corr2d = null; // to read it if bypassing calculations
double [][][] motion_scan = null;
boolean [][] filter5 = new boolean [num_corr_samples][]; // may be calculated in extendMotionScan when read from file
double [][][] motion_scan_filtered = null;
double [][][] extended_scan = null;
int [] remain = new int [num_corr_samples];
// 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";
// 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";
// 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);
continue;
}
ImagePlus imp_accum = new ImagePlus(path_acc);
if (imp_accum.getWidth()==0) {
System.out.println("Failed to read accum data from "+path_acc);
continue;
}
int [] wh = new int[2];
float [][] accum = ShowDoubleFloatArrays.readFloatArray(
imp_accum, // ImagePlus imp,
0, // int num_slices, // (0 - all)
wh); // int [] wh)
boolean batch_mode = true;
generateExtractFilterMovingTargets( // move parameters to clt_parameters
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
fpixels, // final float [][] fpixels,
accum, // final float [][] accum, //
vf_sequence, // final double [][][] vf_sequence, //
frame0, //final int frame0, // for vector_field[0] // source scene corresponding to the first sequence
cuasMotion, // final CuasMotion cuasMotion,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
/*
double [][][][] coord_data2 = getAccumulatedCoordinates(
vf_sequence, // final double [][][] vector_fields, // centers
accum, // final double [][] accum_data, // should be around 0, no low-freq
target_radius, // final double centroid_radius,
n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
cuasMotion.tilesX, // final int tilesX){
no_border, // final boolean no_border,
// Moving target LMA
lma_sigma, // final double lma_sigma,
lma_r0, // final double lma_r0,
lma_ovrsht, // final double lma_ovrsht,
// CUAS Motion LMA parameters
lma_fit_xy, // final boolean lma_fit_xy,
lma_fit_a, // final boolean lma_fit_a,
lma_fit_c, // final boolean lma_fit_c,
lma_fit_r, // final boolean lma_fit_r,
lma_fit_k, // final boolean lma_fit_k,
lambda, // final double lambda,
lambda_good, // final double lambda_good,
lambda_bad, // final double lambda_bad,
lambda_max, // final double lambda_max,
rms_diff, // final double rms_diff,
num_iter, // final int num_iter,
debugLevel); // final int debugLevel);
double [][][] coord_data = coord_data2[0];
double [][][] coord_lma = coord_data2[1];
showVectorFieldsSequence(
coord_data, // double [][][] vector_fields_sequence,
0.0, // double speed_min,
0.0, // double speed_pref,
1.0, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_all+"-VF-TEST", // String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequenceLMA(
coord_lma, // double [][][] target_scene_sequence, // rename
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_all+"-LMA-TEST", // String title,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
// int [] targets_remain = new int [coord_data.length];
int [] targets_remain = new int [coord_data.length];
double [][][] coord_data_filtered = filterAndShowTargets(
coord_data, // double [][][] coord_data,
target_strength, // double target_strength,
target_frac, // double [][] target_frac,
slice_titles, // String [] slice_titles, //
title_targets_filt+"-VF-TEST-FILTERED", // String title_targets_filt,
targets_remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
true, // show_vector_field); // boolean show)
null); // do not save //QuadCLT parentCLT)
int remained_total = printRemain(targets_remain, "Total good targets", true);
double [][][] coord_data_filtered_lma = filterAndShowTargetsLMA(
coord_lma,// double [][][] coord_data,
lma_rms, // double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
lma_arms, // double lma_arms, // = 0.03; // Maximal absolutre RMS
lma_rrms, // double lma_rrms, // = 0.03; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
lma_mina, // double lma_mina, // = 1.0; // Minimal A (amplitude)
lma_maxr, // double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0
lma_mink, // double lma_mink, // = 1.0; // Minimal K (overshoot) = 1.0
lma_maxk, // double lma_maxk, // = 1.0; // Minimal K (overshoot) = 3.0
slice_titles, // String [] slice_titles, //
title_targets_filt+"-LMA-TEST-FILTERED", // String title_targets_filt,
targets_remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
true, // show_vector_field); // boolean show)
null); // do not save //QuadCLT parentCLT)
remained_total = printRemain(targets_remain, "coord_data_filtered_lma: Total new targets LMA", true);
// remove tiles that did not pass old vf filter
double [][][] targets_lma_combo = filterMotionScans( // should keep LMA coordinates
coord_data_filtered_lma, // double [][][] scan0,
coord_data_filtered, // double [][][] scan1)
remain);
// create vector field sequence by masking after the last filter
double [][][] targets_vf_combo = filterMotionScans( // should keep LMA coordinates
vf_sequence, // double [][][] scan0,
targets_lma_combo, // double [][][] scan1)
remain);
printRemain(remain, "targets_lma_combo", true);
showVectorFieldsSequenceLMA(
targets_lma_combo, // double [][][] target_scene_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_good+"-LMA-TEST-COMBO", // String title,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
// create larger, 5x5 vector field for accumulation
double [][][] extended_vf_sequence = extendMotionScan(
targets_vf_combo, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
2, // final int range, // 1 or 2
remain); // final int [] remain)
printRemain(remain, "extended5x5_vf_sequence", true);
float [][] fpixels_accumulated5x5 = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
true, // final boolean fill_zeros,
fpixels, // final float [][] fpixels,
extended_vf_sequence, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
half_accum_range, // final int half_range,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
// zero-fill undefined tiles
ShowDoubleFloatArrays.showArrays(
fpixels_accumulated5x5,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
true,
title_accumulated+"-TARGETS5x5", // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
slice_titles); // titles_accum);
double velocity_scale = 1.0/corr_offset;
double [][][] targets60hz = new double [fpixels.length][][];
// boolean ra_background = true;
float [][] background = fpixels;
if (ra_background) {
background = runningAverage(
fpixels, // final float [][] fpixels,
corr_pairs, // final int ra_length,
cuasMotion.gpu_max_width); // final int width)
}
float [][] replaced_targets = cuasMotion.shiftAndRenderTargets(
clt_parameters, // CLTParameters clt_parameters,
mask_width, // final double mask_width,
mask_blur, // final double mask_blur,
mask_round, // final boolean round,
fpixels_accumulated5x5, // final float [][] target_keyframes,
extended_vf_sequence, // final double [][][] vector_field,
targets_lma_combo, // final double [][][] target_positions,
background, // final float [][] background, // background image
frame0, // final int frame0,
corr_step, // final int frame_step,
velocity_scale, // final double velocity_scale, // 1.0/(disparity in frames)
targets60hz, // final double [][][] targets60hz,
false, // final boolean batch_mode,
debugLevel); // final int debugLevel)
// if (show_full_images) {
ShowDoubleFloatArrays.showArrays(
replaced_targets,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
true,
title_accumulated+"-REPLACED-TARGETS", // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
scene_titles); // titles_accum);
// String diamond_path_1x = "/media/elphel/NVME/lwir16-proc/eagle_mountain/graphics/diamond21x17.png";
// String diamond_path_2x = "/media/elphel/NVME/lwir16-proc/eagle_mountain/graphics/diamond43x35_2px.png";
// String diamond_path_2x = "/media/elphel/NVME/lwir16-proc/eagle_mountain/graphics/TDbox_dashed43x43_2px.png";
// String diamond_path = scale2x? diamond_path_2x : diamond_path_1x;
ImagePlus imp_color = convertToRgbAnnotateTargets(
clt_parameters, // CLTParameters clt_parameters,
input_range, // final double input_range, // 5
scale2x, // boolean scale2x,
target_type, // final int target_type, // = 0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
replaced_targets, // final float [][] fpixels,
targets60hz, // final double [][][] targets60hz,
frame0, // final int frame0,
corr_step, // final int frame_step,
cuasMotion.gpu_max_width, // final int width,
title_accumulated+"-COLOR", // String title,
scene_titles, // String [] titles,
null, // diamond_path, // //String diamond_path, null - use resources
debugLevel); // final int debugLevel) {
// save tiff in model directory
if (imp_color != null) {
// temporary, will use model directory
String save_directory = "/media/elphel/NVME/lwir16-proc/eagle_mountain/linked/movement/selected/video/";
String video_path_tmp = save_directory + imp_name+"-TARGETS";
String video_path = saveAsVideo(
clt_parameters, // CLTParameters clt_parameters,
parentCLT, // QuadCLT scene, // if not null - use it's model directory
null, // video_path_tmp, // String file_path,
imp_color, // ImagePlus imp_color,
debugLevel); // int debugLevel) {
imp_color.show();
}
*/
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
// three arrays needed
fpixels, // final float [][] fpixels,
vf_sequence, // final double [][][] vf_sequence, // center tiles (not extended), null /non-null only
// frame0, // final int frame0, // for vector_field[0] // source scene corresponding to the first sequence
cuasMotion, // final CuasMotion cuasMotion,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
continue;
}
motion_scan = getVectorFieldHyper(vf_path); // title_vf); // String path)
// extended_scan = getVectorFieldHyper(vf_extended_path); // String path)
// if (extended_scan == null) {
boolean show_vector_field = false; //true;
boolean show_2d_correlations = false; //true;
boolean show_full_images = false; //true;
if (motion_scan == null) {
System.out.println ("testCuasScanMotion(): Failed to read Vector Field from file, calculating");
// readVectorField(String path)
String dbg_title = imp_name;
// double [][][]
corr2d = show_2d_correlations? new double [num_corr_samples][][] : null;
motion_scan = getMotionScan(
false, // batch_mode, // boolean batch_mode,
clt_parameters, // CLTParameters clt_parameters,
cuasMotion, // CuasMotion cuasMotion,
fpixels, // float [][] fpixels,
start_frame, // int start_frame,
corr_pairs, // int corr_pairs,
corr_offset, // int corr_offset,
corr_step, // int corr_step,
smooth, // boolean smooth,
fat_zero, // double fat_zero,
cent_radius, // double cent_radius,
n_recenter, // int n_recenter,
-rstr, // double rstr,
dbg_title, // String title,
corr2d, // double [][][] corr2d, // null or [(fpixels.length - seq_length - start_frame) / corr_step)[][]
debugLevel); // int debugLevel) {
if (show_2d_correlations) { // may be read to re-process with vector field
int corr_size = 2 * GPUTileProcessor.DTT_SIZE -1;
double [][] dbg_2d_corrs = ImageDtt.corr_partial_dbg( // not used in lwir
corr2d, // final double [][][] corr_data, // [layer][tile][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
cuasMotion.tilesX, // final int tilesX,
corr_size, //final int corr_size, // 15
clt_parameters.corr_border_contrast, // final double border_contrast,
debugLevel); // final int globalDebugLevel)
ShowDoubleFloatArrays.showArrays(
dbg_2d_corrs,
cuasMotion.tilesX * (corr_size + 1),
cuasMotion.tilesY * (corr_size + 1),
true,
title_cor2d, // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
slice_titles);
}
if (debugLevel > -4) {
System.out.println("scan DONE");
}
}
// starting from the motion_scan[][][] - calculated or read from file. corr2d is curently unused, maybe we'll have to save restore
double [][][] motion_scan_original = cloneMotionScan(motion_scan, remain);
printRemain(remain, "motion_scan_original", true);
int niter;
int max_iter = 20; // 100;
double [][][] targets_good = new double [motion_scan.length][motion_scan[0].length][]; // will combine good targets
double [][][] targets_bad = new double [motion_scan.length][motion_scan[0].length][]; // will combine good targets
for (niter=0; niter < max_iter; niter++) {
// remove known bad targets. TODO: maybe will need to modify corr2d and recalculate, if the same tile is shared by a target and background
motion_scan = subtractMotionScans(
motion_scan, // double [][][] scan0, // all tried for targets
targets_bad, // double [][][] scan1) // good targets
remain);
printRemain(remain, "motion_scan wo bad", true);
// filter remaining (no known bad ones)
filter5 = filterMotionScan(
motion_scan, // final double [][][] motion_scan,
cuasMotion.tilesX, // final int tilesX)
max_range, // final int range, // 1 or 2
null, // final boolean [][] filtered, // same format as output, previously selected
remain, // final int [] remain){
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost); // double speed_boost);
printRemain(remain, "filter5", true);
motion_scan_filtered = applyFilter(
motion_scan, // double [][][] motion_scan,
filter5); // boolean [][] filter5)
// remove know good (already processed)
motion_scan_filtered = subtractMotionScans(
motion_scan_filtered, // double [][][] scan0, // all tried for targets
targets_good, // double [][][] scan1) // good targets
remain);
printRemain(remain, "filtered wo good", true);
// Anything remains? we'll see agter extension
extended_scan = extendMotionScan(
motion_scan_filtered, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
1, // final int range, // 1 or 2
remain); // final int [] remain)
int remained_total = printRemain(remain, "extended_scan", true);
if ((debugLevel >-4) && (remain !=null)) {
System.out.println("testCuasScanMotion() Total new tiles to process for "+remain.length+" scene sequences is "+remained_total);
for (int nscan = 0; nscan < remain.length; nscan++) {
System.out.print(nscan+":"+remain[nscan]+", ");
}
System.out.println();
}
if (remained_total == 0) {
break;
}
// there are some tiles left to try
if (show_vector_field) {
//title_vf_all
showVectorFieldsSequence(
motion_scan, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_vf_all+"-n"+niter,// String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequence(
motion_scan, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_vf+"-n"+niter, // String title,
true, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequence(
motion_scan_filtered, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_vf_filtered+"-n"+niter, // String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequence(
extended_scan, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_vf_extended+"-n"+niter, // String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
// show good and bad accumulated here too?
}
if (debugLevel > -4) {
System.out.println("Starting render, iteration = "+niter);
}
float [][] fpixels_rendered = cuasMotion.shiftAndRenderTest(
clt_parameters, // CLTParameters clt_parameters,
fpixels, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (debugLevel > -4) {
System.out.println("Render DONE");
}
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
false, // final boolean fill_zeros,
fpixels, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
half_accum_range, // final int half_range,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
// show just fpixels_accumulated
// move outside? compare to slice_titles known
if (show_full_images) {
ShowDoubleFloatArrays.showArrays(
fpixels_accumulated,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
true,
title_accumulated+"-n"+niter, // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
slice_titles); // titles_accum);
}
// replace center frames with the accumulated ones
for (int nseq = 0; nseq < fpixels_accumulated.length; nseq++){
fpixels_rendered[frame0 + nseq * corr_step] = fpixels_accumulated[nseq];
}
if (debugLevel > -4) {
System.out.println("Accumulation DONE");
}
float [][][] fpixels_hyper = {fpixels,fpixels_rendered};
String [] hyper_titles_top = {"Source","Rendered"};
if (show_full_images) {
ImagePlus imp_hyper = ShowDoubleFloatArrays.showArraysHyperstack(
fpixels_hyper, // float[][][] pixels,
cuasMotion.gpu_max_width, // int width,
title_rendered_hyper+"-n"+niter, // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
scene_titles, // String [] titles, // all slices*frames titles or just slice titles or null
hyper_titles_top, // String [] frame_titles, // frame titles or null
true); // boolean show)
}
// double target_radius = cent_radius; // for now - make separate
// target_max
double [][][][] coord_data2 = getAccumulatedCoordinates(
motion_scan_filtered, // final double [][][] vector_fields, // centers
fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq
target_radius, // final double centroid_radius,
n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
cuasMotion.tilesX, // final int tilesX){
no_border, // final boolean no_border,
// Moving target LMA
lma_sigma, // final double lma_sigma,
lma_r0, // final double lma_r0,
lma_ovrsht, // final double lma_ovrsht,
// CUAS Motion LMA parameters
lma_fit_xy, // final boolean lma_fit_xy,
lma_fit_a, // final boolean lma_fit_a,
lma_fit_c, // final boolean lma_fit_c,
lma_fit_r, // final boolean lma_fit_r,
lma_fit_k, // final boolean lma_fit_k,
lambda, // final double lambda,
lambda_good, // final double lambda_good,
lambda_bad, // final double lambda_bad,
lambda_max, // final double lambda_max,
rms_diff, // final double rms_diff,
num_iter, // final int num_iter,
debugLevel); // final int debugLevel);
double [][][] coord_data = coord_data2[0];
double [][][] coord_lma = coord_data2[1];
if (show_vector_field) {
showVectorFieldsSequence(
coord_data, // double [][][] vector_fields_sequence,
0.0, // double speed_min,
0.0, // double speed_pref,
1.0, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_all+"-n"+niter, // String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequenceLMA(
coord_lma, // double [][][] target_scene_sequence, // rename
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_all+"-LMA-n"+niter, // String title,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
}
int [] targets_remain = new int [coord_data.length];
double [][][] coord_data_filtered = filterAndShowTargets(
coord_data, // double [][][] coord_data,
target_strength, // double target_strength,
target_frac, // double [][] target_frac,
slice_titles, // String [] slice_titles, //
title_targets_filt+"-n"+niter, // String title_targets_filt,
targets_remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
show_vector_field, // boolean show)
null); // do not save //QuadCLT parentCLT)
remained_total = printRemain(targets_remain, "coord_data_filtered: Total new targets", true);
if (remained_total == 0) {
break;
}
double [][][] coord_data_filtered_lma = filterAndShowTargetsLMA(
coord_lma, // double [][][] coord_data,
lma_rms, // double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
lma_arms, // double lma_arms, // = 0.03; // Maximal absolutre RMS
lma_rrms, // double lma_rrms, // = 0.03; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
lma_mina, // double lma_mina, // = 1.0; // Minimal A (amplitude)
lma_maxr, // double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0
lma_mink, // double lma_mink, // = 1.0; // Minimal K (overshoot) = 1.0
lma_maxk, // double lma_maxk, // = 1.0; // Minimal K (overshoot) = 3.0
slice_titles, // String [] slice_titles, //
title_targets_filt+"-n"+niter, // String title_targets_filt,
targets_remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
show_vector_field, // boolean show)
null); // do not save //QuadCLT parentCLT)
remained_total = printRemain(targets_remain, "coord_data_filtered: Total new targets", true);
// add good targets to targets_good
targets_good = combineMotionScans(
targets_good, // double [][][] scan0,
coord_data_filtered, // double [][][] scan1)
remain);
printRemain(remain, "targets_good", true);
if (show_vector_field) {
showVectorFieldsSequence(
targets_good, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_good+"-n"+niter,// String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
}
double [][][] targets_bad_last = subtractMotionScans(
motion_scan_filtered, // double [][][] scan0, // all tried for targets
coord_data_filtered, // double [][][] scan1) // good targets
remain);
printRemain(remain, "targets_bad_last", true);
// add bad targets to targets_bad
targets_bad = combineMotionScans(
targets_bad, // double [][][] scan0,
targets_bad_last, // double [][][] scan1)
remain); //
printRemain(remain, "targets_bad", true);
float [][] fpixels_accumulated_filtered = getTargetImages(
coord_data_filtered, // final double [][][] vector_fields, // centers , just null/not null
fpixels_accumulated, // final float [][] accum_data, // should be around 0, no low-freq
cuasMotion.tilesX); // final int tilesX)
if (show_full_images) {
ShowDoubleFloatArrays.showArrays(
fpixels_accumulated_filtered,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
true,
title_acc_targets+"-n"+niter, // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
slice_titles); // titles_accum);
}
if (debugLevel > -4) {
System.out.println("Iteration "+niter+" DONE.");
}
} //for (niter=0; niter < max_iter; niter++)
show_vector_field = true;
show_full_images = true;
// make good motion vectors from good targets
double [][][] motion_good = filterMotionScans(
motion_scan_original, // double [][][] scan1 // or just use motion_scan - it has only bad removed
targets_good, // double [][][] scan1){ // keep scan0 that is in scan1
remain);
printRemain(remain, "All done: motion_good", true);
// make extended from all good
extended_scan = extendMotionScan(
motion_good, // motion_scan_filtered, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
1, // final int range, // 1 or 2
remain); // final int [] remain)
printRemain(remain, "targets_good", true);
if (show_vector_field) {
showVectorFieldsSequence(
motion_good, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_vf_good,// String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequence(
targets_good, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_good,// String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequence(
extended_scan, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_extended_good,// String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
}
// Render for all good
float [][] fpixels_rendered = cuasMotion.shiftAndRenderTest(
clt_parameters, // CLTParameters clt_parameters,
fpixels, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (debugLevel > -4) {
System.out.println("Render all good DONE");
}
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
false, // final boolean fill_zeros,
fpixels, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
half_accum_range, // final int half_range,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (show_full_images) {
ShowDoubleFloatArrays.showArrays( // good
fpixels_accumulated,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
true,
title_accumulated+"-n"+niter, // "-corr2d"+"-"+frame0+"-"+frame1+"-"+corr_pairs,
slice_titles); // titles_accum);
}
// replace center frames with the accumulated ones
for (int nseq = 0; nseq < fpixels_accumulated.length; nseq++){
fpixels_rendered[frame0 + nseq * corr_step] = fpixels_accumulated[nseq];
}
if (debugLevel > -4) {
System.out.println("Accumulation all good DONE");
}
float [][][] fpixels_hyper = {fpixels,fpixels_rendered};
String [] hyper_titles_top = {"Source","Rendered"};
if (show_full_images) {
ImagePlus imp_hyper = ShowDoubleFloatArrays.showArraysHyperstack( // good
fpixels_hyper, // float[][][] pixels,
cuasMotion.gpu_max_width, // int width,
title_rendered_hyper+"-n"+niter, // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
scene_titles, // String [] titles, // all slices*frames titles or just slice titles or null
hyper_titles_top, // String [] frame_titles, // frame titles or null
true); // boolean show)
}
// double target_radius = cent_radius; // for now - make separate
// target_max
double [][][][] coord_data2 = getAccumulatedCoordinates(
motion_good, // final double [][][] vector_fields, // centers
fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq
target_radius, // final double centroid_radius,
n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
cuasMotion.tilesX, // final int tilesX){
no_border, // final boolean no_border,
// Moving target LMA
lma_sigma, // final double lma_sigma,
lma_r0, // final double lma_r0,
lma_ovrsht, // final double lma_ovrsht,
// CUAS Motion LMA parameters
lma_fit_xy, // final boolean lma_fit_xy,
lma_fit_a, // final boolean lma_fit_a,
lma_fit_c, // final boolean lma_fit_c,
lma_fit_r, // final boolean lma_fit_r,
lma_fit_k, // final boolean lma_fit_k,
lambda, // final double lambda,
lambda_good, // final double lambda_good,
lambda_bad, // final double lambda_bad,
lambda_max, // final double lambda_max,
rms_diff, // final double rms_diff,
num_iter, // final int num_iter,
debugLevel); // final int debugLevel);
double [][][] coord_data = coord_data2[0];
double [][][] coord_lma = coord_data2[1];
if (show_vector_field) {
showVectorFieldsSequence(
coord_data, // double [][][] vector_fields_sequence,
0.0, // double speed_min,
0.0, // double speed_pref,
1.0, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_all+"-COMBO", // String title,
false, // boolean nan_effective_strength,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
showVectorFieldsSequenceLMA(
coord_lma, // double [][][] target_scene_sequence, // rename
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
title_targets_all+"-LMA-COMBO", // String title,
true, // boolean show,
cuasMotion.tilesX); // int tilesX) {
}
int [] targets_remain = new int [coord_data.length];
double [][][] coord_data_filtered = filterAndShowTargets(
coord_data, // double [][][] coord_data,
target_strength, // double target_strength,
target_frac, // double [][] target_frac,
slice_titles, // String [] slice_titles, //
title_targets_filt+"-n"+niter, // String title_targets_filt,
targets_remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
show_vector_field, // boolean show)
null); // do not save //QuadCLT parentCLT)
int remained_total = printRemain(targets_remain, "Total good targets", true);
double [][][] coord_data_filtered_lma = filterAndShowTargetsLMA(
coord_lma,// double [][][] coord_data,
lma_rms, // double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
lma_arms, // double lma_arms, // = 0.03; // Maximal absolutre RMS
lma_rrms, // double lma_rrms, // = 0.03; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
lma_mina, // double lma_mina, // = 1.0; // Minimal A (amplitude)
lma_maxr, // double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0
lma_mink, // double lma_mink, // = 1.0; // Minimal K (overshoot) = 1.0
lma_maxk, // double lma_maxk, // = 1.0; // Minimal K (overshoot) = 3.0
slice_titles, // String [] slice_titles, //
title_targets_filt+"-n"+niter, // String title_targets_filt,
targets_remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
show_vector_field, // boolean show)
null); // do not save //QuadCLT parentCLT)
remained_total = printRemain(targets_remain, "coord_data_filtered: Total new targets LMA", true);
processMovingTargets(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
fpixels, // final float [][] fpixels,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
debugLevel); // final int debugLevel)
if (debugLevel > -4) {
System.out.println("testCuasScanMotion() Total good targets for "+targets_remain.length+" scene sequences is "+remained_total);
}
continue;
if (debugLevel > -4) {
System.out.println("All DONE");
}
} // while (true) {
}
......@@ -1465,7 +736,9 @@ public class CuasMotion {
for (int nseq = 0; nseq < remain.length; nseq++) {
remained_total += remain[nseq];
}
System.out.println(s+": total tiles for "+remain.length+" scene sequences is "+remained_total);
if (s != null) {
System.out.println(s+": total tiles for "+remain.length+" scene sequences is "+remained_total);
}
if (all) {
for (int nscan = 0; nscan < remain.length; nscan++) {
System.out.print(nscan+":"+remain[nscan]+", ");
......@@ -1555,7 +828,7 @@ public class CuasMotion {
public static double[][][] filterAndShowTargets(
public static double[][][] filterAndShowTargets( // for motion vectors
double [][][] coord_data,
double target_strength,
double [][] target_frac,
......@@ -1684,7 +957,7 @@ public class CuasMotion {
tile2);
}
// find max
double [] mv = Correlation2d.getMaxXYCm( // last, average
double [] mv = Correlation2d.getMaxXYCm( // last, average may be null
pix_tile, // corrs.length-1], // double [] data,
tile2, // int data_width, // = 2 * transform_size - 1; // negative - will return center fraction
centroid_radius, // double radius, // 0 - all same weight, > 0 cosine(PI/2*sqrt(dx^2+dy^2)/rad)
......@@ -2309,7 +1582,8 @@ public class CuasMotion {
int num_scenes = fpixels.length;
int num_corr_samples = (num_scenes - seq_length - start_frame) / corr_step;
double [][][] motion_scan = new double [num_corr_samples][][];
IJ.showStatus("Performing Motion Scan");
IJ.showProgress(0.0);
for (int nscan = 0; nscan < motion_scan.length; nscan++) {
int frame0 = start_frame + corr_step * nscan;
int frame1 = frame0 + corr_offset;
......@@ -2394,7 +1668,9 @@ public class CuasMotion {
title+"-vector_field"+suffix_param,
dbg_titles);
}
IJ.showProgress(1.0*(nscan+1) / motion_scan.length);
}
IJ.showProgress(1.0);
return motion_scan;
}
......@@ -3147,13 +2423,6 @@ public class CuasMotion {
stackfp[i] = (FloatProcessor) stack.getProcessor(i+1);
}
System.out.println("stackfp.length="+stackfp.length);
// TODO: multithreaded
/*
for (int i = 0; i < stackfp.length; i++) {
stackfp[i] = (FloatProcessor) stackfp[i].resize(stackfp[i].getWidth() * 2, stackfp[i].getHeight()*2);
}
*/
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
......@@ -3170,14 +2439,7 @@ public class CuasMotion {
stack.addSlice(labels[i],stackfp[i]);
}
imp = new ImagePlus(imp_title, stack); // imp.getTitle(),stack);
// imp.show();
}
// imp.show();
/*
ImageConverter imageConverter = new ImageConverter(imp);
imageConverter.convertToRGB(); // very slow - need multitherading
*/
// ImageStack conv_stack = imp.getStack();
final FloatProcessor [] float_processors = new FloatProcessor[imp.getStack().getSize()];
final ColorProcessor [] color_processors = new ColorProcessor[float_processors.length];
final String [] cp_labels = new String [imp.getStack().getSize()];
......@@ -3212,8 +2474,6 @@ public class CuasMotion {
// imp.show();
final Color fcolor = annotate_color_mono;
final ImageStack fstack_scenes = imp.getImageStack();
// final int width = imp_scenes_pair[nstereo].getWidth();
// final int height = imp_scenes_pair[nstereo].getHeight();
final int posX= width - scale * 119; // 521;
final int posY= height + scale * 1; // 513;
final Font font = new Font("Monospaced", Font.PLAIN, scale2x? 24: 12);
......@@ -3399,30 +2659,544 @@ public class CuasMotion {
return webm_path;
}
public static void processMovingTargets(
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
final float [][] fpixels,
String [] scene_titles, // recreate slice_titles from scene titles?
final int debugLevel) {
CuasMotion cuasMotion = new CuasMotion (
clt_parameters, // CLTParameters clt_parameters,
parentCLT, // QuadCLT parentCLT,
debugLevel); // int debugLevel)
public static void generateExtractFilterMovingTargets( // move parameters to clt_parameters
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
final float [][] fpixels,
final float [][] accum, //
final double [][][] vf_sequence, //
final int frame0, // for vector_field[0] // source scene corresponding to the first sequence
final CuasMotion cuasMotion,
String [] scene_titles, // recreate slice_titles from scene titles?
String [] slice_titles,
final int debugLevel) {
int start_frame = 0;
int corr_offset = clt_parameters.imp.cuas_corr_offset;
int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
boolean half_step = clt_parameters.imp.cuas_half_step; // true;
// String x3d_path = parentCLT.getX3dDirectory();
String model_prefix = parentCLT.getImageName();
int seq_length = corr_offset + corr_pairs;
int corr_step = half_step ? (corr_offset/2) : corr_offset;
int num_corr_samples = (fpixels.length - seq_length - start_frame) / corr_step;
String [] slice_titles = new String [num_corr_samples];
for (int nscan = 0; nscan < num_corr_samples; nscan++) {
int frame_cent = start_frame + corr_step * nscan + seq_length/2; // debug only
slice_titles[nscan] = scene_titles[frame_cent];
}
boolean show_vector_field = true;
boolean show_full_images = true;
show_vector_field &= !batch_mode;
show_full_images &= !batch_mode;
double [][][] vf_sequence = locateAndFreezeTargets(
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
fpixels, // final float [][] fpixels,
cuasMotion, // final CuasMotion cuasMotion,
scene_titles, // String [] scene_titles, // recreate slice_titles from scene titles?
slice_titles, // String [] slice_titles,
debugLevel); // final int debugLevel)
// final String model_dir =
generateExtractFilterMovingTargets( // move parameters to clt_parameters
clt_parameters, // CLTParameters clt_parameters,
batch_mode, // final boolean batch_mode,
parentCLT, // QuadCLT parentCLT, //
// three arrays needed
fpixels, // final float [][] fpixels,
vf_sequence, // final double [][][] vf_sequence, // center tiles (not extended), null /non-null only
// frame0, // final int frame0, // for vector_field[0] // source scene corresponding to the first sequence
cuasMotion, // 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 [][][] locateAndFreezeTargets(
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
final float [][] fpixels,
final CuasMotion cuasMotion,
String [] scene_titles, // recreate slice_titles from scene titles?
String [] slice_titles,
final int debugLevel) {
int corr_offset = clt_parameters.imp.cuas_corr_offset;
int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
double fat_zero = clt_parameters.imp.cuas_fat_zero;
double cent_radius = clt_parameters.imp.cuas_cent_radius;
int n_recenter = clt_parameters.imp.cuas_n_recenter;
double rstr = clt_parameters.imp.cuas_rstr;// 0.003; // clt_parameters.imp.rln_sngl_rstr; // FIXME: ADD
double speed_min = clt_parameters.imp.cuas_speed_min;
double speed_pref = clt_parameters.imp.cuas_speed_pref;
double speed_boost = clt_parameters.imp.cuas_speed_boost;
boolean smooth = clt_parameters.imp.cuas_smooth; // true;
boolean half_step = clt_parameters.imp.cuas_half_step; // true;
int max_range = clt_parameters.imp.cuas_max_range;
int num_cycles = clt_parameters.imp.cuas_num_cycles;
double target_radius = clt_parameters.imp.cuas_target_radius;
double target_strength = clt_parameters.imp.cuas_target_strength;
double [][] target_frac = new double [clt_parameters.imp.cuas_target_frac.length][2];
boolean no_border= clt_parameters.imp.cuas_no_border; // true;
// Moving target LMA
double lma_sigma = clt_parameters.imp.cuas_lma_sigma; // = 3.0;
double lma_r0 = clt_parameters.imp.cuas_lma_r0; // = 3.0; //maximum with with overshoot
double lma_ovrsht = clt_parameters.imp.cuas_lma_ovrsht; // = 2.0;
// CUAS Motion LMA parameters
boolean lma_fit_xy= clt_parameters.imp.cuas_lma_fit_xy; // true;
boolean lma_fit_a= clt_parameters.imp.cuas_lma_fit_a; // true;
boolean lma_fit_c= clt_parameters.imp.cuas_lma_fit_c; // true;
boolean lma_fit_r= clt_parameters.imp.cuas_lma_fit_r; // true;
boolean lma_fit_k= clt_parameters.imp.cuas_lma_fit_k; // true;
double lambda = clt_parameters.imp.cuas_lambda; // = 0.1;
double lambda_good = clt_parameters.imp.cuas_lambda_good; // = 0.5;
double lambda_bad = clt_parameters.imp.cuas_lambda_bad; // = 8;
double lambda_max = clt_parameters.imp.cuas_lambda_max; // = 100;
double rms_diff = clt_parameters.imp.cuas_rms_diff; // = 0.001; // relative RMS improvement
int num_iter = clt_parameters.imp.cuas_num_iter; // = 20;
// CUAS Motion LMA filter parameters
double lma_rms = clt_parameters.imp.cuas_lma_rms; // = 1.5; // Maximal RMS, regardless of amplitude
double lma_arms = clt_parameters.imp.cuas_lma_arms; // = 0.06; // Maximal absolute RMS, sufficient for any amplitude
double lma_rrms = clt_parameters.imp.cuas_lma_rrms; // = 0.15; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
double lma_mina = clt_parameters.imp.cuas_lma_mina; // = 1.0; // Minimal A (amplitude)
double lma_maxr = clt_parameters.imp.cuas_lma_maxr; // = 5.0; // Maximal radius (>3.8)
double lma_mink = clt_parameters.imp.cuas_lma_mink; // = 0.0; // Minimal K (overshoot) <0.007
double lma_maxk = clt_parameters.imp.cuas_lma_maxk; // = 5.0; // Minimal K (overshoot) > 3.8
double input_range = clt_parameters.imp.cuas_input_range; // 5;
int iter_show = clt_parameters.imp.cuas_iter_show; //1; // Maximal enhancement iteration to show intermediate result (0 - none)
boolean corr2d_save_show = clt_parameters.imp.cuas_2d_save_show; //true;
boolean intermed_low = clt_parameters.imp.cuas_intermed_low; //true;
boolean intermed_high = clt_parameters.imp.cuas_intermed_high; //true;
for (int i = 0; i < target_frac.length; i++) {
if (clt_parameters.imp.cuas_target_frac[i].length >= 2) {
target_frac[i][0] = clt_parameters.imp.cuas_target_frac[i][0];
target_frac[i][1] = clt_parameters.imp.cuas_target_frac[i][1];
} else {
System.out.println("testCuasScanMotion(): wrong format for a pair of strength, fraction values.");
}
}
int start_frame = 0;
int num_scenes = fpixels.length; // .getStack().getSize()- first_corr; // includes average
int seq_length = corr_offset + corr_pairs;
int corr_step = half_step ? (corr_offset/2) : corr_offset;
int num_corr_samples = (num_scenes - seq_length - start_frame) / corr_step;
final int frame0 = start_frame + seq_length/2;
final int half_accum_range = corr_pairs/2;
int [] remain = new int [num_corr_samples];
String model_prefix = parentCLT.getImageName()+getParametersSuffix(clt_parameters,null);
double [][][] corr2d = corr2d_save_show? new double [num_corr_samples][][] : null;
double [][][] motion_scan = getMotionScan(
false, // batch_mode, // boolean batch_mode,
clt_parameters, // CLTParameters clt_parameters,
cuasMotion, // CuasMotion cuasMotion,
fpixels, // float [][] fpixels,
start_frame, // int start_frame,
corr_pairs, // int corr_pairs,
corr_offset, // int corr_offset,
corr_step, // int corr_step,
smooth, // boolean smooth,
fat_zero, // double fat_zero,
cent_radius, // double cent_radius,
n_recenter, // int n_recenter,
-rstr, // double rstr,
model_prefix, // String title,
corr2d, // double [][][] corr2d, // null or [(fpixels.length - seq_length - start_frame) / corr_step)[][]
debugLevel); // int debugLevel) {
if (corr2d_save_show) { // may be read to re-process with vector field
int corr_size = 2 * GPUTileProcessor.DTT_SIZE -1;
double [][] dbg_2d_corrs = ImageDtt.corr_partial_dbg( // not used in lwir
corr2d, // final double [][][] corr_data, // [layer][tile][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
cuasMotion.tilesX, // final int tilesX,
corr_size, //final int corr_size, // 15
clt_parameters.corr_border_contrast, // final double border_contrast,
debugLevel); // final int globalDebugLevel)
ImagePlus imp_corr2d = ShowDoubleFloatArrays.makeArrays(
dbg_2d_corrs, // double[][] pixels,
cuasMotion.tilesX * (corr_size + 1),
cuasMotion.tilesY * (corr_size + 1),
model_prefix+"-CORR2D", // -OFFS"+corr_offset+"-PAIRS"+corr_pairs, // String title,
slice_titles);
if (!batch_mode) {
imp_corr2d.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_corr2d); // ImagePlus imp)
}
if (debugLevel > -4) {
System.out.println("scan DONE");
}
// starting from the motion_scan[][][] - calculated or read from file. corr2d is curently unused, maybe we'll have to save restore
double [][][] motion_scan_original = cloneMotionScan(motion_scan, remain);
printRemain(remain, "motion_scan_original", true);
int niter;
// int max_iter = 20; // 100;
double [][][] targets_good = new double [motion_scan.length][motion_scan[0].length][]; // will combine good targets lma
double [][][] targets_bad = new double [motion_scan.length][motion_scan[0].length][]; // will combine good targets centroids
/// float [][] fpixels_accumulated_filtered = null;
for (niter=0; niter < num_cycles; niter++) {
// boolean no_improve = false;
boolean save_filtered_low = (intermed_low && (niter < iter_show));
boolean save_filtered_high = (intermed_high && (niter < iter_show));
boolean save_filtered_gig = save_filtered_high && (debugLevel >0);
// remove known bad targets. TODO: maybe will need to modify corr2d and recalculate, if the same tile is shared by a target and background
motion_scan = subtractMotionScans( // motion vectors
motion_scan, // double [][][] scan0, // all tried for targets
targets_bad, // double [][][] scan1) // good targets
remain);
if (debugLevel > -4) printRemain(remain, "motion_scan wo bad", true);
// filter remaining (no known bad ones)
boolean[][] filter5 = filterMotionScan(
motion_scan, // final double [][][] motion_scan,
cuasMotion.tilesX, // final int tilesX)
max_range, // final int range, // 1 or 2
null, // final boolean [][] filtered, // same format as output, previously selected
remain, // final int [] remain){
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost); // double speed_boost);
if (debugLevel > -4) printRemain(remain, "filter5", true);
double [][][] motion_scan_filtered = applyFilter( // motion vectors
motion_scan, // double [][][] motion_scan,
filter5); // boolean [][] filter5)
// remove known good (already processed)
motion_scan_filtered = subtractMotionScans( // motion vectors
motion_scan_filtered, // double [][][] scan0, // all tried for targets
targets_good, // double [][][] scan1) // good targets (lma-vect)
remain);
if (debugLevel > -4) printRemain(remain, "filtered wo good", true);
// Anything remains? we'll see after extension
double [][][] extended_scan = extendMotionScan(
motion_scan_filtered, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
1, // final int range, // 1 or 2
remain); // final int [] remain)
int remained_total = 0;
if (debugLevel > -4) remained_total = printRemain(remain, "extended_scan", true);
else remained_total = printRemain(remain, null, false);
if (remained_total == 0) {
// no_improve = true;
// if (fpixels_accumulated_filtered != null) {
break;
// }
}
// there are some tiles left to try
if (save_filtered_low) {
//title_vf_all
ImagePlus imp_vf = showVectorFieldsSequence(
motion_scan, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"VF-ALL-n"+niter,// String title,
false, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_vf);
ImagePlus imp_vf_nan = showVectorFieldsSequence(
motion_scan, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"VF-ALL-NAN-n"+niter, // String title,
true, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_vf_nan);
ImagePlus imp_vf_filt = showVectorFieldsSequence(
motion_scan_filtered, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"VF-FILT-n"+niter, // String title,
false, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_vf_filt);
ImagePlus imp_vf_ext = showVectorFieldsSequence(
extended_scan, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"VF-EXT-n"+niter, // String title,
false, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_vf_ext);
// show good and bad accumulated here too?
}
float [][] fpixels_accumulated = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
false, // final boolean fill_zeros,
fpixels, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
half_accum_range, // final int half_range,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (save_filtered_high) {
ImagePlus imp_acc = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
model_prefix+"-ACCUMULATED-n"+niter, // String title,
slice_titles);
imp_acc.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_acc); // ImagePlus imp)
}
// replace center frames with the accumulated ones
if (debugLevel > -4) {
System.out.println("Starting render, iteration = "+niter);
}
// show just fpixels_accumulated
// move outside? compare to slice_titles known
if (save_filtered_gig) { // huge file
float [][] fpixels_rendered = cuasMotion.shiftAndRenderTest(
clt_parameters, // CLTParameters clt_parameters,
fpixels, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (debugLevel > -4) {
System.out.println("Render DONE, iteration "+niter);
}
for (int nseq = 0; nseq < fpixels_accumulated.length; nseq++){
fpixels_rendered[frame0 + nseq * corr_step] = fpixels_accumulated[nseq];
}
if (debugLevel > -4) {
System.out.println("Accumulation DONE iteration "+niter);
}
float [][][] fpixels_hyper = {fpixels,fpixels_rendered};
String [] hyper_titles_top = {"Source","Rendered"};
ImagePlus imp_hyper = ShowDoubleFloatArrays.showArraysHyperstack(
fpixels_hyper, // float[][][] pixels,
cuasMotion.gpu_max_width, // int width,
model_prefix+"-OVERLAP-n"+niter, // String title, "time_derivs-rt"+diff_time_rt+"-rxy"+diff_time_rxy,
scene_titles, // String [] titles, // all slices*frames titles or just slice titles or null
hyper_titles_top, // String [] frame_titles, // frame titles or null
!batch_mode); // boolean show)
imp_hyper.getProcessor().setMinAndMax(-input_range/2, input_range/2);
parentCLT.saveImagePlusInModelDirectory(imp_hyper); // ImagePlus imp)
}
// Calculate both centroid and LMA target parametes, return both
double [][][][] coord_data2 = getAccumulatedCoordinates(
motion_scan_filtered, // final double [][][] vector_fields, // centers
fpixels_accumulated, // final double [][] accum_data, // should be around 0, no low-freq
target_radius, // final double centroid_radius,
n_recenter, // final int n_recenter, // re-center window around new maximum. 0 -no refines (single-pass)
cuasMotion.tilesX, // final int tilesX){
no_border, // final boolean no_border,
// Moving target LMA
lma_sigma, // final double lma_sigma,
lma_r0, // final double lma_r0,
lma_ovrsht, // final double lma_ovrsht,
// CUAS Motion LMA parameters
lma_fit_xy, // final boolean lma_fit_xy,
lma_fit_a, // final boolean lma_fit_a,
lma_fit_c, // final boolean lma_fit_c,
lma_fit_r, // final boolean lma_fit_r,
lma_fit_k, // final boolean lma_fit_k,
lambda, // final double lambda,
lambda_good, // final double lambda_good,
lambda_bad, // final double lambda_bad,
lambda_max, // final double lambda_max,
rms_diff, // final double rms_diff,
num_iter, // final int num_iter,
debugLevel); // final int debugLevel);
double [][][] coord_centroid = coord_data2[0]; // centroid
double [][][] coord_lma = coord_data2[1]; // lma
if (save_filtered_low) {
// Does not use target speed preference at all
ImagePlus imp_centroid = showVectorFieldsSequence(
coord_centroid, // double [][][] vector_fields_sequence,
0.0, // double speed_min, //
0.0, // double speed_pref,
1.0, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-CENTROID-n"+niter, // String title,
false, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_centroid); // ImagePlus imp)
ImagePlus imp_lma = showVectorFieldsSequenceLMA(
coord_lma, // double [][][] target_scene_sequence, // rename
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-LMA-n"+niter, // String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_lma); // ImagePlus imp)
}
double [][][] coord_centroids_filtered = filterAndShowTargets( // generates motion vectors?
coord_centroid, // double [][][] coord_data,
target_strength, // double target_strength,
target_frac, // double [][] target_frac,
slice_titles, // String [] slice_titles, //
model_prefix+"-CENTROIDS-FILTERED-n"+niter, // String title_targets_filt,
remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
save_filtered_low && !batch_mode, // boolean show)
(save_filtered_low? parentCLT : null)); // do not save //QuadCLT parentCLT)
remained_total = 0;
if (debugLevel > -4) remained_total = printRemain(remain, "coord_data_filtered: Total new targets", true);
else remained_total = printRemain(remain, null, false);
if (remained_total == 0) {
// no_improve = true;
// if (fpixels_accumulated_filtered != null) {
break;
// }
}
double [][][] coord_data_filtered_lma = filterAndShowTargetsLMA(
coord_lma, // double [][][] coord_data,
lma_rms, // double lma_rms, // = 1.5; // Maximal RMS (should always match, regardless if A)
lma_arms, // double lma_arms, // = 0.03; // Maximal absolutre RMS
lma_rrms, // double lma_rrms, // = 0.03; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
lma_mina, // double lma_mina, // = 1.0; // Minimal A (amplitude)
lma_maxr, // double lma_maxr, // = 5.0; // Minimal K (overshoot) = 3.0
lma_mink, // double lma_mink, // = 1.0; // Minimal K (overshoot) = 1.0
lma_maxk, // double lma_maxk, // = 1.0; // Minimal K (overshoot) = 3.0
slice_titles, // String [] slice_titles, //
model_prefix+"-TARGETS-FILTERED-LMA-n"+niter, // String title_targets_filt,
remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
save_filtered_low && !batch_mode, // boolean show)
(save_filtered_low? parentCLT : null)); // do not save //QuadCLT parentCLT)
if (debugLevel > -4) remained_total = printRemain(remain, "coord_data_filtered_lma: Total new targets", true);
// add good targets to targets_good
targets_good = combineMotionScans( // lma-vectors
targets_good, // double [][][] scan0,
coord_data_filtered_lma, // coord_centroids_filtered, // double [][][] scan1)
remain);
if (debugLevel > -4) printRemain(remain, "targets_good", true);
if (save_filtered_low) { // targets_good now has
ImagePlus imp_good = showVectorFieldsSequenceLMA(
targets_good, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-TARGETS-GOOD-n"+niter,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_good); // ImagePlus imp)
}
// remove all good (by the LMA)
double [][][] targets_bad_last = subtractMotionScans( // centroids
motion_scan_filtered, // double [][][] scan0, // all tried for targets
targets_good, // coord_centroids_filtered, // double [][][] scan1) // good targets
remain);
if (debugLevel > -4) printRemain(remain, "targets_bad_last", true);
// add bad targets to targets_bad
targets_bad = combineMotionScans( // centroids
targets_bad, // double [][][] scan0,
targets_bad_last, // double [][][] scan1)
remain); //
if (debugLevel > -4) printRemain(remain, "targets_bad", true);
// TODO See if they are needed here at all
/*
fpixels_accumulated_filtered = getTargetImages(
coord_centroids_filtered, // final double [][][] vector_fields, // centers , just null/not null
fpixels_accumulated, // final float [][] accum_data, // should be around 0, no low-freq
cuasMotion.tilesX); // final int tilesX)
if (save_filtered_high) {
ImagePlus imp_acc_filt = ShowDoubleFloatArrays.makeArrays(
fpixels_accumulated_filtered, // double[][] pixels,
cuasMotion.gpu_max_width,
cuasMotion.gpu_max_height,
model_prefix+"-ACCUMULATED-FILTERED-n"+niter, // String title,
slice_titles);
imp_acc_filt.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_acc_filt.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_acc_filt); // ImagePlus imp)
}
*/
if (debugLevel > -4) {
System.out.println("Iteration "+niter+" DONE.");
}
// if (no_improve) {
// if (debugLevel > -4) {
// System.out.println("There was no improvement, exiting the loop, iteration "+niter+" .");
// }
// }
} //for (niter=0; niter < max_iter; niter++)
double [][][] motion_good = filterMotionScans(
motion_scan_original, // double [][][] scan1 // or just use motion_scan - it has only bad removed
targets_good, // double [][][] scan1){ // keep scan0 that is in scan1
remain);
if (debugLevel > -4) printRemain(remain, "All done: motion_good", true);
if (intermed_low) { // save final
ImagePlus imp_good = showVectorFieldsSequenceLMA(
targets_good, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-TARGETS-GOOD",// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_good); // ImagePlus imp)
ImagePlus imp_mv_good = showVectorFieldsSequence(
targets_good, // double [][][] vector_fields_sequence,
speed_min, // double speed_min,
speed_pref, // double speed_pref,
speed_boost, // double speed_boost,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-MOTIONS-GOOD",// String title,
false, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_mv_good); // ImagePlus imp)
}
return motion_good;
}
public static void generateExtractFilterMovingTargets( // move parameters to clt_parameters
CLTParameters clt_parameters,
final boolean batch_mode,
QuadCLT parentCLT, //
final float [][] fpixels,
final double [][][] vf_sequence, //
// final int frame0, // for vector_field[0] // source scene corresponding to the first sequence
final CuasMotion cuasMotion,
String [] scene_titles, // recreate slice_titles from scene titles?
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 int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
final boolean half_step = clt_parameters.imp.cuas_half_step; // true;
......@@ -3467,14 +3241,51 @@ public class CuasMotion {
int target_type = clt_parameters.imp.cuas_target_type; //0; // 0 - unknown, 1 - known, 2 - friend, 3 - foe
double input_range = clt_parameters.imp.cuas_input_range; // 5;
boolean scale2x = clt_parameters.imp.cuas_scale2x; //true;
boolean ra_background = clt_parameters.imp.cuas_ra_background; //true;
boolean intermed_low = clt_parameters.imp.cuas_intermed_low; //true;
boolean intermed_high = clt_parameters.imp.cuas_intermed_high; //true;
boolean save_mono = clt_parameters.imp.cuas_save_mono; //true;
boolean save_color = clt_parameters.imp.cuas_save_color; //true;
boolean save_video = clt_parameters.imp.cuas_save_video; //true;
int start_frame = 0;
int seq_length = corr_offset + corr_pairs;
final int frame0 = start_frame + seq_length/2;
// create accum from fpixels
double [][][] extended_scan = extendMotionScan(
vf_sequence, // final double [][][] motion_scan,
null, // filter5, // final boolean [][] filtered, // centers, should be non-overlapped
cuasMotion.tilesX, // final int tilesX)
1, // final int range, // 1 or 2
null); // remain); // final int [] remain)
float [][]accum = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
false, // final boolean fill_zeros,
fpixels, // final float [][] fpixels,
extended_scan, // final double [][][] vector_field,
frame0, // final int frame0, // for vector_field[0]
corr_step, // final int frame_step,
half_accum_range, // final int half_range,
smooth, // final boolean smooth,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
if (intermed_high) {
ImagePlus imp_accumulated = ShowDoubleFloatArrays.makeArrays(
accum, // float[][] pixels,
cuasMotion.gpu_max_width, // int width,
cuasMotion.gpu_max_height, // int height,
model_prefix+"-ACCUMULATED", //String title,
slice_titles); //String [] titles)
imp_accumulated.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_accumulated.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_accumulated); // ImagePlus imp)
}
double [][][][] coord_data2 = getAccumulatedCoordinates(
vf_sequence, // final double [][][] vector_fields, // centers
......@@ -3502,7 +3313,7 @@ public class CuasMotion {
debugLevel); // final int debugLevel);
double [][][] coord_data = coord_data2[0];
double [][][] coord_lma = coord_data2[1];
if (show_vector_field || intermed_low) {
if (intermed_low) {
ImagePlus imp_vf = showVectorFieldsSequence(
coord_data, // double [][][] vector_fields_sequence,
0.0, // double speed_min,
......@@ -3511,16 +3322,14 @@ public class CuasMotion {
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-VF-UNFILTERED", // String title,
false, // boolean nan_effective_strength,
show_vector_field, // boolean show,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
if (intermed_low) {
parentCLT.saveImagePlusInModelDirectory(imp_vf);
}
parentCLT.saveImagePlusInModelDirectory(imp_vf);
ImagePlus imp_lma = showVectorFieldsSequenceLMA(
coord_lma, // double [][][] target_scene_sequence, // rename
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-LMA-UNFILTERED", // String title,
show_vector_field, // boolean show,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
if (intermed_low) {
parentCLT.saveImagePlusInModelDirectory(imp_lma);
......@@ -3536,7 +3345,7 @@ public class CuasMotion {
model_prefix+"-VF-FILTERED", // String title_targets_filt,
remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
show_vector_field, // boolean show)
intermed_low && !batch_mode, // boolean show)
intermed_low?parentCLT:null); // parentCLT to save in model directory, null - do not save
if (debugLevel > -4) printRemain(remain, "Total good targets", true);
......@@ -3553,7 +3362,7 @@ public class CuasMotion {
model_prefix+"-LMA-FILTERED", // String title_targets_filt,
remain, // int [] targets_remain,
cuasMotion.tilesX, // int tilesX)
show_vector_field, // show_vector_field); // boolean show)
intermed_low && !batch_mode, // show_vector_field); // boolean show)
intermed_low?parentCLT:null); // parentCLT to save in model directory, null - do not save
if (debugLevel > -4) printRemain(remain, "coord_data_filtered_lma: Total new targets LMA", true);
......@@ -3573,12 +3382,10 @@ public class CuasMotion {
targets_lma_combo, // double [][][] target_scene_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-FILTERED-COMBO", // String title,
show_vector_field, // boolean show,
intermed_low && !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
if (intermed_low) {
parentCLT.saveImagePlusInModelDirectory(imp_filtered_combo); // ImagePlus imp)
}
if (intermed_low) parentCLT.saveImagePlusInModelDirectory(imp_filtered_combo); // ImagePlus imp)
// create larger, 5x5 vector field for accumulation
double [][][] extended_vf_sequence = extendMotionScan(
......@@ -3596,13 +3403,10 @@ public class CuasMotion {
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-EXTENDED", // String title,
false, // boolean nan_effective_strength,
show_vector_field, // boolean show,
intermed_low && !batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
if (intermed_low) {
parentCLT.saveImagePlusInModelDirectory(imp_extended);
}
if (intermed_low) parentCLT.saveImagePlusInModelDirectory(imp_extended);
float [][] fpixels_accumulated5x5 = cuasMotion.shiftAndRenderAccumulate(
clt_parameters, // CLTParameters clt_parameters,
true, // final boolean fill_zeros,
......@@ -3623,10 +3427,9 @@ public class CuasMotion {
cuasMotion.gpu_max_height, // int height,
model_prefix+"-TARGETS5x5", //String title,
slice_titles); //String [] titles)
if (show_full_images) {
imp_accumulated5x5.show();
}
imp_accumulated5x5.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (intermed_high) {
if (!batch_mode) imp_accumulated5x5.show();
parentCLT.saveImagePlusInModelDirectory(imp_accumulated5x5); // ImagePlus imp)
}
......@@ -3658,18 +3461,18 @@ public class CuasMotion {
targets60hz, // final double [][][] targets60hz,
batch_mode, // final boolean batch_mode,
debugLevel); // final int debugLevel)
ImagePlus imp_replaced_targets = ShowDoubleFloatArrays.makeArrays(
replaced_targets, // float[][] pixels,
cuasMotion.gpu_max_width, // int width,
cuasMotion.gpu_max_height, // int height,
model_prefix+"-REPLACED-TARGETS"+(ra_background? "-RABG":""), //String title,
scene_titles); //String [] titles)
if (show_full_images) {
imp_replaced_targets.show();
}
if (save_mono) {
ImagePlus imp_replaced_targets = ShowDoubleFloatArrays.makeArrays(
replaced_targets, // float[][] pixels,
cuasMotion.gpu_max_width, // int width,
cuasMotion.gpu_max_height, // int height,
model_prefix+"-REPLACED-TARGETS"+(ra_background? "-RABG":""), //String title,
scene_titles); //String [] titles)
imp_replaced_targets.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_replaced_targets.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_replaced_targets); // ImagePlus imp)
}
ImagePlus imp_color = convertToRgbAnnotateTargets(
......@@ -3688,17 +3491,14 @@ public class CuasMotion {
debugLevel); // final int debugLevel) {
// save tiff in model directory
if (imp_color != null) {
if (show_full_images) {
imp_color.show();
}
if (save_color) {
if (!batch_mode) {
imp_color.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_color); // ImagePlus imp)
}
// temporary, will use model directory
//// String save_directory = "/media/elphel/NVME/lwir16-proc/eagle_mountain/linked/movement/selected/video/";
//// String video_path_tmp = save_directory + model_prefix+"-TARGETS";
if (save_video) {
// String video_path =
saveAsVideo( // will take name from the image title
clt_parameters, // CLTParameters clt_parameters,
parentCLT, // QuadCLT scene, // if not null - use it's model directory
......@@ -3707,7 +3507,23 @@ public class CuasMotion {
debugLevel); // int debugLevel) {
}
}
}
public static String getParametersSuffix(
CLTParameters clt_parameters,
String prefix) {
int corr_offset = clt_parameters.imp.cuas_corr_offset;
int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
double rstr = clt_parameters.imp.cuas_rstr;// 0.003; // clt_parameters.imp.rln_sngl_rstr; // FIXME: ADD
double lma_rms = clt_parameters.imp.cuas_lma_rms; // = 1.5; // Maximal RMS, regardless of amplitude
double lma_arms = clt_parameters.imp.cuas_lma_arms; // = 0.06; // Maximal absolute RMS, sufficient for any amplitude
double lma_rrms = clt_parameters.imp.cuas_lma_rrms; // = 0.15; // Maximal relative to A rms. OK is when (RMS < cuas_lma_arms) || (RMS < cuas_lma_rrms * A)
double lma_mina = clt_parameters.imp.cuas_lma_mina; // = 1.0; // Minimal A (amplitude)
double fat_zero = clt_parameters.imp.cuas_fat_zero;
String ps = ((prefix != null)?prefix:"") + "-OFFS"+corr_offset+"-PAIRS"+corr_pairs+"-RSTR"+rstr+"-RMS"+lma_rms+"-SRMS"+lma_arms+"-RRMS"+lma_rrms+"-AMP"+lma_mina+"-FZ"+fat_zero;
return ps;
}
}
......@@ -2442,6 +2442,9 @@ public class Correlation2d {
}
}
double mx = data[imax];
if (mx < 0) {
return null; //negative maximum
}
int ix0 = imax % data_width;
int iy0 = imax / data_width;
if (exclude_margins) {
......@@ -2523,6 +2526,9 @@ public class Correlation2d {
x0 += sx / s0;
y0 += sy / s0;
frac = s0 / (s0 + s_other);
if (Double.isNaN(s0)) {
return null; // all negative
}
}
}
if (calc_fraction) {
......@@ -2530,12 +2536,18 @@ public class Correlation2d {
if (debug){
System.out.println("getMaxXYCm() -> "+rslt[0]+":"+rslt[1] +" ("+rslt[2]+"), frac = " + rslt[3]);
}
if (Double.isNaN(rslt[0]) || Double.isNaN(rslt[1]) || Double.isNaN(rslt[2])) {
System.out.println("getMaxXYCm():NaN");
}
return rslt;
} else {
double [] rslt = {x0 - center_xy, y0 - center_xy, mx};
if (debug){
System.out.println("getMaxXYCm() -> "+rslt[0]+":"+rslt[1] +" ("+rslt[2]+")");
}
if (Double.isNaN(rslt[0]) || Double.isNaN(rslt[1]) || Double.isNaN(rslt[2])) {
System.out.println("getMaxXYCm():NaN");
}
return rslt;
}
}
......
......@@ -708,6 +708,8 @@ min_str_neib_fpn 0.35
public int cuas_corr_offset = 20; // offset between motion detection pairs
public boolean cuas_half_step = false; // half step (=cuas_corr_offset/2) when scanning for motion
public int cuas_max_range = 2; // how far to extend local max: 1 3x3 neighbors, 2 - 5x5 neighbs
public int cuas_num_cycles = 10; // number of cycles of testing and removing bad targets
// boosting weight of moving targets
public double cuas_speed_min = 0.2; // minimal pixels per range (per cuas_corr_offset)
public double cuas_speed_pref = 0.5; // preferable speed (boost weights for faster targets)
......@@ -753,6 +755,8 @@ min_str_neib_fpn 0.35
public boolean cuas_ra_background = true; // apply running average to the background of the moving targets (false - use high-noise no-averaged images
// which files to save in the model directory:
public int cuas_iter_show = 1; // Maximal enhancement iteration to show intermediate result (0 - none)
public boolean cuas_2d_save_show = true; // save/show 2D correlation
public boolean cuas_intermed_low = true; // save intermediate vector fields and target coordinates from the LMA (80x64 layers)
public boolean cuas_intermed_high = true; // save pixel-resolution accumulated images (640x512)
public boolean cuas_save_mono = true; // save 32-bit monochrome target+backgrounds Tiffs (before optional scaling)
......@@ -2183,6 +2187,8 @@ min_str_neib_fpn 0.35
"Reduce step for motion detection = offset/2, if false = offset.");
gd.addNumericField("Local max range", this.cuas_max_range, 0,3,"",
"While filtering local correlation maximums: 1 - 3x3 neighbors, 2 - 5x5 ones.");
gd.addNumericField("Number of enhancement cycles", this.cuas_num_cycles, 0,3,"",
"Number of cycles of testing and removing bad targets from compoetition with weaker neighbors.");
gd.addMessage("=== Moving target filtering ===");
gd.addNumericField("Minimal speed", this.cuas_speed_min, 5,8,"ppr",
......@@ -2260,7 +2266,7 @@ min_str_neib_fpn 0.35
"Taget mask to replace static background with moving target.");
gd.addNumericField("Mask transition width", this.cuas_mask_blur, 5,8,"pix",
"Transition between opaque and transparent mask.");
gd.addCheckbox ("Mask round", this.cuas_mask_round,
gd.addCheckbox ("Mask round", this.cuas_mask_round,
"Use round mask. Unchesked - use sharp square mask without any transition.");
gd.addNumericField("Targets icon type", this.cuas_target_type, 0,3,"",
......@@ -2274,6 +2280,10 @@ min_str_neib_fpn 0.35
"Apply running average to the background of the moving targets (false - use high-noise no-averaged images.");
gd.addMessage("=== Saving intermediate and final images and video ===");
gd.addNumericField("Maximal iteration to save/show", this.cuas_iter_show, 0,3,"",
"Maximal enhancement iteration to save/ show intermediate result (0 - none).");
gd.addCheckbox ("Save/show 2D correlations", this.cuas_2d_save_show,
"Save and optionally show 2D correlations.");
gd.addCheckbox ("Save tile-resolution intermediate images", this.cuas_intermed_low,
"Save intermediate vector fields and target coordinates from the LMA (80x64 layers).");
gd.addCheckbox ("Save pixel-resolution intermediate images",this.cuas_intermed_high,
......@@ -3243,6 +3253,8 @@ min_str_neib_fpn 0.35
this.cuas_corr_offset = (int) gd.getNextNumber();
this.cuas_half_step = gd.getNextBoolean();
this.cuas_max_range = (int) gd.getNextNumber();
this.cuas_num_cycles = (int) gd.getNextNumber();
this.cuas_speed_min = gd.getNextNumber();
this.cuas_speed_pref = gd.getNextNumber();
this.cuas_speed_boost = gd.getNextNumber();
......@@ -3282,6 +3294,8 @@ min_str_neib_fpn 0.35
this.cuas_scale2x = gd.getNextBoolean();
this.cuas_ra_background = gd.getNextBoolean();
this.cuas_iter_show= (int) gd.getNextNumber();
this.cuas_2d_save_show = gd.getNextBoolean();
this.cuas_intermed_low = gd.getNextBoolean();
this.cuas_intermed_high = gd.getNextBoolean();
this.cuas_save_mono = gd.getNextBoolean();
......@@ -4172,6 +4186,7 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"cuas_corr_offset", this.cuas_corr_offset+""); // int
properties.setProperty(prefix+"cuas_half_step", this.cuas_half_step+""); // boolean
properties.setProperty(prefix+"cuas_max_range", this.cuas_max_range+""); // int
properties.setProperty(prefix+"cuas_num_cycles", this.cuas_num_cycles+""); // int
properties.setProperty(prefix+"cuas_speed_min", this.cuas_speed_min+""); // double
properties.setProperty(prefix+"cuas_speed_pref", this.cuas_speed_pref+""); // double
......@@ -4212,6 +4227,8 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"cuas_scale2x", this.cuas_scale2x+""); // boolean
properties.setProperty(prefix+"cuas_ra_background", this.cuas_ra_background+""); // boolean
properties.setProperty(prefix+"cuas_iter_show", this.cuas_iter_show+""); // int
properties.setProperty(prefix+"cuas_2d_save_show", this.cuas_2d_save_show+""); // boolean
properties.setProperty(prefix+"cuas_intermed_low", this.cuas_intermed_low+""); // boolean
properties.setProperty(prefix+"cuas_intermed_high", this.cuas_intermed_high+""); // boolean
properties.setProperty(prefix+"cuas_save_mono", this.cuas_save_mono+""); // boolean
......@@ -5074,6 +5091,7 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"cuas_corr_offset")!=null) this.cuas_corr_offset=Integer.parseInt(properties.getProperty(prefix+"cuas_corr_offset"));
if (properties.getProperty(prefix+"cuas_half_step")!=null) this.cuas_half_step=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_half_step"));
if (properties.getProperty(prefix+"cuas_max_range")!=null) this.cuas_max_range=Integer.parseInt(properties.getProperty(prefix+"cuas_max_range"));
if (properties.getProperty(prefix+"cuas_num_cycles")!=null) this.cuas_num_cycles=Integer.parseInt(properties.getProperty(prefix+"cuas_num_cycles"));
if (properties.getProperty(prefix+"cuas_speed_min")!=null) this.cuas_speed_min=Double.parseDouble(properties.getProperty(prefix+"cuas_speed_min"));
if (properties.getProperty(prefix+"cuas_speed_pref")!=null) this.cuas_speed_pref=Double.parseDouble(properties.getProperty(prefix+"cuas_speed_pref"));
......@@ -5115,6 +5133,8 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"cuas_scale2x")!=null) this.cuas_scale2x=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_scale2x"));
if (properties.getProperty(prefix+"cuas_ra_background")!=null) this.cuas_ra_background=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_ra_background"));
if (properties.getProperty(prefix+"cuas_iter_show")!=null) this.cuas_iter_show=Integer.parseInt(properties.getProperty(prefix+"cuas_iter_show"));
if (properties.getProperty(prefix+"cuas_2d_save_show")!=null) this.cuas_2d_save_show=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_2d_save_show"));
if (properties.getProperty(prefix+"cuas_intermed_low")!=null) this.cuas_intermed_low=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_intermed_low"));
if (properties.getProperty(prefix+"cuas_intermed_high")!=null) this.cuas_intermed_high=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_intermed_high"));
if (properties.getProperty(prefix+"cuas_save_mono")!=null) this.cuas_save_mono=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_save_mono"));
......@@ -5978,6 +5998,7 @@ min_str_neib_fpn 0.35
imp.cuas_corr_offset = this.cuas_corr_offset;
imp.cuas_half_step = this.cuas_half_step;
imp.cuas_max_range = this.cuas_max_range;
imp.cuas_num_cycles = this.cuas_num_cycles;
imp.cuas_speed_min = this.cuas_speed_min;
imp.cuas_speed_pref = this.cuas_speed_pref;
imp.cuas_speed_boost = this.cuas_speed_boost;
......@@ -6017,6 +6038,8 @@ min_str_neib_fpn 0.35
imp.cuas_scale2x = this.cuas_scale2x;
imp.cuas_ra_background = this.cuas_ra_background;
imp.cuas_iter_show= this.cuas_iter_show;
imp.cuas_2d_save_show = this.cuas_2d_save_show;
imp.cuas_intermed_low = this.cuas_intermed_low;
imp.cuas_intermed_high = this.cuas_intermed_high;
imp.cuas_save_mono = this.cuas_save_mono;
......
......@@ -19688,136 +19688,5 @@ public class QuadCLTCPU {
}
return;
}
/*
public static void copyJP4src(
final CLTParameters clt_parameters,
final QuadCLT [] quadCLTs,
final int [] range, // [earlies, latest]
final boolean skip_existing,
final boolean search_KML,
final int debugLevel) { // throws Exception
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(range[0]);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nScene = ai.getAndIncrement(); nScene <= range[1]; nScene = ai.getAndIncrement()) {
quadCLTs[nScene].copyJP4src(
clt_parameters, // CLTParameters clt_parameters,
skip_existing, // boolean skip_existing,
search_KML, // boolean search_KML,
debugLevel); // final int debugLevel) // throws Exception
}
}
};
}
ImageDtt.startAndJoin(threads);
return;
}
public void copyJP4src(
CLTParameters clt_parameters,
boolean skip_existing,
boolean search_KML,
final int debugLevel) // throws Exception
{
int min_dbg = 0;
String [] sourceFiles= correctionsParameters.getSourcePaths();
String set_name = getImageName();
SetChannels [] set_channels = setChannels(set_name,debugLevel); // only for specified image timestamp
ArrayList<String> path_list = new ArrayList<String>();
if (set_channels != null) for (int i = 0; i < set_channels.length; i++) {
for (int fn:set_channels[i].file_number) {
path_list.add(sourceFiles[fn]);
}
}
// For RGB/LWIR call twice (separate for each modality)
String jp4_copy_path= correctionsParameters.selectX3dDirectory(
set_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.jp4SubDir,
true, // smart,
true); //newAllowed, // save
File dir = (new File(jp4_copy_path)); // .getParentFile();
boolean already_copied = false;
if (!dir.exists()){
dir.mkdirs();
if (debugLevel >= min_dbg) System.out.println("Created "+dir);
} else if (skip_existing) {
if (dir.list().length > 0) {
already_copied = true;
}
}
// if (clt_parameters.imp.ims_use) {
// setupIMS(
// clt_parameters, // CLTParameters clt_parameters,
// skip_existing, // boolean skip_existing,
// debugLevel); // int debugLevel);
// }
if (search_KML && (set_channels !=null)) { // TODO: make it look in both MAIN and AUX. Look in only the same scene?
writeKml(
debugLevel ); // also generated with x3d model
}
if (already_copied) {
if (debugLevel >= min_dbg) System.out.println("Skipping existing directory "+dir);
return;
}
for (String fname:path_list) {
if (fname.contains(set_name)) { // only files containing set name // TODO:improve
File file = new File(fname);
try {
Files.copy(
(file).toPath(),
(new File(jp4_copy_path + Prefs.getFileSeparator()+file.getName())).toPath(),
StandardCopyOption.REPLACE_EXISTING);
if (debugLevel >= min_dbg) System.out.println("Copied "+fname+" -> "+dir);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Failed to copy "+fname+" -> "+dir);
}
}
}
if (debugLevel >= min_dbg) System.out.println("jp4_copy_path = "+jp4_copy_path);
}
@Deprecated
public void setupIMS( // not needed, restoreNoModel() and restoreFromModel call restoreIMS
CLTParameters clt_parameters,
boolean skip_existing, // for now not used
int debugLevel) {
if (!clt_parameters.imp.ims_use) {
return;
}
int min_dbg = 0;
String jp4_copy_path= correctionsParameters.selectX3dDirectory(
getImageName(), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.jp4SubDir,
true, // smart,
true); //newAllowed, // save
File dir = (new File(jp4_copy_path)); // .getParentFile();
boolean already_copied = false; // FIXME?
if (!dir.exists()){
dir.mkdirs();
if (debugLevel >= min_dbg) System.out.println("Created "+dir);
} else if (skip_existing) {
if (dir.list().length > 0) {
already_copied = true;
}
}
String ims_path = dir.getParent() + Prefs.getFileSeparator()+getImageName()+correctionsParameters.imsSuffix;
double [] saved_offset = readImsOffset(
ims_path, // String ims_path,
debugLevel); // int debugLevel)
if ((saved_offset == null) || (saved_offset[0] != clt_parameters.imp.ims_offset) || (saved_offset[1] != clt_parameters.imp.gmt_plus)) {
saveIms(
clt_parameters.imp.ims_offset,
clt_parameters.imp.gmt_plus, // double gmt_plus,
ims_path,
debugLevel);
}
}
*/
}
......@@ -522,7 +522,7 @@ public class TDCorrTile {
null, // boolean [] fpn_mask,
false, // boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
false); // boolean debug)
if (mv[2] > min_str) {
if ((mv != null) && (mv[2] > min_str)) {
vector_field[iTile] = new double [] {mv[0], mv[1], mv[2]-min_str, mv[3]};
}
}
......
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