Commit 8991226b authored by Andrey Filippov's avatar Andrey Filippov

Tweaking software to handle more precise disparity measurements

parent 957badd3
......@@ -6,7 +6,7 @@
** Copyright (C) 2017 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
**
** CLTPass3d.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
......@@ -28,9 +28,9 @@ import java.util.concurrent.atomic.AtomicInteger;
public class CLTPass3d{
// static double max_overexposed = 0.8; // TODO: make parameter
public double [][] disparity; // per-tile disparity set for the pass[tileY][tileX]
public double [][] disparity; // per-tile disparity set for the pass[tileY][tileX]
public int [][] tile_op; // what was done in the current pass
private double [][] disparity_sav; // saved disaprity
private double [][] disparity_sav; // saved disaprity
private int [][] tile_op_sav; // saved tile_op
public double [][] disparity_map = null; // add 4 layers - worst difference for the port
double [] calc_disparity = null; // composite disparity, calculated from "disparity", and "disparity_map" fields
......@@ -45,7 +45,7 @@ public class CLTPass3d{
// Bg disparity & strength is calculated from the supertiles and used instead of the tile disparity if it is too weak. Assuming, that
// foreground features should have good correlation details, and if the tile does not nhave them it likely belongs to the background.
// calculate disparity and strength from the (lapped) supertiles, using lowest allowed (>= minBgDisparity) disparity histogram maximums
// of the supertiles this tile belongs to
// of the supertiles this tile belongs to
private double minBgDisparity = 0.0;
private double minBgFract = 0.0; // Use the lowest maximum if the strength strength (of all maximus >= minBgDisparity)
// exceeds minBgFract, otherwise proceed to the next one (and accumulate strength)
......@@ -61,14 +61,14 @@ public class CLTPass3d{
public Rectangle texture_bounds;
public int dbg_index;
public int disparity_index = ImageDtt.DISPARITY_INDEX_CM; // may also be ImageDtt.DISPARITY_INDEX_POLY
SuperTiles superTiles = null;
TileProcessor tileProcessor;
public CLTPass3d (TileProcessor tileProcessor)
{
this.tileProcessor = tileProcessor;
}
public CLTPass3d (TileProcessor tileProcessor, int mode)
{
this.tileProcessor = tileProcessor;
......@@ -77,7 +77,7 @@ public class CLTPass3d{
tile_op = new int [tileProcessor.getTilesY()][tileProcessor.getTilesX()];
disparity = new double [tileProcessor.getTilesY()][tileProcessor.getTilesX()];
break;
}
}
......@@ -85,7 +85,7 @@ public class CLTPass3d{
{
return this.tileProcessor;
}
public double [][][][] getTextureTiles()
{
return texture_tiles;
......@@ -121,7 +121,7 @@ public class CLTPass3d{
if (n < 3) scales[n] = 1.0/255.0; // R,B,G
else if (n == 3) scales[n] = 1.0; //alpha
else if (n < 8) scales[n] = 1.0; // ports 0..3
else scales[n] = 1.0/255.0; // RBG rms, in 1/255 units, but small
else scales[n] = 1.0/255.0; // RBG rms, in 1/255 units, but small
}
double [][] tileTones = new double [num_layers][numTiles];
for (int ty = 0; ty < tilesY; ty++ ) if (texture_tiles[ty] != null){
......@@ -140,7 +140,7 @@ public class CLTPass3d{
}
return tileTones;
}
public String getTextureName()
{
if (texture != null) {
......@@ -149,8 +149,8 @@ public class CLTPass3d{
return "null-texture-name";
}
}
// Will not work if texture is disabled
public void updateSelection(){ // add updating border tiles?
int tilesX = tileProcessor.getTilesX();
......@@ -165,34 +165,34 @@ public class CLTPass3d{
if (maxY < ty) maxY = ty;
if (minY > ty) minY = ty;
} else {
selected[ty * tilesX + tx] = false; // may be omitted
selected[ty * tilesX + tx] = false; // may be omitted
}
}
texture_bounds = new Rectangle(minX, minY, maxX - minX +1, maxY - minY +1 );
}
public Rectangle getTextureBounds(){
return texture_bounds;
}
public boolean isProcessed(){
return calc_disparity != null;
return calc_disparity != null;
}
public boolean isMeasured(){
return is_measured;
// return (disparity_map != null) && (disparity != null); // disparity == null for composite scans
}
public boolean isCombo(){
return is_combo;
return is_combo;
}
/**
* Called after each measurement
*/
public void resetProcessed(){
public void resetProcessed(){
if (disparity_map != null) fixNaNDisparity();
calc_disparity = null; // composite disparity, calculated from "disparity", and "disparity_map" fields
calc_disparity_hor = null; // composite disparity, calculated from "disparity", and "disparity_map" fields
......@@ -206,8 +206,8 @@ public class CLTPass3d{
// border_tiles = null; // these are border tiles, zero out alpha
// selected = null; // which tiles are selected for this layer
superTiles = null;
}
/**
* Get FPGA-calculated per-tile maximal differences between the particular image and the average one.
......@@ -220,24 +220,24 @@ public class CLTPass3d{
for (int i = 0; i< ImageDtt.QUAD; i++) these_diffs[i] = disparity_map[ImageDtt.IMG_DIFF0_INDEX + i];
return these_diffs;
}
public void resetCalc(){ // only needed if the same task was reused
calc_disparity = null;
strength = null;
strength_hor = null;
strength_vert = null;
superTiles = null;
}
public boolean [] getSelected(){
return selected;
}
public boolean [] getBorderTiles(){
return this.border_tiles;
}
public void setSelected (boolean [] selected) {
this.selected = selected;
}
......@@ -245,7 +245,7 @@ public class CLTPass3d{
this.border_tiles = border_tiles;
}
public void fixNaNDisparity()
{
fixNaNDisparity(
......@@ -261,8 +261,8 @@ public class CLTPass3d{
disparity_map[ImageDtt.DISPARITY_INDEX_VERT],
disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH]);
}
public void fixNaNDisparity(
boolean [] select, // which tiles to correct (null - all)
double [] disparity,
......@@ -316,7 +316,7 @@ public class CLTPass3d{
}
}
}
public double [] combineHorVertStrength(
boolean combineHor,
boolean combineVert)
......@@ -336,7 +336,7 @@ public class CLTPass3d{
}
return strength;
}
public double [] combineSuper(
boolean updateStrength, // use ST strength if true, keep original (update disparity only) if false
double stStrengthScale,
......@@ -347,7 +347,7 @@ public class CLTPass3d{
double [] strength = getStrength();
double [] disparity = getDisparity(0);
for (int i = 0; i < disparity.length; i++){
if (strength[i] < useSuper) {
disparity[i] = bgTileDisparity[i];
......@@ -360,12 +360,12 @@ public class CLTPass3d{
public double [] getOverexposedFraction(){
return (disparity_map != null)? disparity_map[ImageDtt.OVEREXPOSED] : null;
}
/**
* Returns per-tile correlation "strength". Initially - copy of the FPGA-generated data, but later may be replaced by a combination
* of the combined data from 4-sensor (4-pair) correlation and horizontal/vertical pairs only to improve detection of vertical/
* horizontal features
* horizontal features
* @return line-scan array of per-tile correlation strength by reference (not a copy), so it can be modified
*/
public double [] getStrength(){
......@@ -375,13 +375,13 @@ public class CLTPass3d{
strength = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX].clone();
if (trustedCorrelation > 0.0){
for (int i = 0; i < strength.length; i++){
if (Math.abs(disparity_map[disparity_index][i]) > trustedCorrelation) strength[i] = 0.0; // too far
if (Math.abs(disparity_map[disparity_index][i]) > trustedCorrelation) strength[i] = 0.0; // too far
}
}
double [] overexposed = disparity_map[ImageDtt.OVEREXPOSED];
if ((max_overexposure > 0.0) && (overexposed != null)){
for (int i = 0; i < strength.length; i++){
if (overexposed[i] > max_overexposure) strength[i] = 0.0; // too overexposed
if (overexposed[i] > max_overexposure) strength[i] = 0.0; // too overexposed
}
}
}
......@@ -405,16 +405,16 @@ public class CLTPass3d{
strength_hor = disparity_map[ImageDtt.DISPARITY_INDEX_HOR_STRENGTH].clone();
if (trustedCorrelation > 0.0){
for (int i = 0; i < strength_hor.length; i++){
if (Math.abs(disparity_map[ImageDtt.DISPARITY_INDEX_HOR][i]) > trustedCorrelation) strength_hor[i] = 0.0; // too far
if (Math.abs(disparity_map[ImageDtt.DISPARITY_INDEX_HOR][i]) > trustedCorrelation) strength_hor[i] = 0.0; // too far
}
}
double [] overexposed = disparity_map[ImageDtt.OVEREXPOSED];
if ((max_overexposure > 0.0) && (overexposed != null)){
for (int i = 0; i < strength_hor.length; i++){
if (overexposed[i] > max_overexposure) strength_hor[i] = 0.0; // too overexposed
if (overexposed[i] > max_overexposure) strength_hor[i] = 0.0; // too overexposed
}
}
}
return strength_hor;
}
......@@ -429,25 +429,25 @@ public class CLTPass3d{
strength_vert = disparity_map[ImageDtt.DISPARITY_INDEX_VERT_STRENGTH].clone();
if (trustedCorrelation > 0.0){
for (int i = 0; i < strength_vert.length; i++){
if (Math.abs(disparity_map[ImageDtt.DISPARITY_INDEX_VERT][i]) > trustedCorrelation) strength_vert[i] = 0.0; // too far
if (Math.abs(disparity_map[ImageDtt.DISPARITY_INDEX_VERT][i]) > trustedCorrelation) strength_vert[i] = 0.0; // too far
}
}
double [] overexposed = disparity_map[ImageDtt.OVEREXPOSED];
if ((max_overexposure > 0.0) && (overexposed != null)){
for (int i = 0; i < strength_hor.length; i++){
if (overexposed[i] > max_overexposure) strength_vert[i] = 0.0; // too overexposed
if (overexposed[i] > max_overexposure) strength_vert[i] = 0.0; // too overexposed
}
}
}
return strength_vert;
}
/**
* Get Get combine per-tile disparity values from correlation combined with pre-programmed initial disparity shift.
* @return line-scan array of per-tile disparity by reference (not a copy), so it can be modified
*/
public double [] getDisparity() // get calculated combo disparity
{
return getDisparity(0);
......@@ -472,7 +472,7 @@ public class CLTPass3d{
return calc_disparity_combo;
}
}
// methods to "condition" measured disparity values
public void conditionDisparity()
{
......@@ -500,7 +500,7 @@ public class CLTPass3d{
}
calc_disparity_combo = calc_disparity.clone(); // for now - just clone, can be modified separately and combined with hor/vert
}
/**
* Replaces current combo disparity for tiles that are weak and do not have any neighbor within disparity range from this one
* @param selection optional boolean mask of tiles to use/update
......@@ -509,8 +509,8 @@ public class CLTPass3d{
* @param disparityFar minimal acceptable disparity for weak tiles
* @param disparityNear maximal acceptable disparity for weak tiles
* @return mask of weak (replaced) tiles
*
* Replace weak by a weighted average of non-weak. If there are none - use weak ones, including this one too.
*
* Replace weak by a weighted average of non-weak. If there are none - use weak ones, including this one too.
*/
public boolean[] replaceWeakOutlayers(
final boolean [] selection,
......@@ -524,14 +524,14 @@ public class CLTPass3d{
{
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int nTiles = tilesX*tilesY;
final boolean [] weakOutlayers = new boolean [nTiles];
int [] dirs8 = {-tilesX, -tilesX + 1, 1, tilesX +1, tilesX, tilesX - 1, -1, -tilesX - 1};
final int [] dirs = dirs8;
final double [] disparity = getDisparity(0);
final double [] strength = getStrength();
final double absMinDisparity = 0.5 * disparityFar; // adjust? below this is definitely wrong (weak)
final double absMinDisparity = 0.5 * disparityFar; // adjust? below this is definitely wrong (weak)
final double absMaxDisparity = 1.5 * disparityNear; // change?
final int dbg_nTile = (debugLevel > 0) ? 43493: -1; // x=77,y=134; // 42228; // x = 108, y = 130 46462; // 41545;
final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax);
......@@ -539,6 +539,7 @@ public class CLTPass3d{
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 < nTiles; nTile = ai.getAndIncrement()) {
if (((strength[nTile] < weakStrength) ||
......@@ -589,14 +590,15 @@ public class CLTPass3d{
}
}
};
}
}
ImageDtt.startAndJoin(threads);
// second pass - replace outliers
final double [] src_disparity = disparity.clone();
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
if (nTile == dbg_nTile){
......@@ -609,7 +611,7 @@ public class CLTPass3d{
if (!weakOutlayers[nTile1] && ((selection == null) || selection[nTile1 ]) ) {
double w = strength[nTile1];
sw += w;
sd += w * src_disparity[nTile1];
sd += w * src_disparity[nTile1];
}
}
if (sw == 0) { // Nothing strong around - repeat with weak and this one too.
......@@ -624,7 +626,7 @@ public class CLTPass3d{
w = strength[nTile1];
if (!Double.isNaN( src_disparity[nTile1])) {
sw += w;
sd += w * src_disparity[nTile1];
sd += w * src_disparity[nTile1];
}
}
}
......@@ -636,11 +638,11 @@ public class CLTPass3d{
}
}
};
}
}
ImageDtt.startAndJoin(threads);
return weakOutlayers;
}
public boolean [] getUntestedBackgroundBorder (
final boolean [] known,
final double [] disparity,
......@@ -656,6 +658,7 @@ public class CLTPass3d{
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()) {
if (known[nTile]){
......@@ -673,11 +676,11 @@ public class CLTPass3d{
}
}
};
}
}
ImageDtt.startAndJoin(threads);
return untested_bgnd;
}
public boolean [] measuredTiles ()
{
final int tilesX = tileProcessor.getTilesX();
......@@ -688,6 +691,7 @@ public class CLTPass3d{
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()) {
int tX = nTile % tilesX;
......@@ -696,11 +700,11 @@ public class CLTPass3d{
}
}
};
}
}
ImageDtt.startAndJoin(threads);
return measured;
}
public void saveTileOpDisparity()
{
disparity_sav =disparity.clone();
......@@ -718,7 +722,7 @@ public class CLTPass3d{
restoreTileOpDisparity();
saveTileOpDisparity();
}
public int setTileOpDisparity(
boolean [] selection,
double [] disparity)
......@@ -731,7 +735,7 @@ public class CLTPass3d{
selection, // boolean [] selection,
disparity); // double [] disparity)
}
public int setTileOpDisparity(
int tile_op,
boolean [] selection,
......@@ -765,7 +769,7 @@ public class CLTPass3d{
}
return num_op_tiles;
}
/**
* Set next measurement disparity from last calculated
*/
......@@ -773,14 +777,14 @@ public class CLTPass3d{
{
setTileOpDisparity(null, getDisparity(0));
}
public double [] getSecondMaxDiff (
final boolean averaged)
{
final double [][] diffs = getDiffs();
if (diffs == null) return null;
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int num_tiles = tilesX * tilesY;
......@@ -790,6 +794,7 @@ public class CLTPass3d{
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()) {
int imax1 = 0;
......@@ -804,7 +809,7 @@ public class CLTPass3d{
}
}
};
}
}
ImageDtt.startAndJoin(threads);
if (!averaged) return second_max;
final TileNeibs tnImage = new TileNeibs(tilesX, tilesY); // num_tiles/tilesX);
......@@ -813,6 +818,7 @@ public class CLTPass3d{
ai.set(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()) if (measured[nTile]) {
double sw = 0.0;
......@@ -824,17 +830,17 @@ public class CLTPass3d{
swd += dir_weights[dir] * second_max[nTile1] ;
}
}
second_max_averaged[nTile] = swd/sw;
second_max_averaged[nTile] = swd/sw;
}
}
};
}
}
ImageDtt.startAndJoin(threads);
return second_max_averaged;
}
// same, but 2 steps around
public boolean [] getUntestedBackgroundBorder2 (
final boolean [] known,
......@@ -851,6 +857,7 @@ public class CLTPass3d{
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()) {
if (known[nTile]){
......@@ -868,21 +875,21 @@ public class CLTPass3d{
}
}
};
}
}
ImageDtt.startAndJoin(threads);
return untested_bgnd;
}
public SuperTiles getSuperTiles()
{
return this.superTiles;
}
public SuperTiles setSuperTiles(
double step_near,
double step_far,
......@@ -897,6 +904,15 @@ public class CLTPass3d{
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
double max_abs_tilt, // 2.0; // pix per tile
double max_rel_tilt, // 0.2; // (pix / disparity) per tile
double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
int measSel)
{
this.superTiles = new SuperTiles(
......@@ -914,18 +930,35 @@ public class CLTPass3d{
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // final boolean smplWnd, // use window functions for the samples
max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
far_power, // 1.0; // Raise disparity to this power before averaging for far objects
// true, // boolean null_if_none,
measSel);
return this.superTiles;
}
public double [] showDisparityHistogram(
double [][][][] disparity_strength, // pre-calculated disparity/strength [per super-tile][per-measurement layer][2][tiles] or null
boolean [][] tile_sel, // null or per-measurement layer, per-tile selection. For each layer null - do not use, {} - use all
boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, // use window functions for the samples
double max_abs_tilt, // 2.0; // pix per tile
double max_rel_tilt, // 0.2; // (pix / disparity) per tile
double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
int measSel)
{
if (this.superTiles == null){
......@@ -940,6 +973,15 @@ public class CLTPass3d{
smplNum, // = 3; // Number after removing worst
smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // use window functions for the samples
max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
far_power, // 1.0; // Raise disparity to this power before averaging for far objects
measSel);
}
......@@ -958,13 +1000,13 @@ public class CLTPass3d{
return rslt;
}
return getBgDispStrength(
this.minBgDisparity,
this.minBgDisparity,
this.minBgFract);
}
public double [][] getBgDispStrength(
final double minBgDisparity,
final double minBgDisparity,
final double minBgFract)
{
if (superTiles == null){
......@@ -972,7 +1014,7 @@ public class CLTPass3d{
}
if ((minBgDisparity != this.minBgDisparity) || (minBgFract != this.minBgFract)){
this.minBgDisparity = minBgDisparity;
this.minBgFract = minBgFract;
this.minBgFract = minBgFract;
superTiles.bgDisparity = null; // per super-tile
superTiles.bgStrength = null; // per super-tile
bgTileDisparity = null; // per tile
......@@ -980,7 +1022,7 @@ public class CLTPass3d{
}
if ((superTiles.bgDisparity == null) || (superTiles.bgStrength == null)){
if (superTiles.getBgDispStrength(
minBgDisparity,
minBgDisparity,
minBgFract) == null) {
superTiles.bgDisparity = null; // per super-tile
superTiles.bgStrength = null; // per super-tile
......@@ -989,7 +1031,7 @@ public class CLTPass3d{
return null; // failed
}
// now lap-combine supertiles, get this.* from superTiles.*
double [][] bgTileDispStrength = superTiles.getBgTileDispStrength();
bgTileDisparity = bgTileDispStrength[0];
bgTileStrength = bgTileDispStrength[1];
......@@ -997,7 +1039,7 @@ public class CLTPass3d{
double [][] rslt = {bgTileDisparity,bgTileStrength};
return rslt;
}
public double [] getBgDisparity(){
return bgTileDisparity;
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -572,6 +572,7 @@ private Panel panel1,
addButton("Infinity offset", panelClt3, color_configure);
addButton("Setup CLT Batch parameters", panelClt3, color_configure);
addButton("CLT batch process", panelClt3, color_process);
addButton("CM Test", panelClt3, color_stop);
// addButton("JTabbed", panelClt3, color_stop);
// addButton("Demo", panelClt3, color_process);
......@@ -3752,7 +3753,7 @@ private Panel panel1,
/* ======================================================================== */
} else if (label.equals("Setup CLT parameters")) {
CLT_PARAMETERS.showDialog();
CLT_PARAMETERS.showJDialog();
return;
/* ======================================================================== */
} else if (label.equals("Setup CLT")) {
......@@ -3769,7 +3770,7 @@ private Panel panel1,
} else if (label.equals("Select CLT image")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
ImagePlus imp_src = WindowManager.getCurrentImage();
if (imp_src==null){
......@@ -3802,7 +3803,7 @@ private Panel panel1,
} else if (label.equals("Select second CLT image")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
ImagePlus imp_src = WindowManager.getCurrentImage();
if (imp_src==null){
......@@ -3837,7 +3838,7 @@ private Panel panel1,
} else if (label.equals("CLT stack")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
if (DBG_IMP == null) {
ImagePlus imp_src = WindowManager.getCurrentImage();
......@@ -3937,7 +3938,7 @@ private Panel panel1,
System.out.println("--- Free memory="+runtime.freeMemory()+" (of "+runtime.totalMemory()+")");
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
// process selected image stack
if (DBG_IMP == null) {
ImagePlus imp_src = WindowManager.getCurrentImage();
......@@ -4191,7 +4192,7 @@ private Panel panel1,
//==============================================================================
} else if (label.equals("Create CLT kernels")) {
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
PROPERTIES,
......@@ -4250,7 +4251,7 @@ private Panel panel1,
}
} else if (label.equals("Read CLT kernels")) {
if (!CLT_PARAMETERS.showDialog()) return;
if (!CLT_PARAMETERS.showJDialog()) return;
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
PROPERTIES,
......@@ -5161,6 +5162,9 @@ private Panel panel1,
PROPERTIES);
}
return;
} else if (label.equals("CM Test")) {
cm_test();
return;
//JTabbedTest
// End of buttons code
......@@ -5185,7 +5189,136 @@ private Panel panel1,
return true;
}
public boolean cm_test() {
double hsize_x = 1.5;
double hsize_y = 1.5;
int steps = 20;
double sigma = 0.0;
boolean separable = true; // false;
double pwr = 1.0;
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set CLT parameters",400,300);
gd.addNumericField("Half size X", hsize_x, 6, 8, "pix",
"Correlation maximum half width in disparity direction");
gd.addNumericField("Half size Y", hsize_y, 6, 8, "pix",
"Correlation maximum half width in orthogonal direction");
gd.addNumericField("Number of steps", steps, 0, 6, "",
"Number of steps to subdivide [0,1) half-interval");
gd.addNumericField("Low pass sigma", sigma, 3, 6, "pix",
"Correlation maximum half width in orthogonal direction");
gd.addCheckbox ("X/Y separable", separable);
gd.addNumericField("Value power", pwr, 6, 8, "",
"Raise values to this power before calculating CM");
gd.showDialog();
if (gd.wasCanceled()) return false;
DoubleGaussianBlur gb=new DoubleGaussianBlur();
hsize_x = gd.getNextNumber();
hsize_y = gd.getNextNumber();
steps = (int) gd.getNextNumber();
sigma = gd.getNextNumber();
separable = gd.getNextBoolean();
pwr = gd.getNextNumber();
int size_x = 2*((int) Math.round(hsize_x+ 2*sigma+1)) + 1;
int size_y = 2*((int) Math.round(hsize_y+ 2*sigma+1)) + 1;
System.out.println("size_x="+size_x+", size_y="+size_y+" sigma = "+sigma+" separable "+separable+" pwr=" + pwr);
String [] titles = new String[steps];
double [][] data = new double [steps][size_x*size_y];
for (int i = 0;i<steps; i++) {
double dx = 1.0*i/steps;
titles[i] = IJ.d2s(dx,3);
for (int iy = 0; iy < size_y; iy++) {
double y = (iy - (size_y - 1)/2)/hsize_y;
if ((y >= -1.0) && (y <= 1.0)) {
double ay = separable ? (0.5*(Math.cos(y * Math.PI) + 1.0)):1.0;
for (int ix = 0; ix < size_x; ix++) {
double x = (ix - (size_x - 1)/2 - dx)/hsize_x;
double r = separable? Math.abs(x) : Math.sqrt(x*x+y*y);
// if ((r >= -hsize_x) && (x <= hsize_x)) {
if (r <= 1.0) {
double ax = 0.5*(Math.cos(r * Math.PI) + 1.0);
data[i][iy*size_x+ix] = ax*ay;
}
}
}
}
}
(new showDoubleFloatArrays()) .showArrays(data, size_x, size_y, true, "pre-gauss", titles);
if (sigma > 0.0) {
for (int i = 0; i < steps; i++) {
gb.blurDouble(
data[i],
size_x,
size_y,
sigma,
sigma,
0.01);
}
(new showDoubleFloatArrays()) .showArrays(data, size_x, size_y, true, "blured", titles);
}
double [] cm_x = new double [steps];
for (int i = 0;i<steps; i++) {
double s0=0,sx=0;
for (int iy = 0; iy < size_y; iy++ ) {
for (int ix = 0; ix < size_x; ix++ ) {
double d = Math.pow(data[i][iy*size_y+ix], pwr);
s0+=d;
sx+=ix*d;
}
}
cm_x[i] = sx/s0 - (size_x - 1)/2;
}
for (int i = 0;i <= steps/2; i++) {
double dx = 1.0*i/steps;
System.out.println(String.format("%3d %8.5f %8.5f %8.5f %8.5f %8.5f", i, dx, cm_x[i],cm_x[i]-dx, cm_x[i]/(dx+0.00000001), dx/(cm_x[i]+0.00000001)));
}
return true;
/*
double s0 = 0, sx=0,sy = 0;
for (int y = - iradius ; y <= iradius; y++){
int dataY = icenter[1] +y;
if ((dataY >= 0) && (dataY < data_size)){
int y2 = y*y;
for (int x = - iradius ; x <= iradius; x++){
int dataX = icenter[0] +x;
double r2 = y2 + x * x;
// if ((dataX >= 0) && (dataX < data_size) && (square || ((y2 + x * x) <= ir2))){
if ((dataX >= 0) && (dataX < data_size) && (square || (r2 <= ir2))){
// double w = max_corr_double? (1.0 - r2/ir2):1.0;
// double d = w* data[dataY * data_size + dataX];
double d = data[dataY * data_size + dataX];
s0 += d;
sx += d * dataX;
sy += d * dataY;
}
}
}
}
double [] rslt = {sx / s0, sy / s0};
*
* showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(double_stack, imp_src.getWidth(), imp_src.getHeight(), true, "BEFORE_CLT_PROC", rbg_titles);
*
gb.blurDouble(
results[indexVar],
size,
size,
blurVarianceSigma,
blurVarianceSigma,
0.01);
*/
}
private boolean loadCorrelations(){
String []patterns={".corr-tiff",".tiff",".tif"};
......
......@@ -5,6 +5,7 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
......@@ -109,7 +110,13 @@ public class GenericJTabbedDialog implements ActionListener {
}
if (tooltip != null) {
label.setToolTipText(tooltip);
if (component != null) component.setToolTipText(tooltip);
if (component != null) {
component.setToolTipText(tooltip);
Component [] comps = component.getComponents();
if ((comps != null) && (comps.length >0)) {
((JComponent) comps[0]).setToolTipText(tooltip);
}
}
}
labels.get(labels.size()-1).add(label);
components.get(components.size()-1).add(component);
......@@ -148,6 +155,7 @@ public class GenericJTabbedDialog implements ActionListener {
inp_units.putClientProperty("type", "String");
inp_units.setLayout(new FlowLayout(FlowLayout.LEFT));
addLine(label, inp_units, tooltip);
}
public void addNumericField(String label, double defaultValue, int digits) { // as in IJ
......
......@@ -67,12 +67,18 @@ public class ImageDtt {
static int DISPARITY_VARIATIONS_INDEX = 11; // index of strength data in disparity map ==6
static int IMG_DIFF0_INDEX = 12; // index of noise- normalized image difference for port 0 in disparity map
static int OVEREXPOSED = 16; // index of overexposed fraction of all pixels
// remove when not needed
static int DBG0_INDEX = 17; // index of dbg0 data (copy of CM)
static int DBG1_INDEX = 18; // index of dbg1 data (poly 1)
static int DBG2_INDEX = 19; // index of dbg2 data (poly 2)
static int DBG3_INDEX = 20; // index of dbg3 data (poly 3)
static String [] DISPARITY_TITLES = {
"int_disp","int_y_disp","cm_disp","cm_y_disp","hor_disp","hor_strength","vert_disp","vert_strength",
"poly_disp", "poly_y_disp", "strength_disp", "vary_disp","diff0","diff1","diff2","diff3","overexp"};
"poly_disp", "poly_y_disp", "strength_disp", "vary_disp","diff0","diff1","diff2","diff3","overexp",
"dbg0","dbg1","dbg2","dbg3"};
static int TCORR_COMBO_RSLT = 0; // normal combined correlation from all selected pairs (mult/sum)
static int TCORR_COMBO_SUM = 1; // sum of channle correlations from all selected pairs
static int TCORR_COMBO_SUM = 1; // sum of channel correlations from all selected pairs
static int TCORR_COMBO_HOR = 2; // combined correlation from 2 horizontal pairs (0,1). Used to detect vertical features
static int TCORR_COMBO_VERT = 3; // combined correlation from 2 vertical pairs (0,1). Used to detect horizontal features
static String [] TCORR_TITLES = {"combo","sum","hor","vert"};
......@@ -1365,6 +1371,7 @@ public class ImageDtt {
public double [][][][][][] clt_aberrations_quad_corr(
final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double [][] disparity_array, // [tilesY][tilesX] - individual per-tile expected disparity
......@@ -1539,6 +1546,7 @@ public class ImageDtt {
}
// add optional initialization of debug layers here
if (disparity_map != null){
for (int i = 0; i<disparity_map.length;i++){
if ((i != OVEREXPOSED) || (saturation_imp!= null)){
......@@ -2138,6 +2146,11 @@ public class ImageDtt {
clt_mismatch[3*pair + 2 ][tIndex] = Double.NaN;
}
}
if (disparity_map[DBG0_INDEX] != null) disparity_map[DBG0_INDEX][tIndex] = Double.NaN;
if (disparity_map[DBG1_INDEX] != null) disparity_map[DBG1_INDEX][tIndex] = Double.NaN;
if (disparity_map[DBG2_INDEX] != null) disparity_map[DBG2_INDEX][tIndex] = Double.NaN;
if (disparity_map[DBG3_INDEX] != null) disparity_map[DBG3_INDEX][tIndex] = Double.NaN;
} else {
double [] corr_max_XYi = {icorr_max[0],icorr_max[1]};
disparity_map[DISPARITY_INDEX_INT][tIndex] = transform_size - 1 -corr_max_XYi[0];
......@@ -2149,7 +2162,7 @@ public class ImageDtt {
// disparity_map[DISPARITY_VARIATIONS_INDEX][tIndex] = (rms[1]*tcorr_combo[1][max_index])/(rms[0]*tcorr_combo[0][max_index]); // correlation combo value at the integer maximum
disparity_map[DISPARITY_VARIATIONS_INDEX][tIndex] = (tcorr_combo[TCORR_COMBO_SUM][max_index])/(tcorr_combo[TCORR_COMBO_RSLT][max_index]); // correlation combo value at the integer maximum
// Calculate "center of mass" coordinates
double [] corr_max_XYm = getMaxXYCm( // get fractiona center as a "center of mass" inside circle/square from the integer max
double [] corr_max_XYm = getMaxXYCm( // get fractional center as a "center of mass" inside circle/square from the integer max
tcorr_combo[TCORR_COMBO_RSLT], // [data_size * data_size]
corr_size,
icorr_max, // integer center coordinates (relative to top left)
......@@ -2159,7 +2172,7 @@ public class ImageDtt {
disparity_map[DISPARITY_INDEX_CM][tIndex] = transform_size - 1 -corr_max_XYm[0];
disparity_map[DISPARITY_INDEX_CM+1][tIndex] = transform_size - 1 -corr_max_XYm[1];
// returns x and strength, not x,y
double [] corr_max_XS_hor = getMaxXSOrtho( // get fractiona center as a "center of mass" inside circle/square from the integer max
double [] corr_max_XS_hor = getMaxXSOrtho( // get fractional center as a "center of mass" inside circle/square from the integer max
tcorr_combo[TCORR_COMBO_HOR], // [data_size * data_size]
enh_ortho_scale, // [data_size]
corr_size,
......@@ -2168,7 +2181,7 @@ public class ImageDtt {
(globalDebugLevel > 0) && (tileX == debug_tileX) && (tileY == debug_tileY)); // debugMax);
disparity_map[DISPARITY_INDEX_HOR][tIndex] = transform_size - 1 - corr_max_XS_hor[0];
disparity_map[DISPARITY_INDEX_HOR_STRENGTH][tIndex] = corr_max_XS_hor[1];
double [] corr_max_XS_vert = getMaxXSOrtho( // get fractiona center as a "center of mass" inside circle/square from the integer max
double [] corr_max_XS_vert = getMaxXSOrtho( // get fractional center as a "center of mass" inside circle/square from the integer max
tcorr_combo[TCORR_COMBO_VERT], // [data_size * data_size]
enh_ortho_scale, // [data_size]
corr_size,
......@@ -2180,12 +2193,25 @@ public class ImageDtt {
// Calculate polynomial interpolated maximum coordinates
double [] corr_max_XY = getMaxXYPoly( // get interpolated maximum coordinates using 2-nd degree polynomial
pa,
tcorr_combo[TCORR_COMBO_RSLT], // [data_size * data_size]
tcorr_combo[TCORR_COMBO_RSLT], // [data_size * data_size]
corr_size,
icorr_max, // integer center coordinates (relative to top left)
corr_max_weights_poly, // [(radius+1) * (radius+1)]
max_search_radius_poly, // max_search_radius, for polynomial - always use 1
icorr_max, // integer center coordinates (relative to top left)
corr_max_weights_poly, // [(radius+1) * (radius+1)]
max_search_radius_poly, // max_search_radius, for polynomial - always use 1
imgdtt_params.poly_pwr, // double value_pwr, // raise value to this power (trying to compensate sticking to integer values)
imgdtt_params.poly_value_to_weight, //boolean poly_value_to_weight, // multiply weight by value
debugMax);
//double
if (corr_max_XY != null){
corr_max_XY[0] = transform_size - 1 -corr_max_XY[0];
corr_max_XY[1] = transform_size - 1 -corr_max_XY[1];
} else {
corr_max_XY = new double[2];
corr_max_XY[0] = Double.NaN;
corr_max_XY[1] = Double.NaN;
}
/*
if (corr_max_XY != null){
disparity_map[DISPARITY_INDEX_POLY][tIndex] = transform_size - 1 -corr_max_XY[0];
disparity_map[DISPARITY_INDEX_POLY+1][tIndex] = transform_size - 1 -corr_max_XY[1];
......@@ -2193,6 +2219,42 @@ public class ImageDtt {
disparity_map[DISPARITY_INDEX_POLY][tIndex] = Double.NaN;
disparity_map[DISPARITY_INDEX_POLY+1][tIndex] = Double.NaN;
}
*/
disparity_map[DISPARITY_INDEX_POLY][tIndex] = corr_max_XY[0];
disparity_map[DISPARITY_INDEX_POLY+1][tIndex] = corr_max_XY[1];
// just debug (up to 4 layers)
if (disparity_map[DBG0_INDEX] != null) {
disparity_map[DBG0_INDEX][tIndex] = transform_size - 1 -corr_max_XYm[0];
}
if (disparity_map[DBG2_INDEX] != null) {
disparity_map[DBG2_INDEX][tIndex] = corr_max_XY[0];
}
if (disparity_map[DBG1_INDEX] != null) {
disparity_map[DBG1_INDEX][tIndex] = disparity_map[DBG0_INDEX][tIndex];
if (!Double.isNaN(corr_max_XY[0]) &&
(Math.abs(disparity_map[DISPARITY_INDEX_CM][tIndex] - corr_max_XY[0]) < imgdtt_params.max_poly_diff) &&
(disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] > imgdtt_params.min_poly_strength)) { // debug threshold
disparity_map[DBG1_INDEX][tIndex] = corr_max_XY[0];
disparity_map[DBG3_INDEX][tIndex] = Double.NaN;
} else { // show only "bad" and strong poly
if (disparity_map[DISPARITY_STRENGTH_INDEX][tIndex] > imgdtt_params.min_poly_strength) {
disparity_map[DBG3_INDEX][tIndex] = disparity_map[DBG2_INDEX][tIndex];
} else {
disparity_map[DBG3_INDEX][tIndex] = Double.NaN;
}
}
// if (disparity_map[DBG3_INDEX] != null) {
// disparity_map[DBG3_INDEX][tIndex] = disparity_map[DBG2_INDEX][tIndex] - disparity_map[DBG0_INDEX][tIndex];
// }
}
if (imgdtt_params.mix_corr_poly) {
// apply
disparity_map[DISPARITY_INDEX_CM][tIndex] = disparity_map[DBG1_INDEX][tIndex];
// TODO: add Y for correction !!!!
}
//
if (corr_mode == 0) extra_disparity = disparity_map[DISPARITY_INDEX_INT][tIndex];
else if (corr_mode == 1) extra_disparity = disparity_map[DISPARITY_INDEX_CM][tIndex];
else if (corr_mode == 2) extra_disparity = disparity_map[DISPARITY_INDEX_POLY][tIndex];
......@@ -2912,6 +2974,8 @@ public class ImageDtt {
int [] icenter, // integer center coordinates (relative to top left)
double [] weights, // [(radius+1) * (radius+1)]
int radius,
double value_pwr, // raise value to this power (trying to compensate sticking to integer values)
boolean poly_value_to_weight, // multiply weight by value
boolean debug)
{
// TODO: make sure it is within 1pxx1px square from the integer maximum? If not - return null and use center of mass instead?
......@@ -2935,8 +2999,16 @@ public class ImageDtt {
mdata[indx][0][1] = dataY;
mdata[indx][1] = new double [1];
mdata[indx][1][0] = data[dataY * data_size + dataX];
if (value_pwr != 1.0) {
if (mdata[indx][1][0] > 0) {
mdata[indx][1][0] = Math.pow(mdata[indx][1][0], value_pwr);
} else {
mdata[indx][1][0] = 0.0;
}
}
mdata[indx][2] = new double [1];
mdata[indx][2][0] = weights[ay * (radius + 1) + ax];
if (poly_value_to_weight) mdata[indx][2][0] *= mdata[indx][1][0];
indx++;
}
}
......
......@@ -6,7 +6,7 @@
** Copyright (C) 2017 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
**
** MacroCorrelation.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
......@@ -38,13 +38,13 @@ public class MacroCorrelation {
this.tp = tp;
final int pTilesX = tp.getTilesX();
final int pTilesY = tp.getTilesY();
final int tileSize = tp.getTileSize(); //
final int tileSize = tp.getTileSize(); //
final int mTilesX = (pTilesX + tileSize - 1) / tileSize; // clt_aberrations_quad_corr truncates
final int mTilesY = (pTilesY + tileSize - 1) / tileSize;
this.mtp = new TileProcessor(
mTilesX, // int tilesX,
mTilesY, // int tilesY,
tileSize, // int tileSize,
tileSize, // int tileSize,
tp.superTileSize, // int superTileSize,
tp.getMagicScale(), // double scale,
trusted_correlation, // double trustedCorrelation,
......@@ -55,7 +55,7 @@ public class MacroCorrelation {
final CLTPass3d src_scan, // results of the normal correlations (now expecting infinity)
// final double [][][] other_channels, // other channels to correlate, such as average RGB (first index - subcamera, 2-nd - channel, 3-rd - pixel)
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
GeometryCorrection geometryCorrection,
final double macro_disparity_low,
final double macro_disparity_high,
final double macro_disparity_step,
......@@ -64,7 +64,7 @@ public class MacroCorrelation {
double [][][] input_data = CLTMacroSetData( // perform single pass according to prepared tiles operations and disparity
src_scan, // final CLTPass3d src_scan, // results of the normal correlations (now expecting infinity)
null); // final double [][][] other_channels, // other channels to correlate, such as average RGB (first index - subcamera, 2-nd - channel, 3-rd - pixel)
mtp.resetCLTPasses();
for (double mdisp = macro_disparity_low; mdisp < (macro_disparity_high - macro_disparity_step); mdisp +=macro_disparity_step){
final CLTPass3d macro_scan = new CLTPass3d(mtp);
......@@ -72,28 +72,28 @@ public class MacroCorrelation {
CLTMacroSetMeasure( // perform single pass according to prepared tiles operations and disparity
macro_scan, // final CLTPass3d macro_scan, // new, will be filled out
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
geometryCorrection, // GeometryCorrection geometryCorrection,
mdisp, // final double macro_disparity,
false, // final boolean show_corr_partial,
false, // final boolean show_corr_combo,
debugLevel); // final int debugLevel)
CLTMacroMeasure( // perform single pass according to prepared tiles operations and disparity
macro_scan, // final CLTPass3d macro_scan, //
macro_scan, // final CLTPass3d macro_scan, //
input_data, // final double [][][] input_data,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
geometryCorrection, // GeometryCorrection geometryCorrection,
""+mdisp, // final String suffix,
false, // final boolean show_corr_partial,
false, // final boolean show_corr_combo,
debugLevel); // final int debugLevel)
mtp.clt_3d_passes.add(macro_scan);
}
return mtp;
}
public double [][][] CLTMacroSetData( // perform single pass according to prepared tiles operations and disparity
final CLTPass3d src_scan, // results of the normal correlations (now expecting infinity)
final double [][][] other_channels // other channels to correlate, such as average RGB (first index - subcamera, 2-nd - channel, 3-rd - pixel)
......@@ -105,14 +105,14 @@ public class MacroCorrelation {
// final int dbg_y = 160;
final int pTilesX = tp.getTilesX();
final int pTilesY = tp.getTilesY();
final int tileSize = tp.getTileSize(); //
final int tileSize = tp.getTileSize(); //
final int mTilesX = (pTilesX + tileSize - 1) / tileSize; // clt_aberrations_quad_corr truncates
final int mTilesY = (pTilesY + tileSize - 1) / tileSize;
final int mTiles = mTilesX * mTilesY;
final int mTiles = mTilesX * mTilesY;
final int num_chn = tmp_input? 3: (1 + ((other_channels == null) ? 0 : (other_channels[0].length)));
final double [][][] input_data = new double [ImageDtt.QUAD][num_chn][mTiles*tileSize*tileSize];
// double [][] tiles_tone = src_scan.getTileRBGA( No, we need individual subcameras
// 4); // int num_layers);
// 4); // int num_layers);
for (int sub_cam =0; sub_cam < input_data.length; sub_cam++){
for (int pty = 0; pty < pTilesY; pty++){
for (int ptx = 0; ptx < pTilesX; ptx++){
......@@ -122,7 +122,7 @@ public class MacroCorrelation {
if (tmp_input) {
input_data[sub_cam][1][mTile]= input_data[sub_cam][0][mTile];
input_data[sub_cam][2][mTile]= input_data[sub_cam][0][mTile];
} else {
} else {
for (int other_chn = 1; other_chn < num_chn; other_chn++){
input_data[sub_cam][other_chn][mTile] = other_channels[sub_cam][other_chn-1][pTile];
}
......@@ -133,13 +133,13 @@ public class MacroCorrelation {
}
return input_data;
}
public CLTPass3d CLTMacroSetMeasure( // perform single pass according to prepared tiles operations and disparity
final CLTPass3d macro_scan, // new, will be filled out
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
GeometryCorrection geometryCorrection,
final double macro_disparity,
final boolean show_corr_partial,
final boolean show_corr_combo,
......@@ -147,10 +147,10 @@ public class MacroCorrelation {
{
final int pTilesX = tp.getTilesX();
final int pTilesY = tp.getTilesY();
final int tileSize = tp.getTileSize(); //
final int tileSize = tp.getTileSize(); //
final int mTilesX = (pTilesX + tileSize - 1) / tileSize; // clt_aberrations_quad_corr truncates
final int mTilesY = (pTilesY + tileSize - 1) / tileSize;
int op = ImageDtt.setImgMask(0, 0xf);
op = ImageDtt.setPairMask(op,0xf);
op = ImageDtt.setForcedDisparity(op,true);
......@@ -170,10 +170,10 @@ public class MacroCorrelation {
}
public CLTPass3d CLTMacroMeasure( // perform single pass according to prepared tiles operations and disparity
final CLTPass3d macro_scan, //
final CLTPass3d macro_scan, //
final double [][][] input_data,
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
GeometryCorrection geometryCorrection,
final String suffix,
final boolean show_corr_partial,
final boolean show_corr_combo,
......@@ -181,7 +181,7 @@ public class MacroCorrelation {
{
int mTilesY = macro_scan.tile_op.length;
int mTilesX = macro_scan.tile_op[0].length;
// undecided, so 2 modes of combining alpha - same as rgb, or use center tile only
if (debugLevel > -1){
int numTiles = 0;
......@@ -222,18 +222,19 @@ public class MacroCorrelation {
// double [][][][] texture_tiles = save_textures ? new double [tilesY][tilesX][][] : null; // ["RGBA".length()][];
ImageDtt image_dtt = new ImageDtt();
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
8, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
macro_scan.tile_op, // per-tile operation bit codes
macro_scan.disparity, // clt_parameters.disparity, // final double disparity,
input_data, // final double [][][] imade_data, // first index - number of image in a quad
null, // boolean [][] saturation_imp, // (near) saturated pixels or null
// correlation results - final and partial
// correlation results - final and partial
clt_corr_combo, // [tp.tilesY][tp.tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
clt_corr_partial, // clt_corr_partial, // [tp.tilesY][tp.tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
null, // [tp.tilesY][tp.tilesX][pair]{dx,dy,weight}[(2*transform_size-1)*(2*transform_size-1)] // transpose unapplied. null - do not calculate
// Use it with disparity_maps[scan_step]? clt_mismatch, // [tp.tilesY][tp.tilesX][pair]{dx,dy,weight}[(2*transform_size-1)*(2*transform_size-1)] // transpose unapplied. null - do not calculate
disparity_map, // [12][tp.tilesY * tp.tilesX]
null, // [tp.tilesY][tp.tilesX]["RGBA".length()][];
null, // [tp.tilesY][tp.tilesX]["RGBA".length()][];
mTilesX * clt_parameters.transform_size, // imp_quad[0].getWidth(), // final int width,
clt_parameters.fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_sym,
......@@ -241,8 +242,8 @@ public class MacroCorrelation {
clt_parameters.corr_red,
clt_parameters.corr_blue,
clt_parameters.corr_sigma,
clt_parameters.corr_normalize, // normalize correlation results by rms
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.corr_normalize, // normalize correlation results by rms
min_corr_selected, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
clt_parameters.enhortho_width, // 2; // reduce weight of center correlation pixels from center (0 - none, 1 - center, 2 +/-1 from center)
......@@ -262,10 +263,10 @@ public class MacroCorrelation {
clt_parameters.kernel_step,
clt_parameters.transform_size,
clt_parameters.clt_window,
shiftXY, //
shiftXY, //
0.0, // disparity_corr, // final double disparity_corr, // disparity at infinity
null, // (clt_parameters.fcorr_ignore? null: this.fine_corr),
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.corr_magic_scale, // still not understood coefficient that reduces reported disparity value. Seems to be around 0.85
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
31, // clt_parameters.tileX, // final int debug_tileX,
......@@ -341,11 +342,11 @@ public class MacroCorrelation {
}
return macro_scan;
}
public CLTPass3d refineMacro(
final double [][][] input_data,
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
GeometryCorrection geometryCorrection,
final double trustedCorrelation,
final double disp_far, // limit results to the disparity range, far - start with 1 step above 0 (was valid for all)
final double disp_near,
......@@ -367,18 +368,18 @@ public class MacroCorrelation {
false, // final boolean usePoly, // use polynomial method to find max), valid if useCombo == false
1); // final int debugLevel)
if (refined_macro == null) return null;
CLTMacroMeasure( // perform single pass according to prepared tiles operations and disparity
refined_macro, // final CLTPass3d macro_scan, //
refined_macro, // final CLTPass3d macro_scan, //
input_data, // final double [][][] input_data,
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
geometryCorrection, // GeometryCorrection geometryCorrection,
geometryCorrection, // GeometryCorrection geometryCorrection,
""+mtp.clt_3d_passes, // final String suffix,
false, // final boolean show_corr_partial,
false, // final boolean show_corr_combo,
0); // final int debugLevel)
return refined_macro;
}
public ArrayList <CLTPass3d> prepareMeasurementsFromMacro(
......@@ -397,7 +398,7 @@ public class MacroCorrelation {
final int dbg_x,
final int dbg_y,
final int debugLevel)
{
class DispStrength{
double disparity;
......@@ -410,13 +411,14 @@ public class MacroCorrelation {
double [] arr = {disparity, strength};
return arr;
}
@Override
public String toString(){
return String.format("disparity=%7.3f strength=%7.4f",disparity, strength);
}
}
final int mTilesX = mtp.getTilesX();
final int mTilesY = mtp.getTilesY();
final int mTiles = mTilesX * mTilesY;
final int mTiles = mTilesX * mTilesY;
final ArrayList <CLTPass3d> measurements = new ArrayList <CLTPass3d>();
final TileNeibs tnSurface = new TileNeibs(mtp.getTilesX(), mtp.getTilesY());
final Thread[] threads = ImageDtt.newThreadArray(tp.threadsMax);
......@@ -433,7 +435,7 @@ public class MacroCorrelation {
final double disp_near8 = disp_near/tp.getTileSize(); // here tp, not mtp
final double corr_magic_scale = mtp.getMagicScale();
//mtp.clt_3d_passes
final double [] neib_weights = {
mc_ortho_weight,
mc_diag_weight,
......@@ -447,6 +449,7 @@ public class MacroCorrelation {
final double kexp = (mc_trust_sigma == 0.0) ? 0.0: (0.5/mc_trust_sigma/mc_trust_sigma);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
int this_thread = ai_thread.getAndIncrement();
......@@ -462,7 +465,7 @@ public class MacroCorrelation {
for (int dir = 0; dir < neib_weights.length; dir++){ // 8 - center
int mTile = tnSurface.getNeibIndex(mTile0, dir);
if ((mTile >= 0) && (neib_weights[dir] != 0.0)) {
int mty = mTile / mTilesX;
int mty = mTile / mTilesX;
int mtx = mTile % mTilesX;
if (pass.tile_op[mty][mtx] != 0 ) { // current tile has valid data
double mdisp = pass.disparity_map[disparity_index][mTile];
......@@ -516,7 +519,7 @@ public class MacroCorrelation {
macro_ds[mTile0] = new double[ds_list_keep.size()][];
int indx=0;
for (DispStrength ds:ds_list_keep){
macro_ds[mTile0][indx++] = ds.toArray();
macro_ds[mTile0][indx++] = ds.toArray();
}
if (max_meas[this_thread] < ds_list_keep.size()){
max_meas[this_thread] = ds_list_keep.size();
......@@ -544,7 +547,7 @@ public class MacroCorrelation {
if (debugLevel > -1){
System.out.println("prepareMeasurementsFromMacro(): longest="+longest+" total_meas="+total_meas);
}
int op = ImageDtt.setImgMask(0, 0xf);
op = ImageDtt.setPairMask(op,0xf);
op = ImageDtt.setForcedDisparity(op,true);
......@@ -554,22 +557,23 @@ public class MacroCorrelation {
for (int i = 0; i < longest; i++){
measurements.add(new CLTPass3d(tp, 0 )); // mode 0 - initialize tile_op and disparity arrays
}
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
// int this_thread = ai_thread.getAndIncrement();
int tileSize = tp.getTileSize();
int tilesX = tp.getTilesX();
int tilesY = tp.getTilesY();
for (int mTile = ai.getAndIncrement(); mTile < mTiles; mTile = ai.getAndIncrement()) {
int dl = (mTile == dbg_tile) ? debugLevel : -1;
if (dl > 0){
System.out.println("prepareMeasurementsFromMacro().1 mTile0="+mTile);
}
if (macro_ds[mTile] != null){
int mty = mTile / mTilesX;
int mty = mTile / mTilesX;
int mtx = mTile % mTilesX;
int ty0 = mty * tileSize;
int tx0 = mtx * tileSize;
......@@ -592,6 +596,6 @@ public class MacroCorrelation {
ImageDtt.startAndJoin(threads);
return measurements;
}
}
/**
** MeasuredLayer - per-tile measured disparity/strength pairs,
** multiple layers can be used for 4-disparity and 2 (hor/vert) pairs
** separately
** separately
**
** Copyright (C) 2017 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
**
** MeasuredLayer.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
......@@ -87,7 +87,7 @@ public class MeasuredLayers {
this.superTileSize = superTileSize;
this.lapWeight = getLapWeights();
}
/**
* Get number of tiles in the image horizontally
* @return tilesX
......@@ -114,22 +114,22 @@ public class MeasuredLayers {
{
return superTileSize;
}
/**
* Set measured layer
* Set measured layer
* @param num_layer number of the layer to set
* @param disparity array of per-tile disparity values (linescan order),
* NaN deletes the tile
* NaN deletes the tile
* @param strength array of per-tile disparity values (linescan order),
* 0.0 strength is OK - does not delete the tile
* @param selection optional tile selection (or null). If unselected, tile is deleted
* @param selection optional tile selection (or null). If unselected, tile is deleted
*/
public void setLayer (
int num_layer,
double [] disparity,
double [] strength,
boolean [] selection) // may be null
{
{
if (layers[num_layer] == null) {
int llen = disparity.length;
if (layers[num_layer] == null) {
......@@ -153,17 +153,17 @@ public class MeasuredLayers {
}
}
}
/**
* Set disparity values for selected measurement layer
* Set disparity values for selected measurement layer
* @param num_layer number of the layer to set
* @param disparity array of per-tile disparity values (linescan order),
* NaN deletes the tile. New tile set strength = 0.0
* NaN deletes the tile. New tile set strength = 0.0
*/
public void setDisparity (
int num_layer,
double [] disparity)
{
{
if (layers[num_layer] == null) {
int llen = disparity.length;
if (layers[num_layer] == null) {
......@@ -185,14 +185,14 @@ public class MeasuredLayers {
/**
* Set strength values for selected measurement layer. Does not allocate new tiles
* if that element was null
* if that element was null
* @param num_layer number of the layer to set
* @param strength array of per-tile strength values (linescan order)
*/
public void setStrength (
int num_layer,
double [] strength)
{
{
if (layers[num_layer] != null) {
for (int i = 0; i < strength.length; i++){
if (layers[num_layer][i] != null){
......@@ -201,7 +201,7 @@ public class MeasuredLayers {
}
}
}
/**
* Change tile selection for the layer. Can only unselect existing tiles, not add new ones
* @param num_layer number of the layer to set
......@@ -211,19 +211,19 @@ public class MeasuredLayers {
public void setSelection (
int num_layer,
boolean [] selection)
{
{
for (int i = 0; i < selection.length; i++){
if (!selection[i]){
layers[num_layer][i] = null;
}
}
}
/**
* Get total number of the measurement layers in this object
* @return number of layers (some may be uninitialized
*/
public int getNumLayers()
{
if (layers == null){
......@@ -237,7 +237,7 @@ public class MeasuredLayers {
* Get array of disparity values for the selected layer
* @param num_layer number of the layer to read
* @return array of per-tile disparity values (in linescan order),
* Double.NaN for missing tiles
* Double.NaN for missing tiles
*/
public double [] getDisparity(
int num_layer)
......@@ -252,12 +252,12 @@ public class MeasuredLayers {
}
return disparity;
}
/**
* Get array of correlation strength values for the selected layer
* @param num_layer number of the layer to read
* @return array of per-tile strength values (in linescan order),
* 0.0 for missing tiles
* 0.0 for missing tiles
*/
public double [] getStrength(
......@@ -273,7 +273,7 @@ public class MeasuredLayers {
}
return strength;
}
/**
* Get array of existing tiles for the selected layer
* @param num_layer number of the layer to read
......@@ -284,11 +284,11 @@ public class MeasuredLayers {
{
boolean [] selection = new boolean [layers[num_layer].length];
for (int i = 0; i < selection.length; i++){
selection[i] = layers[num_layer][i] != null;
selection[i] = layers[num_layer][i] != null;
}
return selection;
}
/**
* Calculate weights for overlapping supertiles to multiply correlation strengths
* @return square 2-d array of weights 0.0 ... 1.0, each dimension twice the
......@@ -303,10 +303,10 @@ public class MeasuredLayers {
}
for (int i = 0; i < superTileSize; i++){
for (int j = 0; j < superTileSize; j++){
lapWeight[i] [ j] = lapWeight1d[i]*lapWeight1d[j];
lapWeight[i] [ j] = lapWeight1d[i]*lapWeight1d[j];
lapWeight[superTileSize2 - 1 - i][ j] = lapWeight[i][j];
lapWeight[i] [superTileSize2 - 1 - j] = lapWeight[i][j];
lapWeight[superTileSize2 - 1 - i][superTileSize2 - 1 - j] = lapWeight[i][j];
lapWeight[i] [superTileSize2 - 1 - j] = lapWeight[i][j];
lapWeight[superTileSize2 - 1 - i][superTileSize2 - 1 - j] = lapWeight[i][j];
}
}
double s = 0.0;
......@@ -318,7 +318,7 @@ public class MeasuredLayers {
System.out.println("getLapWeights: sum = "+s);
return lapWeight;
}
public double [] getLapWeights1d(){
int indx = 0;
final int superTileSize2 = 2 * superTileSize;
......@@ -330,13 +330,13 @@ public class MeasuredLayers {
}
return weights;
}
/**
* Get window function for tile samples (currently just 3x3) in a line-scan order
* @param smplSide square sample side
* @return [smplSide * smplSide]array of weights, 1.0 in the center
*/
static double [] getSampleWindow(int smplSide, boolean all1){
double [] weights = new double [smplSide * smplSide];
for (int sy = 0; sy < smplSide; sy++){
......@@ -346,9 +346,9 @@ public class MeasuredLayers {
}
return weights;
}
/**
* Get selection for the specific measurement layer and supertile X,Y coordinates
* in the image. Combined with input selection
......@@ -384,7 +384,7 @@ public class MeasuredLayers {
if ((x >= 0) && (x < tilesX)) {
int indx = y * tilesX + x;
int indx_st = dy * st2 + dx;
if (((sel_in == null) || sel_in[indx_st]) &&
if (((sel_in == null) || sel_in[indx_st]) &&
(layers[num_layer][indx] != null) &&
(layers[num_layer][indx].getStrength() >= strength_floor)){
selection[indx_st] = true;
......@@ -398,7 +398,7 @@ public class MeasuredLayers {
if (null_if_none && (num_selected == 0)) return null;
return selection;
}
/**
* Get selection for the specific measurement layer and supertile X,Y coordinates
......@@ -456,12 +456,12 @@ public class MeasuredLayers {
if (null_if_none && (num_selected == 0)) return null;
return selection;
}
/**
* Get selection when disparity/strength is already calculated. Useful when
* disparity/strength are not just measured values, by sampled over an area
* @param disparityStrength array of {disparity, strength} where each is
* a linescan data of the (2 * superTileSize) * (2 * superTileSize)
* a linescan data of the (2 * superTileSize) * (2 * superTileSize)
* @param sel_in optional input selection array or null - use all
* @param null_if_none return null if selection has no tiles enabled
* @return boolean array of per-tile enabled/disabled values in linescan
......@@ -483,17 +483,17 @@ public class MeasuredLayers {
num_selected ++;
}
}
if (null_if_none && (num_selected == 0)) return null;
return selection;
}
/**
* Get selection when disparity/strength is already calculated. Useful when
* disparity/strength are not just measured values, by sampled over an area
* Includes low/high limits for disparity values
* @param disparityStrength array of {disparity, strength} where each is
* a linescan data of the (2 * superTileSize) * (2 * superTileSize)
* a linescan data of the (2 * superTileSize) * (2 * superTileSize)
* @param sel_in optional input selection array or null - use all
* @param disp_far low limit for disparity, Double.NaN - do not check
* @param disp_near high limit for disparity, Double.NaN - do not check
......@@ -517,20 +517,20 @@ public class MeasuredLayers {
((sel_in == null) || (sel_in[i]))){
if ( (Double.isNaN(disp_far) || (disparityStrength[0][i] >= disp_far)) &&
(Double.isNaN(disp_near) || (disparityStrength[0][i] <= disp_near))) {
}
selection[i] = true;
num_selected ++;
}
}
if (null_if_none && (num_selected == 0)) return null;
return selection;
}
/**
* Get number of "true" elements in a boolean array. Null is OK, it results in 0
* @param selected boolean array to count set elements in
......@@ -570,7 +570,7 @@ public class MeasuredLayers {
}
return sw;
}
/**
* Get disparity and correlation strength for the specific measurement layer and
* supertile X,Y coordinates in the image. Combined with input selection
......@@ -659,10 +659,10 @@ public class MeasuredLayers {
return ds;
}
/**
* Get double-size (for overlapping) array of disparities and strengths for the supertile
* Using best (producing lowest disparity variance) subset of neighbor tiles
......@@ -675,8 +675,8 @@ public class MeasuredLayers {
* sample weight
* @param strength_pow raise correlation strength (after subtracting strength_floor) to this power
* to use as a sample weight
* @param smplSide size of the square sample side
* @param smplNum number of averaged samples (should be <= smplSide * smplSide and > 1)
* @param smplSide size of the square sample side
* @param smplNum number of averaged samples (should be <= smplSide * smplSide and > 1)
* @param smplRms maximal square root of variance (in disparity pixels) to accept the result
* @param null_if_none return null if there are no usable tiles in the result
* @param smplWnd multiply samples weights by a window function
......@@ -704,19 +704,19 @@ public class MeasuredLayers {
int st_half = superTileSize/2;
double [][] ds = new double [2][st2*st2];
final int dbg_tile = ((stX == 22) && (stY == 19)) ? (5 + 7*16) : -1;// 50397;
int num_selected = 0;
int smpl_center = smplSide /2;
int st2e = st2 + smplSide;
int smplLen = smplSide*smplSide;
final double [] smpl_weights = getSampleWindow(smplSide, !smplWnd);
double [] disp = new double [st2e * st2e];
double [] weight = new double [st2e * st2e];
double [] disp = new double [st2e * st2e];
double [] weight = new double [st2e * st2e];
int st_halfe = st_half + smpl_center;
double smplVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
if (layers[num_layer] != null) {
for (int dy = 0; dy < st2e; dy ++){
int y = superTileSize * stY -st_halfe + dy;
......@@ -726,7 +726,7 @@ public class MeasuredLayers {
if ((x >= 0) && (x < tilesX)) {
int indx = y * tilesX + x;
int indx_ste = dy * st2e + dx;
if (layers[num_layer][indx] != null){ // apply sel_in later
disp[indx_ste] = layers[num_layer][indx].getDisparity();
double w = layers[num_layer][indx].getStrength() - strength_floor;
......@@ -766,15 +766,15 @@ public class MeasuredLayers {
if (weight[indxe] > 0.0){
int indxs = sy * smplSide + sx;
smpl_sel[indxs] = true;
smpl_d[indxs] = disp[indxe];
smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
smpl_d[indxs] = disp[indxe];
smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
sum_wnd += smpl_weights[indxs];
num_in_sample ++;
}
}
}
if (num_in_sample >= smplNum){ // try, remove worst
// calculate
// calculate
double sd=0.0, sd2 = 0.0, sw = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
double dw = smpl_d[i] * smpl_w[i];
......@@ -796,13 +796,13 @@ public class MeasuredLayers {
}
}
if (iworst < 0){
System.out.println("**** this is a BUG in getDisparityStrengthML() ****");
System.out.println("**** this is a BUG1 in getDisparityStrengthML() ****");
break;
}
// remove worst sample
smpl_sel[iworst] = false;
double dw = smpl_d[iworst] * smpl_w[iworst];
sd -= dw;
sd -= dw;
sd2 -= dw * smpl_d[iworst];
sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
......@@ -823,14 +823,14 @@ public class MeasuredLayers {
System.out.println("**** this is a BUG in getDisparityStrengthML(), shoud not happen ? ****");
}
}
}
}
}
}
return ds;
}
/**
* Verify that selected points are not all on the same line
* Verify that selected points are not all on the same line
* @param sel 2-d sample selection in linescan order
* @param side square samples side
* @return true if there are enough samples for plane extraction, false otherwise
......@@ -862,7 +862,7 @@ public class MeasuredLayers {
}
/**
* Verify that selected points are not all on the same line, even if the specified one is removed
* Verify that selected points are not all on the same line, even if the specified one is removed
* @param indx index of the point to be removed
* @param sel 2-d sample selection in linescan order
* @param side square samples side
......@@ -882,7 +882,7 @@ public class MeasuredLayers {
sel[indx] = true;
return rslt;
}
// testing - redirecting all existing requests to this one with floating planes
public double[][] getDisparityStrengthMLTilted (
int num_layer,
......@@ -895,28 +895,40 @@ public class MeasuredLayers {
int smplNum, // = 3; // Number after removing worst (should be >1)
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, //
double damp_tilt, //
double max_abs_tilt, // 2.0; // pix per tile
double max_rel_tilt, // 0.2; // (pix / disparity) per tile
double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
boolean null_if_none,
int debugLevel)
{
boolean use_new = true; // false;
if (use_new) {
return getDisparityStrengthMLTilted (
num_layer, // int num_layer,
stX, // int stX,
stY, // int stY,
sel_in, // boolean [] sel_in,
null, // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
null, // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
strength_floor, // double strength_floor,
strength_pow, // double strength_pow,
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
smplNum, // int smplNum, // = 3; // Number after removing worst (should be >1)
smplRms, // double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
smplWnd, // boolean smplWnd, //
2.0, // double max_abs_tilt, // = 2.0; // pix per tile
0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
damp_tilt, // double damp_tilt, //
max_abs_tilt, // double max_abs_tilt, // = 2.0; // pix per tile
max_rel_tilt, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
far_power, // 1.0; // Raise disparity to this power before averaging for far objects
null_if_none, // boolean null_if_none,
debugLevel); // int debugLevel)
} else {
......@@ -925,7 +937,7 @@ public class MeasuredLayers {
stX, // int stX,
stY, // int stY,
sel_in, // boolean [] sel_in,
// null, // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
// null, // double [] tiltXY, // null - free with limit on both absolute (2.0?) and relative (0.2) values
strength_floor, // double strength_floor,
strength_pow, // double strength_pow,
smplSide, // int smplSide, // = 2; // Sample size (side of a square)
......@@ -936,10 +948,15 @@ public class MeasuredLayers {
// 0.2, // double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
null_if_none, // boolean null_if_none,
debugLevel); // int debugLevel)
}
}
// Try two modes of operation: Far tiles (disparity <~4?) use power of disparity, no tilts. Near tiles - current.
// For far tiles power can use closest (lowest disparity) - either power or just census or smth.
// Detect strong background?
public double[][] getDisparityStrengthMLTilted (
int num_layer,
int stX,
......@@ -950,43 +967,62 @@ public class MeasuredLayers {
// to be per-tile of a supertile array
double strength_floor,
double strength_pow,
int smplSide, // = 2; // Sample size (side of a square)
int smplNum, // = 3; // Number after removing worst (should be >1)
double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
int smplSide, // = 3; // Sample size (side of a square)
int smplNum, // = 5; // Number after removing worst (should be >1)
double smplRms, // = 0.3; // Maximal RMS of the remaining tiles in a sample
boolean smplWnd, //
double max_abs_tilt, // = 2.0; // pix per tile
double max_rel_tilt, // = 0.2; // (pix / disparity) per tile
double damp_tilt, //
double max_abs_tilt, // 2.0; // pix per tile
double max_rel_tilt, // 0.2; // (pix / disparity) per tile
double damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
double min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
double transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
int far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
double far_power, // 3.0; // Raise disparity to this power before averaging for far objects
boolean null_if_none,
int debugLevel)
{
if ((layers[num_layer] == null) && null_if_none){
return null;
}
final double [] damping = {damp_tilt, damp_tilt, 0.0}; // 0.0 will be applied to average value, tilt_cost - to both tilts
int st2 = 2 * superTileSize;
int st_half = superTileSize/2;
double [][] ds = new double [2][st2*st2];
final int dbg_tile = ((stX == 22) && (stY == 19)) ? (5 + 7*16) : -1;// 50397;
int num_selected = 0;
int smpl_center = smplSide /2;
double smpl_dcenter = (smplSide -1.0) /2;
int st2e = st2 + smplSide;
int smplLen = smplSide*smplSide;
final double [] smpl_weights = getSampleWindow(smplSide, !smplWnd);
double [] disp = new double [st2e * st2e];
double [] weight = new double [st2e * st2e];
double [] disp = new double [st2e * st2e];
double [] weight = new double [st2e * st2e];
int st_halfe = st_half + smpl_center;
double smplVar = smplRms * smplRms; // maximal variance (weighted average of the squared difference from the mean)
PolynomialApproximation pa = new PolynomialApproximation();
double thresholdLin = 1.0E-20; // threshold ratio of matrix determinant to norm for linear approximation (det too low - fail)
double thresholdQuad = 1.0E-30; // threshold ratio of matrix determinant to norm for quadratic approximation (det too low - fail)
double disp_pwr_far = min_tilt_disp - transition/2.0;
double disp_pwr_near = min_tilt_disp + transition/2.0;
double disp_pwr_near2 = disp_pwr_near + smplRms;
double [] disp_pwr = null;
boolean far_mode_en = (far_mode == 1) || (far_mode == 2);
boolean remove_far_only = (far_mode == 2);
if (far_mode_en) {
disp_pwr = new double [st2e * st2e];
}
int num_far = 0;
boolean [] smpl_far_sel = null;
double [] smpl_pwr_d = null;
double [] smpl_far_d = null;
double [] smpl_far_w = null;
int num_in_sample_far = 0;
if (layers[num_layer] != null) {
for (int dy = 0; dy < st2e; dy ++){
int y = superTileSize * stY -st_halfe + dy;
......@@ -996,16 +1032,20 @@ public class MeasuredLayers {
if ((x >= 0) && (x < tilesX)) {
int indx = y * tilesX + x;
int indx_ste = dy * st2e + dx;
if (layers[num_layer][indx] != null){ // apply sel_in later
disp[indx_ste] = layers[num_layer][indx].getDisparity();
double w = layers[num_layer][indx].getStrength() - strength_floor;
if (w > 0) {
if (strength_pow != 1.0) w = Math.pow(w, strength_pow);
// w *= lapWeight[dy][dx];
disp[indx_ste] = layers[num_layer][indx].getDisparity();
disp[indx_ste] = layers[num_layer][indx].getDisparity(); // same?
weight[indx_ste] = w;
num_selected ++;
if (far_mode_en && (disp[indx_ste] < disp_pwr_near2) && (disp[indx_ste] > 0)) {
disp_pwr[indx_ste] = Math.pow(disp[indx_ste], far_power);
num_far++;
}
}
}
}
......@@ -1029,6 +1069,12 @@ public class MeasuredLayers {
double [] smpl_d = new double [smplLen];
double [] smpl_p = new double [smplLen];
double [] smpl_w = new double [smplLen];
if (far_mode_en ) {
smpl_far_sel = new boolean [smplLen];
smpl_pwr_d = new double [smplLen];
smpl_far_w = new double [smplLen];
num_in_sample_far = 0;
}
for (int sy = 0; sy < smplSide; sy++){
int y = dy + sy; // - smpl_center;
for (int sx = 0; sx < smplSide; sx++){
......@@ -1037,13 +1083,22 @@ public class MeasuredLayers {
if (weight[indxe] > 0.0){
int indxs = sy * smplSide + sx;
smpl_sel[indxs] = true;
smpl_d[indxs] = disp[indxe];
smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
smpl_d[indxs] = disp[indxe];
smpl_w[indxs] = weight[indxe] * smpl_weights[indxs];
sum_wnd += smpl_weights[indxs];
num_in_sample ++;
if (far_mode_en && (disp_pwr[indxe]>0.0)) {
smpl_far_sel[indxs] = true;
smpl_pwr_d[indxs] = disp_pwr[indxe];
smpl_far_w[indxs] = smpl_w[indxs];
num_in_sample_far++;
}
}
}
}
if (far_mode_en ) {
smpl_far_d = smpl_d.clone();
}
if (num_in_sample >= smplNum){ // try, remove worst
sample_loop:
{
......@@ -1098,21 +1153,21 @@ public class MeasuredLayers {
double max_tilt = Math.min(max_abs_tilt, max_rel_tilt * approx2d[0][2]);
boolean overlimit = (Math.abs(approx2d[0][0]) > max_tilt) || (Math.abs(approx2d[0][1]) > max_tilt);
if (overlimit) {
approx2d[0][0] = Math.min(approx2d[0][0], max_tilt);
approx2d[0][1] = Math.min(approx2d[0][1], max_tilt);
approx2d[0][0] = Math.max(approx2d[0][0], -max_tilt);
approx2d[0][0] = Math.min(approx2d[0][0], max_tilt);
approx2d[0][1] = Math.min(approx2d[0][1], max_tilt);
approx2d[0][0] = Math.max(approx2d[0][0], -max_tilt);
approx2d[0][1] = Math.max(approx2d[0][1], -max_tilt);
}
// subtract tilt from disparity
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
int indxs = sy * smplSide + sx;
if (smpl_sel[indxs]) {
if (smpl_sel[indxs]) {
smpl_p[indxs] = approx2d[0][0] * (sx - smpl_dcenter) + approx2d[0][1] * (sy - smpl_dcenter) + approx2d[0][2];
}
}
}
if (overlimit){ // re-calculate disparity average (in the center)
double sd=0.0;
for (int indxs = 0; indxs < smplLen;indxs++) if (smpl_sel[indxs]) {
......@@ -1136,15 +1191,15 @@ public class MeasuredLayers {
sd2 += dw * smpl_d[indxs];
sw += smpl_w[indxs];
}
// remove worst - it should not make remaining set
// remove worst - it should not make remaining set
if (num_in_sample > smplNum) { // remove worst if it is not the last run where only calculations are needed
// double d_mean = sd/sw;
// double d_mean = sd/sw;
int iworst = -1;
double dworst2 = 0.0;
for (int indxs = 0; indxs < smplLen; indxs++) if (smpl_sel[indxs]) {
// double d2 = (smpl_d[i] - d_mean);
// double d2 = (smpl_d[i] - d_mean);
double d2 = smpl_d[indxs] - smpl_p[indxs];
d2 *=d2;
if (d2 > dworst2) {
......@@ -1166,21 +1221,21 @@ public class MeasuredLayers {
}
// remove worst sample
smpl_sel[iworst] = false;
// double dw = smpl_d[iworst] * smpl_w[iworst];
// sd -= dw;
// sd2 -= dw * smpl_d[iworst];
// sw -= smpl_w[iworst];
// double dw = smpl_d[iworst] * smpl_w[iworst];
// sd -= dw;
// sd2 -= dw * smpl_d[iworst];
// sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
num_in_sample --;
} else {
break;
}
} // removing worst tiles, all done,
} // removing worst tiles, all done,
// calculate variance of the remaining set
if (sw > 0.0) {
// sd /= sw;
// sd2 /= sw;
// sd /= sw;
// sd2 /= sw;
double var = sd2/sw; // - sd * sd;
if (var < smplVar) { // good, save in the result array
ds[0][indx] = d_center;
......@@ -1188,7 +1243,7 @@ public class MeasuredLayers {
ds[1][indx] = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change
}
}
} else { // fixed tilt
// tilt around center
double [] tiltXY= {0.0,0.0};
......@@ -1199,7 +1254,7 @@ public class MeasuredLayers {
tiltXY = atiltXY[indx];
}
}
if ((tiltXY != null) && (tiltXY[0] != 0.0) && (tiltXY[1] != 0.0)){
for (int sy = 0; sy < smplSide; sy++){
for (int sx = 0; sx < smplSide; sx++){
......@@ -1212,7 +1267,7 @@ public class MeasuredLayers {
}
// calculate
// calculate
double sd=0.0, sd2 = 0.0, sw = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_sel[i]) {
double dw = smpl_d[i] * smpl_w[i];
......@@ -1232,15 +1287,16 @@ public class MeasuredLayers {
iworst = i;
dworst2 = d2;
}
//remove_far_only
}
if (iworst < 0){
System.out.println("**** this is a BUG in getDisparityStrengthML() ****");
System.out.println("**** this is a BUG2 in getDisparityStrengthML() ****");
break;
}
// remove worst sample
smpl_sel[iworst] = false;
double dw = smpl_d[iworst] * smpl_w[iworst];
sd -= dw;
sd -= dw;
sd2 -= dw * smpl_d[iworst];
sw -= smpl_w[iworst];
sum_wnd -= smpl_weights[iworst];
......@@ -1263,20 +1319,93 @@ public class MeasuredLayers {
}
}
}
}
// now apply far if needed
if (num_in_sample_far > 0) { // calculate small far disparity, then merge with normal one
// remove extra
// smpl_pwr_d - disparity to power
// smpl_far_d - just disparity
if (num_in_sample_far >= smplNum){ // try, remove worst
double sd=0.0, sd2 = 0.0, sw = 0.0;
double sdp =0.0; // , sdp2 = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_far_sel[i]) {
double dw = smpl_far_d[i] * smpl_far_w[i];
sd += dw;
sd2 += dw * smpl_far_d[i];
sw += smpl_far_w[i];
double dpw = smpl_pwr_d[i] * smpl_far_w[i];
sdp += dpw;
// sdp2 += dpw * smpl_pwr_d[i];
}
// remove worst (before power), update sd2, sd and sw
while ((num_in_sample_far > smplNum) && (sw > 0)){ // try, remove worst
double d_mean = sd/sw;
int iworst = -1;
double dworst2 = 0.0;
for (int i = 0; i < smplLen; i++) if (smpl_far_sel[i]) {
double d2 = (smpl_far_d[i] - d_mean);
d2 *=d2;
if ((d2 > dworst2) && (!remove_far_only ||(smpl_far_d[i] < d_mean))) {
iworst = i;
dworst2 = d2;
}
}
if (iworst < 0){
System.out.println("**** this is a BUG3 in getDisparityStrengthML() ****");
break;
}
// remove worst sample
smpl_far_sel[iworst] = false;
double dw = smpl_far_d[iworst] * smpl_far_w[iworst];
sd -= dw;
sd2 -= dw * smpl_far_d[iworst];
sw -= smpl_far_w[iworst];
sum_wnd -= smpl_weights[iworst];
num_in_sample_far --;
// Remove from the power average too
sdp -= smpl_pwr_d[iworst] * smpl_far_w[iworst];
}
// calculate variance of the remaining set
if (sw > 0.0) {
sd /= sw;
sd2 /= sw;
double var = sd2 - sd * sd;
if (var < smplVar) { // good, save in the result array (here use linear disparity
// here need to combine two filtering modes - "tilted" and "far"
sdp = Math.pow(sdp/sw, 1.0/far_power);
if (sdp < disp_pwr_near) { // otherwise keep tilted mode result
double far_w = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change
if (sdp < disp_pwr_far) {
ds[0][indx] = sdp;
ds[1][indx] = far_w;
} else { // interpolate
double k = (sdp - disp_pwr_far) / transition;
ds[0][indx] = (1.0 - k) * sdp + k * ds[0][indx];
ds[1][indx] = (1.0 - k) * far_w + k * ds[1][indx];
}
}
ds[0][indx] = sd;
ds[1][indx] = sw * lapWeight[dy][dx] /sum_wnd; // average weights, multiply by window //** TODO: change
}
} else {
num_in_sample = 0;
System.out.println("**** this is a BUG4 in getDisparityStrengthML(), shoud not happen ? ****");
}
}
}
}
}
}
return ds;
}
public void growSelection(
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
boolean [] tiles,
......@@ -1293,7 +1422,7 @@ public class MeasuredLayers {
for (int tileX = 0; tileX < (tilesX - 1); tileX++){
int tindx = tileY * tilesX + tileX;
if ((prohibit == null) || (!prohibit[tindx] && !prohibit[tindx + 1])) {
tiles[tindx + 1] |= src_tiles[tindx];
tiles[tindx + 1] |= src_tiles[tindx];
}
}
......@@ -1325,5 +1454,5 @@ public class MeasuredLayers {
hor = !hor;
}
}
}
......@@ -3572,7 +3572,7 @@ public class QuadCLT {
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// may use this.StartTime to report intermediate steps execution times
String name=(String) imp_quad[0].getProperty("name");
String name=this.correctionsParameters.getModelName((String) imp_quad[0].getProperty("name"));
// int channel= Integer.parseInt((String) imp_src.getProperty("channel"));
// int channel= (Integer) imp_quad[0].getProperty("channel");
String path= (String) imp_quad[0].getProperty("path");
......@@ -3666,6 +3666,7 @@ public class QuadCLT {
}
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
double [][][][][][] clt_data = image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // final double disparity,
......@@ -4740,6 +4741,7 @@ public class QuadCLT {
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......@@ -5632,13 +5634,13 @@ public class QuadCLT {
debugLevel);
tp.clt_3d_passes.add(bgnd_data);
// if (show_init_refine)
if (debugLevel > -1) {
if ((debugLevel > -2) && clt_parameters.show_first_bg) {
tp.showScan(
tp.clt_3d_passes.get(0), // CLTPass3d scan,
"bgnd_data-"+tp.clt_3d_passes.size());
}
//TODO: Move away form here?
//TODO: Move away from here?
ImagePlus imp_bgnd = getBackgroundImage(
clt_parameters,
colorProcParameters,
......@@ -5827,7 +5829,8 @@ public class QuadCLT {
tp.clt_3d_passes.add(refined);
/// if (debugLevel > 1)
if (debugLevel > 0)
// if (debugLevel > 0)
if ((debugLevel > -2) && clt_parameters.show_first_bg)
tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
"before_makeUnique-"+refine_pass);
......@@ -5973,8 +5976,9 @@ public class QuadCLT {
threadsMax, // maximal number of threads to launch
updateStatus,
debugLevel);
if (debugLevel > -1){
System.out.println("CLTMeasure("+refine_pass+")");
// if (debugLevel > -1){
if (debugLevel > -2){
System.out.println("?.CLTMeasure("+refine_pass+")");
}
if (show_init_refine) tp.showScan(
tp.clt_3d_passes.get(refine_pass), // CLTPass3d scan,
......@@ -7041,7 +7045,7 @@ public class QuadCLT {
"after_pass3-"+(next_pass-1)); //String title)
}
String x3d_path= correctionsParameters.selectX3dDirectory( // for x3d and obj
this.image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
true, // smart,
true); //newAllowed, // save
......@@ -7058,7 +7062,7 @@ public class QuadCLT {
try {
wfOutput = new WavefrontExport(
x3d_path,
this.image_name,
correctionsParameters.getModelName(this.image_name),
clt_parameters,
correctionsParameters,
geometryCorrection,
......@@ -7117,7 +7121,7 @@ public class QuadCLT {
clt_parameters,
colorProcParameters,
rgbParameters,
this.image_name+"-img_infinity", // +scanIndex,
correctionsParameters.getModelName(this.image_name)+"-img_infinity", // +scanIndex,
bgndIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
......@@ -7198,7 +7202,7 @@ public class QuadCLT {
clt_parameters,
colorProcParameters,
rgbParameters,
this.image_name+"-img"+scanIndex,
correctionsParameters.getModelName(this.image_name)+"-img"+scanIndex,
scanIndex,
threadsMax, // maximal number of threads to launch
updateStatus,
......@@ -7275,9 +7279,9 @@ public class QuadCLT {
if ((x3d_path != null) && (x3dOutput != null)){
// x3d_path+=Prefs.getFileSeparator()+this.image_name+".x3d";
// x3d_path+=Prefs.getFileSeparator()+correctionsParameters.getModelName(this.image_name)+".x3d";
// x3dOutput.generateX3D(x3d_path);
x3dOutput.generateX3D(x3d_path+Prefs.getFileSeparator()+this.image_name+".x3d");
x3dOutput.generateX3D(x3d_path+Prefs.getFileSeparator()+correctionsParameters.getModelName(this.image_name)+".x3d");
}
if (wfOutput != null){
wfOutput.close();
......@@ -7562,7 +7566,7 @@ public class QuadCLT {
debugLevel);
String path= correctionsParameters.selectX3dDirectory(
//TODO: Which one to use - name or this.image_name ?
this.image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
// name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
true, // smart,
......@@ -7711,7 +7715,7 @@ public class QuadCLT {
String path= correctionsParameters.selectX3dDirectory(
//TODO: Which one to use - name or this.image_name ?
this.image_name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.getModelName(this.image_name), // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
correctionsParameters.x3dModelVersion,
// name, // quad timestamp. Will be ignored if correctionsParameters.use_x3d_subdirs is false
true, // smart,
......@@ -7841,6 +7845,7 @@ public class QuadCLT {
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......@@ -8054,6 +8059,7 @@ public class QuadCLT {
final double disparity_corr = (z_correction == 0) ? 0.0 : geometryCorrection.getDisparityFromZ(1.0/z_correction);
image_dtt.clt_aberrations_quad_corr(
clt_parameters.img_dtt, // final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
1, // final int macro_scale, // to correlate tile data instead of the pixel data: 1 - pixels, 8 - tiles
tile_op, // per-tile operation bit codes
disparity_array, // clt_parameters.disparity, // final double disparity,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3518,7 +3518,7 @@ public class TileProcessor {
final boolean show_scan = show_filter_scan || (debugLevel > 1);
showDoubleFloatArrays sdfa_instance = null;
if ((debugLevel > -2) && ((debugLevel > -1) || show_scan)) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
if (debugLevel > 0){
if (debugLevel > -2){
System.out.println("FilterScan(,,"+disparity_far+", " +disparity_near+", "+ sure_smth);
}
final int tlen = tilesY * tilesX;
......@@ -3747,7 +3747,8 @@ public class TileProcessor {
return these_tiles;
}
// Next runs before filter, maybe should be after or combined otherwise (i.e filter strengths, but keep original disparities. Or use disparity
// to some power when averaging here)
public int [] combineOrthoDisparity(
final CLTPass3d scan, // scan data
final boolean or_hor, // true; // Apply ortho correction to horizontal correlation (vertical features)
......@@ -3760,6 +3761,8 @@ public class TileProcessor {
final double or_threshold, // 1.5; // Minimal scaled offsetg ortho strength to normal strength needed for replacement
final double or_absHor, // 0.15; // Minimal horizontal absolute scaled offset ortho strength needed for replacement
final double or_absVert, // 0.19; // Minimal vertical absolute scaled offset ortho strength needed for replacement
final double or_maxDisp, // 5.0; // Maximal disparity to apply ortho correction
final boolean show_ortho, // show replacement of disparity/strength by those of hor/vert
final int debugLevel)
{
double [] disparity = scan.getDisparity(0); // calculated, to be modified
......@@ -3769,6 +3772,31 @@ public class TileProcessor {
double [] strength_hor = scan.getHorStrength(); // .clone();
double [] strength_vert = scan.getVertStrength(); // .clone();
int [] replaced = new int[strength.length];
double [][] dbg_img = null;
String [] dbg_titles = {"disparity", // 0
"orig_disparity", // 1
"hor_disparity", // 2
"hor_disparity_mod", // 3
"vert_disparity", // 4
"vert_disparity_mod",// 5
"strength", // 6
"orig_strength", // 7
"hor_strength", // 8
"hor_strength_mod", // 9
"vert_strength", // 10
"vert_strength_mod", // 11
"replaced"}; // 12
if (show_ortho) {
dbg_img=new double [dbg_titles.length][];
dbg_img[1] = disparity.clone();
dbg_img[2] = disparity_hor.clone();
dbg_img[4] = disparity_vert.clone();
dbg_img[7] = strength.clone();
dbg_img[8] = strength_hor.clone();
dbg_img[10] = strength_vert.clone();
}
if (or_hor){
for (int i = 0; i < strength_hor.length; i++){
strength_hor[i] *= or_scale;
......@@ -3780,6 +3808,11 @@ public class TileProcessor {
or_sharp, // double k, // sharpen in orthogonal direction with (-k,2*k-1,-k). 0 - no sharpening
or_offset, // double offset, // subtract from strength, limit by 0.0
false); // boolean vert) // true - sharpen vertically, blur horizontally. False - sharpen horizontally, blur vertically
if (show_ortho) {
dbg_img[3] = disparity_hor.clone();
dbg_img[9] = strength_hor.clone();
}
}
if (or_vert){
for (int i = 0; i < strength_vert.length; i++){
......@@ -3792,12 +3825,16 @@ public class TileProcessor {
or_sharp, // double k, // sharpen in orthogonal direction with (-k,2*k-1,-k). 0 - no sharpening
or_offset, // double offset, // subtract from strength, limit by 0.0
true); // boolean vert) // true - sharpen vertically, blur horizontally. False - sharpen horizontally, blur vertically
if (show_ortho) {
dbg_img[5] = disparity_vert.clone();
dbg_img[11] = strength_vert.clone();
}
}
double ko = (or_threshold - 1) * or_offset;
double ao = (or_asym - 1) * or_offset;
if (or_hor){
for (int i = 0; i < strength_hor.length; i++){
if (
if ( (disparity_hor[i] < or_maxDisp) &&
(strength_hor[i] > or_absHor) &&
(strength_hor[i] > or_threshold * strength[i] - ko) &&
(!or_vert || (strength_hor[i] > or_asym * strength_vert[i] - ao))){
......@@ -3809,7 +3846,7 @@ public class TileProcessor {
}
if (or_vert){
for (int i = 0; i < strength_vert.length; i++){
if (
if ( (disparity_vert[i] < or_maxDisp) &&
(strength_vert[i] > or_absVert) &&
(strength_vert[i] > or_threshold * strength[i] - ko) &&
(!or_hor || (strength_vert[i] > or_asym * strength_hor[i] - ao))){
......@@ -3819,6 +3856,15 @@ public class TileProcessor {
}
}
}
if (show_ortho) {
dbg_img[0] = disparity.clone();
dbg_img[6] = strength.clone();
dbg_img[12] = new double [replaced.length];
for (int i = 0; i < replaced.length; i++) {
dbg_img[12][i] = replaced[i];
}
(new showDoubleFloatArrays()).showArrays(dbg_img, tilesX, tilesY, true, "ortho_internal",dbg_titles);
}
return replaced;
}
......@@ -4192,6 +4238,8 @@ public class TileProcessor {
clt_parameters.or_threshold, // 1.5; // Minimal scaled offsetg ortho strength to normal strength needed for replacement
clt_parameters.or_absHor, // 0.15; // Minimal horizontal absolute scaled offset ortho strength needed for replacement
clt_parameters.or_absVert, // 0.19; // Minimal vertical absolute scaled offset ortho strength needed for replacement
clt_parameters.or_maxDisp, // 5.0; // Maximal disparity to apply ortho correction
show_ortho, // show replacement of disparity/strength by those of hor/vert
debugLevel);
if (clt_parameters.poles_fix) {
......@@ -4311,6 +4359,13 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -4328,6 +4383,13 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -4457,7 +4519,7 @@ public class TileProcessor {
for (int i = 0; i < masked_filtered.length; i++){
if (!grown[i]) masked_filtered[i] = Double.NaN;
}
if (show_super){
if (show_super && false){ // something is broken, java.lang.NullPointerException at TileProcessor.refinePassSetup(TileProcessor.java:4488)
String [] dbg_disp_tiltes={"masked", "filtered", "disp_combo", "disparity","st_disparity", "strength",
"st_strength","outlayers","these","border","border_tiles"}; // ,"before","after","after1","after2","after3","neib"};
double [][] dbg_disp = new double [dbg_disp_tiltes.length][];
......@@ -5083,7 +5145,7 @@ public class TileProcessor {
// if (use_supertiles || show_st) {
String [] dbg_st_titles = {"raw", "sampled", "blurred"+clt_parameters.stSigma,"max-min-max"};
double [][] dbg_hist = new double[dbg_st_titles.length][];
if (show_st) { // otherwise only blured version is needed
if (show_st) { // otherwise only blurred version is needed
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
......@@ -5098,6 +5160,13 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
scan_prev.setSuperTiles(
......@@ -5114,6 +5183,13 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
}
......@@ -5133,6 +5209,13 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
if (show_st) { // otherwise only blured version is needed
dbg_hist[2] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -5162,6 +5245,13 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
}
......@@ -5187,6 +5277,14 @@ public class TileProcessor {
clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.plBlurBinHor, // final double bin_blur_hor, // Blur disparity histograms for horizontal clusters by this sigma (in bins)
clt_parameters.plBlurBinVert, // final double bin_blur_vert, // Blur disparity histograms for constant disparity clusters by this sigma (in bins)
clt_parameters.plMaxDiffHor, // final double max_diff_hor, // maximal disparity difference (to assign to a cluster (of Double.NaN) at first run for horizontal planes
......@@ -5261,6 +5359,14 @@ public class TileProcessor {
clt_parameters.stSmplRms, // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // final boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.plDiscrTolerance, // final double plDiscrTolerance, // = 0.4; // Maximal disparity difference from the plane to consider tile
clt_parameters.plDiscrDispRange, // final double plDiscrDispRange, // = 0.6; // Parallel move known planes around original know value for the best overall fit
clt_parameters.plDiscrSteps, // final int plDiscrSteps, // = 3; // Number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)
......@@ -5375,6 +5481,15 @@ public class TileProcessor {
clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
debugLevel, // 1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -5967,6 +6082,9 @@ public class TileProcessor {
clt_parameters.or_threshold, // 1.5; // Minimal scaled offsetg ortho strength to normal strength needed for replacement
clt_parameters.or_absHor, // 0.15; // Minimal horizontal absolute scaled offset ortho strength needed for replacement
clt_parameters.or_absVert, // 0.19; // Minimal vertical absolute scaled offset ortho strength needed for replacement
clt_parameters.or_maxDisp, // 5.0; // Maximal disparity to apply ortho correction
clt_parameters.show_ortho_combine, // show replacement of disparity/strength by those of hor/vert
debugLevelInner);
if (clt_parameters.poles_fix) {
......@@ -6026,7 +6144,7 @@ public class TileProcessor {
// final int threadsMax, // maximal number of threads to launch
// final boolean updateStatus,
batch_mode ? -5: 2); //debugLevel);
} else {
} else { //!ortho_old
these_tiles= combineHorVertDisparity_old(
scan_prev, // final CLTPass3d scan,
scan_bg.selected, // clt_3d_passes.get(0).selected, // final boolean [] bg_tiles, // get from selected in clt_3d_passes.get(0);
......@@ -6091,6 +6209,15 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // Use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
......@@ -6108,6 +6235,15 @@ public class TileProcessor {
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stSmplWnd, // boolean smplWnd, // use window functions for the samples
clt_parameters.fs_max_abs_tilt, // 2.0; // Maximal absolute tilt in pixels/tile
clt_parameters.fs_max_rel_tilt, // 0.2; // Maximal relative tilt in pixels/tile/disparity
clt_parameters.fs_damp_tilt, // 0.001; // Damp tilt to handle insufficient (co-linear)data
clt_parameters.fs_min_tilt_disp, // 4.0; // Disparity switch between filtering modes - near objects use tilts, far - use max disparity
clt_parameters.fs_transition, // 1.0; // Mode transition range (between tilted and maximal disparity)
clt_parameters.fs_far_mode, // 1; // Far objects filtering mode (0 - off, 1 - power of disparity)
clt_parameters.fs_far_power, // 1.0; // Raise disparity to this power before averaging for far objects
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
......
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