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
b4d24102
Commit
b4d24102
authored
Jan 09, 2026
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using disparity planes OK
parent
44cb1d7e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1051 additions
and
393 deletions
+1051
-393
GroundPlane.java
...ain/java/com/elphel/imagej/tileprocessor/GroundPlane.java
+361
-59
OpticalFlow.java
...ain/java/com/elphel/imagej/tileprocessor/OpticalFlow.java
+690
-334
No files found.
src/main/java/com/elphel/imagej/tileprocessor/GroundPlane.java
View file @
b4d24102
...
...
@@ -23,6 +23,7 @@ import ij.text.TextWindow;
public
class
GroundPlane
{
public
static
final
String
GROUND_PLANE_PREFIX
=
"groundplane"
;
public
double
[][]
to_ground_xyzatr
=
null
;
public
double
[]
disparity_plane
=
null
;
public
double
frac_good
=
Double
.
NaN
;
// fraction of "ground" tiles used to find local ground plane
public
double
[]
lla
=
null
;
// GPS LLA
public
double
[]
quat_enu
=
null
;
// IMS orientation quaternion == d2.getQEnu()
...
...
@@ -38,13 +39,18 @@ public class GroundPlane {
public
double
[][]
getToGroundPlane
(){
return
to_ground_xyzatr
;
}
public
double
[]
getDisparityTilts
(){
return
disparity_plane
;
}
public
GroundPlane
()
{}
public
GroundPlane
(
double
[][]
to_ground_xyzatr
,
double
[]
disparity_plane
,
double
frac_good
,
double
[]
lla
,
double
[]
quat_enu
)
{
this
.
to_ground_xyzatr
=
new
double
[][]
{
to_ground_xyzatr
[
0
].
clone
(),
to_ground_xyzatr
[
1
].
clone
()};
// will fail if any is null - both needed
this
.
disparity_plane
=
disparity_plane
;
this
.
frac_good
=
frac_good
;
this
.
lla
=
lla
.
clone
();
this
.
quat_enu
=
quat_enu
.
clone
();
...
...
@@ -143,7 +149,7 @@ public class GroundPlane {
String
header
=
"timestamp\tX\tY\tZ\tAzimuth\tTilt\tRoll\tGood"
+
"\tLatitude\tLongitude\tAltitude"
+
"\tqenu[0]\tqenu[1]\tqenu[2]\tqenu[3]"
+
"\tcam-A\tcam-T\tcam-R"
;
"\tcam-A\tcam-T\tcam-R
\tdisp-TX\tdisp-TY\tdisp_center
"
;
StringBuffer
sb
=
new
StringBuffer
();
for
(
String
ts:
planes_map
.
keySet
())
{
GroundPlane
gp
=
planes_map
.
get
(
ts
);
...
...
@@ -160,7 +166,8 @@ public class GroundPlane {
sb
.
append
(
ts
+
"\t"
+
xyzatr
[
0
][
0
]+
"\t"
+
xyzatr
[
0
][
1
]+
"\t"
+
xyzatr
[
0
][
2
]+
"\t"
+
xyzatr
[
1
][
0
]+
"\t"
+
xyzatr
[
1
][
1
]+
"\t"
+
xyzatr
[
1
][
2
]);
sb
.
append
(
"\t"
+
frac_good
+
"\t"
+
lla
[
0
]+
"\t"
+
lla
[
1
]+
"\t"
+
lla
[
2
]);
sb
.
append
(
"\t"
+
qenu
[
0
]+
"\t"
+
qenu
[
1
]+
"\t"
+
qenu
[
2
]+
"\t"
+
qenu
[
3
]);
sb
.
append
(
"\t"
+
ref_abs_atr_enu
[
0
]+
"\t"
+
ref_abs_atr_enu
[
1
]+
"\t"
+
ref_abs_atr_enu
[
2
]+
"\n"
);
sb
.
append
(
"\t"
+
ref_abs_atr_enu
[
0
]+
"\t"
+
ref_abs_atr_enu
[
1
]+
"\t"
+
ref_abs_atr_enu
[
2
]);
sb
.
append
(
"\t"
+
gp
.
disparity_plane
[
0
]+
"\t"
+
gp
.
disparity_plane
[
1
]+
"\t"
+
gp
.
disparity_plane
[
2
]+
"\n"
);
}
if
(
path
!=
null
)
{
String
footer
=(
comment
!=
null
)
?
(
"Comment: "
+
comment
):
""
;
...
...
@@ -181,6 +188,9 @@ public class GroundPlane {
double
[]
d
=
ErsCorrection
.
parseDoublesCSV
(
properties
.
getProperty
(
prefix
+
"to_ground_xyzatr"
));
to_ground_xyzatr
=
new
double
[][]
{{
d
[
0
],
d
[
1
],
d
[
2
]},{
d
[
3
],
d
[
4
],
d
[
5
]}};
}
if
(
properties
.
getProperty
(
prefix
+
"disparity_plane"
)!=
null
)
{
disparity_plane
=
ErsCorrection
.
parseDoublesCSV
(
properties
.
getProperty
(
prefix
+
"disparity_plane"
));
}
if
(
properties
.
getProperty
(
prefix
+
"frac_good"
)!=
null
)
{
frac_good
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"frac_good"
));
}
...
...
@@ -197,6 +207,7 @@ public class GroundPlane {
properties
.
setProperty
(
prefix
+
"to_ground_xyzatr"
,
String
.
format
(
"%f, %f, %f, %f, %f, %f"
,
to_ground_xyzatr
[
0
][
0
],
to_ground_xyzatr
[
0
][
1
],
to_ground_xyzatr
[
0
][
2
],
to_ground_xyzatr
[
1
][
0
],
to_ground_xyzatr
[
1
][
1
],
to_ground_xyzatr
[
1
][
2
]));
properties
.
setProperty
(
prefix
+
"disparity_plane"
,
String
.
format
(
"%f, %f, %f"
,
disparity_plane
[
0
],
disparity_plane
[
1
],
disparity_plane
[
2
]));
properties
.
setProperty
(
prefix
+
"frac_good"
,
String
.
format
(
"%f"
,
frac_good
));
properties
.
setProperty
(
prefix
+
"lla"
,
String
.
format
(
"%f, %f, %f"
,
lla
[
0
],
lla
[
1
],
lla
[
2
]));
properties
.
setProperty
(
prefix
+
"quat_enu"
,
String
.
format
(
"%f, %f, %f, %f"
,
...
...
@@ -204,8 +215,9 @@ public class GroundPlane {
}
public
static
GroundPlane
getGroundPlane
(
CLTParameters
clt_parameters
,
CLTParameters
clt_parameters
,
final
QuadCLT
ref_scene
,
final
double
[]
gnd_disp
,
// if not null
final
int
debugLevel
)
{
final
double
gnd_percent_low
=
0.01
;
// discard lowest overliers
final
double
gnd_percent_high
=
0.2
;
// 0.9; // high ground percentile
...
...
@@ -227,6 +239,7 @@ public class GroundPlane {
normal_damping
,
// final double normal_damping,
ref_scene
.
getTilesX
(),
// final int width,
good_tiles
,
// final boolean [] good_tiles, // null or boolean[data.length] // should all be false
gnd_disp
,
// final double [] gnd_disp, // if not null
dbg_title
,
// final String dbg_title,
debugLevel
);
// final int debugLevel)
if
(
to_ground_xyzatr_frac
==
null
)
{
...
...
@@ -234,8 +247,26 @@ public class GroundPlane {
}
double
[][]
to_ground_xyzatr
=
{
to_ground_xyzatr_frac
[
0
],
to_ground_xyzatr_frac
[
1
]};
double
frac_good
=
to_ground_xyzatr_frac
[
2
][
0
];
// Until fixed, run independently
double
[]
disparity_plane
=
getDisparityPlaneDualPass
(
// returns to_ground_xyzatr (rotated around the ground point nadir of teh drone)
ref_scene
,
// final QuadCLT ref_Clt,
gnd_percent_low
,
// final double gnd_percent_low,
gnd_percent_high
,
// final double gnd_percent_high,
gnd_max_high_over
,
// final double gnd_max_high_over,
min_good1
,
// final int min_good1, // minimal good tiles after pass1
max_abs_diff
,
// final double max_abs_diff, // maximal absolute disparity difference from the plane
max_rel_diff
,
// final double max_rel_diff, // maximal relative disparity difference from the plane
normal_damping
,
// final double normal_damping,
ref_scene
.
getTilesX
(),
// final int width,
good_tiles
,
// final boolean [] good_tiles, // null or boolean[data.length] // should all be false
gnd_disp
,
// final double [] gnd_disp, // if not null
dbg_title
+
"-disp"
,
// final String dbg_title,
debugLevel
);
// final int debugLevel)
return
new
GroundPlane
(
to_ground_xyzatr
,
// double [][] to_ground_xyzatr,
disparity_plane
,
// double [] disparity_plane,
frac_good
,
// double frac_good,
ref_scene
.
getLla
(),
// double [] lla,
ref_scene
.
getQEnu
());
// double [] quat_enu) {
...
...
@@ -254,6 +285,7 @@ public class GroundPlane {
final
double
normal_damping
,
final
int
width
,
final
boolean
[]
good_tiles
,
// null or boolean[data.length] // should all be false
final
double
[]
gnd_disp
,
// if not null
final
String
dbg_title
,
final
int
debugLevel
)
{
boolean
print_histogram
=
debugLevel
>
0
;
...
...
@@ -473,14 +505,14 @@ public class GroundPlane {
to_ground_xyzatr_centered[1]
};
*/
if
(
dbg_title
!=
null
)
{
if
(
(
dbg_title
!=
null
)
||
(
gnd_disp
!=
null
)
)
{
// rotate ref_disparity and show
double
[][]
pXpYD_ground
=
OpticalFlow
.
transformToScenePxPyD
(
null
,
// final Rectangle full_woi_in, // show larger than sensor WOI (or null) IN TILES
ref_disparity
,
// final double [] disparity_ref, // invalid tiles - NaN in disparity
virtual_camera_from_camera
,
// final double [][] scene_xyzatr, // camera center in world coordinates, camera orientation relative to world frame
ref_Clt
);
// final QuadCLT scene_QuadClt)
double
[]
gnd_disparity
=
new
double
[
ref_disparity
.
length
];
double
[]
gnd_disparity
=
(
gnd_disp
!=
null
)
?
gnd_disp
:
new
double
[
ref_disparity
.
length
];
Arrays
.
fill
(
gnd_disparity
,
Double
.
NaN
);
for
(
int
i
=
0
;
i
<
ref_disparity
.
length
;
i
++)
{
double
[]
xyd
=
pXpYD_ground
[
i
];
...
...
@@ -488,55 +520,48 @@ public class GroundPlane {
gnd_disparity
[
i
]
=
xyd
[
2
];
}
}
if
(
dbg_title
!=
null
)
{
double
[][]
wxyz_gnd
=
OpticalFlow
.
transformToWorldXYZ
(
gnd_disparity
,
// final double [] disparity_ref, // invalid tiles - NaN in disparity
ref_Clt
,
// final QuadCLT quadClt, // now - may be null - for testing if scene is rotated ref
ImageDtt
.
THREADS_MAX
);
// int threadsMax)
double
[]
ref_z
=
new
double
[
ref_disparity
.
length
];
double
[]
gnd_z
=
new
double
[
ref_disparity
.
length
];
Arrays
.
fill
(
ref_z
,
Double
.
NaN
);
Arrays
.
fill
(
gnd_z
,
Double
.
NaN
);
for
(
int
i
=
0
;
i
<
ref_disparity
.
length
;
i
++)
{
double
[]
wxyz0
=
wxyz
[
i
];
double
[]
wxyz_g0
=
wxyz_gnd
[
i
];
if
(
wxyz0
!=
null
)
ref_z
[
i
]
=
wxyz0
[
2
];
if
(
wxyz_g0
!=
null
)
gnd_z
[
i
]
=
wxyz_g0
[
2
];
}
String
[]
dbg_titles
=
{
"ref_disparity"
,
"ground_disparity"
,
"ref_z"
,
"gnd_z"
,
"masked_z"
,
"weights"
};
double
[][]
dbg_data
=
new
double
[
dbg_titles
.
length
][];
dbg_data
[
0
]
=
ref_disparity
;
dbg_data
[
1
]
=
gnd_disparity
;
dbg_data
[
2
]
=
ref_z
;
dbg_data
[
3
]
=
gnd_z
;
dbg_data
[
4
]
=
gnd_z
.
clone
();
dbg_data
[
5
]
=
weights
.
clone
();
for
(
int
i
=
0
;
i
<
mask3
.
length
;
i
++)
{
if
(!
mask3
[
i
])
{
dbg_data
[
4
][
i
]
=
Double
.
NaN
;
dbg_data
[
5
][
i
]
=
Double
.
NaN
;
double
[][]
wxyz_gnd
=
OpticalFlow
.
transformToWorldXYZ
(
gnd_disparity
,
// final double [] disparity_ref, // invalid tiles - NaN in disparity
ref_Clt
,
// final QuadCLT quadClt, // now - may be null - for testing if scene is rotated ref
ImageDtt
.
THREADS_MAX
);
// int threadsMax)
double
[]
ref_z
=
new
double
[
ref_disparity
.
length
];
double
[]
gnd_z
=
new
double
[
ref_disparity
.
length
];
Arrays
.
fill
(
ref_z
,
Double
.
NaN
);
Arrays
.
fill
(
gnd_z
,
Double
.
NaN
);
for
(
int
i
=
0
;
i
<
ref_disparity
.
length
;
i
++)
{
double
[]
wxyz0
=
wxyz
[
i
];
double
[]
wxyz_g0
=
wxyz_gnd
[
i
];
if
(
wxyz0
!=
null
)
ref_z
[
i
]
=
wxyz0
[
2
];
if
(
wxyz_g0
!=
null
)
gnd_z
[
i
]
=
wxyz_g0
[
2
];
}
String
[]
dbg_titles
=
{
"ref_disparity"
,
"ground_disparity"
,
"ref_z"
,
"gnd_z"
,
"masked_z"
,
"weights"
};
double
[][]
dbg_data
=
new
double
[
dbg_titles
.
length
][];
dbg_data
[
0
]
=
ref_disparity
;
dbg_data
[
1
]
=
gnd_disparity
;
dbg_data
[
2
]
=
ref_z
;
dbg_data
[
3
]
=
gnd_z
;
dbg_data
[
4
]
=
gnd_z
.
clone
();
dbg_data
[
5
]
=
weights
.
clone
();
for
(
int
i
=
0
;
i
<
mask3
.
length
;
i
++)
{
if
(!
mask3
[
i
])
{
dbg_data
[
4
][
i
]
=
Double
.
NaN
;
dbg_data
[
5
][
i
]
=
Double
.
NaN
;
}
}
ref_Clt
.
saveDoubleArrayInModelDirectory
(
dbg_title
+
"-result"
,
// String suffix,
dbg_titles
,
// String [] labels, // or null
dbg_data
,
// double [][] data,
width
,
// int width, // int tilesX,
dbg_data
[
0
].
length
/
width
);
// int height, // int tilesY,
}
ref_Clt
.
saveDoubleArrayInModelDirectory
(
dbg_title
+
"-result"
,
// String suffix,
dbg_titles
,
// String [] labels, // or null
dbg_data
,
// double [][] data,
width
,
// int width, // int tilesX,
dbg_data
[
0
].
length
/
width
);
// int height, // int tilesY,
/*
ShowDoubleFloatArrays.showArrays(
dbg_data,
width,
height,
true,
dbg_title+"-ground_disparity",
dbg_titles);
*/
}
ErsCorrection
.
printVectors
(
virtual_camera_from_camera
);
// to_ground_xyzatr_centered);
/// ref_Clt.getErsCorrection().printVectors (to_ground_xyzatr_centered[0], to_ground_xyzatr_centered[1]);
ref_Clt
.
getErsCorrection
().
printVectors
(
virtual_camera_from_camera
[
0
],
virtual_camera_from_camera
[
1
]);
...
...
@@ -547,10 +572,259 @@ public class GroundPlane {
// return to_ground_xyzatr_centered;
}
public
static
double
[]
getDisparityPlaneDualPass
(
// returns to_ground_xyzatr (rotated around the ground point nadir of teh drone)
final
QuadCLT
ref_Clt
,
final
double
gnd_percent_low
,
final
double
gnd_percent_high
,
final
double
gnd_max_high_over
,
final
int
min_good1
,
// minimal good tiles after pass1
final
double
max_abs_diff
,
// maximal absolute disparity difference from the plane
final
double
max_rel_diff
,
// maximal relative disparity difference from the plane
final
double
normal_damping
,
final
int
width
,
final
boolean
[]
good_tiles
,
// null or boolean[data.length] // should all be false
final
double
[]
gnd_disp
,
// if not null
final
String
dbg_title
,
final
int
debugLevel
)
{
boolean
print_histogram
=
debugLevel
>
0
;
double
blur_frac
=
0.01
;
// 0.03
double
weight_frac
=
0.3
;
// multiply weight by w= 1/(1 + (err/k_max_diff)^2)
boolean
use_lma
=
true
;
int
num_bins
=
1000
;
String
dbg_title1
=
(
dbg_title
!=
null
)
?
(
dbg_title
+
"-stage1"
)
:
null
;
String
dbg_title2
=
(
dbg_title
!=
null
)
?
(
dbg_title
+
"-stage2"
)
:
null
;
String
dbg_title3
=
(
dbg_title
!=
null
)
?
(
dbg_title
+
"-stage3"
)
:
null
;
double
[][]
dls
=
ref_Clt
.
getDLS
();
if
(
dls
==
null
)
{
return
null
;
}
double
[][]
ds
=
new
double
[][]
{
dls
[
use_lma
?
1
:
0
].
clone
(),
dls
[
2
]};
final
double
[]
ref_disparity
=
ds
[
0
];
final
double
[]
ref_strength
=
ds
[
1
];
final
double
inf_disp_ref
=
ref_Clt
.
getDispInfinityRef
();
if
(
inf_disp_ref
!=
0
)
{
if
(
debugLevel
>-
3
)
{
System
.
out
.
println
(
"getPlaneDualPass(): applying disparity at infinity correctio, subrtacting "
+
inf_disp_ref
);
}
for
(
int
i
=
0
;
i
<
ref_disparity
.
length
;
i
++)
{
ref_disparity
[
i
]
-=
inf_disp_ref
;
}
}
final
int
height
=
ref_disparity
.
length
/
width
;
final
double
[]
xy0
=
{
width
/
2
,
height
/
2
};
double
avg_val
=
weightedAverage
(
ref_disparity
,
// double [] data, // may have NaNs
ref_strength
);
// double [] weights)
double
hist_low
=
0.0
;
double
hist_high
=
1.5
*
avg_val
;
double
[]
hist
=
getHistogram1d
(
ref_disparity
,
// double [] data, // may have NaNs
ref_strength
,
// double [] weights,
hist_low
,
// double hist_low,
hist_high
,
// double hist_high,
num_bins
,
// int num_bins,
debugLevel
);
// int debugLevel)
double
[]
fractions
=
{
gnd_percent_low
,
gnd_percent_high
};
double
[]
percentiles
=
getPercentiles
(
hist
,
// double [] hist,
fractions
);
// double [] fractions)
double
low_lim
=
hist_low
+
percentiles
[
0
]
*
(
hist_high
-
hist_low
);
double
high_lim
=
hist_low
+
percentiles
[
1
]
*
(
hist_high
-
hist_low
);
if
(
high_lim
>
(
low_lim
+
gnd_max_high_over
))
{
high_lim
=
low_lim
+
gnd_max_high_over
;
}
boolean
[]
mask
=
new
boolean
[
ref_disparity
.
length
];
int
num_good1
=
0
;
for
(
int
i
=
0
;
i
<
mask
.
length
;
i
++)
{
if
((
ref_disparity
[
i
]
>=
low_lim
)
&&
(
ref_disparity
[
i
]
<=
high_lim
))
{
mask
[
i
]
=
true
;
num_good1
++;
}
}
// first mask may be small (if the image was tilted a lot)
if
(
debugLevel
>-
3
)
{
System
.
out
.
println
(
"getPlaneDualPass(): num_good1="
+
num_good1
+
" low_lim="
+
low_lim
+
" high_lim="
+
high_lim
+
" fractions=["
+
fractions
[
0
]+
","
+
fractions
[
1
]+
"]"
);
}
double
[]
tilts_stage1
=
getPlane
(
// {approx2d[0][0], approx2d[0][1], approx2d[0][2], xy0[0], xy0[1]}; // tiltX, tiltY, offset
ref_disparity
,
// final double [] data,
mask
,
// final boolean [] mask,
ref_strength
,
// final double [] weight,
width
,
// final int width,
xy0
,
// final double [] xy0,
normal_damping
,
// final double normal_damping,
ref_Clt
,
// final QuadCLT dbg_scene,
dbg_title1
);
// String dbg_title)
if
(
tilts_stage1
==
null
)
{
System
.
out
.
println
(
"getPlaneDualPass(): tilts_stage1= null"
);
return
null
;
}
if
(
debugLevel
>-
3
)
{
System
.
out
.
println
(
"getPlaneDualPass() stage1: tiltX="
+
tilts_stage1
[
0
]+
" tiltY="
+
tilts_stage1
[
1
]+
" offset="
+
tilts_stage1
[
2
]+
" fraction good1="
+(
1.0
*
num_good1
/
ref_disparity
.
length
)+
" num_good1="
+
num_good1
);
}
boolean
[]
mask2
=
new
boolean
[
ref_disparity
.
length
];
int
num_good2
=
0
;
double
max_diff
=
Math
.
min
(
max_abs_diff
,
max_rel_diff
*
low_lim
);
if
(
debugLevel
>-
3
)
{
System
.
out
.
println
(
"getPlaneDualPass() stage1: max_abs_diff="
+
max_abs_diff
+
", max_rel_diff="
+
max_rel_diff
+
", low_lim="
+
low_lim
+
", max_diff="
+
max_diff
);
}
for
(
int
i
=
0
;
i
<
ref_disparity
.
length
;
i
++)
{
int
x
=
i
%
width
;
int
y
=
i
/
width
;
double
dx
=
x
-
xy0
[
0
];
double
dy
=
y
-
xy0
[
1
];
double
plane
=
tilts_stage1
[
0
]
*
dx
+
tilts_stage1
[
1
]
*
dy
+
tilts_stage1
[
2
];
// data_tilted[i] = ref_disparity[i] - plane;
double
d_tilted
=
ref_disparity
[
i
]
-
plane
;
if
(
Math
.
abs
(
d_tilted
)
<=
max_diff
)
{
mask2
[
i
]
=
true
;
num_good2
++;
}
}
if
(
debugLevel
>-
3
)
{
System
.
out
.
println
(
"getPlaneDualPass(): num_good2="
+
num_good2
+
" max_diff="
+
max_diff
);
}
// re-calculate disparity tilts with mask2
double
[]
tilts_stage2
=
getPlane
(
// {approx2d[0][0], approx2d[0][1], approx2d[0][2], xy0[0], xy0[1]}; // tiltX, tiltY, offset
ref_disparity
,
// final double [] data,
mask2
,
// final boolean [] mask,
ref_strength
,
// final double [] weight,
width
,
// final int width,
xy0
,
// final double [] xy0,
normal_damping
,
// final double normal_damping,
ref_Clt
,
// final QuadCLT dbg_scene,
dbg_title2
);
// String dbg_title)
if
(
tilts_stage2
==
null
)
{
System
.
out
.
println
(
"getPlaneDualPass(): tilts_stage2= null"
);
return
null
;
}
double
[]
data_tilted
=
new
double
[
ref_disparity
.
length
];
for
(
int
i
=
0
;
i
<
ref_disparity
.
length
;
i
++)
{
int
x
=
i
%
width
;
int
y
=
i
/
width
;
double
dx
=
x
-
xy0
[
0
];
double
dy
=
y
-
xy0
[
1
];
double
plane
=
tilts_stage2
[
0
]
*
dx
+
tilts_stage2
[
1
]
*
dy
+
tilts_stage2
[
2
];
data_tilted
[
i
]
=
ref_disparity
[
i
]
-
plane
;
}
// int num_bins2 = 100
double
[]
hist2
=
getHistogram1d
(
data_tilted
,
// double [] data, // may have NaNs
ref_strength
,
// double [] weights,
-
max_diff
,
// double hist_low,
max_diff
,
// double hist_high,
num_bins
,
// int num_bins,
debugLevel
);
// int debugLevel)
double
[]
hist2_bkp
=
print_histogram
?
hist2
.
clone
()
:
null
;
(
new
DoubleGaussianBlur
()).
blur1Direction
(
hist2
,
// double [] pixels,
hist2
.
length
,
// int width,
1
,
// int height,
blur_frac
*
num_bins
,
// double sigma,
0.02
,
// double accuracy,
true
);
// boolean xDirection
int
hist_max
=
0
;
for
(
int
i
=
1
;
i
<
hist2
.
length
;
i
++)
{
if
(
hist2
[
i
]
>
hist2
[
hist_max
])
{
hist_max
=
i
;
}
}
if
(
print_histogram
)
{
System
.
out
.
println
(
"blur_frac="
+
blur_frac
+
", max_diff="
+
max_diff
);
System
.
out
.
println
(
"index, histogram,lpf_histogram"
);
for
(
int
i
=
0
;
i
<
hist2
.
length
;
i
++)
{
System
.
out
.
println
(
i
+
", "
+
hist2_bkp
[
i
]+
", "
+
hist2
[
i
]);
}
}
double
val
=
-
max_diff
+
2
*
max_diff
*
hist_max
/
hist2
.
length
;
boolean
[]
mask3
=
new
boolean
[
ref_disparity
.
length
];
double
max_diff2
=
max_diff
*
max_diff
;
double
[]
weights
=
ref_strength
.
clone
();
int
num_good3
=
0
;
for
(
int
i
=
0
;
i
<
mask3
.
length
;
i
++)
{
double
d
=
data_tilted
[
i
]
-
val
;
double
k
=
d
/(
weight_frac
*
max_diff
);
weights
[
i
]
*=
1.0
/(
1.0
+
k
*
k
);
if
(
d
*
d
<
max_diff2
)
{
mask3
[
i
]
=
true
;
num_good3
++;
}
}
if
(
debugLevel
>-
3
)
{
System
.
out
.
println
(
"getPlaneDualPass(): num_good3="
+
num_good3
+
" max_diff="
+
max_diff
);
}
double
[]
tilts_stage3
=
getPlane
(
// {approx2d[0][0], approx2d[0][1], approx2d[0][2], xy0[0], xy0[1]}; // tiltX, tiltY, offset
ref_disparity
,
// final double [] data,
mask3
,
// final boolean [] mask,
weights
,
// final double [] weight,
width
,
// final int width,
xy0
,
// final double [] xy0,
normal_damping
,
// final double normal_damping,
ref_Clt
,
// final QuadCLT dbg_scene,
dbg_title3
);
// String dbg_title)
if
(
tilts_stage3
==
null
)
{
System
.
out
.
println
(
"getPlaneDualPass(): tilts_stage3= null"
);
return
null
;
}
/*
double [] disparity_plane = new double[ref_disparity.length];
for (int i = 0; i < ref_disparity.length; i++) {
int x = i % width;
int y = i / width;
double dx = x-xy0[0];
double dy = y-xy0[1];
disparity_plane[i] = tilts_stage3[0] * dx + tilts_stage3[1] * dy + tilts_stage3[2];
}
return disparity_plane;
*/
return
new
double
[]
{
tilts_stage3
[
0
],
tilts_stage3
[
1
],
tilts_stage3
[
2
],
1.0
*
num_good3
/
ref_disparity
.
length
};
}
public
static
double
[]
rotateRefDisparity
(
final
QuadCLT
ref_Clt
,
double
[]
ref_disparity
,
final
double
[][]
scene_xyzatr
)
{
double
[][]
pXpYD_ground
=
OpticalFlow
.
transformToScenePxPyD
(
null
,
// final Rectangle full_woi_in, // show larger than sensor WOI (or null) IN TILES
ref_disparity
,
// final double [] disparity_ref, // invalid tiles - NaN in disparity
scene_xyzatr
,
// final double [][] scene_xyzatr, // camera center in world coordinates, camera orientation relative to world frame
ref_Clt
);
// final QuadCLT scene_QuadClt)
double
[]
rot_disparity
=
new
double
[
ref_disparity
.
length
];
Arrays
.
fill
(
rot_disparity
,
Double
.
NaN
);
for
(
int
i
=
0
;
i
<
ref_disparity
.
length
;
i
++)
{
double
[]
xyd
=
pXpYD_ground
[
i
];
if
(
xyd
!=
null
)
{
rot_disparity
[
i
]
=
xyd
[
2
];
}
}
return
rot_disparity
;
}
public
static
double
[][]
prepareTerrainRender
(
final
CLTParameters
clt_parameters
,
final
QuadCLT
ref_Clt
,
final
int
debugLevel
)
{
boolean
use_disparity_plane
=
debugLevel
<
1000
;
// until fixed with 3D
GroundPlane
gp
=
ref_Clt
.
getGroundPlane
();
if
(
gp
==
null
)
{
System
.
out
.
println
(
"prepareTerrainRender(): scene "
+
ref_Clt
.
toString
()+
" GroundPlane == null."
);
...
...
@@ -563,18 +837,43 @@ public class GroundPlane {
}
double
[][]
ground_xyzatr
=
ErsCorrection
.
invertXYZATR
(
to_ground_xyzatr
);
// straight down from the camera, then rotated
double
altitude
=
ground_xyzatr
[
0
][
2
];
double
true_disparity
=
ref_Clt
.
getGeometryCorrection
().
getDisparityFromZ
(-
altitude
);
double
corrected_disparity
=
true_disparity
+
ref_Clt
.
getDispInfinityRef
();
double
[]
terrain
=
new
double
[
ref_Clt
.
getTilesX
()*
ref_Clt
.
getTilesY
()];
Arrays
.
fill
(
terrain
,
corrected_disparity
);
int
tilesX
=
ref_Clt
.
getTilesX
();
int
tilesY
=
ref_Clt
.
getTilesY
();
double
[]
terrain_plane
=
new
double
[
tilesX
*
tilesY
];
if
(
use_disparity_plane
)
{
int
[]
xy0
=
{
tilesX
/
2
,
tilesY
/
2
};
double
inf_disparity
=
ref_Clt
.
getDispInfinityRef
();
double
[]
disparity_tilts
=
gp
.
getDisparityTilts
();
for
(
int
i
=
0
;
i
<
terrain_plane
.
length
;
i
++)
{
int
x
=
i
%
tilesX
;
int
y
=
i
/
tilesX
;
double
dx
=
x
-
xy0
[
0
];
double
dy
=
y
-
xy0
[
1
];
terrain_plane
[
i
]
=
disparity_tilts
[
0
]
*
dx
+
disparity_tilts
[
1
]
*
dy
+
disparity_tilts
[
2
]
+
inf_disparity
;
}
}
else
{
Arrays
.
fill
(
terrain_plane
,
corrected_disparity
);
// +0.3); // 260); // 0.256);
}
double
[][]
virt_camera
=
virtCameraFromToGround
(
// virtual to reference
to_ground_xyzatr
);
// double [][] to_ground_xyzatr
double
[][]
stereo_xyzatr
=
ErsCorrection
.
invertXYZATR
(
virt_camera
);
// double [][] center_rot_xyzatr = {new double [3],stereo_xyzatr[1]};
/*
double [] terrain_plane = rotateRefDisparity(
ref_Clt, // final QuadCLT ref_Clt,
terrain_plane, // double [] terrain,
stereo_xyzatr); // virt_camera); // final double [][] scene_xyzatr)
*/
ref_Clt
.
setTerrain
(
clt_parameters
,
// CLTParameters clt_parameters,
terrain
,
// double [] terrain,
debugLevel
);
// int debugLevel)
double
[][]
virt_camera
=
virtCameraFromToGround
(
to_ground_xyzatr
);
// double [][] to_ground_xyzatr
return
virt_camera
;
clt_parameters
,
// CLTParameters clt_parameters,
terrain_plane
,
// double [] terrain,
debugLevel
);
// int debugLevel)
return
stereo_xyzatr
;
}
public
static
double
[][]
virtCameraFromToGround
(
...
...
@@ -583,6 +882,9 @@ public class GroundPlane {
double
[][]
ground_xyzatr
=
ErsCorrection
.
invertXYZATR
(
to_ground_xyzatr
);
// straight down from the camera, then rotated
double
[][]
virtual_camera_from_ground_xyz
=
ErsCorrection
.
invertXYZATR
(
new
double
[][]
{
ground_xyzatr
[
0
],
new
double
[
3
]});
double
[][]
virtual_camera_from_camera
=
ErsCorrection
.
combineXYZATR
(
ground_xyzatr
,
virtual_camera_from_ground_xyz
);
/// double [][] virtual_camera_from_camera = ErsCorrection.combineXYZATR(virtual_camera_from_ground_xyz, ground_xyzatr);
// double [][] virtual_camera_from_camera = ErsCorrection.combineXYZATR(ground_xyzatr, virtual_camera_from_ground_xyz);
virtual_camera_from_camera
[
1
]
=
to_ground_xyzatr
[
1
];
return
virtual_camera_from_camera
;
}
/*
...
...
src/main/java/com/elphel/imagej/tileprocessor/OpticalFlow.java
View file @
b4d24102
...
...
@@ -1771,7 +1771,7 @@ public class OpticalFlow {
// use offsX, offsY as fractional shift and for data interpolation
if
(
offsX
>=
.
5
)
offsX
-=
1.0
;
if
(
offsY
>=
.
5
)
offsY
-=
1.0
;
// flowXY_frac[iMTile] = new double [] {offsX, offsY};
// flowXY_frac[iMTile] = new double [] {offsX, offsY};
flowXY_frac
[
iMTile
]
=
new
double
[]
{-
offsX
,
-
offsY
};
double
min_tX
=
Double
.
NaN
,
max_tX
=
Double
.
NaN
,
min_tY
=
Double
.
NaN
,
max_tY
=
Double
.
NaN
;
for
(
int
iY
=
0
;
iY
<
fullTileSize
;
iY
++)
{
...
...
@@ -1803,7 +1803,7 @@ public class OpticalFlow {
}
int
iwidth
=
imax_tX
-
imin_tX
+
1
;
int
iheight
=
imax_tY
-
imin_tY
+
1
;
//// if ((iwidth <= 0) || (iheight <= 0)) {
//// if ((iwidth <= 0) || (iheight <= 0)) {
if
((
iwidth
<=
1
)
||
(
iheight
<=
1
))
{
System
.
out
.
println
(
"prepareSceneTiles(): iwidth ="
+
iwidth
+
", iheight ="
+
iheight
+
", min_tX="
+
min_tX
+
", imin_tY="
+
imin_tY
+
", max_tX="
+
max_tX
+
", imax_tY="
+
imax_tY
);
continue
;
...
...
@@ -2023,10 +2023,10 @@ public class OpticalFlow {
};
}
ImageDtt
.
startAndJoin
(
threads
);
if
(
debug_level
>
0
)
{
// show debug image
String
title
=
reference_QuadClt
.
getImageName
()
+
"-"
+
scene_QuadClt
.
getImageName
()+
"ref-scene"
;
/*
...
...
@@ -2035,13 +2035,13 @@ public class OpticalFlow {
scene_tiles, // double [][][] source_tiles,
scene_QuadClt, // final QuadCLT qthis,
margin); // final int margin); // extra margins over 16x16 tiles to accommodate distorted destination tiles
*/
*/
showCompareMacroTiles
(
title
,
// String title,
new
double
[][][][]
{
reference_tiles
,
scene_tiles
},
// double [][][][] source_tiles_sets,
scene_QuadClt
,
// final QuadCLT qthis,
margin
);
// final int margin); // extra margins over 16x16 tiles to accommodate distorted destination tiles
String
[]
dbg_titles
=
{
"dX"
,
"dY"
};
String
dbg_title
=
"flowXY_frac"
;
// TODO: Visualize RMS of individual tiles fitting
double
[][]
dbg_img
=
new
double
[
2
][
macroTilesX
*
macroTilesY
];
...
...
@@ -2053,22 +2053,22 @@ public class OpticalFlow {
}
}
if
(
debug_level
>
1
+
0
)
{
ShowDoubleFloatArrays
.
showArrays
(
dbg_img
,
macroTilesX
,
macroTilesY
,
true
,
dbg_title
,
dbg_titles
);
ShowDoubleFloatArrays
.
showArrays
(
dbg_img
,
macroTilesX
,
macroTilesY
,
true
,
dbg_title
,
dbg_titles
);
}
}
// System.out.println("fillTilesNans() DONE.");
// System.out.println("fillTilesNans() DONE.");
return
scene_tiles
;
}
/**
* Prepare reference tiles for correlation with the scene ones. Tiles include 5 layers: disparity,
* strength and 3 average color components (red, blue and green).
...
...
@@ -6450,9 +6450,11 @@ public class OpticalFlow {
// All done with refining orientations and disparities
boolean
air_mode_en
=
clt_parameters
.
imp
.
air_mode_en
;
// fast airplane mode
if
(
air_mode_en
)
{
double
[]
gnd_disp
=
new
double
[
master_CLT
.
getTilesX
()
*
master_CLT
.
getTilesY
()];
GroundPlane
gp
=
GroundPlane
.
getGroundPlane
(
clt_parameters
,
// CLTParameters clt_parameters,
master_CLT
,
// final QuadCLT ref_scene,
gnd_disp
,
// final double [] gnd_disp, // if not null
debugLevel
);
// final int debugLevel)
master_CLT
.
setGroundPlane
(
gp
);
master_CLT
.
saveInterProperties
(
// save properties for interscene processing (extrinsics, ers, ...)
...
...
@@ -6519,6 +6521,7 @@ public class OpticalFlow {
normal_damping
,
// final double normal_damping,
master_CLT
.
getTilesX
(),
// final int width,
good_tiles
,
// final boolean [] good_tiles, // null or boolean[data.length] // should all be false
null
,
// final double [] gnd_disp, // if not null
dbg_title
,
// final String dbg_title,
debugLevel
);
// final int debugLevel)
...
...
@@ -7365,18 +7368,25 @@ public class OpticalFlow {
if
(
export_terrain_sequence
&&
!
clt_parameters
.
imp
.
lock_position
)
{
double
[]
stereo_offset
=
ZERO3
;
double
[]
stereo_atr
=
null
;
double
[][]
g
round_normal_pose
=
GroundPlane
.
prepareTerrainRender
(
double
[][]
g
np
=
GroundPlane
.
prepareTerrainRender
(
clt_parameters
,
// final CLTParameters clt_parameters,
master_CLT
,
// final QuadCLT ref_Clt,
debugLevel
);
// final int debugLevel)
if
(
ground_normal_pose
!=
null
)
{
stereo_offset
=
new
double
[]
{-
ground_normal_pose
[
0
][
0
],-
ground_normal_pose
[
0
][
1
],-
ground_normal_pose
[
0
][
2
]};
stereo_atr
=
ground_normal_pose
[
1
];
double
[][]
ignp
=
null
;
if
(
gnp
!=
null
)
{
ignp
=
ErsCorrection
.
invertXYZATR
(
gnp
);
// stereo_offset = new double [] {-ground_normal_pose[0][0],-ground_normal_pose[0][1],-ground_normal_pose[0][2]};
stereo_offset
=
gnp
[
0
];
// stereo_pose[0];
// stereo_atr = gnp[1]; // stereo_pose[1];
stereo_atr
=
new
double
[]
{-
ignp
[
1
][
0
],-
ignp
[
1
][
1
],-
ignp
[
1
][
2
]};
// stereo_pose[1];
if
(
debugLevel
>
-
3
)
{
System
.
out
.
println
(
"Using airplane mode terrane as a single horizontal plane"
);
System
.
out
.
println
(
"stereo_offset = ["
+
stereo_offset
[
0
]+
", "
+
stereo_offset
[
1
]+
", "
+
stereo_offset
[
2
]+
"]"
);
System
.
out
.
println
(
"stereo_atr = ["
+
stereo_atr
[
0
]+
", "
+
stereo_atr
[
1
]+
", "
+
stereo_atr
[
2
]+
"]"
);
// TODO add provisions to the non-flat terrain -modify terrain slice, keeping ground_normal_pose as a horizontal plane.
System
.
out
.
println
(
"ignp[0] = ["
+
ignp
[
0
][
0
]+
", "
+
ignp
[
0
][
1
]+
", "
+
ignp
[
0
][
2
]+
"]"
);
System
.
out
.
println
(
"ignp[1] = ["
+
ignp
[
1
][
0
]+
", "
+
ignp
[
1
][
1
]+
", "
+
ignp
[
1
][
2
]+
"]"
);
}
}
combo_dsn_final
=
master_CLT
.
restoreComboDSI
(
true
);
if
((
combo_dsn_final
.
length
<=
COMBO_DSN_INDX_TERRAIN
)
||
(
combo_dsn_final
[
COMBO_DSN_INDX_TERRAIN
]
==
null
))
{
...
...
@@ -7384,8 +7394,8 @@ public class OpticalFlow {
}
else
{
double
[]
terrain_disparity
=
combo_dsn_final
[
COMBO_DSN_INDX_TERRAIN
];
/*
String scenes_suffix_test = master_CLT.getImageName()+"-TERRAIN-
TEST
"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
/*
*/
String
scenes_suffix_test
=
master_CLT
.
getImageName
()+
"-TERRAIN-
DISP
"
;
// quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus
imp_terrain_test
=
renderSceneSequence
(
clt_parameters
,
// CLTParameters clt_parameters,
master_CLT
.
hasCenterClt
(),
// boolean mode_cuas,
...
...
@@ -7409,7 +7419,9 @@ public class OpticalFlow {
master_CLT
.
saveImagePlusInModelDirectory
(
null
,
// "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_test
);
// imp_scenes); // ImagePlus imp)
*/
/*
String scenes_suffix = master_CLT.getImageName()+"-TERRAIN"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
...
...
@@ -7422,8 +7434,9 @@ public class OpticalFlow {
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
stereo_offset
,
// ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
stereo_atr
,
// null, // double [] stereo_atr, // offset reference orientation (cuas)
ZERO3, // stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
null, // stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
new double [][] {stereo_offset,stereo_atr}, //
1, // int sensor_mask,
scenes_suffix, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
...
...
@@ -7434,7 +7447,328 @@ public class OpticalFlow {
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain); // imp_scenes); // ImagePlus imp)
String scenes_suffix_mod = master_CLT.getImageName()+"-TERRAIN-MOD"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_mod = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
ZERO3, // new double [] {-ignp[0][0],-ignp[0][1],-ignp[0][2]}, // stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
null, // stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
new double [][] {{-ignp[0][0],-ignp[0][1],-ignp[0][2]},stereo_atr}, // stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
1, // int sensor_mask,
scenes_suffix_mod, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_mod); // imp_scenes); // ImagePlus imp)
String scenes_suffix_mod1 = master_CLT.getImageName()+"-TERRAIN-MOD1"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_mod1 = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
ZERO3, // new double [] {ignp[0][0],-ignp[0][1],ignp[0][2]}, // stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
null, // stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
new double [][] {{ignp[0][0],-ignp[0][1],ignp[0][2]}, stereo_atr},// stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
1, // int sensor_mask,
scenes_suffix_mod1, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_mod1); // imp_scenes); // ImagePlus imp)
String scenes_suffix_mod2 = master_CLT.getImageName()+"-TERRAIN-MOD2"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_mod2 = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
ZERO3, // new double [] {-gnp[0][0], gnp[0][1], -gnp[0][2]}, // stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
null, // stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
new double [][]{{-gnp[0][0], gnp[0][1], -gnp[0][2]},stereo_atr},
1, // int sensor_mask,
scenes_suffix_mod2, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_mod2); // imp_scenes); // ImagePlus imp)
String scenes_suffix_move = master_CLT.getImageName()+"-TERRAIN-MOVE"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_move = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
ZERO3, // stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
null, // stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
new double [][] {stereo_offset, ZERO3},
1, // int sensor_mask,
scenes_suffix_move, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_move); // imp_scenes); // ImagePlus imp)
String scenes_suffix_rot = master_CLT.getImageName()+"-TERRAIN-ROT"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_rot = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
ZERO3, // stereo_offset, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
null, // stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
new double [][] {ZERO3,stereo_atr},
1, // int sensor_mask,
scenes_suffix_rot, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_rot); // imp_scenes); // ImagePlus imp)
*/
/*
String scenes_suffix_inv = master_CLT.getImageName()+"-TERRAIN-INV"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_inv = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
new double [] {-stereo_offset[0],-stereo_offset[1],-stereo_offset[1]}, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
new double [] {-stereo_atr[0], -stereo_atr[1], -stereo_atr[1]}, //stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
1, // int sensor_mask,
scenes_suffix_inv, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_inv); // imp_scenes); // ImagePlus imp)
String scenes_suffix_inv2 = master_CLT.getImageName()+"-TERRAIN-INV2"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_inv2 = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
new double [] {-stereo_offset[0],-stereo_offset[1],-stereo_offset[1]}, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
new double [] { stereo_atr[0], stereo_atr[1], stereo_atr[1]}, //stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
1, // int sensor_mask,
scenes_suffix_inv2, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_inv2); // imp_scenes); // ImagePlus imp)
String scenes_suffix_inv3 = master_CLT.getImageName()+"-TERRAIN-INV3"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_inv3 = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
new double [] { stereo_offset[0], stereo_offset[1], stereo_offset[1]}, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
new double [] {-stereo_atr[0], -stereo_atr[1], -stereo_atr[1]}, //stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
1, // int sensor_mask,
scenes_suffix_inv3, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_inv3); // imp_scenes); // ImagePlus imp)
// ************** same for w/o inversion ****************
String scenes_suffix_ni = master_CLT.getImageName()+"-TERRAIN-NI"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_ni = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
gnp[0], // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
gnp[1], // null, // double [] stereo_atr, // offset reference orientation (cuas)
1, // int sensor_mask,
scenes_suffix_ni, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_ni); // imp_scenes); // ImagePlus imp)
String scenes_suffix_inv_ni = master_CLT.getImageName()+"-TERRAIN-INV_NI"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_inv_ni = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
new double [] {-gnp[0][0], -gnp[0][1], -gnp[0][1]}, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
new double [] {-gnp[1][0], -gnp[1][1], -gnp[1][1]}, //stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
1, // int sensor_mask,
scenes_suffix_inv_ni, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_inv_ni); // imp_scenes); // ImagePlus imp)
String scenes_suffix_inv2_ni = master_CLT.getImageName()+"-TERRAIN-INV2-NI"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_inv2_ni = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
new double [] {-gnp[0][0], -gnp[0][1], -gnp[0][1]}, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
new double [] { gnp[1][0], gnp[1][1], gnp[1][1]}, //stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
1, // int sensor_mask,
scenes_suffix_inv2_ni, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_inv2_ni); // imp_scenes); // ImagePlus imp)
String scenes_suffix_inv3_ni = master_CLT.getImageName()+"-TERRAIN-INV3-NI"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
ImagePlus imp_terrain_inv3_ni = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
master_CLT.hasCenterClt(), // boolean mode_cuas,
false, // boolean um_mono,
clt_parameters.imp.add_average, // boolean insert_average,
null, // float [] average_slice,
clt_parameters.imp.subtract_average, // boolean subtract_average,
clt_parameters.imp.running_average, // int running_average,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
new double [] { gnp[0][0], gnp[0][1], gnp[0][1]}, // ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
new double [] {-gnp[1][0], -gnp[1][1], -gnp[1][1]}, //stereo_atr, // null, // double [] stereo_atr, // offset reference orientation (cuas)
1, // int sensor_mask,
scenes_suffix_inv3_ni, // String suffix,
terrain_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
master_CLT, // ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
master_CLT.saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain_inv3_ni); // imp_scenes); // ImagePlus imp)
*/
}
if
((
combo_dsn_final
.
length
<=
COMBO_DSN_INDX_TERRAIN
)
||
(
combo_dsn_final
[
COMBO_DSN_INDX_TERRAIN
]
==
null
))
{
System
.
out
.
println
(
"No terrain data available"
);
}
else
{
...
...
@@ -8904,12 +9238,53 @@ public class OpticalFlow {
return
min_max_xyzatr
;
}
public
static
ImagePlus
renderSceneSequence
(
CLTParameters
clt_parameters
,
boolean
mode_cuas
,
boolean
um_mono
,
boolean
caculate_average
,
// now only with float pixels
boolean
calculate_average
,
// now only with float pixels
float
[][]
average_slice
,
// [channel][pixel]
boolean
subtract_average
,
int
running_average
,
Rectangle
fov_tiles
,
int
mode3d
,
// for older compatibility mode3d = -1 for RAW, 0 - INF, 1 - FG, 2 BG
boolean
toRGB
,
double
[]
stereo_xyz
,
// offset reference camera {x,y,z}
double
[]
stereo_atr_in
,
// offset reference orientation (cuas)
int
sensor_mask
,
String
suffix_in
,
double
[]
ref_disparity
,
QuadCLT
[]
quadCLTs
,
QuadCLT
ref_scene
,
// int ref_index,
int
threadsMax
,
int
debugLevel
)
{
return
renderSceneSequence
(
clt_parameters
,
// CLTParameters clt_parameters,
mode_cuas
,
// boolean mode_cuas,
um_mono
,
// boolean um_mono,
calculate_average
,
// boolean calculate_average, // now only with float pixels
average_slice
,
//float [][] average_slice, // [channel][pixel]
subtract_average
,
// boolean subtract_average,
running_average
,
// int running_average,
fov_tiles
,
// Rectangle fov_tiles,
mode3d
,
// int mode3d, // for older compatibility mode3d = -1 for RAW, 0 - INF, 1 - FG, 2 BG
toRGB
,
// boolean toRGB,
stereo_xyz
,
// double [] stereo_xyz, // offset reference camera {x,y,z}
stereo_atr_in
,
// double [] stereo_atr_in, // offset reference orientation (cuas)
null
,
// double [][] post_rotate,
sensor_mask
,
// int sensor_mask,
suffix_in
,
// String suffix_in,
ref_disparity
,
// double [] ref_disparity,
quadCLTs
,
// QuadCLT [] quadCLTs,
ref_scene
,
// QuadCLT ref_scene, // int ref_index,
threadsMax
,
// int threadsMax,
debugLevel
);
// int debugLevel)
}
public
static
ImagePlus
renderSceneSequence
(
CLTParameters
clt_parameters
,
boolean
mode_cuas
,
boolean
um_mono
,
boolean
calculate_average
,
// now only with float pixels
float
[][]
average_slice
,
// [channel][pixel]
boolean
subtract_average
,
int
running_average
,
...
...
@@ -8918,6 +9293,7 @@ public class OpticalFlow {
boolean
toRGB
,
double
[]
stereo_xyz
,
// offset reference camera {x,y,z}
double
[]
stereo_atr_in
,
// offset reference orientation (cuas)
double
[][]
post_rotate
,
int
sensor_mask
,
String
suffix_in
,
double
[]
ref_disparity
,
...
...
@@ -8925,21 +9301,21 @@ public class OpticalFlow {
QuadCLT
ref_scene
,
// int ref_index,
int
threadsMax
,
int
debugLevel
)
{
boolean
insert_average
=
((
average_slice
!=
null
)
&&
((
average_slice
[
0
]
!=
null
))
)||
ca
culate_average
;
// now only with float pixels
boolean
insert_average
=
((
average_slice
!=
null
)
&&
((
average_slice
[
0
]
!=
null
))
)||
cal
culate_average
;
// now only with float pixels
boolean
corr_raw_ers
=
true
;
double
[]
stereo_atr
=
(
stereo_atr_in
!=
null
)?
stereo_atr_in:
ZERO3
;
// maybe later play with rotated camera
/// boolean mode_cuas = (stereo_atr[0] != 0) || (stereo_atr[1] != 0) || (stereo_atr[2] != 0);
// boolean um_mono = clt_parameters.imp.um_mono;
double
um_sigma
=
clt_parameters
.
imp
.
um_sigma
;
double
um_weight
=
clt_parameters
.
imp
.
um_weight
;
boolean
mb_en
=
clt_parameters
.
imp
.
mb_en
&&
(
fov_tiles
==
null
)
&&
(
mode3d
>
0
);
double
mb_tau
=
clt_parameters
.
imp
.
mb_tau
;
// 0.008; // time constant, sec
double
mb_max_gain
=
clt_parameters
.
imp
.
mb_max_gain
;
// 5.0; // motion blur maximal gain (if more - move second point more than a pixel
/// insert_average = (mode3d == 1); // merged
insert_average
&=
(
mode3d
==
1
);
// merged
if
(
mode3d
!=
1
)
{
running_average
=
0
;
}
/// boolean mode_cuas = (stereo_atr[0] != 0) || (stereo_atr[1] != 0) || (stereo_atr[2] != 0);
// boolean um_mono = clt_parameters.imp.um_mono;
double
um_sigma
=
clt_parameters
.
imp
.
um_sigma
;
double
um_weight
=
clt_parameters
.
imp
.
um_weight
;
boolean
mb_en
=
clt_parameters
.
imp
.
mb_en
&&
(
fov_tiles
==
null
)
&&
(
mode3d
>
0
);
double
mb_tau
=
clt_parameters
.
imp
.
mb_tau
;
// 0.008; // time constant, sec
double
mb_max_gain
=
clt_parameters
.
imp
.
mb_max_gain
;
// 5.0; // motion blur maximal gain (if more - move second point more than a pixel
/// insert_average = (mode3d == 1); // merged
insert_average
&=
(
mode3d
==
1
);
// merged
if
(
mode3d
!=
1
)
{
running_average
=
0
;
}
final
float
fum_weight
=
(
float
)
um_weight
;
boolean
merge_all
=
clt_parameters
.
imp
.
merge_all
||
!
um_mono
;
// no unsharp mask -> terrain->merge_all
if
(
mode3d
<
1
)
{
...
...
@@ -8960,302 +9336,282 @@ public class OpticalFlow {
}
if
(
mode_cuas
)
{
suffix
+=
"-CUAS"
;
// add properties too? include offsets
/// suffix+=String.format("%6f:%6f:%6f", stereo_atr[0],stereo_atr[1],stereo_atr[2]);
/// suffix+=String.format("%6f:%6f:%6f", stereo_atr[0],stereo_atr[1],stereo_atr[2]);
}
if
(!
mb_en
)
{
suffix
+=
"-NOMB"
;
// no motion blur
}
int
num_sens
=
ref_scene
.
getNumSensors
();
ErsCorrection
ers_reference
=
ref_scene
.
getErsCorrection
();
int
num_used_sens
=
0
;
for
(
int
i
=
0
;
i
<
num_sens
;
i
++)
if
(((
sensor_mask
>>
i
)
&
1
)
!=
0
)
num_used_sens
++;
int
[]
channels
=
new
int
[
num_used_sens
];
int
nch
=
0
;
for
(
int
i
=
0
;
i
<
num_sens
;
i
++)
if
(((
sensor_mask
>>
i
)
&
1
)
!=
0
)
channels
[
nch
++]
=
i
;
ImageStack
stack_scenes
=
null
;
int
dbg_scene
=
-
95
;
double
[][]
ref_pXpYD
;
double
[][]
ref_pXpYD_or_null
=
null
;
// debugging cuas mode keeping old
if
(
mode_cuas
)
{
// && (dbg_scene > 0)) {
int
around
=
2
;
double
around_sigma
=
4.0
;
int
num_virtual_refines
=
2
;
String
debugSuffix
=
null
;
// "virtual";
ref_pXpYD
=
Cuas
.
transformFromVirtual
(
clt_parameters
,
// CLTParameters clt_parameters,
ref_disparity
,
// double [] disparity_ref,
stereo_xyz
,
// final double [] scene_xyz, // camera center in world (reference) coordinates
stereo_atr
,
// final double [] scene_atr, // camera orientation relative to world (reference) frame
ref_scene
,
// final QuadCLT reference_QuadClt,
around
,
// final int around, // 2 search around for interpolation
around_sigma
,
// final double sigma,
num_virtual_refines
,
// final int num_refines,
debugSuffix
);
// final String debugSuffix)
ref_pXpYD_or_null
=
ref_pXpYD
;
ref_scene
.
getErsCorrection
().
setupERS
();
System
.
out
.
println
(
"Calculated virtual_PxPyD"
);
boolean
debug_virtual_PxPyD
=
(
debugLevel
>
1000
);
if
(
debug_virtual_PxPyD
)
{
String
[]
dbg_titles
=
{
"pX"
,
"pY"
,
"D"
};
double
[][]
dbg_pXpYD
=
new
double
[
dbg_titles
.
length
][
ref_pXpYD
.
length
];
for
(
int
i
=
0
;
i
<
dbg_pXpYD
.
length
;
i
++)
Arrays
.
fill
(
dbg_pXpYD
[
i
],
Double
.
NaN
);
for
(
int
i
=
0
;
i
<
ref_pXpYD
.
length
;
i
++)
if
(
ref_pXpYD
[
i
]
!=
null
)
{
for
(
int
j
=
0
;
j
<
ref_pXpYD
[
i
].
length
;
j
++)
dbg_pXpYD
[
j
][
i
]
=
ref_pXpYD
[
i
][
j
];
}
ImagePlus
imp_virtual_PxPyD
=
ShowDoubleFloatArrays
.
makeArrays
(
dbg_pXpYD
,
ref_scene
.
getTilesX
(),
ref_scene
.
getTilesY
(),
ref_scene
.
getImageName
()+
"-virtual_PxPyD"
,
dbg_titles
);
ref_scene
.
saveImagePlusInModelDirectory
(
null
,
// String suffix,
imp_virtual_PxPyD
);
// ImagePlus imp)
}
}
else
{
ref_pXpYD
=
transformToScenePxPyD
(
// now should work with offset ref_scene
fov_tiles
,
// final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
ref_disparity
,
// final double [] disparity_ref, // invalid tiles - NaN in disparity
ZERO3
,
// stereo_xyz, // ZERO3, // final double [] scene_xyz, // camera center in world coordinates
ZERO3
,
// stereo_atr, // ZERO3, // final double [] scene_atr, // camera orientation relative to world frame
ref_scene
,
// final QuadCLT scene_QuadClt,
ref_scene
,
// final QuadCLT reference_QuadClt, // now - may be null - for testing if scene is rotated ref
threadsMax
);
// int threadsMax)
}
for
(
int
nscene
=
0
;
nscene
<
quadCLTs
.
length
;
nscene
++)
if
(
quadCLTs
[
nscene
]
!=
null
){
if
(
nscene
==
dbg_scene
)
{
System
.
out
.
println
(
"renderSceneSequence(): nscene = "
+
nscene
);
}
String
ts
=
quadCLTs
[
nscene
].
getImageName
();
double
[]
scene_xyz
=
ZERO3
;
double
[]
scene_atr
=
ZERO3
;
if
(
quadCLTs
[
nscene
]
!=
ref_scene
)
{
// Check even for raw, so video frames will match in all modes
scene_xyz
=
ers_reference
.
getSceneXYZ
(
ts
);
scene_atr
=
ers_reference
.
getSceneATR
(
ts
);
if
((
scene_atr
==
null
)
||
(
scene_xyz
==
null
))
{
continue
;
}
if
((
mode3d
>=
0
)
||
corr_raw_ers
)
{
double
[]
scene_ers_xyz_dt
=
ers_reference
.
getSceneErsXYZ_dt
(
ts
);
double
[]
scene_ers_atr_dt
=
ers_reference
.
getSceneErsATR_dt
(
ts
);
quadCLTs
[
nscene
].
getErsCorrection
().
setErsDt
(
scene_ers_xyz_dt
,
// double [] ers_xyz_dt,
scene_ers_atr_dt
);
// double [] ers_atr_dt)(ers_scene_original_xyz_dt);
if
(
mode3d
<
0
)
{
// velocities != 0, but offset=0
scene_xyz
=
ZERO3
;
scene_atr
=
ZERO3
;
}
}
else
{
// ugly, restore for raw mode that should not be rotated/shifted
scene_xyz
=
ZERO3
;
scene_atr
=
ZERO3
;
}
}
if
(!
mode_cuas
&&
(
stereo_xyz
!=
null
))
{
// offset all, including reference scene - now always, it is never null
double
[][]
combo_xyzatr
=
ErsCorrection
.
combineXYZATR
(
stereo_xyz
,
// double [] reference_xyz,
stereo_atr
,
// double [] reference_atr,
scene_xyz
,
// double [] scene_xyz,
scene_atr
);
// double [] scene_atr)
scene_xyz
=
combo_xyzatr
[
0
];
scene_atr
=
combo_xyzatr
[
1
];
}
int
sm
=
merge_all
?
-
1
:
sensor_mask
;
ImagePlus
imp_scene
=
null
;
double
[][]
dxyzatr_dt
=
null
;
// should get velocities from HashMap at reference scene from timestamp , not re-calculate.
if
(
mb_en
)
{
dxyzatr_dt
=
new
double
[][]
{
// for all, including ref
quadCLTs
[
nscene
].
getErsCorrection
().
getErsXYZ_dt
(),
quadCLTs
[
nscene
].
getErsCorrection
().
getErsATR_dt
()};
}
if
(
mb_en
&&
(
dxyzatr_dt
!=
null
))
{
double
[][]
motion_blur
=
getMotionBlur
(
ref_scene
,
// quadCLTs[ref_index], // QuadCLT ref_scene,
quadCLTs
[
nscene
],
// QuadCLT scene, // can be the same as ref_scene
ref_pXpYD
,
// double [][] ref_pXpYD, // here it is scene, not reference!
scene_xyz
,
// double [] camera_xyz,
scene_atr
,
// double [] camera_atr,
dxyzatr_dt
[
0
],
// double [] camera_xyz_dt,
dxyzatr_dt
[
1
],
// double [] camera_atr_dt,
0
,
// int shrink_gaps, // will gaps, but not more that grow by this
debugLevel
);
// int debug_level)
imp_scene
=
QuadCLT
.
renderGPUFromDSI
(
sm
,
// final int sensor_mask,
merge_all
,
// final boolean merge_channels,
null
,
// final Rectangle full_woi_in, // show larger than sensor WOI (or null)
clt_parameters
,
// CLTParameters clt_parameters,
ref_disparity
,
// double [] disparity_ref,
ref_pXpYD_or_null
,
// double [][] ref_pXpYD, // alternative to disparity_ref when reference is not uniform
// motion blur compensation
mb_tau
,
// double mb_tau, // 0.008; // time constant, sec
mb_max_gain
,
// double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel
motion_blur
,
// double [][] mb_vectors, //
scene_xyz
,
// final double [] scene_xyz, // camera center in world coordinates
scene_atr
,
// final double [] scene_atr, // camera orientation relative to world frame
quadCLTs
[
nscene
],
// final QuadCLT scene,
ref_scene
,
// quadCLTs[ref_index], // final QuadCLT ref_scene, // now - may be null - for testing if scene is rotated ref
toRGB
,
// final boolean toRGB,
(
toRGB
?
clt_parameters
.
imp
.
show_color_nan
:
clt_parameters
.
imp
.
show_mono_nan
),
""
,
// String suffix, no suffix here
QuadCLT
.
THREADS_MAX
,
// int threadsMax,
debugLevel
);
// int debugLevel)
ErsCorrection
ers_reference
=
ref_scene
.
getErsCorrection
();
int
num_used_sens
=
0
;
for
(
int
i
=
0
;
i
<
num_sens
;
i
++)
if
(((
sensor_mask
>>
i
)
&
1
)
!=
0
)
num_used_sens
++;
int
[]
channels
=
new
int
[
num_used_sens
];
int
nch
=
0
;
for
(
int
i
=
0
;
i
<
num_sens
;
i
++)
if
(((
sensor_mask
>>
i
)
&
1
)
!=
0
)
channels
[
nch
++]
=
i
;
ImageStack
stack_scenes
=
null
;
int
dbg_scene
=
-
95
;
double
[][]
ref_pXpYD
;
double
[][]
ref_pXpYD_or_null
=
null
;
// debugging cuas mode keeping old
if
(
mode_cuas
)
{
// && (dbg_scene > 0)) {
int
around
=
2
;
double
around_sigma
=
4.0
;
int
num_virtual_refines
=
2
;
String
debugSuffix
=
null
;
// "virtual";
ref_pXpYD
=
Cuas
.
transformFromVirtual
(
clt_parameters
,
// CLTParameters clt_parameters,
ref_disparity
,
// double [] disparity_ref,
stereo_xyz
,
// final double [] scene_xyz, // camera center in world (reference) coordinates
stereo_atr
,
// final double [] scene_atr, // camera orientation relative to world (reference) frame
ref_scene
,
// final QuadCLT reference_QuadClt,
around
,
// final int around, // 2 search around for interpolation
around_sigma
,
// final double sigma,
num_virtual_refines
,
// final int num_refines,
debugSuffix
);
// final String debugSuffix)
ref_pXpYD_or_null
=
ref_pXpYD
;
ref_scene
.
getErsCorrection
().
setupERS
();
System
.
out
.
println
(
"Calculated virtual_PxPyD"
);
boolean
debug_virtual_PxPyD
=
(
debugLevel
>
1000
);
if
(
debug_virtual_PxPyD
)
{
String
[]
dbg_titles
=
{
"pX"
,
"pY"
,
"D"
};
double
[][]
dbg_pXpYD
=
new
double
[
dbg_titles
.
length
][
ref_pXpYD
.
length
];
for
(
int
i
=
0
;
i
<
dbg_pXpYD
.
length
;
i
++)
Arrays
.
fill
(
dbg_pXpYD
[
i
],
Double
.
NaN
);
for
(
int
i
=
0
;
i
<
ref_pXpYD
.
length
;
i
++)
if
(
ref_pXpYD
[
i
]
!=
null
)
{
for
(
int
j
=
0
;
j
<
ref_pXpYD
[
i
].
length
;
j
++)
dbg_pXpYD
[
j
][
i
]
=
ref_pXpYD
[
i
][
j
];
}
ImagePlus
imp_virtual_PxPyD
=
ShowDoubleFloatArrays
.
makeArrays
(
dbg_pXpYD
,
ref_scene
.
getTilesX
(),
ref_scene
.
getTilesY
(),
ref_scene
.
getImageName
()+
"-virtual_PxPyD"
,
dbg_titles
);
ref_scene
.
saveImagePlusInModelDirectory
(
null
,
// String suffix,
imp_virtual_PxPyD
);
// ImagePlus imp)
}
}
else
{
ref_pXpYD
=
transformToScenePxPyD
(
// now should work with offset ref_scene
fov_tiles
,
// final Rectangle [] extra_woi, // show larger than sensor WOI (or null)
ref_disparity
,
// final double [] disparity_ref, // invalid tiles - NaN in disparity
ZERO3
,
// stereo_xyz, // ZERO3, // final double [] scene_xyz, // camera center in world coordinates
ZERO3
,
// stereo_atr, // ZERO3, // final double [] scene_atr, // camera orientation relative to world frame
ref_scene
,
// final QuadCLT scene_QuadClt,
ref_scene
,
// final QuadCLT reference_QuadClt, // now - may be null - for testing if scene is rotated ref
threadsMax
);
// int threadsMax)
}
for
(
int
nscene
=
0
;
nscene
<
quadCLTs
.
length
;
nscene
++)
if
(
quadCLTs
[
nscene
]
!=
null
){
if
(
nscene
==
dbg_scene
)
{
System
.
out
.
println
(
"renderSceneSequence(): nscene = "
+
nscene
);
}
String
ts
=
quadCLTs
[
nscene
].
getImageName
();
double
[]
scene_xyz
=
ZERO3
;
double
[]
scene_atr
=
ZERO3
;
if
(
quadCLTs
[
nscene
]
!=
ref_scene
)
{
// Check even for raw, so video frames will match in all modes
scene_xyz
=
ers_reference
.
getSceneXYZ
(
ts
);
scene_atr
=
ers_reference
.
getSceneATR
(
ts
);
if
((
scene_atr
==
null
)
||
(
scene_xyz
==
null
))
{
continue
;
}
if
((
mode3d
>=
0
)
||
corr_raw_ers
)
{
double
[]
scene_ers_xyz_dt
=
ers_reference
.
getSceneErsXYZ_dt
(
ts
);
double
[]
scene_ers_atr_dt
=
ers_reference
.
getSceneErsATR_dt
(
ts
);
quadCLTs
[
nscene
].
getErsCorrection
().
setErsDt
(
scene_ers_xyz_dt
,
// double [] ers_xyz_dt,
scene_ers_atr_dt
);
// double [] ers_atr_dt)(ers_scene_original_xyz_dt);
if
(
mode3d
<
0
)
{
// velocities != 0, but offset=0
scene_xyz
=
ZERO3
;
scene_atr
=
ZERO3
;
}
}
else
{
// ugly, restore for raw mode that should not be rotated/shifted
scene_xyz
=
ZERO3
;
scene_atr
=
ZERO3
;
}
}
if
(!
mode_cuas
&&
(
stereo_xyz
!=
null
))
{
// offset all, including reference scene - now always, it is never null
double
[][]
combo_xyzatr
=
ErsCorrection
.
combineXYZATR
(
stereo_xyz
,
// double [] reference_xyz,
stereo_atr
,
// double [] reference_atr,
scene_xyz
,
// double [] scene_xyz,
scene_atr
);
// double [] scene_atr)
scene_xyz
=
combo_xyzatr
[
0
];
scene_atr
=
combo_xyzatr
[
1
];
}
if
(!
mode_cuas
&&
(
post_rotate
!=
null
))
{
double
[][]
combo_xyzatr
=
ErsCorrection
.
combineXYZATR
(
scene_xyz
,
// double [] reference_xyz,
scene_atr
,
// double [] reference_atr,
post_rotate
[
0
],
// double [] scene_xyz,
post_rotate
[
1
]);
// double [] scene_atr)
scene_xyz
=
combo_xyzatr
[
0
];
scene_atr
=
combo_xyzatr
[
1
];
}
int
sm
=
merge_all
?
-
1
:
sensor_mask
;
ImagePlus
imp_scene
=
null
;
double
[][]
dxyzatr_dt
=
null
;
// should get velocities from HashMap at reference scene from timestamp , not re-calculate.
if
(
mb_en
)
{
dxyzatr_dt
=
new
double
[][]
{
// for all, including ref
quadCLTs
[
nscene
].
getErsCorrection
().
getErsXYZ_dt
(),
quadCLTs
[
nscene
].
getErsCorrection
().
getErsATR_dt
()};
}
}
else
{
imp_scene
=
QuadCLT
.
renderGPUFromDSI
(
sm
,
// final int sensor_mask,
merge_all
,
// final boolean merge_channels,
fov_tiles
,
// testr, // null, // final Rectangle full_woi_in, // show larger than sensor WOI (or null)
clt_parameters
,
// CLTParameters clt_parameters,
ref_disparity
,
// double [] disparity_ref,
ref_pXpYD_or_null
,
// double [][] ref_pXpYD, // alternative to disparity_ref when reference is not uniform
// not used, just as null/not null now
// null means uniform grid, no view transform. even with 0 rot ERS was changing results
((!
corr_raw_ers
&&
(
mode3d
<
0
))?
null
:
scene_xyz
),
// final double [] scene_xyz, // camera center in world coordinates
((!
corr_raw_ers
&&
(
mode3d
<
0
))?
null
:
scene_atr
),
// final double [] scene_atr, // camera orientation relative to world frame
quadCLTs
[
nscene
],
// final QuadCLT scene,
ref_scene
,
// quadCLTs[ref_index], // final QuadCLT ref_scene, // now - may be null - for testing if scene is rotated ref
toRGB
,
// final boolean toRGB,
(
toRGB
?
clt_parameters
.
imp
.
show_color_nan
:
clt_parameters
.
imp
.
show_mono_nan
),
""
,
// String suffix, no suffix here
QuadCLT
.
THREADS_MAX
,
// int threadsMax,
debugLevel
);
// int debugLevel)
}
if
(
stack_scenes
==
null
)
{
stack_scenes
=
new
ImageStack
(
imp_scene
.
getWidth
(),
imp_scene
.
getHeight
());
if
(
insert_average
)
{
for
(
int
i
=
0
;
i
<
channels
.
length
;
i
++)
{
stack_scenes
.
addSlice
(
"average-"
+
i
,
new
float
[((
float
[])
imp_scene
.
getStack
().
getPixels
(
i
+
1
)).
length
]);
}
}
}
for
(
int
i
=
0
;
i
<
channels
.
length
;
i
++)
{
stack_scenes
.
addSlice
(
ts
+
"-"
+
channels
[
i
],
imp_scene
.
getStack
().
getPixels
(
i
+
1
));
}
}
if
(
insert_average
)
{
// calculate average to average slices (one per channel)
if
(
average_slice
!=
null
)
{
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
float
[]
avg_slice
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
);
System
.
arraycopy
(
average_slice
[
nchn
],
0
,
avg_slice
,
0
,
average_slice
[
nchn
].
length
);
}
}
else
{
int
num_scenes
=
(
stack_scenes
.
getSize
()
/
channels
.
length
)
-
1
;
// remove average
// single-threaded
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
float
[]
avg_slice
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
);
int
num_pix
=
avg_slice
.
length
;
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
float
[]
fpixels
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
1
)*
channels
.
length
+
1
);
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
avg_slice
[
npix
]
+=
fpixels
[
npix
];
}
}
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
avg_slice
[
npix
]
/=
num_scenes
;
}
}
}
// seems that fpixels are automatically updated in the images
}
if
(
running_average
>
1
)
{
int
scene_0
=
insert_average
?
1
:
0
;
int
num_scenes
=
(
stack_scenes
.
getSize
()
/
channels
.
length
)
-
scene_0
;
// remove average
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
int
num_pix
=
((
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
)).
length
;
float
[][]
fpix_orig
=
new
float
[
num_scenes
][];
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
fpix_orig
[
nscene
]
=
((
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
scene_0
)*
channels
.
length
+
1
)).
clone
();
}
int
navg
=
0
;
float
[]
fpix_ra
=
new
float
[
num_pix
];
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
int
nscene_sub
=
nscene
-
running_average
;
float
[]
new_fpix
=
fpix_orig
[
nscene
];
// add new to ra
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix_ra
[
npix
]+=
new_fpix
[
npix
];
}
// subtract old (if >=0)
if
(
nscene_sub
>=
0
)
{
float
[]
old_fpix
=
fpix_orig
[
nscene_sub
];
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix_ra
[
npix
]
-=
old_fpix
[
npix
];
}
}
else
{
navg
++;
}
// update image
float
[]
fpix
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
scene_0
)*
channels
.
length
+
1
);
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix
[
npix
]
=
fpix_ra
[
npix
]/
navg
;
}
}
}
}
if
(
subtract_average
&&
insert_average
)
{
int
num_scenes
=
(
stack_scenes
.
getSize
()
/
channels
.
length
)
-
1
;
// remove average
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
float
[]
avg_slice
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
);
int
num_pix
=
avg_slice
.
length
;
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
float
[]
fpix
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
1
)*
channels
.
length
+
1
);
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix
[
npix
]
-=
avg_slice
[
npix
];
}
}
}
}
/*
// Apply unsharp mask here, in parallel
if (um_mono && !toRGB) {
final ImageStack fstack_scenes = stack_scenes;
final int nSlices = fstack_scenes.getSize();
final Thread[] threads = ImageDtt.newThreadArray(QuadCLT.THREADS_MAX);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSlice = ai.getAndIncrement(); nSlice < nSlices; nSlice = ai.getAndIncrement()) {
FloatProcessor fp = (FloatProcessor) fstack_scenes.getProcessor(nSlice+1);
float [] fpixels = (float[]) fstack_scenes.getPixels(nSlice+1);
float [] fpixels_orig = fpixels.clone();
(new GaussianBlur()).blurFloat(
fp, // FloatProcessor ip,
um_sigma, // double sigmaX,
um_sigma, // double sigmaY,
0.01); // double accuracy)
for (int i = 0; i < fpixels.length; i++) {
fpixels[i] = fpixels_orig[i] - fum_weight * fpixels[i];
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
*/
ImagePlus
imp_scenes
=
new
ImagePlus
(
suffix
,
stack_scenes
);
imp_scenes
.
getProcessor
().
resetMinAndMax
();
// Apply unsharp mask here, in parallel
if
(
um_mono
&&
!
toRGB
)
{
imp_scenes
=
applyUM
(
suffix
,
// final String title, // should include -UM...
imp_scenes
,
// final ImagePlus imp,
um_sigma
,
// final double um_sigma,
um_weight
);
// final double um_weight)
}
if
(
mb_en
&&
(
dxyzatr_dt
!=
null
))
{
double
[][]
motion_blur
=
getMotionBlur
(
ref_scene
,
// quadCLTs[ref_index], // QuadCLT ref_scene,
quadCLTs
[
nscene
],
// QuadCLT scene, // can be the same as ref_scene
ref_pXpYD
,
// double [][] ref_pXpYD, // here it is scene, not reference!
scene_xyz
,
// double [] camera_xyz,
scene_atr
,
// double [] camera_atr,
dxyzatr_dt
[
0
],
// double [] camera_xyz_dt,
dxyzatr_dt
[
1
],
// double [] camera_atr_dt,
0
,
// int shrink_gaps, // will gaps, but not more that grow by this
debugLevel
);
// int debug_level)
imp_scene
=
QuadCLT
.
renderGPUFromDSI
(
sm
,
// final int sensor_mask,
merge_all
,
// final boolean merge_channels,
null
,
// final Rectangle full_woi_in, // show larger than sensor WOI (or null)
clt_parameters
,
// CLTParameters clt_parameters,
ref_disparity
,
// double [] disparity_ref,
ref_pXpYD_or_null
,
// double [][] ref_pXpYD, // alternative to disparity_ref when reference is not uniform
// motion blur compensation
mb_tau
,
// double mb_tau, // 0.008; // time constant, sec
mb_max_gain
,
// double mb_max_gain, // 5.0; // motion blur maximal gain (if more - move second point more than a pixel
motion_blur
,
// double [][] mb_vectors, //
scene_xyz
,
// final double [] scene_xyz, // camera center in world coordinates
scene_atr
,
// final double [] scene_atr, // camera orientation relative to world frame
quadCLTs
[
nscene
],
// final QuadCLT scene,
ref_scene
,
// quadCLTs[ref_index], // final QuadCLT ref_scene, // now - may be null - for testing if scene is rotated ref
toRGB
,
// final boolean toRGB,
(
toRGB
?
clt_parameters
.
imp
.
show_color_nan
:
clt_parameters
.
imp
.
show_mono_nan
),
""
,
// String suffix, no suffix here
QuadCLT
.
THREADS_MAX
,
// int threadsMax,
debugLevel
);
// int debugLevel)
}
else
{
imp_scene
=
QuadCLT
.
renderGPUFromDSI
(
sm
,
// final int sensor_mask,
merge_all
,
// final boolean merge_channels,
fov_tiles
,
// testr, // null, // final Rectangle full_woi_in, // show larger than sensor WOI (or null)
clt_parameters
,
// CLTParameters clt_parameters,
ref_disparity
,
// double [] disparity_ref,
ref_pXpYD_or_null
,
// double [][] ref_pXpYD, // alternative to disparity_ref when reference is not uniform
// not used, just as null/not null now
// null means uniform grid, no view transform. even with 0 rot ERS was changing results
((!
corr_raw_ers
&&
(
mode3d
<
0
))?
null
:
scene_xyz
),
// final double [] scene_xyz, // camera center in world coordinates
((!
corr_raw_ers
&&
(
mode3d
<
0
))?
null
:
scene_atr
),
// final double [] scene_atr, // camera orientation relative to world frame
quadCLTs
[
nscene
],
// final QuadCLT scene,
ref_scene
,
// quadCLTs[ref_index], // final QuadCLT ref_scene, // now - may be null - for testing if scene is rotated ref
toRGB
,
// final boolean toRGB,
(
toRGB
?
clt_parameters
.
imp
.
show_color_nan
:
clt_parameters
.
imp
.
show_mono_nan
),
""
,
// String suffix, no suffix here
QuadCLT
.
THREADS_MAX
,
// int threadsMax,
debugLevel
);
// int debugLevel)
}
if
(
stack_scenes
==
null
)
{
stack_scenes
=
new
ImageStack
(
imp_scene
.
getWidth
(),
imp_scene
.
getHeight
());
if
(
insert_average
)
{
for
(
int
i
=
0
;
i
<
channels
.
length
;
i
++)
{
stack_scenes
.
addSlice
(
"average-"
+
i
,
new
float
[((
float
[])
imp_scene
.
getStack
().
getPixels
(
i
+
1
)).
length
]);
}
}
}
for
(
int
i
=
0
;
i
<
channels
.
length
;
i
++)
{
stack_scenes
.
addSlice
(
ts
+
"-"
+
channels
[
i
],
imp_scene
.
getStack
().
getPixels
(
i
+
1
));
}
}
if
(
insert_average
)
{
// calculate average to average slices (one per channel)
if
(
average_slice
!=
null
)
{
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
float
[]
avg_slice
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
);
System
.
arraycopy
(
average_slice
[
nchn
],
0
,
avg_slice
,
0
,
average_slice
[
nchn
].
length
);
}
}
else
{
int
num_scenes
=
(
stack_scenes
.
getSize
()
/
channels
.
length
)
-
1
;
// remove average
// single-threaded
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
float
[]
avg_slice
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
);
int
num_pix
=
avg_slice
.
length
;
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
float
[]
fpixels
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
1
)*
channels
.
length
+
1
);
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
avg_slice
[
npix
]
+=
fpixels
[
npix
];
}
}
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
avg_slice
[
npix
]
/=
num_scenes
;
}
}
}
// seems that fpixels are automatically updated in the images
}
if
(
running_average
>
1
)
{
int
scene_0
=
insert_average
?
1
:
0
;
int
num_scenes
=
(
stack_scenes
.
getSize
()
/
channels
.
length
)
-
scene_0
;
// remove average
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
int
num_pix
=
((
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
)).
length
;
float
[][]
fpix_orig
=
new
float
[
num_scenes
][];
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
fpix_orig
[
nscene
]
=
((
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
scene_0
)*
channels
.
length
+
1
)).
clone
();
}
int
navg
=
0
;
float
[]
fpix_ra
=
new
float
[
num_pix
];
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
int
nscene_sub
=
nscene
-
running_average
;
float
[]
new_fpix
=
fpix_orig
[
nscene
];
// add new to ra
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix_ra
[
npix
]+=
new_fpix
[
npix
];
}
// subtract old (if >=0)
if
(
nscene_sub
>=
0
)
{
float
[]
old_fpix
=
fpix_orig
[
nscene_sub
];
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix_ra
[
npix
]
-=
old_fpix
[
npix
];
}
}
else
{
navg
++;
}
// update image
float
[]
fpix
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
scene_0
)*
channels
.
length
+
1
);
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix
[
npix
]
=
fpix_ra
[
npix
]/
navg
;
}
}
}
}
if
(
subtract_average
&&
insert_average
)
{
int
num_scenes
=
(
stack_scenes
.
getSize
()
/
channels
.
length
)
-
1
;
// remove average
for
(
int
nchn
=
0
;
nchn
<
channels
.
length
;
nchn
++)
{
float
[]
avg_slice
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
1
);
int
num_pix
=
avg_slice
.
length
;
for
(
int
nscene
=
0
;
nscene
<
num_scenes
;
nscene
++)
{
float
[]
fpix
=
(
float
[])
stack_scenes
.
getPixels
(
nchn
+
(
nscene
+
1
)*
channels
.
length
+
1
);
for
(
int
npix
=
0
;
npix
<
num_pix
;
npix
++)
{
fpix
[
npix
]
-=
avg_slice
[
npix
];
}
}
}
}
ImagePlus
imp_scenes
=
new
ImagePlus
(
suffix
,
stack_scenes
);
imp_scenes
.
getProcessor
().
resetMinAndMax
();
// Apply unsharp mask here, in parallel
if
(
um_mono
&&
!
toRGB
)
{
imp_scenes
=
applyUM
(
suffix
,
// final String title, // should include -UM...
imp_scenes
,
// final ImagePlus imp,
um_sigma
,
// final double um_sigma,
um_weight
);
// final double um_weight)
}
return
imp_scenes
;
}
...
...
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