Commit 54256ab9 authored by Andrey Filippov's avatar Andrey Filippov

Adding temperature to sky discrimination

parent 411af03f
...@@ -35,7 +35,8 @@ public class CLTPass3d{ ...@@ -35,7 +35,8 @@ public class CLTPass3d{
private double [][] disparity_sav; // saved disparity private double [][] disparity_sav; // saved disparity
private int [][] tile_op_sav; // saved tile_op private int [][] tile_op_sav; // saved tile_op
public double [][] disparity_map = null; // add 4 layers - worst difference for the port public double [][] disparity_map = null; // add 4 layers - worst difference for the port
public double [] second_max = null; public double [] second_max = null; // second maximal difference between channels
public double [] avg_val = null; // average pixel value for all channels (for cold sky)
public double [][] lazy_eye_data = null; public double [][] lazy_eye_data = null;
public int lma_cluster_size = -1; public int lma_cluster_size = -1;
public boolean [] lazy_eye_force_disparity = null; public boolean [] lazy_eye_force_disparity = null;
...@@ -325,6 +326,16 @@ public class CLTPass3d{ ...@@ -325,6 +326,16 @@ public class CLTPass3d{
for (int i = 0; i< these_diffs.length; i++) these_diffs[i] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]; // IMG_DIFF0_INDEX does not depend on num sensors for (int i = 0; i< these_diffs.length; i++) these_diffs[i] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + i]; // IMG_DIFF0_INDEX does not depend on num sensors
return these_diffs; return these_diffs;
} }
public double [][] getRBGs (){
if (disparity_map == null) return null;
int numcol = tileProcessor.isMonochrome()? 1: 3;
double [][] these_RBGs = new double[numcol*getNumSensors()][];
for (int i = 0; i< these_RBGs.length; i++) these_RBGs[i] = disparity_map[ImageDtt.getImgToneRGB(getNumSensors()) + i]; // IMG_DIFF0_INDEX does not depend on num sensors
return these_RBGs;
}
//getImgToneRGB()
public void resetCalc(){ // only needed if the same task was reused public void resetCalc(){ // only needed if the same task was reused
calc_disparity = null; calc_disparity = null;
...@@ -751,7 +762,6 @@ public class CLTPass3d{ ...@@ -751,7 +762,6 @@ public class CLTPass3d{
public void resetByDiff( public void resetByDiff(
double max_diff, double max_diff,
double mismatch_override) { double mismatch_override) {
setSecondMax();
if ((disparity_map == null) ||(disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX] == null)) { if ((disparity_map == null) ||(disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX] == null)) {
System.out.println("resetByDiff(): strength is null! (no tiles left)"); System.out.println("resetByDiff(): strength is null! (no tiles left)");
return; return;
...@@ -1161,6 +1171,62 @@ public class CLTPass3d{ ...@@ -1161,6 +1171,62 @@ public class CLTPass3d{
return this.second_max; return this.second_max;
} }
public void setAvgVal(double [] avg_val) { // setting "fake" for the non-measurement scan
this.avg_val = avg_val;
}
public void setAvgVal() {
this.avg_val = getLowResChn();
}
public double [] getAvgVal() {
if (this.avg_val == null) {
setAvgVal();
}
return this.avg_val;
}
public double [] getLowResChn ()
{
final int numcolors = tileProcessor.isMonochrome()?1:3;
final double [][] rbg = getRBGs();
if (rbg == null) return null;
for (int i = 0; i < rbg.length; i++) {
if (rbg[i] == null) return null;
}
final double [] col_weights = {0.25,0.25,0.5};
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int num_tiles = tilesX * tilesY;
final double [] lowres = new double [num_tiles];
final boolean [] measured = measuredTiles ();
final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < num_tiles; nTile = ai.getAndIncrement()) {
double d = 0.0;
if (numcolors == 1) {
for (int i = 0; i < rbg.length; i++) {
d += rbg[i][nTile];
}
} else {
for (int i = 0; i < rbg.length; i++) {
int col= i%numcolors;
d += rbg[i][nTile]*col_weights[col];
}
}
lowres[nTile] = d/getNumSensors();
}
}
};
}
ImageDtt.startAndJoin(threads);
return lowres;
}
public double [] getSecondMaxDiff ( public double [] getSecondMaxDiff (
final boolean averaged) final boolean averaged)
{ {
...@@ -1222,6 +1288,9 @@ public class CLTPass3d{ ...@@ -1222,6 +1288,9 @@ public class CLTPass3d{
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
return second_max_averaged; return second_max_averaged;
} }
@Deprecated @Deprecated
public double [] getFOM( public double [] getFOM(
double w_adisp, double w_adisp,
......
...@@ -71,7 +71,7 @@ import ij.plugin.filter.GaussianBlur; ...@@ -71,7 +71,7 @@ import ij.plugin.filter.GaussianBlur;
public class OpticalFlow { public class OpticalFlow {
public static String [] COMBO_DSN_TITLES = {"disp", "strength","disp_lma","num_valid","change", public static String [] COMBO_DSN_TITLES = {"disp", "strength","disp_lma","num_valid","change",
"disp_bg", "strength_bg","disp_lma_bg","change_bg","disp_fg","disp_bg_all"}; "disp_bg", "strength_bg","disp_lma_bg","change_bg","disp_fg","disp_bg_all","blue_sky"};
public static int COMBO_DSN_INDX_DISP = 0; // cumulative disparity (from CM or POLY), FG public static int COMBO_DSN_INDX_DISP = 0; // cumulative disparity (from CM or POLY), FG
public static int COMBO_DSN_INDX_STRENGTH = 1; // strength, FG public static int COMBO_DSN_INDX_STRENGTH = 1; // strength, FG
public static int COMBO_DSN_INDX_LMA = 2; // masked copy from 0 - cumulative disparity public static int COMBO_DSN_INDX_LMA = 2; // masked copy from 0 - cumulative disparity
...@@ -83,8 +83,7 @@ public class OpticalFlow { ...@@ -83,8 +83,7 @@ public class OpticalFlow {
public static int COMBO_DSN_INDX_CHANGE_BG = 8; // increment, BG public static int COMBO_DSN_INDX_CHANGE_BG = 8; // increment, BG
public static int COMBO_DSN_INDX_DISP_FG = 9; // cumulative disparity (from CM or POLY), FG public static int COMBO_DSN_INDX_DISP_FG = 9; // cumulative disparity (from CM or POLY), FG
public static int COMBO_DSN_INDX_DISP_BG_ALL =10; // cumulative BG disparity (Use FG where no BG is available) public static int COMBO_DSN_INDX_DISP_BG_ALL =10; // cumulative BG disparity (Use FG where no BG is available)
public static int COMBO_DSN_INDX_BLUE_SKY = 11; // Detected featureless infinity (sky)
public static double [] ZERO3 = {0.0,0.0,0.0}; public static double [] ZERO3 = {0.0,0.0,0.0};
public static double LINE_ERR = 0.1; public static double LINE_ERR = 0.1;
...@@ -4133,10 +4132,10 @@ public class OpticalFlow { ...@@ -4133,10 +4132,10 @@ public class OpticalFlow {
final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel; // copied from TQ final int debugLevelInner=clt_parameters.batch_run? -2: debugLevel; // copied from TQ
double min_ref_str = clt_parameters.imp.min_ref_str; double min_ref_str = clt_parameters.imp.min_ref_str;
double sky_seed = 7.0; // start with product of strength by diff_second below this
double sky_seed = 7.0; // start with product of strength by diff_second below this double sky_lim = 15.0; // then expand to product of strength by diff_second below this
double sky_lim = 15.0; // then expand to product of strength by diff_second below this double lma_seed= 2.0; // seed - disparity_lma limit double sky_lim = 15.0; // then expand to product of strength by diff_second below this
int sky_shrink = 4; int sky_shrink = 6;
int sky_expand_extra = 0; // 1? int sky_expand_extra = 0; // 1?
boolean [] ref_blue_sky = null; // turn off "lma" in the ML output boolean [] ref_blue_sky = null; // turn off "lma" in the ML output
...@@ -4198,7 +4197,7 @@ public class OpticalFlow { ...@@ -4198,7 +4197,7 @@ public class OpticalFlow {
} }
// 1. Reference scene DSI // 1. Reference scene DSI
while (quadCLTs[ref_index].getBlueSky() == null) { while ((quadCLTs[ref_index] == null) || (quadCLTs[ref_index].getBlueSky() == null)) { // null
if (build_ref_dsi) { if (build_ref_dsi) {
TwoQuadCLT.copyJP4src( // actually there is no sense to process multiple image sets. Combine with other TwoQuadCLT.copyJP4src( // actually there is no sense to process multiple image sets. Combine with other
// processing? // processing?
...@@ -4232,6 +4231,7 @@ public class OpticalFlow { ...@@ -4232,6 +4231,7 @@ public class OpticalFlow {
dsi[TwoQuadCLT.DSI_STRENGTH_AUX] = aux_last_scan[1]; dsi[TwoQuadCLT.DSI_STRENGTH_AUX] = aux_last_scan[1];
dsi[TwoQuadCLT.DSI_DISPARITY_AUX_LMA] = aux_last_scan[2]; dsi[TwoQuadCLT.DSI_DISPARITY_AUX_LMA] = aux_last_scan[2];
dsi[TwoQuadCLT.DSI_SPREAD_AUX] = aux_last_scan[3]; dsi[TwoQuadCLT.DSI_SPREAD_AUX] = aux_last_scan[3];
dsi[TwoQuadCLT.DSI_AVGVAL_AUX] = aux_last_scan[4];
if (quadCLT_main.correctionsParameters.clt_batch_dsi_cm_strength) { if (quadCLT_main.correctionsParameters.clt_batch_dsi_cm_strength) {
CLTPass3d scan = new CLTPass3d(quadCLTs[ref_index].tp); CLTPass3d scan = new CLTPass3d(quadCLTs[ref_index].tp);
...@@ -4258,16 +4258,24 @@ public class OpticalFlow { ...@@ -4258,16 +4258,24 @@ public class OpticalFlow {
} else { } else {
dsi[TwoQuadCLT.DSI_STRENGTH_AUX] = aux_last_scan[1]; dsi[TwoQuadCLT.DSI_STRENGTH_AUX] = aux_last_scan[1];
} }
int tilesX = quadCLTs[ref_index].getTileProcessor().getTilesX(); // int tilesX = quadCLTs[ref_index].getTileProcessor().getTilesX();
quadCLTs[ref_index].setBlueSky ( boolean retry=false;
sky_seed, // double sky_seed, // = 7.0; // start with product of strength by diff_second below this while (true) {
sky_lim, // double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this quadCLTs[ref_index].setBlueSky (
sky_shrink, // int sky_shrink, // = 4; sky_seed, // double sky_seed, // = 7.0; // start with product of strength by diff_second below this
sky_expand_extra, // int sky_expand_extra, // = 100; // 1? lma_seed,
dsi[TwoQuadCLT.DSI_STRENGTH_AUX], // double [] strength, sky_lim, // double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this
dsi[TwoQuadCLT.DSI_SPREAD_AUX], // double [] spread, sky_shrink, // int sky_shrink, // = 4;
debugLevel); // int debugLevel) sky_expand_extra, // int sky_expand_extra, // = 100; // 1?
dsi[TwoQuadCLT.DSI_STRENGTH_AUX], // double [] strength,
dsi[TwoQuadCLT.DSI_SPREAD_AUX], // double [] spread,
dsi[TwoQuadCLT.DSI_DISPARITY_AUX_LMA], // double [] spread,
dsi[TwoQuadCLT.DSI_AVGVAL_AUX],// double [] avg_val,
batch_mode? -1: 1); /// debugLevel); // int debugLevel)
if (!retry) {
break;
}
}
quadCLTs[ref_index].saveDSIAll ( quadCLTs[ref_index].saveDSIAll (
"-DSI_MAIN", // String suffix, // "-DSI_MAIN" "-DSI_MAIN", // String suffix, // "-DSI_MAIN"
dsi); dsi);
...@@ -4298,12 +4306,15 @@ public class OpticalFlow { ...@@ -4298,12 +4306,15 @@ public class OpticalFlow {
System.out.println("DSI_MAIN file has old format and does not have spread data, will recalculate."); System.out.println("DSI_MAIN file has old format and does not have spread data, will recalculate.");
} else { } else {
quadCLTs[ref_index].setBlueSky ( quadCLTs[ref_index].setBlueSky (
sky_seed, // double sky_seed, // = 7.0; // start with product of strength by diff_second below this sky_seed, // double sky_seed, // = 7.0; // start with product of strength by diff_second below this
sky_lim, // double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this lma_seed, // 2.0; // seed - disparity_lma limit
sky_shrink, // int sky_shrink, // = 4; sky_lim, // double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this
sky_expand_extra, // int sky_expand_extra, // = 100; // 1? sky_shrink, // int sky_shrink, // = 4;
dsi[TwoQuadCLT.DSI_STRENGTH_AUX], // double [] strength, sky_expand_extra, // int sky_expand_extra, // = 100; // 1?
dsi[TwoQuadCLT.DSI_SPREAD_AUX], // double [] spread, dsi[TwoQuadCLT.DSI_STRENGTH_AUX], // double [] strength,
dsi[TwoQuadCLT.DSI_SPREAD_AUX], // double [] spread,
dsi[TwoQuadCLT.DSI_DISPARITY_AUX_LMA], //double [] disp_lma,
dsi[TwoQuadCLT.DSI_AVGVAL_AUX],// double [] avg_val,
debugLevel); // int debugLevel) debugLevel); // int debugLevel)
} }
} }
...@@ -4349,7 +4360,7 @@ public class OpticalFlow { ...@@ -4349,7 +4360,7 @@ public class OpticalFlow {
debugLevel-2); debugLevel-2);
} // split cycles to remove output clutter } // split cycles to remove output clutter
int debug_scene = -15; int debug_scene = -15;
boolean debug2 = true; boolean debug2 = false; // true;
boolean [] reliable_ref = null; boolean [] reliable_ref = null;
if (min_ref_str > 0.0) { if (min_ref_str > 0.0) {
reliable_ref = quadCLTs[ref_index].getReliableTiles( // will be null if does not exist. reliable_ref = quadCLTs[ref_index].getReliableTiles( // will be null if does not exist.
...@@ -4556,6 +4567,9 @@ public class OpticalFlow { ...@@ -4556,6 +4567,9 @@ public class OpticalFlow {
} }
if (photo_en && !reuse_video) { if (photo_en && !reuse_video) {
if (debugLevel > -3) {
System.out.println("**** Running photometric equalization *****");
}
if (combo_dsn_final == null) { // always re-read? if (combo_dsn_final == null) { // always re-read?
combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory( // always re-read? combo_dsn_final =quadCLTs[ref_index].readDoubleArrayFromModelDirectory( // always re-read?
"-INTER-INTRA-LMA", // String suffix, "-INTER-INTRA-LMA", // String suffix,
...@@ -7558,7 +7572,8 @@ public class OpticalFlow { ...@@ -7558,7 +7572,8 @@ public class OpticalFlow {
double [] target_disparity_orig = target_disparity.clone(); // will just use NaN/not NaN to restore tasks before second pass with LMA double [] target_disparity_orig = target_disparity.clone(); // will just use NaN/not NaN to restore tasks before second pass with LMA
// double [][] combo_dsn_final = new double [combo_dsn_titles.length][combo_dsn[0].length]; // double [][] combo_dsn_final = new double [combo_dsn_titles.length][combo_dsn[0].length];
double [][] combo_dsn_final = double [][] combo_dsn_final =
new double [(clt_parameters.rig.mll_max_refines_bg > 0)? combo_dsn_titles_full.length:combo_dsn_titles.length][combo_dsn[0].length]; new double [(clt_parameters.rig.mll_max_refines_bg > 0)?
combo_dsn_titles_full.length:combo_dsn_titles.length][combo_dsn[0].length];
combo_dsn_final[COMBO_DSN_INDX_DISP]= combo_dsn[COMBO_DSN_INDX_DISP].clone(); combo_dsn_final[COMBO_DSN_INDX_DISP]= combo_dsn[COMBO_DSN_INDX_DISP].clone();
for (int i = 1; i < combo_dsn_final.length; i++) { for (int i = 1; i < combo_dsn_final.length; i++) {
Arrays.fill(combo_dsn_final[i], Double.NaN); Arrays.fill(combo_dsn_final[i], Double.NaN);
...@@ -7766,6 +7781,17 @@ public class OpticalFlow { ...@@ -7766,6 +7781,17 @@ public class OpticalFlow {
} }
} }
} }
// add blue sky slice
boolean [] blue_sky = ref_scene.getBlueSky();
double [] payload_blue_sky = combo_dsn_final[combo_dsn_final.length-1]; // last slice, length by titles
Arrays.fill(payload_blue_sky,Double.NaN);
if (blue_sky != null) {
for (int i = 0; i < tiles; i++) {
payload_blue_sky[i] = blue_sky[i] ? 1.0 : 0.0;
}
}
// restore modified parameters // restore modified parameters
clt_parameters.img_dtt.bimax_combine_mode = save_bimax_combine_mode; clt_parameters.img_dtt.bimax_combine_mode = save_bimax_combine_mode;
...@@ -8169,15 +8195,26 @@ public class OpticalFlow { ...@@ -8169,15 +8195,26 @@ public class OpticalFlow {
final int tilesY = ref_scene.getTileProcessor().getTilesY(); final int tilesY = ref_scene.getTileProcessor().getTilesY();
final int tiles = tilesX * tilesY; final int tiles = tilesX * tilesY;
boolean [] blue_sky = ref_scene.getBlueSky(); // COMBO_DSN_TITLES
double [] payload_blue_sky = new double[tiles]; // fix for old files
Arrays.fill(payload_blue_sky,Double.NaN); if (combo_dsn_final.length < COMBO_DSN_TITLES.length) {
if (blue_sky != null) { System.out.println("=== Old data format, rebuilding blue sky ===");
for (int i = 0; i < tiles; i++) { double[][] combo_dsn_final_was = combo_dsn_final;
payload_blue_sky[i] = blue_sky[i] ? 1.0 : 0.0; combo_dsn_final = new double[COMBO_DSN_TITLES.length][];
for (int i = 0; i < combo_dsn_final_was.length; i++) {
combo_dsn_final[i] = combo_dsn_final_was[i];
}
for (int i = combo_dsn_final_was.length; i < combo_dsn_final.length; i++) {
combo_dsn_final[i] = new double[tiles];
Arrays.fill(combo_dsn_final[i],Double.NaN);
}
boolean [] blue_sky = ref_scene.getBlueSky();
if (blue_sky != null) {
for (int i = 0; i < tiles; i++) {
combo_dsn_final[COMBO_DSN_INDX_BLUE_SKY][i] = blue_sky[i] ? 1.0 : 0.0;
}
} }
} }
double fat_zero_single = clt_parameters.getGpuFatZero(ref_scene.isMonochrome()); // for single scene double fat_zero_single = clt_parameters.getGpuFatZero(ref_scene.isMonochrome()); // for single scene
ImageDtt image_dtt; ImageDtt image_dtt;
image_dtt = new ImageDtt( image_dtt = new ImageDtt(
...@@ -8252,7 +8289,7 @@ public class OpticalFlow { ...@@ -8252,7 +8289,7 @@ public class OpticalFlow {
combo_dsn_final[COMBO_DSN_INDX_CHANGE_BG], // increment, BG combo_dsn_final[COMBO_DSN_INDX_CHANGE_BG], // increment, BG
combo_dsn_final[COMBO_DSN_INDX_DISP_FG], //cumulative disparity (from CM or POLY), FG == COMBO_DSN_INDX_DISP combo_dsn_final[COMBO_DSN_INDX_DISP_FG], //cumulative disparity (from CM or POLY), FG == COMBO_DSN_INDX_DISP
combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL],// cumulative BG disparity (Use FG where no BG is available) combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL],// cumulative BG disparity (Use FG where no BG is available)
payload_blue_sky // detected featureless sky - 1.0, reliable - 0.0, no data - NaN combo_dsn_final[COMBO_DSN_INDX_BLUE_SKY] // detected featureless sky - 1.0, reliable - 0.0, no data - NaN
}; };
for (int i = 0; i < payload.length; i++) { for (int i = 0; i < payload.length; i++) {
...@@ -8382,7 +8419,7 @@ public class OpticalFlow { ...@@ -8382,7 +8419,7 @@ public class OpticalFlow {
combo_dsn_final[COMBO_DSN_INDX_CHANGE_BG], // increment, BG combo_dsn_final[COMBO_DSN_INDX_CHANGE_BG], // increment, BG
combo_dsn_final[COMBO_DSN_INDX_DISP_FG], // cumulative disparity (from CM or POLY), FG == COMBO_DSN_INDX_DISP combo_dsn_final[COMBO_DSN_INDX_DISP_FG], // cumulative disparity (from CM or POLY), FG == COMBO_DSN_INDX_DISP
combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL],// cumulative BG disparity (Use FG where no BG is available) combo_dsn_final[COMBO_DSN_INDX_DISP_BG_ALL],// cumulative BG disparity (Use FG where no BG is available)
payload_blue_sky // detected featureless sky - 1.0, reliable - 0.0, no data - NaN combo_dsn_final[COMBO_DSN_INDX_BLUE_SKY] // detected featureless sky - 1.0, reliable - 0.0, no data - NaN
}; };
for (int i = 0; i < payload.length; i++) { for (int i = 0; i < payload.length; i++) {
add_tile_meta( add_tile_meta(
......
...@@ -422,6 +422,7 @@ public class QuadCLTCPU { ...@@ -422,6 +422,7 @@ public class QuadCLTCPU {
* and so on. * and so on.
* *
* @param sky_seed minimal value of strength*spread to seed sky areas * @param sky_seed minimal value of strength*spread to seed sky areas
* @param disparity_seed maximal disparity to seed sky areas (not needed for expand)
* @param sky_lim maximal value of strength*spread over which sky area will * @param sky_lim maximal value of strength*spread over which sky area will
* be expanded * be expanded
* @param sky_shrink shrink initial sky area to eliminate small non-sky areas. * @param sky_shrink shrink initial sky area to eliminate small non-sky areas.
...@@ -431,31 +432,138 @@ public class QuadCLTCPU { ...@@ -431,31 +432,138 @@ public class QuadCLTCPU {
* @param spread 1d array of tile spreads (second maximal difference from * @param spread 1d array of tile spreads (second maximal difference from
* of per-sensor pixel values in a tile to their average * of per-sensor pixel values in a tile to their average
* in scanline order. * in scanline order.
* @param disparity 1d array of tile disparity in scanline order
* @param debugLevel debug level * @param debugLevel debug level
* @return boolean 1d array of the pixels belonging to the blue sky. * @return boolean 1d array of the pixels belonging to the blue sky.
*/ */
public static boolean [] getBlueSky ( public static boolean [] getBlueSky (
double sky_seed, // = 7.0; // start with product of strength by diff_second below this double sky_seed, // = 7.0; // start with product of strength by diff_second below this
double disparity_seed, // 2.0; // seed - disparity_lma limit
double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this
int sky_shrink, // = 4; int sky_shrink, // = 4;
int sky_expand_extra, // = 100; // 1? int sky_expand_extra, // = 100; // 1?
int width, int width,
double [] strength, double [] strength,
double [] spread, double [] spread,
double [] disparity,
double [] avg_val,
int debugLevel) { int debugLevel) {
if ((strength == null) || (spread==null)) { if ((strength == null) || (spread==null)) {
return null; return null;
} }
double [] temp_scales = null;
double cold_scale = 0.2; // <=1.0. 1.0 - disables temperature dependence
double cold_frac = 0.005; // this and lower will scale fom by cold_scale
double hot_frac = 0.9; // this and above will scale fom by 1.0
double min_strength = 0.08;
int seed_rows = 5; // sky should appear in this top rows
int num_bins = 1000;
if (avg_val != null) {
double min_temp = Double.NaN, max_temp=Double.NaN, avg_temp = 0;
int num_def = 0;
for (int i = 0; i < avg_val.length; i++) {
double d = avg_val[i];
if (!Double.isNaN(d)) {
if (!(d <= max_temp)) max_temp = d;
if (!(d >= min_temp)) min_temp = d;
avg_temp += d;
num_def++;
}
}
if (num_def > 00) {
avg_temp/= num_def;
// build a histogram from min to max
double [] hist = new double [num_bins];
double kbin = num_bins/(max_temp - min_temp);
int maxbin = num_bins - 1;
double s = 1.0/num_def;
for (int i = 0; i < avg_val.length; i++) {
double d = avg_val[i];
if (!Double.isNaN(d)) {
int ibin = (int) Math.floor((d - min_temp) * kbin);
if (ibin <0) ibin = 0;
else if (ibin > maxbin) {
ibin = maxbin;
}
hist[ibin] += s;
}
}
for (int i = 1; i < num_bins; i++) { // make cumulative, last is 1.0;
hist[i] += hist[i-1];
}
double temp_cold = min_temp;
double temp_hot = max_temp;
for (int i = 0; i < num_bins; i++) {
if (hist[i] > cold_frac) {
double d = hist[i];
double d_prev = (i > 0)? hist[ i-1 ]: 0.0;
double b_cold = (cold_frac-d_prev)/(d-d_prev) + i;
temp_cold = min_temp + b_cold* (max_temp - min_temp) / num_bins;
break;
}
}
for (int i = num_bins - 2; i >= 0; i--) {
if (hist[i] <= hot_frac) {
double d = hist[i];
double d_next = hist[i+1];
double b_hot = (hot_frac - d)/(d_next - d) + i;
temp_hot = min_temp + b_hot* (max_temp - min_temp) / num_bins;
break;
}
}
temp_scales = new double[avg_val.length];
Arrays.fill(temp_scales, Double.NaN);
double kscale = (1.0 - cold_scale)/(temp_hot - temp_cold);
for (int i = 0; i < avg_val.length; i++) {
double d = avg_val[i];
if (!Double.isNaN(d)) {
if (d < temp_cold) {
temp_scales[i] = cold_scale;
} else if (d > temp_hot) {
temp_scales[i] = 1.0;
} else {
temp_scales[i] = cold_scale + (d - temp_cold) * kscale;
}
}
}
}
}
String [] dbg_in_titles = {"fom", "strength", "spread", "disparity", "avg_val", "tscale"};
String [] dbg_titles = {"sky", "seed", "max", "shrank"}; String [] dbg_titles = {"sky", "seed", "max", "shrank"};
if (debugLevel>0) {
double [] fom = new double[strength.length];
for (int i = 0; i < fom.length; i++) {
fom[i] = Math.max(strength[i], min_strength) * spread[i] * temp_scales[i];
}
(new ShowDoubleFloatArrays()).showArrays(
new double[][] {fom, strength, spread, disparity, avg_val, temp_scales},
width,
fom.length/width,
true,
"sky_input",
dbg_in_titles); // dsrbg_titles);
}
double [][] dbg_img = (debugLevel>0) ? new double [dbg_titles.length][strength.length]:null; double [][] dbg_img = (debugLevel>0) ? new double [dbg_titles.length][strength.length]:null;
boolean [] sky_tiles = new boolean [strength.length]; boolean [] sky_tiles = new boolean [strength.length];
boolean [] prohibit_tiles = new boolean [strength.length]; boolean [] prohibit_tiles = new boolean [strength.length];
for (int i = 0; i < sky_tiles.length; i++) { for (int i = 0; i < sky_tiles.length; i++) {
double d = strength[i] * spread[i]; double d = Math.max(strength[i], min_strength) * spread[i];
sky_tiles[i] = (d < sky_seed); if (temp_scales != null) {
d *=temp_scales[i];
}
prohibit_tiles[i] = (d >= sky_lim); prohibit_tiles[i] = (d >= sky_lim);
int row = i/width;
// sky_tiles[i] = (row < seed_rows) && (d < sky_seed) && !(disparity[i] > disparity_seed);
sky_tiles[i] = (d < sky_seed) && !(disparity[i] > disparity_seed);
} }
//seed_rows
if (dbg_img != null) { if (dbg_img != null) {
for (int i = 0; i < sky_tiles.length; i++) { for (int i = 0; i < sky_tiles.length; i++) {
dbg_img[1][i] = sky_tiles[i]? 1 : 0; dbg_img[1][i] = sky_tiles[i]? 1 : 0;
...@@ -467,6 +575,9 @@ public class QuadCLTCPU { ...@@ -467,6 +575,9 @@ public class QuadCLTCPU {
sky_shrink, // int shrink, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more sky_shrink, // int shrink, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
sky_tiles, // boolean [] tiles, sky_tiles, // boolean [] tiles,
null); // boolean [] prohibit) null); // boolean [] prohibit)
if (seed_rows > 0) {
Arrays.fill(sky_tiles, seed_rows * width, sky_tiles.length, false);
}
if (dbg_img != null) { if (dbg_img != null) {
for (int i = 0; i < sky_tiles.length; i++) { for (int i = 0; i < sky_tiles.length; i++) {
dbg_img[3][i] = sky_tiles[i]? 1 : 0; dbg_img[3][i] = sky_tiles[i]? 1 : 0;
...@@ -510,21 +621,27 @@ public class QuadCLTCPU { ...@@ -510,21 +621,27 @@ public class QuadCLTCPU {
public void setBlueSky ( public void setBlueSky (
double sky_seed, // = 7.0; // start with product of strength by diff_second below this double sky_seed, // = 7.0; // start with product of strength by diff_second below this
double lma_seed, // 2.0; // seed - disparity_lma limit
double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this double sky_lim, // = 15.0; // then expand to product of strength by diff_second below this
int sky_shrink, // = 4; int sky_shrink, // = 4;
int sky_expand_extra, // = 100; // 1? int sky_expand_extra, // = 100; // 1?
double [] strength, double [] strength,
double [] spread, double [] spread,
double [] disp_lma,
double [] avg_val,
int debugLevel) { int debugLevel) {
int width = tp.getTilesX(); int width = tp.getTilesX();
this.blue_sky = getBlueSky ( this.blue_sky = getBlueSky (
sky_seed, // = 7.0; // start with product of strength by diff_second below this sky_seed, // = 7.0; // start with product of strength by diff_second below this
lma_seed, // 2.0; // seed - disparity_lma limit
sky_lim, // = 15.0; // then expand to product of strength by diff_second below this sky_lim, // = 15.0; // then expand to product of strength by diff_second below this
sky_shrink, // = 4; sky_shrink, // = 4;
sky_expand_extra, // = 100; // 1? sky_expand_extra, // = 100; // 1?
width, width,
strength, strength,
spread, spread,
disp_lma,
avg_val,
debugLevel); debugLevel);
} }
...@@ -1020,7 +1137,7 @@ public class QuadCLTCPU { ...@@ -1020,7 +1137,7 @@ public class QuadCLTCPU {
} }
// try to restore DSI generated from interscene if available, if not use single-scene -DSI_MAIN // try to restore DSI generated from interscene if available, if not use single-scene -DSI_MAIN
int dsi_result = -1; int dsi_result = -1;
double [][] dsi_tmp = new double [11][]; double [][] dsi_tmp = new double [OpticalFlow.COMBO_DSN_TITLES.length][];
for (int i = 0; i <DSI_SUFFIXES.length; i++) { for (int i = 0; i <DSI_SUFFIXES.length; i++) {
dsi_result =restoreDSI( dsi_result =restoreDSI(
DSI_SUFFIXES[i], DSI_SUFFIXES[i],
...@@ -9722,6 +9839,7 @@ public class QuadCLTCPU { ...@@ -9722,6 +9839,7 @@ public class QuadCLTCPU {
} }
// copy second_max from the BG pass to the last one (to be used) // copy second_max from the BG pass to the last one (to be used)
tp.clt_3d_passes.get(tp.clt_3d_passes.size()-1).setSecondMax(tp.clt_3d_passes.get(bg_pass).getSecondMax()); tp.clt_3d_passes.get(tp.clt_3d_passes.size()-1).setSecondMax(tp.clt_3d_passes.get(bg_pass).getSecondMax());
tp.clt_3d_passes.get(tp.clt_3d_passes.size()-1).setAvgVal(tp.clt_3d_passes.get(bg_pass).getAvgVal());
///// Refining after all added - end ///// Refining after all added - end
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();
System.out.println("preExpandCLTQuad3d(): processing finished at "+ System.out.println("preExpandCLTQuad3d(): processing finished at "+
...@@ -13965,6 +14083,8 @@ public class QuadCLTCPU { ...@@ -13965,6 +14083,8 @@ public class QuadCLTCPU {
scan.is_measured = true; // but no disparity map/textures scan.is_measured = true; // but no disparity map/textures
scan.is_combo = false; scan.is_combo = false;
scan.has_lma = null; scan.has_lma = null;
scan.setAvgVal();
scan.setSecondMax(); // always needed even with max_chn_diff==0 as it is exported in a file
if (max_chn_diff > 0 ) { if (max_chn_diff > 0 ) {
scan.resetByDiff( scan.resetByDiff(
max_chn_diff, max_chn_diff,
......
...@@ -343,10 +343,11 @@ public class TileNeibs{ ...@@ -343,10 +343,11 @@ public class TileNeibs{
boolean [] src_tiles = tiles.clone(); // just in case boolean [] src_tiles = tiles.clone(); // just in case
// grow // grow
boolean hor = true; boolean hor = true;
int num_prev = 0;
for (; grow > 0; grow--){ for (; grow > 0; grow--){
boolean single = (grow ==1) && hor; boolean single = (grow ==1) && hor;
src_tiles = tiles.clone(); src_tiles = tiles.clone();
int num_new = 0; int num_new = 1; // as if previous pass was successful
if (hor){ if (hor){
for (int tileY = 0; tileY < sizeY; tileY++){ for (int tileY = 0; tileY < sizeY; tileY++){
for (int tileX = 0; tileX < (sizeX - 1); tileX++){ for (int tileX = 0; tileX < (sizeX - 1); tileX++){
...@@ -394,9 +395,10 @@ public class TileNeibs{ ...@@ -394,9 +395,10 @@ public class TileNeibs{
} }
} }
hor = !hor; hor = !hor;
if (num_new == 0){ if ((num_new == 0) && (num_prev == 0)){
break; break;
} }
num_prev = num_new;
} }
} }
......
...@@ -3913,11 +3913,12 @@ ImageDtt.startAndJoin(threads); ...@@ -3913,11 +3913,12 @@ ImageDtt.startAndJoin(threads);
double [] disparity = scan.getDisparity(use_final?0:1); double [] disparity = scan.getDisparity(use_final?0:1);
double [] disparityLMA = scan.getDisparityLMA(); double [] disparityLMA = scan.getDisparityLMA();
double [] second_max_bg = scan.getSecondMax(); double [] second_max_bg = scan.getSecondMax();
double [] avg_val = scan.getAvgVal();
if (!use_final) { if (!use_final) {
scan.setStrength(null); scan.setStrength(null);
} }
double [] strength = scan.getStrength(); double [] strength = scan.getStrength();
return new double [][] {disparity, strength, disparityLMA,second_max_bg}; // second maximal difference between channels in BG return new double [][] {disparity, strength, disparityLMA,second_max_bg, avg_val}; // second maximal difference between channels in BG
} }
// TODO: update for variable length // TODO: update for variable length
......
...@@ -82,6 +82,8 @@ public class TwoQuadCLT { ...@@ -82,6 +82,8 @@ public class TwoQuadCLT {
public static int DSI_STRENGTH_RIG = 8; public static int DSI_STRENGTH_RIG = 8;
public static int DSI_SPREAD_MAIN = 9; public static int DSI_SPREAD_MAIN = 9;
public static int DSI_SPREAD_AUX = 10; public static int DSI_SPREAD_AUX = 10;
public static int DSI_AVGVAL_MAIN = 11;
public static int DSI_AVGVAL_AUX = 12;
public static String DSI_COMBO_SUFFIX = "-DSI_COMBO"; public static String DSI_COMBO_SUFFIX = "-DSI_COMBO";
public static String DSI_MAIN_SUFFIX = "-DSI_MAIN"; public static String DSI_MAIN_SUFFIX = "-DSI_MAIN";
...@@ -97,7 +99,9 @@ public class TwoQuadCLT { ...@@ -97,7 +99,9 @@ public class TwoQuadCLT {
"strength_aux", "strength_aux",
"strength_rig", "strength_rig",
"spread_main", "spread_main",
"spread_aux"}; "spread_aux",
"avgval_main",
"avgval_aux"};
public long startTime; // start of batch processing public long startTime; // start of batch processing
public long startSetTime; // start of set processing public long startSetTime; // start of set processing
......
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