Commit b9f88154 authored by Andrey Filippov's avatar Andrey Filippov

Matching image pairs

parent fec6933a
......@@ -1347,7 +1347,38 @@ public class EyesisCorrectionParameters {
return true;
}
// get list of source files in a directory
public String[] selectSourceFileInSet(String setdir, int debugLevel) {
int num_chn_main = numSubCameras;
int num_chn_aux = ((aux_camera != null)? aux_camera.numSubCameras : 0);
int num_chn_files = num_chn_main + num_chn_aux;
String [] extensions = getSourceSuffixes();// ={this.sourceSuffix};
String [] prefixes = getSourcePrefixes();
extensions[0] = sourceSuffix;
prefixes[0] = sourcePrefix;
MultipleExtensionsFileFilter setFilter = new MultipleExtensionsFileFilter(prefixes,extensions,"Image sets");
File fsetdir = new File(setdir);
ArrayList<File> setFilesList = new ArrayList<File>(); // list of set files
File [] setChnFiles = fsetdir.listFiles(setFilter);
int num_match = setChnFiles.length;
if ( (num_match == num_chn_files) || // all files for main and aux
(num_match == num_chn_main) || // only main camera files
(num_match == num_chn_aux)) // only aux camera files
{ // only use sets of exact number of files
for (File f: setChnFiles) {
setFilesList.add(f);
}
}
String [] sourcePaths = new String[setFilesList.size()];
for (int nFile = 0; nFile < sourcePaths.length; nFile++) {
sourcePaths[nFile]= setFilesList.get(nFile).getPath();
}
return sourcePaths;
}
public boolean selectSourceFiles(boolean allFiles) {
return selectSourceFiles(allFiles, 1); // debug level 1 - modify here
......
......@@ -294,6 +294,11 @@ public class EyesisCorrections {
// FIXME: Use only this PixelMappings's channels, do not mix exposures from main/aux!
public double [] calcReferenceExposures(int debugLevel){
String [] paths=this.correctionsParameters.getSourcePaths();
return calcReferenceExposures(paths, debugLevel);
}
public double [] calcReferenceExposures(String [] paths,int debugLevel){
// String [] paths=this.correctionsParameters.getSourcePaths();
double [] exposures=new double [paths.length];
if (this.correctionsParameters.exposureCorrectionMode<2){
for (int nFile=0;nFile<paths.length;nFile++) {
......
......@@ -699,6 +699,7 @@ private Panel panel1,
addButton("LIST extrinsics", panelClt5, color_report);
addButton("DSI histogram", panelClt5, color_report);
addButton("ML recalc", panelClt5, color_process);
addButton("Inter Test", panelClt5, color_stop);
plugInFrame.add(panelClt5);
}
......@@ -5099,7 +5100,14 @@ private Panel panel1,
CLT_PARAMETERS.batch_run = true;
batchLwir();
return;
/* ======================================================================== */
} else if (label.equals("Inter Test")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
CLT_PARAMETERS.batch_run = true;
testInterScene();
return;
/* ======================================================================== */
} else if (label.equals("CLT rig edit")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
......@@ -5700,6 +5708,9 @@ private Panel panel1,
return true;
}
public boolean getPairImages2() {
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
......@@ -6378,7 +6389,96 @@ private Panel panel1,
}
public boolean testInterScene() {
long startTime=System.nanoTime();
// load needed sensor and kernels files
if (!prepareRigImages()) return false;
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return false;
setAllProperties(PROPERTIES); // batchRig may save properties with the model. Extrinsics will be updated, others should be set here
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Testing Interscene processing ++++++++++++++");
}
if (CLT_PARAMETERS.useGPU()) { // only init GPU instances if it is used
if (GPU_TILE_PROCESSOR == null) {
try {
GPU_TILE_PROCESSOR = new GPUTileProcessor(CORRECTION_PARAMETERS.tile_processor_gpu);
} catch (Exception e) {
System.out.println("Failed to initialize GPU class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} //final int debugLevel);
}
if (CLT_PARAMETERS.useGPU(false) && (QUAD_CLT != null) && (GPU_QUAD == null)) { // if GPU main is needed
try {
GPU_QUAD = GPU_TILE_PROCESSOR.new GpuQuad(
QUAD_CLT,
4,
3);
} catch (Exception e) {
System.out.println("Failed to initialize GpuQuad class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} //final int debugLevel);
QUAD_CLT.setGPU(GPU_QUAD);
}
/*
if (CLT_PARAMETERS.useGPU(true) && (QUAD_CLT_AUX != null) && (GPU_QUAD_AUX == null)) { // if GPU AUX is needed
try {
GPU_QUAD_AUX = GPU_TILE_PROCESSOR. new GpuQuad(//
QUAD_CLT_AUX,
4,
3);
} catch (Exception e) {
System.out.println("Failed to initialize GpuQuad class");
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} //final int debugLevel);
QUAD_CLT_AUX.setGPU(GPU_QUAD_AUX);
}*/
}
try {
TWO_QUAD_CLT.TestInterScene(
QUAD_CLT, // QuadCLT quadCLT_main,
// QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
CLT_PARAMETERS, // EyesisCorrectionParameters.DCTParameters dct_parameters,
DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters debayerParameters,
COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
COLOR_PROC_PARAMETERS_AUX, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters_aux,
CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters channelGainParameters,
RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters rgbParameters,
EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
PROPERTIES, // Properties properties,
THREADS_MAX, //final int threadsMax, // maximal number of threads to launch
UPDATE_STATUS, //final boolean updateStatus,
DEBUG_LEVEL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //final int debugLevel);
if (configPath!=null) {
saveTimestampedProperties( // save config again
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
}
System.out.println("batchRig(): Processing finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
return true;
}
public boolean exportMLData() {
long startTime=System.nanoTime();
......
......@@ -590,7 +590,7 @@ public class GPUTileProcessor {
}
public class GpuQuad{ // quad camera description
public final QuadCLT quadCLT;
public QuadCLT quadCLT;
public final int img_width;
public final int img_height;
public final int kernels_hor; // int kernels_hor,
......@@ -657,6 +657,16 @@ public class GPUTileProcessor {
private boolean geometry_correction_set = false;
private boolean geometry_correction_vector_set = false;
public int gpu_debug_level = 1;
// should only be updated with the same cameras instance
public void updateQuadCLT(final QuadCLT quadCLT) {
this.quadCLT = quadCLT;
resetGeometryCorrection();
resetGeometryCorrectionVector();
bayer_set = false;
}
public QuadCLT getQuadCLT( ) {
return this.quadCLT;
}
public GpuQuad(
final QuadCLT quadCLT,
// final int img_width,
......
......@@ -614,6 +614,15 @@ public class CLTPass3d{
}
calc_disparity_combo = calc_disparity.clone(); // for now - just clone, can be modified separately and combined with hor/vert
}
// bypassing calculations
public void setCalcDisparityStrength(
double [] disparity,
double [] strength) {
this.calc_disparity = disparity;
this.strength = strength;
calc_disparity_combo = calc_disparity.clone();
}
/**
* Replaces current combo disparity for tiles that are weak and do not have any neighbor within disparity range from this one
......
......@@ -80,30 +80,22 @@ public class TileProcessor {
public boolean [] rig_post_poles_sel = null; // Rig tile selection after processing poles
public double [][] main_ds_ml = null; // main camera DSI restored from the COMBO-DSI file to generate ML test files
public boolean monochrome = false; // these are monochrome images
public boolean lwir = false; // all monochrome are lwir
private boolean is_aux = false; // this camera is aux
public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing
public int clt_3d_passes_rig_size = 0; //clt_3d_passes size after initial processing and rig processing
private int tilesX;
private int tilesY;
private double corr_magic_scale = 0.85; // reported correlation offset vs. actual one (not yet understood)
private double trustedCorrelation = 4.0; // trusted measured disparity difference (before scaling)
private double maxOverexposure = 0.5;
private int tileSize = 8; // number of linear pixels in a tile (tile is square tileSize*tileSize)
int superTileSize = 8; // number of linear tiles in a super-tile (supertile is square superTileSize*superTileSize tiles
// or (superTileSize*tileSize) * (superTileSize*tileSize) pixels, currently 64x64 pixels)
double [][] periodics = null;
public int threadsMax = 100; // maximal number of frames to run
public int globalDebugLevel = 0;
public boolean monochrome = false; // these are monochrome images
public boolean lwir = false; // all monochrome are lwir
private boolean is_aux = false; // this camera is aux
public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing
public int clt_3d_passes_rig_size = 0; //clt_3d_passes size after initial processing and rig processing
private int tilesX;
private int tilesY;
private double corr_magic_scale = 0.85; // reported correlation offset vs. actual one (not yet understood)
private double trustedCorrelation = 4.0; // trusted measured disparity difference (before scaling)
private double maxOverexposure = 0.5;
private int tileSize = 8; // number of linear pixels in a tile (tile is square tileSize*tileSize)
int superTileSize = 8; // number of linear tiles in a super-tile (supertile is square superTileSize*superTileSize tiles
double [][] periodics = null;
public int threadsMax = 100; // maximal number of frames to run
public int globalDebugLevel = 0;
public double [][] dbg_filtered_disp_strength;
public double [][] getPeriodcs(){
// todo: add calculation (if null) and reset
return this.periodics;
}
// All parameters are set only once, during instantiation
public TileProcessor(
......@@ -131,6 +123,43 @@ public class TileProcessor {
this.maxOverexposure = maxOverexposure;
this.threadsMax = threadsMax;
}
public TileProcessor(TileProcessor tp) {
this.tilesX = tp.tilesX;
this.tilesY = tp.tilesY;
this.tileSize = tp.tileSize;
this.superTileSize = tp.superTileSize;
this.monochrome = tp.monochrome;
this.lwir = tp.lwir;
this.is_aux = tp.is_aux;
this.corr_magic_scale = tp.corr_magic_scale;
this.trustedCorrelation = tp.trustedCorrelation;
this.maxOverexposure = tp.maxOverexposure;
this.threadsMax = tp.threadsMax;
this.globalDebugLevel = tp.globalDebugLevel;
// next should not be needed for new instance
/*
this.periodics = ErsCorrection.clone2d(tp.periodics); not needed
this.dbg_filtered_disp_strength = tp.dbg_filtered_disp_strength;
public ArrayList <CLTPass3d> clt_3d_passes = null;
public double [][] rig_disparity_strength = null; // Disparity and strength created by a two-camera rig, with disparity scale and distortions of the main camera
public double [][] rig_pre_poles_ds = null; // Rig disparity and strength before processing poles
public double [][] rig_post_poles_ds = null; // Rig disparity and strength after processing poles
public boolean [] rig_pre_poles_sel = null; // Rig tile selection before processing poles
public boolean [] rig_post_poles_sel = null; // Rig tile selection after processing poles
public double [][] main_ds_ml = null; // main camera DSI restored from the COMBO-DSI file to generate ML test files
public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing
public int clt_3d_passes_rig_size = 0; //clt_3d_passes size after initial processing and rig processing
*/
}
public double [][] getPeriodcs(){
// todo: add calculation (if null) and reset
return this.periodics;
}
public boolean isMonochrome() {return monochrome;}
public boolean isLwir() {return lwir;}
public boolean isAux() {return is_aux;}
......@@ -8697,6 +8726,151 @@ ImageDtt.startAndJoin(threads);
titles);
}
public double [] fillNaNs(
final double [] data,
int width,
final int grow,
double diagonal_weight, // relative to ortho
int num_passes,
final int threadsMax) // maximal number of threads to launch
{
final int scan0 = ( 3* grow) / 2;
int height = data.length/width;
double wdiag = 0.25 *diagonal_weight / (diagonal_weight + 1.0);
double wortho = 0.25 / (diagonal_weight + 1.0);
final double [] neibw = {wortho, wdiag, wortho, wdiag, wortho, wdiag, wortho, wdiag};
final int tiles = width * height;
final boolean [] fixed = new boolean [tiles];
int num_fixed = 0;
double davg = 0.0;
for (int i = 0; i < tiles; i++) {
if (!Double.isNaN(data[i])) {
fixed[i] = true;
num_fixed ++;
davg+= data[i];
}
}
if (num_fixed > 0) {
davg /= num_fixed;
} else {
return null;
}
final double fdavg = davg;
final boolean [] grown = fixed.clone();
final TileNeibs tn = new TileNeibs(width, height);
growTiles(
grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
grown,
null,
width,
height);
int num_active = 0;
for (int i = 0; i < tiles; i++) {
if (grown[i] && !fixed[i]) num_active++;
}
if (num_active == 0) {
return data.clone();
}
final int [] active = new int [num_active];
final double [] data_in = data.clone();
final double [] data_out = new double [tiles];
num_active = 0;
for (int i = 0; i < tiles; i++) {
if (grown[i] && !fixed[i]) {
active [num_active++] = i;
data_in[i] = davg; // initial value
}
}
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
// final int numThreads = threads.length;
final AtomicInteger ai = new AtomicInteger(0);
//Set initial values
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int iTile = ai.getAndIncrement(); iTile < active.length; iTile = ai.getAndIncrement()) {
int nt = active[iTile];
double s = 0.0;
int n = 0;
for (int dy = -scan0; dy <= scan0; dy++) {
for (int dx = -scan0; dx <= scan0; dx++) {
int nt1 = tn.getNeibIndex(nt, dx, dy);
if ((nt1 >=0) && fixed[nt1]) {
s += data[nt1];
n++;
}
}
}
if (n > 0) {
data_in[nt] = s/n;
} else {
data_in[nt] = fdavg;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
for (int pass = 0; pass < num_passes; pass ++) {
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int iTile = ai.getAndIncrement(); iTile < active.length; iTile = ai.getAndIncrement()) {
int nt = active[iTile];
double s = 0.0;
double sw = 0.0;
for (int dir = 0; dir < 8; dir++) {
int nt1 = tn.getNeibIndex(nt, dir);
if ((nt1 >=0) && grown[nt1]) {
if (fixed[nt1]) {
s += data[nt1] * neibw[dir];
} else {
s += data_in[nt1] * neibw[dir];
}
sw += neibw[dir];
}
}
// sw should never be 0;
s /= sw;
data_out[nt] = s;
}
}
};
}
ImageDtt.startAndJoin(threads);
if (pass < (num_passes - 1)) {
System.arraycopy(data_out,0,data_in,0,tiles);
}
}
for (int i = 0; i < tiles; i++) if (fixed[i]) {
data_out[i] = data[i];
}
/*
double [][] dbg_img = new double [4][tiles];
String [] titles = {"data", "data_out", "fixed", "grown"};
dbg_img[0] = data;
dbg_img[1] = data_out;
for (int i = 0; i < tiles; i++) {
dbg_img[2][i] = fixed[i] ? 1.0 : 0.0;
dbg_img[3][i] = grown[i] ? 1.0 : 0.0;
}
(new ShowDoubleFloatArrays()).showArrays(
dbg_img,
tilesX,
tilesY,
true,
"filled_NaNs",
titles);
*/
return data_out;
}
/* Create a Thread[] array as large as the number of processors available.
......
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