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

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

parent dafb1ad3
...@@ -2442,6 +2442,9 @@ public class Correlation2d { ...@@ -2442,6 +2442,9 @@ public class Correlation2d {
} }
} }
double mx = data[imax]; double mx = data[imax];
if (mx < 0) {
return null; //negative maximum
}
int ix0 = imax % data_width; int ix0 = imax % data_width;
int iy0 = imax / data_width; int iy0 = imax / data_width;
if (exclude_margins) { if (exclude_margins) {
...@@ -2523,6 +2526,9 @@ public class Correlation2d { ...@@ -2523,6 +2526,9 @@ public class Correlation2d {
x0 += sx / s0; x0 += sx / s0;
y0 += sy / s0; y0 += sy / s0;
frac = s0 / (s0 + s_other); frac = s0 / (s0 + s_other);
if (Double.isNaN(s0)) {
return null; // all negative
}
} }
} }
if (calc_fraction) { if (calc_fraction) {
...@@ -2530,12 +2536,18 @@ public class Correlation2d { ...@@ -2530,12 +2536,18 @@ public class Correlation2d {
if (debug){ if (debug){
System.out.println("getMaxXYCm() -> "+rslt[0]+":"+rslt[1] +" ("+rslt[2]+"), frac = " + rslt[3]); 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; return rslt;
} else { } else {
double [] rslt = {x0 - center_xy, y0 - center_xy, mx}; double [] rslt = {x0 - center_xy, y0 - center_xy, mx};
if (debug){ if (debug){
System.out.println("getMaxXYCm() -> "+rslt[0]+":"+rslt[1] +" ("+rslt[2]+")"); 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; return rslt;
} }
} }
......
...@@ -708,6 +708,8 @@ min_str_neib_fpn 0.35 ...@@ -708,6 +708,8 @@ min_str_neib_fpn 0.35
public int cuas_corr_offset = 20; // offset between motion detection pairs 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 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_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 // boosting weight of moving targets
public double cuas_speed_min = 0.2; // minimal pixels per range (per cuas_corr_offset) 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) public double cuas_speed_pref = 0.5; // preferable speed (boost weights for faster targets)
...@@ -753,6 +755,8 @@ min_str_neib_fpn 0.35 ...@@ -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 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: // 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_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_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) 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 ...@@ -2183,6 +2187,8 @@ min_str_neib_fpn 0.35
"Reduce step for motion detection = offset/2, if false = offset."); "Reduce step for motion detection = offset/2, if false = offset.");
gd.addNumericField("Local max range", this.cuas_max_range, 0,3,"", gd.addNumericField("Local max range", this.cuas_max_range, 0,3,"",
"While filtering local correlation maximums: 1 - 3x3 neighbors, 2 - 5x5 ones."); "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.addMessage("=== Moving target filtering ===");
gd.addNumericField("Minimal speed", this.cuas_speed_min, 5,8,"ppr", gd.addNumericField("Minimal speed", this.cuas_speed_min, 5,8,"ppr",
...@@ -2260,7 +2266,7 @@ min_str_neib_fpn 0.35 ...@@ -2260,7 +2266,7 @@ min_str_neib_fpn 0.35
"Taget mask to replace static background with moving target."); "Taget mask to replace static background with moving target.");
gd.addNumericField("Mask transition width", this.cuas_mask_blur, 5,8,"pix", gd.addNumericField("Mask transition width", this.cuas_mask_blur, 5,8,"pix",
"Transition between opaque and transparent mask."); "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."); "Use round mask. Unchesked - use sharp square mask without any transition.");
gd.addNumericField("Targets icon type", this.cuas_target_type, 0,3,"", gd.addNumericField("Targets icon type", this.cuas_target_type, 0,3,"",
...@@ -2274,6 +2280,10 @@ min_str_neib_fpn 0.35 ...@@ -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."); "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", 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, gd.addCheckbox ("Save tile-resolution intermediate images", this.cuas_intermed_low,
"Save intermediate vector fields and target coordinates from the LMA (80x64 layers)."); "Save intermediate vector fields and target coordinates from the LMA (80x64 layers).");
gd.addCheckbox ("Save pixel-resolution intermediate images",this.cuas_intermed_high, gd.addCheckbox ("Save pixel-resolution intermediate images",this.cuas_intermed_high,
...@@ -3243,6 +3253,8 @@ min_str_neib_fpn 0.35 ...@@ -3243,6 +3253,8 @@ min_str_neib_fpn 0.35
this.cuas_corr_offset = (int) gd.getNextNumber(); this.cuas_corr_offset = (int) gd.getNextNumber();
this.cuas_half_step = gd.getNextBoolean(); this.cuas_half_step = gd.getNextBoolean();
this.cuas_max_range = (int) gd.getNextNumber(); this.cuas_max_range = (int) gd.getNextNumber();
this.cuas_num_cycles = (int) gd.getNextNumber();
this.cuas_speed_min = gd.getNextNumber(); this.cuas_speed_min = gd.getNextNumber();
this.cuas_speed_pref = gd.getNextNumber(); this.cuas_speed_pref = gd.getNextNumber();
this.cuas_speed_boost = gd.getNextNumber(); this.cuas_speed_boost = gd.getNextNumber();
...@@ -3282,6 +3294,8 @@ min_str_neib_fpn 0.35 ...@@ -3282,6 +3294,8 @@ min_str_neib_fpn 0.35
this.cuas_scale2x = gd.getNextBoolean(); this.cuas_scale2x = gd.getNextBoolean();
this.cuas_ra_background = 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_low = gd.getNextBoolean();
this.cuas_intermed_high = gd.getNextBoolean(); this.cuas_intermed_high = gd.getNextBoolean();
this.cuas_save_mono = gd.getNextBoolean(); this.cuas_save_mono = gd.getNextBoolean();
...@@ -4172,6 +4186,7 @@ min_str_neib_fpn 0.35 ...@@ -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_corr_offset", this.cuas_corr_offset+""); // int
properties.setProperty(prefix+"cuas_half_step", this.cuas_half_step+""); // boolean 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_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_min", this.cuas_speed_min+""); // double
properties.setProperty(prefix+"cuas_speed_pref", this.cuas_speed_pref+""); // double properties.setProperty(prefix+"cuas_speed_pref", this.cuas_speed_pref+""); // double
...@@ -4212,6 +4227,8 @@ min_str_neib_fpn 0.35 ...@@ -4212,6 +4227,8 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"cuas_scale2x", this.cuas_scale2x+""); // boolean properties.setProperty(prefix+"cuas_scale2x", this.cuas_scale2x+""); // boolean
properties.setProperty(prefix+"cuas_ra_background", this.cuas_ra_background+""); // 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_low", this.cuas_intermed_low+""); // boolean
properties.setProperty(prefix+"cuas_intermed_high", this.cuas_intermed_high+""); // boolean properties.setProperty(prefix+"cuas_intermed_high", this.cuas_intermed_high+""); // boolean
properties.setProperty(prefix+"cuas_save_mono", this.cuas_save_mono+""); // boolean properties.setProperty(prefix+"cuas_save_mono", this.cuas_save_mono+""); // boolean
...@@ -5074,6 +5091,7 @@ min_str_neib_fpn 0.35 ...@@ -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_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_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_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_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")); 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 ...@@ -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_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_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_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_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")); 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 ...@@ -5978,6 +5998,7 @@ min_str_neib_fpn 0.35
imp.cuas_corr_offset = this.cuas_corr_offset; imp.cuas_corr_offset = this.cuas_corr_offset;
imp.cuas_half_step = this.cuas_half_step; imp.cuas_half_step = this.cuas_half_step;
imp.cuas_max_range = this.cuas_max_range; 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_min = this.cuas_speed_min;
imp.cuas_speed_pref = this.cuas_speed_pref; imp.cuas_speed_pref = this.cuas_speed_pref;
imp.cuas_speed_boost = this.cuas_speed_boost; imp.cuas_speed_boost = this.cuas_speed_boost;
...@@ -6017,6 +6038,8 @@ min_str_neib_fpn 0.35 ...@@ -6017,6 +6038,8 @@ min_str_neib_fpn 0.35
imp.cuas_scale2x = this.cuas_scale2x; imp.cuas_scale2x = this.cuas_scale2x;
imp.cuas_ra_background = this.cuas_ra_background; 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_low = this.cuas_intermed_low;
imp.cuas_intermed_high = this.cuas_intermed_high; imp.cuas_intermed_high = this.cuas_intermed_high;
imp.cuas_save_mono = this.cuas_save_mono; imp.cuas_save_mono = this.cuas_save_mono;
......
...@@ -19688,136 +19688,5 @@ public class QuadCLTCPU { ...@@ -19688,136 +19688,5 @@ public class QuadCLTCPU {
} }
return; 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 { ...@@ -522,7 +522,7 @@ public class TDCorrTile {
null, // boolean [] fpn_mask, null, // boolean [] fpn_mask,
false, // boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask false, // boolean ignore_border, // only if fpn_mask != null - ignore tile if maximum touches fpn_mask
false); // boolean debug) 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]}; 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