Commit 273e58c7 authored by Andrey Filippov's avatar Andrey Filippov

next snapshot

parent be7873b5
......@@ -494,23 +494,40 @@ public class OrangeTest {
40.0, // final double max,
true); // final boolean invert)
{
String title_combo_dt = title_space_conv+"_weights-pre_"+time_rt_scales[time_deriv_patt][0]+"-"+time_rt_scales[time_deriv_patt][1]+(use_max?"-max":"-avg");
String title_weights_pre = title_space_conv+"_weights-pre_"+time_rt_scales[time_deriv_patt][0]+"-"+time_rt_scales[time_deriv_patt][1]+(use_max?"-max":"-avg");
ShowDoubleFloatArrays.showArrays(
weights_pre,
width,
height,
true,
title_combo_dt+".tiff",
title_weights_pre+".tiff",
titles_spatial);
}
int weights_pre_shrink = 2;
int weights_pre_min_seq = 5;
double [][] weights_pre_filt = weightsShrink(
weights_pre, // final double [][] weights_in, // same data convolved with different kernels, may have NaNs
width, // final int width,
weights_pre_shrink, // final int shrink,
weights_pre_min_seq); // final int min_frames)
{
String title_weights_pre_filt = title_space_conv+"_weights-pre-filt_"+time_rt_scales[time_deriv_patt][0]+"-"+time_rt_scales[time_deriv_patt][1]+(use_max?"-max":"-avg");
ShowDoubleFloatArrays.showArrays(
weights_pre_filt,
width,
height,
true,
title_weights_pre_filt+".tiff",
titles_spatial);
}
boolean no_gradients = true; // do not consider patterns 0..3 - when they are near the edge they are too strong
double [][] integrated_pattern_strengths = integrateSpaceConv(
space_conv, // final double [][][][] space_conv,
weights_pre); // final double [][] weights) // may be null [num_images][num_pixels]
weights_pre_filt, // weights_pre); // final double [][] weights) // may be null [num_images][num_pixels]
false); // no_gradients) ; // final boolean no_gradients) { // do not consider patterns 0..3 - when they are near the edge they are too strong
if (show_best && show_pre_best) {
ShowDoubleFloatArrays.showArrays(
integrated_pattern_strengths,
......@@ -521,7 +538,8 @@ public class OrangeTest {
titles_pattern);
}
int [][] best_pattern_frame = getBestConv(
space_conv); // final double [][][][] space_conv)
space_conv, // final double [][][][] space_conv)
no_gradients) ; // final boolean no_gradients) { // do not consider patterns 0..3 - when they are near the edge they are too strong
int patt_mod = 18; // = 54;
if (show_best && show_pre_best) {
double [][] best_pattern_frame_dbg = new double [best_pattern_frame.length][best_pattern_frame[0].length];
......@@ -541,7 +559,9 @@ public class OrangeTest {
}
int [] best_pattern = getBestIntegratedConv(
integrated_pattern_strengths); // double [][] integ_conv){ // [kern][pix]
integrated_pattern_strengths, // double [][] integ_conv){ // [kern][pix]
no_gradients) ; // final boolean no_gradients) { // do not consider patterns 0..3 - when they are near the edge they are too strong
if (show_best && show_pre_best) {
double [] best_pattern_dbg = new double [best_pattern.length];
Arrays.fill(best_pattern_dbg,Double.NaN);
......@@ -1065,7 +1085,8 @@ public class OrangeTest {
public static int [][] getBestConv(
final double [][][][] space_conv){
final double [][][][] space_conv,
final boolean no_gradients) { // do not consider patterns 0..3 - when they are near the edge they are too strong
final int num_scales = space_conv.length; // may be modified, if there will be extra layers
final int num_kernels = space_conv[0].length; // may be modified, if there will be extra layers
final int num_images = space_conv[0][0].length;
......@@ -1087,7 +1108,8 @@ public class OrangeTest {
int best_sgn = 0;
double bestv = 0;
for (int nscale = 0; nscale < num_scales; nscale++) {
for (int dir = 0; dir < num_kernels; dir++) {
int low_dir = no_gradients? 4: 0;
for (int dir = low_dir; dir < num_kernels; dir++) {
double d = space_conv[nscale][dir][fimg][ipix];
if (!Double.isNaN(d)) {
for (int sgn = 0; sgn<2; sgn++) {
......@@ -1119,7 +1141,8 @@ public class OrangeTest {
public static double [][] integrateSpaceConv(
final double [][][][] space_conv,
final double [][] weights) { // may be null [num_images][num_pixels]
final double [][] weights, // may be null [num_images][num_pixels]
final boolean no_gradients) { // do not consider patterns 0..3 - when they are near the edge they are too strong
final int num_scales = space_conv.length; // may be modified, if there will be extra layers
final int num_kernels = space_conv[0].length; // may be modified, if there will be extra layers
final int num_images = space_conv[0][0].length;
......@@ -1139,7 +1162,8 @@ public class OrangeTest {
double w = (weights == null)? 1.0 : weights[fimg][ipix] ;
sum_weights[ipix] += w;
for (int nscale = 0; nscale < num_scales; nscale++) {
for (int dir = 0; dir < num_kernels; dir++) {
int low_dir = no_gradients? 4: 0;
for (int dir = low_dir; dir < num_kernels; dir++) {
double d = space_conv[nscale][dir][fimg][ipix];
if (!Double.isNaN(d)) {
for (int sgn = 0; sgn<num_signs; sgn++) {
......@@ -1190,7 +1214,9 @@ public class OrangeTest {
}
public static int [] getBestIntegratedConv(
double [][] integ_conv){ // [kern][pix]
double [][] integ_conv, // [kern][pix]
final boolean no_gradients) { // do not consider patterns 0..3 - when they are near the edge they are too strong
final int dbg_pix = 135+160*640;
final int num_patt = integ_conv.length;
final int num_pixels = integ_conv[0].length;
final int [] best_index = new int [num_pixels];
......@@ -1200,9 +1226,16 @@ public class OrangeTest {
threads[ithread] = new Thread() {
public void run() {
for (int ipix = ai.getAndIncrement(); ipix < num_pixels; ipix = ai.getAndIncrement()) {
if (ipix == dbg_pix) {
System.out.println("ipix="+ipix);
}
int best_patt = -1;
double bestv = 0;
for (int ipatt = 0; ipatt < num_patt; ipatt++) {
int npatt = ipatt % 9;
if (no_gradients && npatt < 4) {
continue;
}
double d = integ_conv[ipatt][ipix];
if (d > bestv) { // cares of NaN
bestv = d;
......@@ -1617,6 +1650,89 @@ public class OrangeTest {
return weights;
}
public static double [][] weightsShrink(
final double [][] weights_in, // same data convolved with different kernels, may have NaNs
final int width,
final int shrink,
final int min_frames) {
final int num_frames = weights_in.length;
final int num_pixels = weights_in[0].length;
final double [][] weights = new double[num_frames][num_pixels];
final Thread[] threads = ImageDtt.newThreadArray();
final boolean [][] mask = new boolean [num_frames][num_pixels];
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
TileNeibs tn = new TileNeibs(width, num_pixels/width);
public void run() {
for (int nframe = ai.getAndIncrement(); nframe < num_frames; nframe = ai.getAndIncrement()){ // if (w_frame[ipix] > min){
System.arraycopy(weights_in[nframe], 0, weights[nframe], 0, num_pixels);
if (shrink > 0) {
for (int ipix=0; ipix < num_pixels; ipix++) {
mask[nframe][ipix] = !(weights_in[nframe][ipix] > 0);
}
tn. growSelection(
shrink, // int grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
mask[nframe], // final boolean [] tiles,
null); // final boolean [] prohibit)
}
}
}
};
}
ImageDtt.startAndJoin(threads);
// filter by sequence length
if (min_frames > 0) {
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int [] seq_length = new int [num_frames];
for (int ipix = ai.getAndIncrement(); ipix < num_pixels; ipix = ai.getAndIncrement()){
int prev = 0;
for (int nframe = 0; nframe < num_frames; nframe++) {
if (weights_in[nframe][ipix] > 0) {
seq_length[nframe] = ++prev;
} else {
prev = 0;
seq_length[nframe] = 0;
}
}
for (int nframe = num_frames-1; nframe >= 0; nframe--) {
if (seq_length[nframe] > 0) {
if (seq_length[nframe] < min_frames) {
for (int i = 0; i < seq_length[nframe]; i++) {
mask[nframe-i][ipix] = true;
}
}
nframe -= seq_length[nframe]-1; // will be decrease by one more
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nframe = ai.getAndIncrement(); nframe < num_frames; nframe = ai.getAndIncrement()){ // if (w_frame[ipix] > min){
for (int ipix=0; ipix < num_pixels; ipix++) {
if (mask[nframe][ipix]) {
weights[nframe][ipix] = 0;
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return weights;
}
......
......@@ -6313,6 +6313,30 @@ public class OpticalFlow {
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_terrain); // 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 {
double [] elevation_disparity = combo_dsn_final[COMBO_DSN_INDX_DISP];
String scenes_suffix = quadCLTs[quadCLTs.length-1].getImageName()+"-ELEVATION";
ImagePlus imp_elevation = renderSceneSequence(
clt_parameters, // CLTParameters clt_parameters,
false, // boolean um_mono,
null, // Rectangle fov_tiles,
1, // int mode3d,
false, // boolean toRGB,
ZERO3, // double [] stereo_offset, // offset reference camera {x,y,z}
1, // int sensor_mask,
scenes_suffix, // String suffix,
elevation_disparity, // selected_disparity, // double [] ref_disparity,
quadCLTs, // QuadCLT [] quadCLTs,
ref_index, // int ref_index,
threadsMax, // int threadsMax,
debugLevel); // int debugLevel);
quadCLTs[ref_index].saveImagePlusInModelDirectory(
null, // "GPU-SHIFTED-D"+clt_parameters.disparity, // String suffix,
imp_elevation); // imp_scenes); // ImagePlus imp)
}
}
if (export_images) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment