Commit f33de0c3 authored by Andrey Filippov's avatar Andrey Filippov

Added single-scene filtering

parent 65ebce35
......@@ -182,13 +182,14 @@ public class CuasMotion {
for (int nslice = 0; nslice < fpixels.length; nslice++) {
fpixels[nslice] = (float[]) imp_sel.getStack().getPixels(nslice+1);
}
int corr_ra_step = 1;
TDCorrTile [] tdCorrTiles = cuasMotion.correlatePairs(
clt_parameters, // CLTParameters clt_parameters,
fpixels, // float [][] fpixels,
frame0, // int frame0,
frame1, // int frame1,
corr_pairs, // int frame_len,
corr_ra_step, // int corr_ra_step,
smooth, // boolean smooth, // use cosine mask
true, // batch_mode, // final boolean batch_mode,
dbg_suffix, // final String dbg_suffix, // for image_names
......@@ -269,8 +270,11 @@ public class CuasMotion {
String x3d_path = parentCLT.getX3dDirectory();
System.out.println ("Model directory = "+x3d_path);
int corr_offset = clt_parameters.imp.cuas_corr_offset;
int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
int corr_offset = clt_parameters.imp.cuas_corr_offset;
int precorr_ra = clt_parameters.imp.cuas_precorr_ra;
int corr_ra_step = clt_parameters.imp.cuas_corr_step;
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;
......@@ -310,6 +314,7 @@ public class CuasMotion {
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
boolean remove_isolated= clt_parameters.imp.cuas_isolated; // false;
double mask_width = clt_parameters.imp.cuas_mask_width; // 9;
double mask_blur = clt_parameters.imp.cuas_mask_blur; // 3;
......@@ -325,6 +330,7 @@ public class CuasMotion {
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 intermed_giga = clt_parameters.imp.cuas_intermed_giga; //false;
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;
......@@ -351,7 +357,10 @@ public class CuasMotion {
GenericJTabbedDialog gd = new GenericJTabbedDialog("Motion scan parameters");
// gd.addNumericField("Center frame", framecent, 0, 5, "frame", "Center frame");
gd.addNumericField("Number of pairs", corr_pairs, 0, 3, "", "The number of correlation pairs to accumulate.");
gd.addNumericField("Pairs offset", corr_offset, 0, 3, "", "Offset between the correlation pairs");
gd.addNumericField("Pairs offset", corr_offset, 0, 3, "scenes", "Offset between the correlation pairs");
gd.addNumericField("Pre-correlation running average", precorr_ra, 0,3,"scenes", "Smoothing input data by running average before correlation for motion vectors calculations. Target extraction wil still use individual scenes.");
gd.addNumericField("Correlation step after RA", corr_ra_step, 0,3,"scenes", "Decimate correlations after running average");
gd.addCheckbox ("Smooth weights", smooth, "Apply cosine weights when averaging a sequence of correlation pairs.");
gd.addCheckbox ("Half scan step", half_step, "Reduce step for motion detection = offset/2, if false = offset.");
gd.addNumericField("Fat zero", fat_zero, 7, 10, "", "Fat zero for TD->PD conversion");
......@@ -414,6 +423,8 @@ public class CuasMotion {
"Minimal ratio of the overshoot radius to the first 0 radius (typical 1.0).");
gd.addNumericField("Maximal overshoot ratio", lma_maxk, 5,8,"",
"Maximal ratio of the overshoot radius to the first 0 radius (typical 3.0).");
gd.addCheckbox ("Remove single-frame targets", remove_isolated,
"Remove targets that do not have neighbors before/afte.");
gd.addNumericField("Mask diameter", mask_width, 5,8,"pix",
......@@ -440,6 +451,9 @@ public class CuasMotion {
"Save intermediate vector fields and target coordinates from the LMA (80x64 layers).");
gd.addCheckbox ("Save pixel-resolution intermediate images",intermed_high,
"Save pixel-resolution accumulated images (640x512).");
gd.addCheckbox ("Save gigabyte files", intermed_giga,
"Save pixel-resolution huge files, such as hyperstack comparison.");
gd.addCheckbox ("Save monochrome targets+background", save_mono,
"Save 32-bit monochrome targets+background Tiffs (before optional scaling).");
gd.addCheckbox ("Save color targets+background", save_color,
......@@ -465,6 +479,9 @@ public class CuasMotion {
}
corr_pairs = (int) gd.getNextNumber();
corr_offset = (int) gd.getNextNumber();
precorr_ra = (int) gd.getNextNumber();
corr_ra_step = (int) gd.getNextNumber();
smooth = gd.getNextBoolean();
half_step = gd.getNextBoolean();
fat_zero = gd.getNextNumber();
......@@ -504,6 +521,7 @@ public class CuasMotion {
lma_maxr = gd.getNextNumber();
lma_mink = gd.getNextNumber();
lma_maxk = gd.getNextNumber();
remove_isolated = gd.getNextBoolean();
mask_width = gd.getNextNumber();
mask_blur = gd.getNextNumber();
......@@ -517,6 +535,7 @@ public class CuasMotion {
corr2d_save_show = gd.getNextBoolean();
intermed_low = gd.getNextBoolean();
intermed_high = gd.getNextBoolean();
intermed_giga = gd.getNextBoolean();
save_mono = gd.getNextBoolean();
save_color = gd.getNextBoolean();
save_video = gd.getNextBoolean();
......@@ -530,12 +549,13 @@ public class CuasMotion {
if (save_params) {
clt_parameters.imp.cuas_corr_offset = corr_offset;
clt_parameters.imp.cuas_corr_pairs = corr_pairs;
clt_parameters.imp.cuas_precorr_ra = precorr_ra;
clt_parameters.imp.cuas_corr_step = corr_ra_step;
clt_parameters.imp.cuas_fat_zero = fat_zero;
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;
......@@ -578,6 +598,7 @@ public class CuasMotion {
clt_parameters.imp.cuas_lma_maxr = lma_maxr;
clt_parameters.imp.cuas_lma_mink = lma_mink;
clt_parameters.imp.cuas_lma_maxk = lma_maxk;
clt_parameters.imp.cuas_isolated = remove_isolated;
clt_parameters.imp.cuas_mask_width = mask_width;
clt_parameters.imp.cuas_mask_blur = mask_blur;
clt_parameters.imp.cuas_mask_round = mask_round;
......@@ -589,6 +610,7 @@ public class CuasMotion {
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_intermed_giga =intermed_giga;
clt_parameters.imp.cuas_save_mono = save_mono;
clt_parameters.imp.cuas_save_color = save_color;
clt_parameters.imp.cuas_save_video = save_video;
......@@ -606,13 +628,15 @@ public class CuasMotion {
int first_corr = 1; // skip average
int num_scenes = imp_sel.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;
int corr_inc = half_step ? (corr_offset/2) : corr_offset;
int num_corr_samples = (num_scenes - seq_length - start_frame) / corr_inc;
if (debugLevel > -4) {
System.out.println("corr_pairs= "+corr_pairs);
System.out.println("corr_offset= "+corr_offset);
System.out.println("precorr_ra= "+precorr_ra);
System.out.println("corr_ra_step= "+corr_ra_step);
System.out.println("seq_length= "+seq_length);
System.out.println("corr_step= "+corr_step);
System.out.println("corr_inc= "+corr_inc);
System.out.println("num_scenes= "+num_scenes);
System.out.println("start_frame= "+start_frame);
System.out.println("num_corr_samples="+num_corr_samples);
......@@ -648,6 +672,7 @@ public class CuasMotion {
System.out.println("lma_maxr= "+lma_maxr);
System.out.println("lma_mink= "+lma_mink);
System.out.println("lma_maxk= "+lma_maxk);
System.out.println("remove_isolated= "+remove_isolated);
System.out.println("mask_width= "+mask_width);
System.out.println("mask_blur= "+mask_blur);
System.out.println("mask_round= "+mask_round);
......@@ -659,6 +684,7 @@ public class CuasMotion {
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("intermed_giga= "+intermed_giga);
System.out.println("save_mono= "+save_mono);
System.out.println("save_color= "+save_color);
System.out.println("save_video= "+save_video);
......@@ -671,7 +697,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
int frame_cent = start_frame + corr_inc * nscan + seq_length/2; // debug only
slice_titles[nscan] = imp_sel.getStack().getSliceLabel(frame_cent+1+first_corr); // wrong! should be imp_sel.getStack().getSliceLabel(frame_cent+1+first_corr)
}
......@@ -1564,11 +1590,12 @@ public class CuasMotion {
boolean batch_mode,
CLTParameters clt_parameters,
CuasMotion cuasMotion,
float [][] fpixels,
float [][] fpixels, // may be running average
int start_frame,
int corr_pairs,
int corr_offset,
int corr_step,
int corr_inc,
int corr_ra_step, // 5; // correlation step when using rolling average
boolean smooth,
double fat_zero,
double cent_radius,
......@@ -1580,12 +1607,12 @@ public class CuasMotion {
int seq_length = corr_offset + corr_pairs;
int num_scenes = fpixels.length;
int num_corr_samples = (num_scenes - seq_length - start_frame) / corr_step;
int num_corr_samples = (num_scenes - seq_length - start_frame) / corr_inc;
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 frame0 = start_frame + corr_inc * nscan;
int frame1 = frame0 + corr_offset;
int frame_cent = frame0 + seq_length/2; // debug only
String suffix_param = "-"+frame_cent+"-"+corr_offset+"-"+corr_pairs;
......@@ -1596,6 +1623,7 @@ public class CuasMotion {
frame0, // int frame0,
frame1, // int frame1,
corr_pairs, // int frame_len,
corr_ra_step, // int corr_ra_step,
smooth, // boolean smooth, // use cosine mask
true, // batch_mode, // final boolean batch_mode,
dbg_suffix, // final String dbg_suffix, // for image_names
......@@ -1712,14 +1740,16 @@ public class CuasMotion {
int frame0,
int frame1,
int frame_len,
int corr_ra_step,
boolean smooth, // use cosine mask
final boolean batch_mode,
final String dbg_suffix, // for image_names
int debugLevel) {
TDCorrTile [] tdCorrTiles = new TDCorrTile[tilesX * tilesY];
double sw = 0;
for (int dframe = 0; dframe < frame_len; dframe++) {
for (int dframe = corr_ra_step/2; dframe < frame_len; dframe+= corr_ra_step) {
double weight = smooth ? Math.sin((dframe+0.5)/frame_len*Math.PI): 1.0;
if (((frame0+dframe) >= 0) && ((frame1+dframe) < fpixels.length)) {
String dbg_n_suffix = (dbg_suffix != null)? (dbg_suffix+"-"+dframe) : null;
TDCorrTile [] pairTiles = correlatePair(
clt_parameters, // CLTParameters clt_parameters,
......@@ -1734,6 +1764,7 @@ public class CuasMotion {
weight); // final double src_weight)
sw+= weight;
}
}
double scale = 1.0/sw;
for (TDCorrTile tile:tdCorrTiles) if (tile !=null){
tile.scale(scale);
......@@ -2677,13 +2708,15 @@ public class CuasMotion {
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;
int precorr_ra = clt_parameters.imp.cuas_precorr_ra;
int corr_ra_step = clt_parameters.imp.cuas_corr_step;
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;
int corr_inc = half_step ? (corr_offset/2) : corr_offset;
int num_corr_samples = (fpixels.length - seq_length - start_frame) / corr_inc;
String [] slice_titles = new String [num_corr_samples];
for (int nscan = 0; nscan < num_corr_samples; nscan++) {
int frame_cent = start_frame + corr_step * nscan + seq_length/2; // debug only
int frame_cent = start_frame + corr_inc * nscan + seq_length/2; // debug only
slice_titles[nscan] = scene_titles[frame_cent];
}
......@@ -2726,6 +2759,8 @@ public class CuasMotion {
final int debugLevel) {
int corr_offset = clt_parameters.imp.cuas_corr_offset;
int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
int precorr_ra = clt_parameters.imp.cuas_precorr_ra;
int corr_ra_step = clt_parameters.imp.cuas_corr_step;
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;
......@@ -2765,11 +2800,13 @@ public class CuasMotion {
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
boolean remove_isolated= clt_parameters.imp.cuas_isolated;
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;
boolean intermed_giga = clt_parameters.imp.cuas_intermed_giga; //false;
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];
......@@ -2781,29 +2818,51 @@ public class CuasMotion {
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;
int corr_inc = half_step ? (corr_offset/2) : corr_offset;
int num_corr_samples = (num_scenes - seq_length - start_frame) / corr_inc;
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);
float [][] fpixels_ra = fpixels;
if (precorr_ra > 1) {
fpixels_ra = runningAverage(
fpixels, // final float [][] fpixels,
precorr_ra, // final int ra_length,
cuasMotion.gpu_max_width); // final int width)
if (intermed_high) {
ImagePlus imp_ra = ShowDoubleFloatArrays.makeArrays(
fpixels_ra, // float[][] pixels,
cuasMotion.gpu_max_width, // int width,
cuasMotion.gpu_max_height, // int height,
model_prefix+"-SOURCE-RA", //String title,
scene_titles); //String [] titles)
imp_ra.getProcessor().setMinAndMax(-input_range/2, input_range/2);
if (!batch_mode) {
imp_ra.show();
}
parentCLT.saveImagePlusInModelDirectory(imp_ra); // ImagePlus imp)
}
}
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,
fpixels_ra, // float [][] fpixels,
start_frame, // int start_frame,
corr_pairs, // int corr_pairs,
corr_offset, // int corr_offset,
corr_step, // int corr_step,
corr_inc, // int corr_inc,
corr_ra_step, // int corr_ra_step, // 5; // correlation step when using rolling average
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)[][]
corr2d, // double [][][] corr2d, // null or [(fpixels.length - seq_length - start_frame) / corr_inc)[][]
debugLevel); // int debugLevel) {
if (corr2d_save_show) { // may be read to re-process with vector field
......@@ -2841,9 +2900,9 @@ public class CuasMotion {
/// 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);
boolean save_filtered_low = intermed_low && (niter < iter_show);
boolean save_filtered_high = intermed_high && (niter < iter_show);
boolean save_filtered_giga = intermed_giga && (niter < iter_show);
// 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
......@@ -2944,7 +3003,7 @@ public class CuasMotion {
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_inc, // 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
......@@ -2969,13 +3028,13 @@ public class CuasMotion {
// show just fpixels_accumulated
// move outside? compare to slice_titles known
if (save_filtered_gig) { // huge file
if (save_filtered_giga) { // 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_inc, // final int frame_step,
corr_offset, // final int corr_offset, // interframe distance for correlation
true); // final boolean batch_mode) {
......@@ -2985,7 +3044,7 @@ public class CuasMotion {
}
for (int nseq = 0; nseq < fpixels_accumulated.length; nseq++){
fpixels_rendered[frame0 + nseq * corr_step] = fpixels_accumulated[nseq];
fpixels_rendered[frame0 + nseq * corr_inc] = fpixels_accumulated[nseq];
}
if (debugLevel > -4) {
System.out.println("Accumulation DONE iteration "+niter);
......@@ -3199,9 +3258,12 @@ public class CuasMotion {
final int corr_offset = clt_parameters.imp.cuas_corr_offset;
final int corr_pairs = clt_parameters.imp.cuas_corr_pairs;
final int precorr_ra = clt_parameters.imp.cuas_precorr_ra;
final int corr_ra_step = clt_parameters.imp.cuas_corr_step;
final boolean half_step = clt_parameters.imp.cuas_half_step; // true;
final boolean smooth = clt_parameters.imp.cuas_smooth; // true;
final int corr_step = half_step ? (corr_offset/2) : corr_offset;
final int corr_inc = half_step ? (corr_offset/2) : corr_offset;
final int half_accum_range = corr_pairs/2;
final double target_radius = clt_parameters.imp.cuas_target_radius;
final int n_recenter = clt_parameters.imp.cuas_n_recenter;
......@@ -3238,6 +3300,7 @@ public class CuasMotion {
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
boolean remove_isolated= clt_parameters.imp.cuas_isolated;
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;
......@@ -3245,6 +3308,8 @@ public class CuasMotion {
boolean intermed_low = clt_parameters.imp.cuas_intermed_low; //true;
boolean intermed_high = clt_parameters.imp.cuas_intermed_high; //true;
boolean intermed_giga = clt_parameters.imp.cuas_intermed_giga; //false;
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;
......@@ -3266,7 +3331,7 @@ public class CuasMotion {
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_inc, // 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
......@@ -3378,15 +3443,61 @@ public class CuasMotion {
remain);
if (debugLevel > -4) printRemain(remain, "targets_lma_combo", true);
if (intermed_low) {
/*
ImagePlus imp_filtered_combo= showVectorFieldsSequenceLMA(
targets_lma_combo, // double [][][] target_scene_sequence,
targets_vf_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,
intermed_low && !batch_mode, // boolean show,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
*/
ImagePlus imp_filtered_combo = showVectorFieldsSequence(
targets_vf_combo, // 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+"-FILTERED-COMBO", // String title,
false, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
if (intermed_low) parentCLT.saveImagePlusInModelDirectory(imp_filtered_combo); // ImagePlus imp)
parentCLT.saveImagePlusInModelDirectory(imp_filtered_combo); // ImagePlus imp)
}
if (remove_isolated) {
targets_vf_combo = filterIsolatedTargets(
targets_vf_combo, // final double [][][] all_tiles,
remain, // final int [] remain,
cuasMotion.tilesX); // final int tilesX)
// synchronize targets_lma_combo with targets_vf_combo
targets_lma_combo = filterMotionScans( // should keep LMA coordinates
targets_lma_combo, // double [][][] scan0,
targets_vf_combo, // double [][][] scan1)
null);
if (debugLevel > -4) printRemain(remain, "Remained after removing single-frame targets", true);
if (intermed_low) {
ImagePlus imp_no_singles = showVectorFieldsSequence(
targets_vf_combo, // 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+"-NOSINGLES", // String title,
false, // boolean nan_effective_strength,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles); // ImagePlus imp)
ImagePlus imp_no_singles_lma= showVectorFieldsSequenceLMA(
targets_lma_combo, // double [][][] target_scene_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix+"-NOSINGLES-LMA", // String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_no_singles_lma); // ImagePlus imp)
}
}
// create larger, 5x5 vector field for accumulation
double [][][] extended_vf_sequence = extendMotionScan(
targets_vf_combo, // final double [][][] motion_scan,
......@@ -3413,7 +3524,7 @@ public class CuasMotion {
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,
corr_inc, // 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
......@@ -3456,7 +3567,7 @@ public class CuasMotion {
targets_lma_combo, // final double [][][] target_positions,
background, // final float [][] background, // background image
frame0, // final int frame0,
corr_step, // final int frame_step,
corr_inc, // final int frame_step,
velocity_scale, // final double velocity_scale, // 1.0/(disparity in frames)
targets60hz, // final double [][][] targets60hz,
batch_mode, // final boolean batch_mode,
......@@ -3483,7 +3594,7 @@ public class CuasMotion {
replaced_targets, // final float [][] fpixels,
targets60hz, // final double [][][] targets60hz,
frame0, // final int frame0,
corr_step, // final int frame_step,
corr_inc, // final int frame_step,
cuasMotion.gpu_max_width, // final int width,
model_prefix+"-RGB"+ra_bg_suffix, // String title,
scene_titles, // String [] titles,
......@@ -3509,18 +3620,73 @@ public class CuasMotion {
}
}
public static double [][][] filterIsolatedTargets(
final double [][][] all_tiles,
final int [] remain,
final int tilesX) {
final int num_seq = all_tiles.length;
final int num_tiles = all_tiles[0].length;
final double [][][] filtered_tiles = new double [num_seq][num_tiles][];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
TileNeibs tn = new TileNeibs(tilesX, num_tiles/tilesX);
for (int nSeq = ai.getAndIncrement(); nSeq < num_seq; nSeq = ai.getAndIncrement()) {
if (remain != null) {
remain[nSeq] = 0;
}
for (int ntile = 0; ntile < num_tiles; ntile++) if (all_tiles[nSeq][ntile] != null) {
boolean has_neib = true;
look_for_neibs: {
for (int dseq = -1; dseq <= 1; dseq+=2) {
int nSeq1 = nSeq+dseq;
if ((nSeq1 >= 0) && (nSeq1 < num_seq)) {
if (all_tiles[nSeq1][ntile] != null) {
break look_for_neibs;
}
for (int dir = 0; dir < 8; dir++) {
int tile1 = tn.getNeibIndex(ntile, dir);
if ((tile1 >= 0) && (all_tiles[nSeq1][tile1] != null)) {
break look_for_neibs;
}
}
}
}
has_neib = false;
}
if (has_neib) {
filtered_tiles[nSeq][ntile] = all_tiles[nSeq][ntile]; // clone()?
if (remain != null) {
remain[nSeq]++;
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return filtered_tiles;
}
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;
int precorr_ra = clt_parameters.imp.cuas_precorr_ra;
int corr_ra_step = clt_parameters.imp.cuas_corr_step;
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;
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+"-PCRA"+precorr_ra+"-PS"+corr_ra_step;
return ps;
}
......
......@@ -706,6 +706,9 @@ min_str_neib_fpn 0.35
public boolean cuas_smooth = true; // used cosine window when averaging correlations
public int cuas_corr_pairs = 50; // number of correlation pairs to accumulate
public int cuas_corr_offset = 20; // offset between motion detection pairs
public int cuas_precorr_ra = 10; // rolling average before correlation
public int cuas_corr_step = 5; // correlation step when using rolling average
public boolean cuas_half_step = true; // 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
......@@ -745,6 +748,9 @@ min_str_neib_fpn 0.35
public double cuas_lma_mink = 0.0; // Minimal K (overshoot) = 0.0 (<0.007)
public double cuas_lma_maxk = 5.0; // Maximal K (overshoot) = 5.0 (>3.8)
public boolean cuas_isolated = true; // remove targets that do not have neighbors before/after
public double cuas_mask_width = 9;
public double cuas_mask_blur = 3;
public boolean cuas_mask_round = true;
......@@ -761,6 +767,7 @@ min_str_neib_fpn 0.35
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_intermed_giga = false;// save huge (gigabyte) intermediate files
public boolean cuas_save_mono = true; // save 32-bit monochrome target+backgrounds Tiffs (before optional scaling)
public boolean cuas_save_color = true; // save color rendered images (same as videos)
public boolean cuas_save_video = true; // save color rendered images (same as videos)
......@@ -2186,8 +2193,13 @@ min_str_neib_fpn 0.35
"Apply cosine weights when averaging a sequence of correlation pairs.");
gd.addNumericField("Number of pairs", this.cuas_corr_pairs, 0,3,"",
"The number of correlation pairs to accumulate.");
gd.addNumericField("Pairs offset", this.cuas_corr_offset, 0,3,"",
gd.addNumericField("Pairs offset", this.cuas_corr_offset, 0,3,"scenes",
"Offset between the correlation pairs");
gd.addNumericField("Pre-correlation running average", this.cuas_precorr_ra, 0,3,"scenes",
"Smoothing input data by running average before correlation for motion vectors calculations. Target extraction wil still use individual scenes.");
gd.addNumericField("Correlation step after RA", this.cuas_corr_step, 0,3,"scenes",
"Decimate correlations after running average");
gd.addCheckbox ("Half scan step", this.cuas_half_step,
"Reduce step for motion detection = offset/2, if false = offset.");
gd.addNumericField("Local max range", this.cuas_max_range, 0,3,"",
......@@ -2264,6 +2276,10 @@ min_str_neib_fpn 0.35
gd.addNumericField("Maximal overshoot ratio", this.cuas_lma_maxk, 5,8,"",
"Maximal ratio of the overshoot radius to the first 0 radius (typical 3.0).");
gd.addCheckbox ("Remove single-frame targets", this.cuas_isolated,
"Remove targets that do not have neighbors before/afte.");
gd.addMessage("=== Targets video generation (see also Vidoe/Stereo tab) ===");
......@@ -2296,6 +2312,9 @@ min_str_neib_fpn 0.35
"Save intermediate vector fields and target coordinates from the LMA (80x64 layers).");
gd.addCheckbox ("Save pixel-resolution intermediate images",this.cuas_intermed_high,
"Save pixel-resolution accumulated images (640x512).");
gd.addCheckbox ("Save gigabyte files", this.cuas_intermed_giga,
"Save pixel-resolution huge files, such as hyperstack comparison.");
gd.addCheckbox ("Save monochrome targets+background", this.cuas_save_mono,
"Save 32-bit monochrome targets+background Tiffs (before optional scaling).");
gd.addCheckbox ("Save color targets+background", this.cuas_save_color,
......@@ -3259,6 +3278,10 @@ min_str_neib_fpn 0.35
this.cuas_smooth = gd.getNextBoolean();
this.cuas_corr_pairs = (int) gd.getNextNumber();
this.cuas_corr_offset = (int) gd.getNextNumber();
this.cuas_precorr_ra = (int) gd.getNextNumber();
this.cuas_corr_step = (int) gd.getNextNumber();
this.cuas_half_step = gd.getNextBoolean();
this.cuas_max_range = (int) gd.getNextNumber();
this.cuas_num_cycles = (int) gd.getNextNumber();
......@@ -3294,6 +3317,8 @@ min_str_neib_fpn 0.35
this.cuas_lma_mink = gd.getNextNumber();
this.cuas_lma_maxk = gd.getNextNumber();
this.cuas_isolated = gd.getNextBoolean();
this.cuas_mask_width = gd.getNextNumber();
this.cuas_mask_blur = gd.getNextNumber();
this.cuas_mask_round = gd.getNextBoolean();
......@@ -3307,6 +3332,7 @@ min_str_neib_fpn 0.35
this.cuas_2d_save_show = gd.getNextBoolean();
this.cuas_intermed_low = gd.getNextBoolean();
this.cuas_intermed_high = gd.getNextBoolean();
this.cuas_intermed_giga = gd.getNextBoolean();
this.cuas_save_mono = gd.getNextBoolean();
this.cuas_save_color = gd.getNextBoolean();
this.cuas_save_video = gd.getNextBoolean();
......@@ -4193,6 +4219,10 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"cuas_smooth", this.cuas_smooth+""); // boolean
properties.setProperty(prefix+"cuas_corr_pairs", this.cuas_corr_pairs+""); // int
properties.setProperty(prefix+"cuas_corr_offset", this.cuas_corr_offset+""); // int
properties.setProperty(prefix+"cuas_precorr_ra", this.cuas_precorr_ra+""); // int
properties.setProperty(prefix+"cuas_corr_step", this.cuas_corr_step+""); // 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
......@@ -4228,6 +4258,8 @@ min_str_neib_fpn 0.35
properties.setProperty(prefix+"cuas_lma_mink", this.cuas_lma_mink+""); // double
properties.setProperty(prefix+"cuas_lma_maxk", this.cuas_lma_maxk+""); // double
properties.setProperty(prefix+"cuas_isolated", this.cuas_isolated+""); // boolean
properties.setProperty(prefix+"cuas_mask_width", this.cuas_mask_width+""); // double
properties.setProperty(prefix+"cuas_mask_blur", this.cuas_mask_blur+""); // double
properties.setProperty(prefix+"cuas_mask_round", this.cuas_mask_round+""); // boolean
......@@ -4241,6 +4273,7 @@ min_str_neib_fpn 0.35
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_intermed_giga", this.cuas_intermed_giga+""); // boolean
properties.setProperty(prefix+"cuas_save_mono", this.cuas_save_mono+""); // boolean
properties.setProperty(prefix+"cuas_save_color", this.cuas_save_color+""); // boolean
properties.setProperty(prefix+"cuas_save_video", this.cuas_save_video+""); // boolean
......@@ -5099,6 +5132,10 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"cuas_smooth")!=null) this.cuas_smooth=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_smooth"));
if (properties.getProperty(prefix+"cuas_corr_pairs")!=null) this.cuas_corr_pairs=Integer.parseInt(properties.getProperty(prefix+"cuas_corr_pairs"));
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_precorr_ra")!=null) this.cuas_precorr_ra=Integer.parseInt(properties.getProperty(prefix+"cuas_precorr_ra"));
if (properties.getProperty(prefix+"cuas_corr_step")!=null) this.cuas_corr_step=Integer.parseInt(properties.getProperty(prefix+"cuas_corr_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_num_cycles")!=null) this.cuas_num_cycles=Integer.parseInt(properties.getProperty(prefix+"cuas_num_cycles"));
......@@ -5135,6 +5172,8 @@ min_str_neib_fpn 0.35
if (properties.getProperty(prefix+"cuas_lma_mink")!=null) this.cuas_lma_mink=Double.parseDouble(properties.getProperty(prefix+"cuas_lma_mink"));
if (properties.getProperty(prefix+"cuas_lma_maxk")!=null) this.cuas_lma_maxk=Double.parseDouble(properties.getProperty(prefix+"cuas_lma_maxk"));
if (properties.getProperty(prefix+"cuas_isolated")!=null) this.cuas_isolated=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_isolated"));
if (properties.getProperty(prefix+"cuas_mask_width")!=null) this.cuas_mask_width=Double.parseDouble(properties.getProperty(prefix+"cuas_mask_width"));
if (properties.getProperty(prefix+"cuas_mask_blur")!=null) this.cuas_mask_blur=Double.parseDouble(properties.getProperty(prefix+"cuas_mask_blur"));
if (properties.getProperty(prefix+"cuas_mask_round")!=null) this.cuas_mask_round=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_mask_round"));
......@@ -5148,6 +5187,7 @@ min_str_neib_fpn 0.35
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_intermed_giga")!=null) this.cuas_intermed_giga=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_intermed_giga"));
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_color")!=null) this.cuas_save_color=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_save_color"));
if (properties.getProperty(prefix+"cuas_save_video")!=null) this.cuas_save_video=Boolean.parseBoolean(properties.getProperty(prefix+"cuas_save_video"));
......@@ -6007,6 +6047,8 @@ min_str_neib_fpn 0.35
imp.cuas_smooth = this.cuas_smooth;
imp.cuas_corr_pairs = this.cuas_corr_pairs;
imp.cuas_corr_offset = this.cuas_corr_offset;
imp.cuas_precorr_ra = this.cuas_precorr_ra;
imp.cuas_corr_step = this.cuas_corr_step;
imp.cuas_half_step = this.cuas_half_step;
imp.cuas_max_range = this.cuas_max_range;
imp.cuas_num_cycles = this.cuas_num_cycles;
......@@ -6041,6 +6083,8 @@ min_str_neib_fpn 0.35
imp.cuas_lma_mink = this.cuas_lma_mink;
imp.cuas_lma_maxk = this.cuas_lma_maxk;
imp.cuas_isolated = this.cuas_isolated;
imp.cuas_mask_width = this.cuas_mask_width;
imp.cuas_mask_blur = this.cuas_mask_blur;
imp.cuas_mask_round = this.cuas_mask_round;
......@@ -6054,6 +6098,7 @@ min_str_neib_fpn 0.35
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_intermed_giga = this.cuas_intermed_giga;
imp.cuas_save_mono = this.cuas_save_mono;
imp.cuas_save_color = this.cuas_save_color;
imp.cuas_save_video = this.cuas_save_video;
......
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