Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imagej-elphel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
imagej-elphel
Commits
b7ce93be
Commit
b7ce93be
authored
May 31, 2026
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made refineMotionVectors work with fast targets
parent
b691e9f3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
149 additions
and
80 deletions
+149
-80
CuasMotion.java
src/main/java/com/elphel/imagej/cuas/CuasMotion.java
+147
-78
CuasMotionLMA.java
src/main/java/com/elphel/imagej/cuas/CuasMotionLMA.java
+2
-2
No files found.
src/main/java/com/elphel/imagej/cuas/CuasMotion.java
View file @
b7ce93be
...
...
@@ -239,6 +239,10 @@ public class CuasMotion {
public
static
final
int
ANLZ_GE
=
4
;
// list tiles with targets with parameter >= value (such as AMPLITUDE >= 1.0)
public
static
final
int
ANLZ_LE
=
5
;
// list tiles with targets with parameter <= value (such as RMSE <= 0.5)
public
static
final
int
WHEN_PHASE1
=
0
;
// phase 1 RSLT_WHEN start
public
static
final
int
WHEN_PHASE2
=
100
;
// phase 2 RSLT_WHEN start
public
static
final
int
WHEN_FINISH
=
200
;
// RSLT_WHEN start after phase 2
public
int
when_fail
=
0
;
// will maintain (increment) and use for "RSLT_WHEN" when setting RSLT_FAIL
public
static
void
setCuasAnnots
(
String
annot
,
...
...
@@ -804,7 +808,7 @@ public class CuasMotion {
}
/**
* Trying to fix centered mode probably broken when switching to multi-varian targets.
* Trying to fix centered mode probably broken when switching to multi-varian
t
targets.
* It uses data from the selected target variant, including RSLT_X, RSLT_Y data
* @param target_sequence_multi
* @param filter5
...
...
@@ -2013,7 +2017,10 @@ public class CuasMotion {
final
double
[][][]
extended
=
new
double
[
num_seq
][
num_tiles
][];
final
Thread
[]
threads
=
ImageDtt
.
newThreadArray
();
final
AtomicInteger
ai
=
new
AtomicInteger
(
0
);
final
int
dbg_nseq
=
26
;
// 125; // 100; // 161; // 36; // 28; // 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1;
final
int
dbg_tile
=
19
+
34
*
80
;
// 15+33*80; // 12+37*80; //55+38*80; // 51+38*80; // 54+38*80; //52+38*80; // 50+38*80; // 55+38*80; // -(17 + 33*80); // 48+32*80; // 50+38*80; // -1;
for
(
int
irange
=
range
;
irange
>
0
;
irange
--)
{
// to try 5x5, but make sure 3x3 are always as needed
final
int
firange
=
irange
;
ai
.
set
(
0
);
final
int
frange
=
irange
;
for
(
int
ithread
=
0
;
ithread
<
threads
.
length
;
ithread
++)
{
...
...
@@ -2025,13 +2032,15 @@ public class CuasMotion {
double
[][]
ms
=
motion_scan
[
nSeq
];
boolean
has_filter
=
(
filtered
!=
null
)
&&
(
filtered
[
nSeq
]
!=
null
);
boolean
[]
centers
=
has_filter
?
filtered
[
nSeq
]
:
new
boolean
[
ms
.
length
];
if
(
nSeq
==
dbg_nseq
)
{
System
.
out
.
println
(
"extendMotionScan(): nSeq="
+
nSeq
+
" irange="
+
firange
+
" has_filter="
+
has_filter
);
}
if
(!
has_filter
)
{
for
(
int
i
=
0
;
i
<
centers
.
length
;
i
++)
{
centers
[
i
]
=
(
ms
[
i
]
!=
null
)
&&
Double
.
isNaN
(
ms
[
i
][
CuasMotionLMA
.
RSLT_STRONGER
])
&&
// should not have stronger neighbor
(
Double
.
isNaN
(
ms
[
i
][
CuasMotionLMA
.
RSLT_FAIL
])
||
(
ms
[
i
][
CuasMotionLMA
.
RSLT_FAIL
]==
CuasMotionLMA
.
FAIL_NONE
)
||
(
ms
[
i
][
CuasMotionLMA
.
RSLT_FAIL
]==
CuasMotionLMA
.
FAIL_PENDING
));
// By Claude on 05/07/2026
(
ms
[
i
][
CuasMotionLMA
.
RSLT_FAIL
]==
CuasMotionLMA
.
FAIL_NONE
));
}
}
if
((
filtered
!=
null
)
&&
(
filtered
[
nSeq
]
==
null
))
{
...
...
@@ -2040,6 +2049,9 @@ public class CuasMotion {
for
(
int
tileY
=
0
;
tileY
<
tilesY
;
tileY
++)
{
for
(
int
tileX
=
0
;
tileX
<
tilesX
;
tileX
++)
{
int
ntile
=
tileX
+
tilesX
*
tileY
;
if
((
nSeq
==
dbg_nseq
)
&&
(
ntile
==
dbg_tile
))
{
System
.
out
.
println
(
"extendMotionScan(): nSeq="
+
nSeq
+
" irange="
+
firange
+
" ntile="
+
ntile
);
}
if
(
centers
[
ntile
])
{
num
++;
double
[]
mv
=
motion_scan
[
nSeq
][
ntile
];
...
...
@@ -2231,8 +2243,8 @@ public class CuasMotion {
final
int
corr_offset_eff
=
corr_offset
*
Math
.
max
(
1
,
Math
.
min
(
corr_offset_scale
,
corr_pairs_ref
/
corr_offset
));
// Hard-coded debug selectors: set >= 0 to enable per-scan/per-tile visualisation
final
int
dbg_nseq
=
125
;
// 100; // 161; // 36; // 28; // 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1;
final
int
dbg_tile
=
15
+
33
*
80
;
// 12+37*80; //55+38*80; // 51+38*80; // 54+38*80; //52+38*80; // 50+38*80; // 55+38*80; // -(17 + 33*80); // 48+32*80; // 50+38*80; // -1;
final
int
dbg_nseq
=
26
;
//
125; // 100; // 161; // 36; // 28; // 97; // 40; // 41; // 157; // -(116); // 57; // 20; // -1;
final
int
dbg_tile
=
1
9
+
34
*
80
;
// 1
5+33*80; // 12+37*80; //55+38*80; // 51+38*80; // 54+38*80; //52+38*80; // 50+38*80; // 55+38*80; // -(17 + 33*80); // 48+32*80; // 50+38*80; // -1;
final
int
corr_offset_scale_eff
=
corr_offset_eff
/
corr_offset
;
// actual scale after clamping
if
((
dbg_nseq
<
0
)
||
(
dbg_nseq
>=
targets_nonoverlap
.
length
)
||
(
dbg_tile
<
0
)
||
(
dbg_tile
>=
targets_nonoverlap
[
dbg_nseq
].
length
))
{
debugLevel
=
-
2
;
...
...
@@ -2248,6 +2260,8 @@ public class CuasMotion {
if
(
debugLevel
>=
0
)
{
System
.
out
.
println
(
"\nrefineMotionVectors(): dbg_iter_index="
+
dbg_iter_index
+
", corr_offset="
+
corr_offset
+
", corr_offset_scale="
+
corr_offset_scale
+
", corr_offset_eff="
+
corr_offset_eff
+
", recalc_mv_boost="
+
recalc_mv_boost
+
", corr_pairs_ref="
+
corr_pairs_ref
+
(
corr_offset_scale_eff
!=
corr_offset_scale
?
" (CLAMPED from "
+
corr_offset_scale
+
" to "
+
corr_offset_scale_eff
+
")"
:
""
)+
", dbg_nseq="
+
dbg_nseq
+
", dbg_tile="
+
dbg_tile
);
}
...
...
@@ -6624,7 +6638,8 @@ public class CuasMotion {
*/
public
static
int
[]
removeWeakerDuplicates
(
// needs sortMultiTargets before (assuming earlier - stronger) and after (to remove null)
final
double
[][][][]
target_multi
,
final
double
pix_tolerance
)
{
final
double
pix_tolerance
,
final
int
when_fail
)
{
final
double
pix_tolerance2
=
pix_tolerance
*
pix_tolerance
;
final
int
num_seq
=
target_multi
.
length
;
final
int
num_tiles
=
target_multi
[
0
].
length
;
...
...
@@ -6649,15 +6664,11 @@ public class CuasMotion {
double
dty
=
ty2
-
ty1
;
double
dt2
=
dtx
*
dtx
+
dty
*
dty
;
if
(
dt2
<
pix_tolerance2
)
{
// indx2 is a duplicate, remove its reference from the list
/*
if ((targets[indx2][CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE) &&
(targets[indx2][CuasMotionLMA.RSLT_FAIL] == CuasMotionLMA.FAIL_NONE)) {
adup_good.getAndIncrement();
}
*/
// FAIL_NONE for both is now tested above
adup_good
.
getAndIncrement
();
targets
[
indx2
]
=
null
;
// targets[indx2] = null;
targets
[
indx2
][
CuasMotionLMA
.
RSLT_FAIL
]
=
CuasMotionLMA
.
FAIL_DUPLICATE
;
targets
[
indx2
][
CuasMotionLMA
.
RSLT_WHEN
]
=
when_fail
;
adup
.
getAndIncrement
();
break
;
// for (int indx1 = 0; indx1 < indx2; indx1++) if (targets[indx1] != null){
}
...
...
@@ -8117,7 +8128,7 @@ public class CuasMotion {
int
[]
totals
=
null
;
int
[]
passes
=
new
int
[
num_corr_samples
];
// debugging filter5
String
model_prefix
=
parentCLT
.
getImageName
()+
getParametersSuffix
(
clt_parameters
,
null
)+(
cuasMotion
.
slow_targets
?
"-SLOW"
:
"-FAST"
);
cuasMotion
.
when_fail
=
CuasMotion
.
WHEN_PHASE1
;
if
(
clt_parameters
.
imp
.
cuas_reuse_centered
)
{
// By Claude on 05/24/2026
String
x3d_path
=
parentCLT
.
getX3dDirectory
();
String
centered_path
=
x3d_path
+
Prefs
.
getFileSeparator
()
+
model_prefix
+
"-ROUND_TWO_GOOD"
+
".tiff"
;
...
...
@@ -8134,7 +8145,8 @@ public class CuasMotion {
// final double [][][][] target_sequence_multi = null;
double
[][][][]
target_sequence_multi
=
null
;
int
niter
=
0
;
// maybe start from 19 to match skipped non-center and have the same file names
// int niter=0; // maybe start from 19 to match skipped non-center and have the same file names
cuasMotion
.
when_fail
=
CuasMotion
.
WHEN_PHASE1
;
if
(
reuse_non_centered
)
{
String
x3d_path
=
parentCLT
.
getX3dDirectory
();
String
noncentered_path
=
x3d_path
+
Prefs
.
getFileSeparator
()
+
model_prefix
+
"-ROUND_ONE"
+
".tiff"
;
...
...
@@ -8174,7 +8186,7 @@ public class CuasMotion {
// Calculate and set motion vectors strengths/failures
setEffectiveStrengthMV
(
// calculate tiles effective strength by the motion vectors. Combine with the target LMA?
target_sequence_multi
,
// final double [][][] motion_scan,
niter
,
// int niter, // save iteration number on failure if >=
cuasMotion
.
when_fail
,
// int niter, // save iteration number on failure if >=
cuasMotion
.
tilesX
,
// final int tilesX)
// Let them fail here and not be considered at all
min_score_mv
,
// 0, // final double min_score_mv,
...
...
@@ -8183,9 +8195,10 @@ public class CuasMotion {
speed_boost
);
// double speed_boost);
// first pass, using non-centered targets
for
(;
niter
<
num_cycles
;
niter
++)
{
boolean
save_filtered_low
=
intermed_low
&&
(
niter
<
iter_show
);
boolean
save_filtered_high
=
intermed_high
&&
(
niter
<
iter_show
);
for
(
int
it_indx
=
0
;
it_indx
<
num_cycles
;
it_indx
++)
{
// local iteration index for WHEN
cuasMotion
.
when_fail
=
CuasMotion
.
WHEN_PHASE1
+
it_indx
;
boolean
save_filtered_low
=
intermed_low
&&
(
it_indx
<
iter_show
);
boolean
save_filtered_high
=
intermed_high
&&
(
it_indx
<
iter_show
);
totals
=
getRemain
(
target_sequence_multi
,
// final double [][][][] target_sequence_multi,
num_all
,
// int [] num_all_in,
...
...
@@ -8206,18 +8219,19 @@ public class CuasMotion {
if
(
debugLevel
>
-
4
)
System
.
out
.
println
(
"No undefined tiles left, breaking loop"
);
break
;
}
if
(
save_filtered_low
&&
debug_more
)
{
ImagePlus
imp_ms1
=
showTargetSequence
(
motion_sequence
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-MS1-n"
+
niter
,
// String title,
model_prefix
+
"-MS1-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_ms1
);
}
if
(
save_filtered_low
&&
debug_more
)
{
String
title
=
model_prefix
+
"-PRE-SELECT-n"
+
niter
;
String
title
=
model_prefix
+
"-PRE-SELECT-n"
+
cuasMotion
.
when_fail
;
ImagePlus
imp_pre_select
=
showTargetSequence
(
target_sequence_multi
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
...
...
@@ -8251,7 +8265,7 @@ public class CuasMotion {
filter5
,
cuasMotion
.
tilesX
,
cuasMotion
.
tilesY
,
model_prefix
+
"-FILTER5_SELECTED_MULTI-n"
+
niter
,
// Selected to test
model_prefix
+
"-FILTER5_SELECTED_MULTI-n"
+
cuasMotion
.
when_fail
,
// Selected to test
slice_titles
);
if
(!
batch_mode
)
{
imp_filter5
.
show
();
...
...
@@ -8283,7 +8297,7 @@ public class CuasMotion {
ImagePlus
imp_novl
=
showTargetSequence
(
targets_nonoverlap
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-SELECTED-TO-TRY-n"
+
niter
,
// String title,
model_prefix
+
"-SELECTED-TO-TRY-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_novl
);
...
...
@@ -8291,7 +8305,7 @@ public class CuasMotion {
ImagePlus
imp_ext
=
showTargetSequence
(
extended_scan
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-EXTENDED-n"
+
niter
,
// String title,
model_prefix
+
"-EXTENDED-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_ext
);
...
...
@@ -8320,7 +8334,7 @@ public class CuasMotion {
corr_offset
,
// int corr_offset, // interframe distance for correlation
save_filtered_high
,
// boolean save_filtered_high,
model_prefix
,
// String model_prefix,
niter
,
// int niter,
cuasMotion
.
when_fail
,
// int niter,
input_range
,
// double input_range,
lmax_fraction
,
// double lmax_fraction,
...
...
@@ -8392,14 +8406,14 @@ public class CuasMotion {
target_sequence_multi
,
// final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi
,
// final double [][][] new_sequence,
0
,
// final int num_best, // if >0, limit number of best results to add
niter
,
// final int when_iter,
cuasMotion
.
when_fail
,
// final int when_iter,
debugLevel
);
// final int debugLevel);
if
(
debugLevel
>
-
4
)
{
System
.
out
.
println
(
"Added "
+
num_new
+
" new tiles as good/bad with BOOST="
+
boost_accum_pairs
);
}
if
(
save_filtered_low
)
{
String
title
=
model_prefix
+
"-ADDED_NEW_MULTI-n"
+
niter
;
String
title
=
model_prefix
+
"-ADDED_NEW_MULTI-n"
+
cuasMotion
.
when_fail
;
if
(
boost_accum_pairs
>
1.0
)
{
title
+=
"-BOOST"
+
boost_accum_pairs
;
}
...
...
@@ -8434,7 +8448,7 @@ public class CuasMotion {
corr_offset
,
// int corr_offset, // interframe distance for correlation
save_filtered_high
,
// boolean save_filtered_high,
model_prefix
,
// String model_prefix,
niter
,
// int niter,
cuasMotion
.
when_fail
,
// int niter,
input_range
,
// double input_range,
lmax_fraction
,
// double lmax_fraction,
...
...
@@ -8506,14 +8520,14 @@ public class CuasMotion {
target_sequence_multi
,
// final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi
,
// final double [][][] new_sequence,
0
,
// final int num_best, // if >0, limit number of best results to add
niter
,
// final int when_iter,
cuasMotion
.
when_fail
,
// final int when_iter,
debugLevel
);
// final int debugLevel);
if
(
debugLevel
>
-
4
)
{
System
.
out
.
println
(
"Added "
+
num_new
+
" new tiles as good/bad, base (no boost mode)"
);
}
if
(
save_filtered_low
)
{
String
title
=
model_prefix
+
"-ADDED_NEW_MULTI-n"
+
niter
;
String
title
=
model_prefix
+
"-ADDED_NEW_MULTI-n"
+
cuasMotion
.
when_fail
;
ImagePlus
imp_new_scores
=
showTargetSequence
(
target_sequence_multi
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
...
...
@@ -8538,9 +8552,9 @@ public class CuasMotion {
null
,
// int [] num_noncentered_in,
num_good
,
// int [] num_good_in,
num_bad
);
// int [] num_bad_in)
if
(
debugLevel
>
-
4
)
printStats
(
"After iteration "
+
niter
,
true
,
num_all
,
num_undef
,
num_good
,
num_bad
);
if
(
debugLevel
>
-
4
)
printStats
(
"After iteration "
+
cuasMotion
.
when_fail
,
true
,
num_all
,
num_undef
,
num_good
,
num_bad
);
if
(
debugLevel
>
-
4
)
{
System
.
out
.
println
(
"Non-centered iteration "
+
niter
+
" DONE.\n"
);
System
.
out
.
println
(
"Non-centered iteration "
+
cuasMotion
.
when_fail
+
" DONE.\n"
);
}
}
//for (niter=0; niter < max_iter; niter++)
...
...
@@ -8557,9 +8571,12 @@ public class CuasMotion {
}
}
// end of phase 1
if
(
debugLevel
>
-
4
)
{
System
.
out
.
println
(
"\n========================== Starting centered iterations =============================.\n"
);
}
cuasMotion
.
when_fail
=
CuasMotion
.
WHEN_PHASE2
;
// whill be overwritten inside loop
// By Claude on 05/05/2026 — optional MV refinement parameters for centered loop
int
recalc_mv_num
=
slow_mode
?
0
:
clt_parameters
.
imp
.
cuas_recalc_mv_num
;
double
recalc_mv_boost
=
clt_parameters
.
imp
.
cuas_recalc_mv_boost
;
...
...
@@ -8617,7 +8634,7 @@ public class CuasMotion {
if
(
early_en
)
{
int
[]
early_fail
=
earlyFail
(
// Fail after Phase 1
target_sequence_multi
,
// final double [][][][] target_multi,
niter
,
// final int niter,
cuasMotion
.
when_fail
,
// final int niter,
early_boosts
,
// final boolean early_boosts,
early_mscore
,
// final double min_mscore,
early_vstr
,
// final double min_vstr,
...
...
@@ -8643,10 +8660,11 @@ public class CuasMotion {
true
);
// final boolean trim_nulls) { // trim null targets
int
[]
num_duplicates
=
removeWeakerDuplicates
(
// needs sortMultiTargets and after
target_sequence_multi
,
// final double [][][][] target_multi,
duplicate_tolerance
);
// final double pix_tolerance)
duplicate_tolerance
,
// final double pix_tolerance)
cuasMotion
.
when_fail
);
// final int when_fail)
if
(
debugLevel
>
-
4
)
System
.
out
.
println
(
"Removed "
+
num_duplicates
[
1
]+
" good duplicate targets (total with bad - "
+
num_duplicates
[
0
]+
")."
);
sortMultiTargets
(
sortMultiTargets
(
// moves FAILED after good (and duplicates are now FAILED
target_sequence_multi
,
// final double [][][][] target_multi,
true
);
// final boolean trim_nulls) { // trim null targets
...
...
@@ -8674,15 +8692,18 @@ public class CuasMotion {
}
}
/*
int niter_lim = niter+ num_cycles;
int iter_show1 = iter_show + niter;
int niter0 = niter; // for debugging, so (niter - niter0) will start from 0
for
(;
niter
<
niter_lim
;
niter
++)
{
*/
// for (; niter < niter_lim; niter++) {
for
(
int
it_indx2
=
0
;
it_indx2
<
num_cycles
;
it_indx2
++)
{
cuasMotion
.
when_fail
=
CuasMotion
.
WHEN_PHASE2
+
it_indx2
;
boolean
good_only
=
false
;
boolean
show_empty
=
true
;
// false; // show scenes with no (valid) targets
boolean
save_filtered_low
=
intermed_low
&&
(
niter
<
iter_show1
);
boolean
save_filtered_high
=
intermed_high
&&
(
niter
<
iter_show1
);
boolean
save_filtered_low
=
intermed_low
&&
(
it_indx2
<
iter_show
);
boolean
save_filtered_high
=
intermed_high
&&
(
it_indx2
<
iter_show
);
totals
=
getRemain
(
target_sequence_multi
,
// final double [][][][] target_sequence_multi,
num_all
,
// int [] num_all_in,
...
...
@@ -8717,7 +8738,7 @@ public class CuasMotion {
filter5
,
cuasMotion
.
tilesX
,
cuasMotion
.
tilesY
,
model_prefix
+
"-FILTER5_SELECTED_MULTI_CENTERED-n"
+
niter
,
// Selected to test
model_prefix
+
"-FILTER5_SELECTED_MULTI_CENTERED-n"
+
cuasMotion
.
when_fail
,
// Selected to test
slice_titles
);
if
(!
batch_mode
)
{
imp_filter5
.
show
();
...
...
@@ -8729,7 +8750,7 @@ public class CuasMotion {
ImagePlus
imp_marked_used
=
showTargetSequence
(
target_sequence_multi
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-MARKED_USED-n"
+
niter
,
// String title,
model_prefix
+
"-MARKED_USED-n"
+
cuasMotion
.
when_fail
,
// String title,
good_only
,
// final boolean good_only,
show_empty
,
// final boolean show_empty, // show scenes with no (valid) targets
!
batch_mode
,
// boolean show,
...
...
@@ -8745,7 +8766,7 @@ public class CuasMotion {
break
;
}
// render and process in centered mode
/*
double [][][] targets_nonoverlap = applyFilter( // motion vectors // will have nulls not top try
target_sequence_multi, // double [][][][] target_sequence_multi
filter5); // boolean [][] filter5)
...
...
@@ -8756,15 +8777,32 @@ public class CuasMotion {
ImagePlus imp_novl = showTargetSequence(
targets_nonoverlap, // double [][][] vector_fields_sequence,
slice_titles, // String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-SELECTED-TO-TRY-CENTERED-n"
+
niter
,
// String title,
model_prefix+"-SELECTED-TO-TRY-CENTERED-n"+
cuasMotion.when_fail
,// String title,
!batch_mode, // boolean show,
cuasMotion.tilesX); // int tilesX) {
parentCLT.saveImagePlusInModelDirectory(imp_novl);
}
*/
int
num_new
=
0
;
boolean
need_sel_to_try
=
true
;
double
effective_boost
=
boost_accum_pairs
;
// default virtual exposure scale
if
(
accum_boosted
)
{
double
[][][]
targets_nonoverlap
=
applyFilter
(
// motion vectors // will have nulls not top try
target_sequence_multi
,
// double [][][][] target_sequence_multi
filter5
);
// boolean [][] filter5)
if
(
save_filtered_low
&&
debug_more
&&
need_sel_to_try
)
{
// targets_nonoverlap will contain motion vectors used fro the next fpixels_accumulated
ImagePlus
imp_novl
=
showTargetSequence
(
targets_nonoverlap
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-SELECTED-TO-TRY-CENTERED-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_novl
);
need_sel_to_try
=
false
;
}
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use updated motion vector
// By Claude on 05/05/2026 — re-correlate with spatial mask around known target
if
(
recalc_mv_num
>
0
)
{
...
...
@@ -8791,7 +8829,7 @@ public class CuasMotion {
speed_pref
,
// double speed_pref,
speed_boost
,
// double speed_boost);
"-first"
,
// String dbg_suffix,
niter
-
niter0
,
// int dbg_iter_index,
cuasMotion
.
when_fail
,
// int dbg_iter_index,
debugLevel
);
// -1); // debugLevel); // int debugLevel)
if
(
recalc_mv_num
>
1
)
{
refineMotionVectors
(
// just testing conversion
...
...
@@ -8815,10 +8853,20 @@ public class CuasMotion {
speed_pref
,
// double speed_pref,
speed_boost
,
// double speed_boost);
"-second"
,
// String dbg_suffix,
niter
-
niter0
,
// int dbg_iter_index,
cuasMotion
.
when_fail
,
// int dbg_iter_index,
debugLevel
);
// -1); // debugLevel); // int debugLevel)
}
}
boolean
debug_extra
=
debugLevel
>
-
5
;
if
(
save_filtered_low
&&
debug_more
&&
debug_extra
)
{
ImagePlus
imp_ext
=
showTargetSequence
(
targets_nonoverlap
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-BEFORE-EXTENDED-CENTERED-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_ext
);
}
double
[][][]
extended_scan
=
extendMotionScan
(
targets_nonoverlap
,
// final double [][][] motion_scan,
null
,
// filter5, // final boolean [][] filtered, // centers, should be non-overlapped
...
...
@@ -8829,7 +8877,7 @@ public class CuasMotion {
ImagePlus
imp_ext
=
showTargetSequence
(
extended_scan
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-EXTENDED-CENTERED-n"
+
niter
,
// String title,
model_prefix
+
"-EXTENDED-CENTERED-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_ext
);
...
...
@@ -8851,7 +8899,7 @@ public class CuasMotion {
corr_offset
,
// int corr_offset, // interframe distance for correlation
save_filtered_high
,
// boolean save_filtered_high,
model_prefix
,
// String model_prefix,
niter
,
// int niter,
cuasMotion
.
when_fail
,
// int niter,
input_range
,
// double input_range,
lmax_fraction
,
// double lmax_fraction,
...
...
@@ -8923,14 +8971,28 @@ public class CuasMotion {
targets_new_multi
,
// final double [][][] new_sequence,
// add just one best here?
1
,
// final int num_best, // if >0, limit number of best results to add
niter
,
// final int when_iter,
cuasMotion
.
when_fail
,
// final int when_iter,
debugLevel
);
// final int debugLevel);
if
(
debugLevel
>
-
4
)
{
System
.
out
.
println
(
"Added "
+
num_new
+
" new tiles as good/bad at boosted iteration "
+
niter
+
"."
);
System
.
out
.
println
(
"Added "
+
num_new
+
" new tiles as good/bad at boosted iteration "
+
cuasMotion
.
when_fail
+
"."
);
}
}
if
(
accum_base
)
{
double
[][][]
targets_nonoverlap
=
applyFilter
(
// motion vectors // will have nulls not top try
target_sequence_multi
,
// double [][][][] target_sequence_multi
filter5
);
// boolean [][] filter5)
if
(
save_filtered_low
&&
debug_more
&&
need_sel_to_try
)
{
// targets_nonoverlap will contain motion vectors used fro the next fpixels_accumulated
ImagePlus
imp_novl
=
showTargetSequence
(
targets_nonoverlap
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-SELECTED-TO-TRY-CENTERED-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_novl
);
}
// Andrey 05/05/2026 moved here (earlier) so shiftAndRenderAccumulate() will use updated motion vector
// By Claude on 05/05/2026 — re-correlate with spatial mask around known target
if
(
recalc_mv_num
>
0
)
{
...
...
@@ -8955,7 +9017,7 @@ public class CuasMotion {
speed_pref
,
// double speed_pref,
speed_boost
,
// double speed_boost);
"-first"
,
// String dbg_suffix,
niter
-
niter0
,
// int dbg_iter_index,
cuasMotion
.
when_fail
,
// int dbg_iter_index,
debugLevel
);
// -1); // debugLevel); // int debugLevel)
if
(
recalc_mv_num
>
1
)
{
refineMotionVectors
(
...
...
@@ -8979,7 +9041,7 @@ public class CuasMotion {
speed_pref
,
// double speed_pref,
speed_boost
,
// double speed_boost);
"-second"
,
// String dbg_suffix,
niter
-
niter0
,
// int dbg_iter_index,
cuasMotion
.
when_fail
,
// int dbg_iter_index,
debugLevel
);
// -1); // debugLevel); // int debugLevel)
}
}
...
...
@@ -8993,7 +9055,7 @@ public class CuasMotion {
ImagePlus
imp_ext
=
showTargetSequence
(
extended_scan
,
// double [][][] vector_fields_sequence,
slice_titles
,
// String [] titles, // all slices*frames titles or just slice titles or null
model_prefix
+
"-EXTENDED-CENTERED-n"
+
niter
,
// String title,
model_prefix
+
"-EXTENDED-CENTERED-n"
+
cuasMotion
.
when_fail
,
// String title,
!
batch_mode
,
// boolean show,
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_ext
);
...
...
@@ -9014,7 +9076,7 @@ public class CuasMotion {
corr_offset
,
// int corr_offset, // interframe distance for correlation
save_filtered_high
,
// boolean save_filtered_high,
model_prefix
,
// String model_prefix,
niter
,
// int niter,
cuasMotion
.
when_fail
,
// int niter,
input_range
,
// double input_range,
lmax_fraction
,
// double lmax_fraction,
...
...
@@ -9083,19 +9145,19 @@ public class CuasMotion {
debugLevel
);
// int debugLevel);
//int
num_new
+
=
addNewResults
(
int
num_new1
=
addNewResults
(
target_sequence_multi
,
// final double [][][] target_sequence, // will only process non-nulls here
targets_new_multi
,
// final double [][][] new_sequence,
// add just one best here?
1
,
// final int num_best, // if >0, limit number of best results to add
niter
,
// final int when_iter,
cuasMotion
.
when_fail
,
// final int when_iter,
debugLevel
);
// final int debugLevel);
num_new
+=
num_new1
;
if
(
debugLevel
>
-
4
)
{
System
.
out
.
println
(
"Added "
+
num_new
+
" new tiles as good/bad at base iteration "
+
niter
+
"."
);
System
.
out
.
println
(
"Added "
+
num_new
1
+
" new tiles as good/bad at base iteration "
+
cuasMotion
.
when_fail
+
"."
);
}
if
(
save_filtered_low
)
{
String
title
=
model_prefix
+
"-ADDED_NEW_CENTERED_MULTI-n"
+
niter
;
String
title
=
model_prefix
+
"-ADDED_NEW_CENTERED_MULTI-n"
+
cuasMotion
.
when_fail
;
title
+=
"-BOOST"
+
effective_boost
+
"-NOBOOST"
;
// boost_accum_pairs;
ImagePlus
imp_new_scores
=
showTargetSequence
(
target_sequence_multi
,
// double [][][] vector_fields_sequence,
...
...
@@ -9122,10 +9184,10 @@ public class CuasMotion {
num_good
,
// int [] num_good_in,
num_bad
);
// int [] num_bad_in)
if
(
debugLevel
>
-
4
)
printStats
(
"After centered iteration "
+
niter
,
true
,
num_all
,
num_undef
,
num_good
,
num_bad
);
if
(
debugLevel
>
-
4
)
printStats
(
"After centered iteration "
+
cuasMotion
.
when_fail
,
true
,
num_all
,
num_undef
,
num_good
,
num_bad
);
if
(
debugLevel
>
-
4
)
{
System
.
out
.
print
((
new
SimpleDateFormat
(
"yyyy/MM/dd HH:mm:ss"
).
format
(
Calendar
.
getInstance
().
getTime
())+
": "
));
System
.
out
.
println
(
"Centered iteration "
+
niter
+
" DONE.\n"
);
System
.
out
.
println
(
"Centered iteration "
+
cuasMotion
.
when_fail
+
" DONE.\n"
);
}
}
//for (niter=0; niter < max_iter; niter++)
boolean
good_only
=
false
;
...
...
@@ -9741,7 +9803,8 @@ public class CuasMotion {
// mark all "used" targets (non-centered, after all centered are added) as failed
public
static
void
failUsed
(
final
double
[][][][]
target_sequence
)
{
final
double
[][][][]
target_sequence
,
final
int
when_fail
)
{
final
int
num_seq
=
target_sequence
.
length
;
final
int
num_tiles
=
target_sequence
[
0
].
length
;
final
Thread
[]
threads
=
ImageDtt
.
newThreadArray
();
...
...
@@ -9757,6 +9820,7 @@ public class CuasMotion {
double
[]
target
=
target_sequence
[
nSeq
][
ntile
][
ntarg
];
if
((
target
!=
null
)
&&
(
target
[
CuasMotionLMA
.
RSLT_FAIL
]
==
CuasMotionLMA
.
FAIL_NONE
)
&&
(
target
[
CuasMotionLMA
.
RSLT_CENTERED
]
==
CuasMotionLMA
.
CENTERED_USED
))
{
target
[
CuasMotionLMA
.
RSLT_FAIL
]
=
CuasMotionLMA
.
FAIL_USED
;
target
[
CuasMotionLMA
.
RSLT_WHEN
]
=
when_fail
;
}
}
}
...
...
@@ -10373,7 +10437,9 @@ public class CuasMotion {
}
// Used non-centered tiles are not needed anymore, mark them as failed to simplify processing
failUsed
(
targets_multi
);
// final double [][][][] target_sequence) {
if
(
debugLevel
>
-
4
)
System
.
out
.
println
(
"Using "
+
cuasMotion
.
when_fail
+
" for RSLT_WHEN in failUsed()"
);
failUsed
(
targets_multi
,
// final double [][][][] target_sequence) {
cuasMotion
.
when_fail
++
);
// final int when_fail);
boolean
debug_extra
=
debugLevel
>
-
5
;
if
(
intermed_low
&&
debug_more
&&
debug_extra
)
{
ImagePlus
imp_dup
=
showTargetSequence
(
...
...
@@ -10401,10 +10467,12 @@ public class CuasMotion {
cuasMotion
.
tilesX
);
// int tilesX) {
parentCLT
.
saveImagePlusInModelDirectory
(
imp_dup
);
}
// Will not mark as failed for duplicates - implement?
if
(
debugLevel
>
-
4
)
System
.
out
.
println
(
"Using "
+
cuasMotion
.
when_fail
+
" for RSLT_WHEN in removeWeakerDuplicates()"
);
int
[]
num_duplicates
=
removeWeakerDuplicates
(
// needs sortMultiTargets and after
targets_multi
,
// final double [][][][] target_multi,
duplicate_tolerance
);
// final double pix_tolerance)
duplicate_tolerance
,
// final double pix_tolerance)
cuasMotion
.
when_fail
++);
// final int when_fail)
if
(
intermed_low
&&
debug_more
&&
debug_extra
)
{
ImagePlus
imp_dup
=
showTargetSequence
(
targets_multi
,
// double [][][] vector_fields_sequence,
...
...
@@ -10539,11 +10607,16 @@ public class CuasMotion {
}
// apply filter5 to targets_good
findStrongerNeighbor
(
// does not modify "when"
if
(
debugLevel
>
-
4
)
System
.
out
.
println
(
"Using "
+
cuasMotion
.
when_fail
+
" for RSLT_WHEN in findStrongerNeighbor()"
);
findStrongerNeighbor
(
// does not modify "when" - now 05.30.2026 does
targets_multi
,
// final double [][][][] target_multi,
filter5
,
// final boolean [][] filter5)
true
,
// false, // final boolean mark_failed,
cuasMotion
.
when_fail
++,
// final int when_fail,
cuasMotion
.
tilesX
);
// final int tilesX) {
if
(
intermed_low
&&
debug_more
)
{
ImagePlus
imp_neibs
=
showTargetSequence
(
targets_multi
,
// double [][][] vector_fields_sequence,
...
...
@@ -10657,6 +10730,7 @@ public class CuasMotion {
final
double
[][][][]
target_multi
,
final
int
[][]
filter5
,
final
boolean
mark_failed
,
final
int
when_fail
,
final
int
tilesX
)
{
final
int
range
=
2
;
final
int
num_seq
=
target_multi
.
length
;
...
...
@@ -10701,6 +10775,7 @@ public class CuasMotion {
}
if
(
mark_failed
&&
(
filter5
[
nSeq
][
ntile
]
!=
ntarg
))
{
targets
[
ntarg
][
CuasMotionLMA
.
RSLT_FAIL
]
=
CuasMotionLMA
.
FAIL_NEIGHBOR
;
targets
[
ntarg
][
CuasMotionLMA
.
RSLT_WHEN
]
=
when_fail
;
}
}
}
...
...
@@ -10777,10 +10852,6 @@ public class CuasMotion {
motion_sequence_fast
,
// double [][][] target_sequence,
false
,
// boolean slow_mode,
debugLevel
);
// final int debugLevel)
double
[][][][]
targets_good_multi
=
targets_fast
;
/*
* Before running with slow_en== true, verify temporal (scene) offset between slow and fast mode.
...
...
@@ -10812,6 +10883,7 @@ public class CuasMotion {
targets_slow
,
// final double [][][][] targets_slow,
slow_score
);
// final double scale_slow){ // if >0, limit number of best results to add
}
this
.
when_fail
=
CuasMotion
.
WHEN_FINISH
;
sortMultiTargets
(
// maybe only needed after slow branch?
targets_good_multi
,
// final double [][][][] target_multi,
...
...
@@ -10824,9 +10896,6 @@ public class CuasMotion {
fpixels
,
// float [][] fpixels,
targets_good_multi
,
// double [][][][] targets_good_multi, // all targets, including conflicting
debugLevel
);
// final int debugLevel)
}
setTargets
(
targets_nonconflict
);
return
;
...
...
src/main/java/com/elphel/imagej/cuas/CuasMotionLMA.java
View file @
b7ce93be
...
...
@@ -166,7 +166,7 @@ public class CuasMotionLMA {
"Phase1-index"
,
"Phase1-score"
,
"Phase1-amplitude"
,
"Phase1-mscore"
,
"Phase1-vstr"
,
"Phase1-vboost"
,
"Phase1-exp_boost"
};
public
static
final
String
EXTRA_SLICE_DISCARD_ON_LOAD
=
"Targets"
;
public
static
final
int
FAIL_PENDING
=
-
1
;
// By Claude on 05/07/2026: motion sentinel — tile tracked but not yet processed by LMA
//
public static final int FAIL_PENDING = -1; // By Claude on 05/07/2026: motion sentinel — tile tracked but not yet processed by LMA
public
static
final
int
FAIL_NONE
=
0
;
public
static
final
int
FAIL_MOTION
=
1
;
// motion strength/fraction too low, also - motion score too low
public
static
final
int
FAIL_NO_MAX
=
2
;
// no suitable local maximum
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment