Loading src/main/java/com/elphel/imagej/cameras/CLTParameters.java +2 −2 Original line number Diff line number Diff line Loading @@ -1544,8 +1544,8 @@ public class CLTParameters { if (properties.getProperty(prefix+"max_corr_radius")!=null) this.max_corr_radius=Double.parseDouble(properties.getProperty(prefix+"max_corr_radius")); // for compatibility with old settings if (properties.getProperty(prefix+"enhortho_width")!=null) this.img_dtt.enhortho_width=Integer.parseInt(properties.getProperty(prefix+"enhortho_width")); if (properties.getProperty(prefix+"enhortho_scale")!=null) this.img_dtt.enhortho_scale=Double.parseDouble(properties.getProperty(prefix+"enhortho_scale")); if (properties.getProperty(prefix+"enhortho_width")!=null) this.img_dtt.setEnhOrthoWidth(Integer.parseInt(properties.getProperty(prefix+"enhortho_width"))); if (properties.getProperty(prefix+"enhortho_scale")!=null) this.img_dtt.setEnhOrthoScale(Double.parseDouble(properties.getProperty(prefix+"enhortho_scale"))); // for compatibility with old settings if (properties.getProperty(prefix+"max_corr_double")!=null) this.max_corr_double=Boolean.parseBoolean(properties.getProperty(prefix+"max_corr_double")); Loading src/main/java/com/elphel/imagej/correction/EyesisCorrections.java +17 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,18 @@ public class EyesisCorrections { false, false); } public void initPixelMapping( int debugLevel) { String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel); this.pixelMapping=new PixelMapping( sensorPaths, correctionsParameters.firstSubCameraConfig, // int first_channel, // 0 - old way correctionsParameters.numSubCameras, // int num_channels, // 0 - any true, // boolean update_channel, // false (replace file channel with effective channel (subtract first_channel) debugLevel); } public void initSensorFiles( int debugLevel, boolean missing_ok, Loading @@ -132,6 +144,10 @@ public class EyesisCorrections { ){ this.sharpKernelPaths=null; this.smoothKernelPaths=null; if (this.pixelMapping == null) { // NOTE: will not notice switching sensor files ! initPixelMapping(debugLevel); } /* String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel); this.pixelMapping=new PixelMapping( sensorPaths, Loading @@ -139,6 +155,7 @@ public class EyesisCorrections { correctionsParameters.numSubCameras, // int num_channels, // 0 - any true, // boolean update_channel, // false (replace file channel with effective channel (subtract first_channel) debugLevel); */ if (all_sensors) { this.usedChannels = new boolean [this.pixelMapping.sensors.length]; for (int i = 0; i < this.usedChannels.length; i++) { Loading src/main/java/com/elphel/imagej/correction/Eyesis_Correction.java +304 −4 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ import com.elphel.imagej.lwir.LwirReader; import com.elphel.imagej.readers.EyesisTiff; import com.elphel.imagej.tensorflow.TensorflowInferModel; import com.elphel.imagej.tileprocessor.DttRad2; import com.elphel.imagej.tileprocessor.GeometryCorrection; import com.elphel.imagej.tileprocessor.ImageDtt; import com.elphel.imagej.tileprocessor.MLStats; import com.elphel.imagej.tileprocessor.QuadCLT; Loading Loading @@ -728,6 +729,7 @@ private Panel panel1, addButton("AUX planes", panelLWIR, color_conf_process_aux); addButton("AUX ASSIGN", panelLWIR, color_process_aux); addButton("AUX OUT 3D", panelLWIR, color_process_aux); addButton("Main to AUX", panelLWIR, color_process_aux); addButton("LWIR_TEST", panelLWIR, color_conf_process); addButton("LWIR_ACQUIRE", panelLWIR, color_conf_process); Loading Loading @@ -3958,12 +3960,12 @@ private Panel panel1, IJ.showMessage("Warning",msg); return; } /* EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL, true, // true - ignore missing files true, // boolean all_sensors, COLOR_PROC_PARAMETERS.correct_vignetting); //boolean correct_vignetting */ QUAD_CLT.resetGeometryCorrection(); QUAD_CLT.initGeometryCorrection(DEBUG_LEVEL+2); Loading Loading @@ -4450,6 +4452,10 @@ private Panel panel1, return; } } @SuppressWarnings("unused") QuadCLT dbg_qc_main = QUAD_CLT; @SuppressWarnings("unused") QuadCLT dbg_qc_aux = QUAD_CLT_AUX; ///======================================== int num_infinity_corr = infinity_corr? CLT_PARAMETERS.inf_repeat : 1; Loading Loading @@ -4684,7 +4690,12 @@ private Panel panel1, EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); clt3d_aux(adjust_extrinsics, adjust_poly); return; } else if (label.equals("Main to AUX")) { DEBUG_LEVEL=MASTER_DEBUG_LEVEL; EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); mainToAux(); return; // } else if (label.equals("CLT planes")) { DEBUG_LEVEL=MASTER_DEBUG_LEVEL; EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); Loading Loading @@ -5106,6 +5117,295 @@ private Panel panel1, // End of buttons code } } /* ======================================================================== */ public boolean mainToAux() { if (QUAD_CLT == null){ QUAD_CLT = new QuadCLT ( QuadCLT.PREFIX, PROPERTIES, EYESIS_CORRECTIONS, CORRECTION_PARAMETERS); if (DEBUG_LEVEL > 0){ System.out.println("Created new QuadCLT instance, will need to read CLT kernels"); } } if (QUAD_CLT_AUX == null){ if (EYESIS_CORRECTIONS_AUX == null) { EYESIS_CORRECTIONS_AUX = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS.getAux()); } QUAD_CLT_AUX = new QuadCLT ( QuadCLT.PREFIX_AUX, PROPERTIES, EYESIS_CORRECTIONS_AUX, CORRECTION_PARAMETERS.getAux()); if (DEBUG_LEVEL > 0){ System.out.println("Created new QuadCLT instance, will need to read CLT kernels for aux camera"); } } @SuppressWarnings("unused") QuadCLT dbg_QUAD_CLT = QUAD_CLT; @SuppressWarnings("unused") QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX; ImagePlus imp_sel = WindowManager.getCurrentImage(); if (imp_sel==null){ IJ.showMessage("Error","There are no images open\nProcess canceled"); return false; } ImageStack stack_sel = imp_sel.getStack(); String [] labels = stack_sel.getSliceLabels(); int indx = 0; for (int i = 0; i < labels.length; i++) { if (labels[i] !=null) indx++; } boolean just2 = (indx == 2) && (labels[0] != null) && (labels[1] != null); String [] choices = {"---", "disparity","strength"}; double min_strength = 0.18; // use some configurable parameters boolean use_wnd = true; boolean split_fg_bg = true; double split_fbg_rms = 0.2; // split small source samples tp FG/BG if all aux tile RMS exceeds this value GenericDialog gd = new GenericDialog("Select disparity and strength slices"); indx = 0; for (int i = 0; i < labels.length; i++) { if (labels[i] !=null) { gd.addChoice(((indx++) + 1)+": " +labels[i], choices, choices[just2 ? (i + 1) : 0]); } } gd.addMessage("--- main-to-aux depth map parameters ---"); gd.addNumericField("Minimal EO correlation strength", min_strength, 3, 6, ""); gd.addCheckbox("Use window for AUX tiles to reduce weight of the hi-res tiles near low-res tile boundaries" , use_wnd); gd.addCheckbox("Split FG and BG if hi-res disparity varies for the same low-res tile", split_fg_bg); gd.addNumericField("Aux disparity thershold to split FG and BG", split_fbg_rms, 3, 6, ""); WindowTools.addScrollBars(gd); gd.showDialog(); if (gd.wasCanceled()) return false; int [] selections = new int[indx]; indx = 0; for (int i = 0; i < selections.length; i++) { selections[i] = gd.getNextChoiceIndex(); } min_strength = gd.getNextNumber(); use_wnd = gd.getNextBoolean(); split_fg_bg = gd.getNextBoolean(); split_fbg_rms = gd.getNextNumber(); int index_disparity = -1, index_strength=-1; indx = 0; for (int i = 0; i < labels.length; i++) if (labels[i] != null) { if ((index_disparity < 0) && (selections[indx] == 1)) { index_disparity = i; } if ((index_strength < 0) && (selections[indx] == 2)) { index_strength = i; } if ((index_disparity >= 0 ) &&(index_strength >= 0 )) { break; } indx++; } int width = imp_sel.getWidth(); int height = imp_sel.getHeight(); String title = imp_sel.getTitle()+"-DS"; float [][] f_ds = new float [2][]; f_ds[0] = (float[]) stack_sel.getPixels(index_disparity+1); f_ds[1] = (float[]) stack_sel.getPixels(index_strength+1); double [][] ds = new double [2][width*height]; for (int l = 0; l < ds.length; l++) { for (int i = 0; i < ds[l].length; i++) { ds[l][i] = f_ds[l][i]; } } String [] titles = {"disparity","strength"}; (new ShowDoubleFloatArrays()) .showArrays(ds, width, height, true, title, titles); int tile_size = CLT_PARAMETERS.transform_size; int [] wh_aux = QUAD_CLT_AUX.getGeometryCorrection().getSensorWH(); int tilesX_aux = wh_aux[0] / tile_size; int tilesY_aux = wh_aux[1] / tile_size; // int num_slices = split_fg_bg? 7:2; String [] fgbg_titles = {"disparity","strength", "rms","rms-split","fg-disp","fg-str","bg-disp","bg-str"}; String [] rslt_titles = split_fg_bg ? fgbg_titles :titles; double [][] ds_aux = DepthMapMainToAux( ds, // double [][] ds, QUAD_CLT.getGeometryCorrection(), // GeometryCorrection geometryCorrection_main, QUAD_CLT_AUX.getGeometryCorrection(), // GeometryCorrection geometryCorrection_aux, CLT_PARAMETERS, min_strength, // double min_strength, use_wnd, split_fg_bg, split_fbg_rms, DEBUG_LEVEL); // int debug_level (new ShowDoubleFloatArrays()).showArrays(ds_aux, tilesX_aux, tilesY_aux, true, title+"_TOAUX", rslt_titles); return true; } public double [][] DepthMapMainToAux( double [][] ds, GeometryCorrection geometryCorrection_main, GeometryCorrection geometryCorrection_aux, CLTParameters clt_Parameters, double min_strength, boolean use_wnd, boolean split_fg_bg, double split_fbg_rms, int debug_level ){ class DS{ double disparity; // gt disparity double strength; // gt strength int tx; // gt tile x int ty; // gt tile x double fx; // fractional aux tile X (0.0..1.0) for optional window double fy; // fractional aux tile Y (0.0..1.0) for optional window // DS (double disparity, double strength){ // this.disparity = disparity; // this.strength = strength; // } DS (double disparity, double strength, int tx, int ty, double fx, double fy){ this.disparity = disparity; this.strength = strength; this.tx = tx; this.ty = ty; this.fx = fx; this.fy = fy; } @Override public String toString() { return String.format("Disparity (str) = % 6f (%5f), tx=%d ty=%d fx=%5f fy=%5f\n", disparity, strength,tx,ty,fx,fy); } } int tile_size = clt_Parameters.transform_size; int [] wh_main = geometryCorrection_main.getSensorWH(); int [] wh_aux = geometryCorrection_aux.getSensorWH(); int tilesX_main = wh_main[0] / tile_size; int tilesY_main = wh_main[1] / tile_size; int tilesX_aux = wh_aux[0] / tile_size; int tilesY_aux = wh_aux[1] / tile_size; ArrayList<ArrayList<DS>> ds_list = new ArrayList<ArrayList<DS>>(); for (int nt = 0; nt < tilesX_aux * tilesY_aux; nt++) { ds_list.add(new ArrayList<DS>()); } for (int ty = 0; ty < tilesY_main; ty++) { double centerY = ty * tile_size + tile_size/2; for (int tx = 0; tx < tilesX_main; tx++) { int nt = ty*tilesX_main + tx; double centerX = tx * tile_size + tile_size/2; double disparity = ds[0][nt]; double strength = ds[1][nt]; if ((strength >= min_strength) && !Double.isNaN(disparity)) { double [] dpxpy_aux = geometryCorrection_aux.getFromOther( geometryCorrection_main, // GeometryCorrection other_gc, centerX, // double other_px, centerY, // double other_py, disparity); // double other_disparity) double fx = dpxpy_aux[1]/tile_size; double fy = dpxpy_aux[2]/tile_size; int tx_aux = (int) Math.floor(fx); int ty_aux = (int) Math.floor(fy); fx -= tx_aux; fy -= ty_aux; if ((ty_aux >= 0) && (ty_aux < tilesY_aux) && (tx_aux >= 0) && (tx_aux < tilesX_aux)) { int nt_aux = ty_aux * tilesX_aux + tx_aux; ds_list.get(nt_aux).add(new DS(dpxpy_aux[0], strength, tx, ty, fx, fy)); } } } } // simple average (ignoring below minimal) int num_slices = split_fg_bg? 8:2; double [][] ds_aux_avg = new double [num_slices][tilesX_aux * tilesY_aux]; for (int ty = 0; ty < tilesY_aux; ty++) { for (int tx = 0; tx < tilesX_aux; tx++) { if ((ty == 4) && (tx == 12)) { System.out.println("tx = "+tx+", ty = "+ty); } int nt = ty * tilesX_aux + tx; ds_aux_avg[0][nt] = Double.NaN; ds_aux_avg[1][nt] = 0.0; if(ds_list.get(nt).isEmpty()) continue; Collections.sort(ds_list.get(nt), new Comparator<DS>() { @Override public int compare(DS lhs, DS rhs) { return rhs.disparity > lhs.disparity ? -1 : (rhs.disparity < lhs.disparity ) ? 1 : 0; } }); double sw = 0.0, swd = 0.0, swd2 = 0.0; for (DS dsi: ds_list.get(nt)) { double w = dsi.strength; if (use_wnd) { w *= Math.sin(Math.PI * (dsi.fx + 0.5/tile_size)) * Math.sin(Math.PI * (dsi.fy + 0.5/tile_size)); } sw += w; double wd = w * dsi.disparity; swd += wd; swd2 += wd * dsi.disparity; } ds_aux_avg[0][nt] = swd/sw; ds_aux_avg[1][nt] = sw/ds_list.get(nt).size(); if (split_fg_bg) { ds_aux_avg[2][nt] = Math.sqrt( (swd2 * sw - swd * swd) / (sw * sw)); ds_aux_avg[3][nt] = ds_aux_avg[2][nt]; // rms ds_aux_avg[4][nt] = ds_aux_avg[0][nt]; // fg disp ds_aux_avg[5][nt] = ds_aux_avg[1][nt]; // fg strength ds_aux_avg[6][nt] = ds_aux_avg[0][nt]; // bg disp ds_aux_avg[7][nt] = ds_aux_avg[1][nt]; // bg strength if (ds_aux_avg[2][nt] >= split_fbg_rms) { // splitting while minimizing sum of 2 squared errors double [][] swfb = new double [2][ds_list.get(nt).size() -1]; double [][] swdfb = new double [2][ds_list.get(nt).size() -1]; double [] s2fb = new double [ds_list.get(nt).size() -1]; for (int n = 0; n < s2fb.length; n++) { // split position double [] s2 = new double[2]; for (int i = 0; i <= s2fb.length; i++) { int fg = (i > n)? 1 : 0; // 0 - bg, 1 - fg DS dsi = ds_list.get(nt).get(i); double w = dsi.strength; if (use_wnd) { w *= Math.sin(Math.PI * dsi.fx) * Math.sin(Math.PI * dsi.fy); } swfb[fg][n] += w; double wd = w * dsi.disparity; swdfb[fg][n] += wd; s2[fg] += wd * dsi.disparity; } s2fb[n] = ((s2[0] * swfb[0][n] - swdfb[0][n] * swdfb[0][n]) / swfb[0][n] + (s2[1] * swfb[1][n] - swdfb[1][n] * swdfb[1][n]) / swfb[1][n]) / (swfb[0][n] + swfb[1][n]); } // now find the n with lowest s2fb and use it to split fg/bg. Could be done in a single pass, but with saved arrays // it is easier to verify int nsplit = 0; for (int i = 1; i < s2fb.length; i++) if (s2fb[i] < s2fb[nsplit]) { nsplit = i; } ds_aux_avg[3][nt] = s2fb[nsplit]; // rms split ds_aux_avg[4][nt] = swdfb[1][nsplit] / swfb[1][nsplit] ; // fg disp ds_aux_avg[5][nt] = swfb[1][nsplit]/ (s2fb.length - nsplit) ; // fg strength ds_aux_avg[6][nt] = swdfb[0][nsplit] / swfb[0][nsplit] ; // bg disp ds_aux_avg[7][nt] = swfb[0][nsplit]/ (nsplit + 1) ; // bg strength } } } } return ds_aux_avg; } //getGeometryCorrection ///data_ssd/lwir3d/results/saved/1562390490_233403/v11/ /* ======================================================================== */ public String getSaveCongigPath() { String configPath=null; Loading Loading @@ -9879,8 +10179,8 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg gd.addNumericField("JPEG scale (%)", 100* processParameters.JPEG_scale,0); gd.addCheckbox ("Save current settings with results", processParameters.saveSettings); gd.addCheckbox ("Update ImageJ status", UPDATE_STATUS); WindowTools.addScrollBars(gd); gd.addNumericField("Debug Level:", MASTER_DEBUG_LEVEL, 0); WindowTools.addScrollBars(gd); gd.showDialog(); if (gd.wasCanceled()) return false; processParameters.eyesisMode= gd.getNextBoolean(); Loading Loading
src/main/java/com/elphel/imagej/cameras/CLTParameters.java +2 −2 Original line number Diff line number Diff line Loading @@ -1544,8 +1544,8 @@ public class CLTParameters { if (properties.getProperty(prefix+"max_corr_radius")!=null) this.max_corr_radius=Double.parseDouble(properties.getProperty(prefix+"max_corr_radius")); // for compatibility with old settings if (properties.getProperty(prefix+"enhortho_width")!=null) this.img_dtt.enhortho_width=Integer.parseInt(properties.getProperty(prefix+"enhortho_width")); if (properties.getProperty(prefix+"enhortho_scale")!=null) this.img_dtt.enhortho_scale=Double.parseDouble(properties.getProperty(prefix+"enhortho_scale")); if (properties.getProperty(prefix+"enhortho_width")!=null) this.img_dtt.setEnhOrthoWidth(Integer.parseInt(properties.getProperty(prefix+"enhortho_width"))); if (properties.getProperty(prefix+"enhortho_scale")!=null) this.img_dtt.setEnhOrthoScale(Double.parseDouble(properties.getProperty(prefix+"enhortho_scale"))); // for compatibility with old settings if (properties.getProperty(prefix+"max_corr_double")!=null) this.max_corr_double=Boolean.parseBoolean(properties.getProperty(prefix+"max_corr_double")); Loading
src/main/java/com/elphel/imagej/correction/EyesisCorrections.java +17 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,18 @@ public class EyesisCorrections { false, false); } public void initPixelMapping( int debugLevel) { String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel); this.pixelMapping=new PixelMapping( sensorPaths, correctionsParameters.firstSubCameraConfig, // int first_channel, // 0 - old way correctionsParameters.numSubCameras, // int num_channels, // 0 - any true, // boolean update_channel, // false (replace file channel with effective channel (subtract first_channel) debugLevel); } public void initSensorFiles( int debugLevel, boolean missing_ok, Loading @@ -132,6 +144,10 @@ public class EyesisCorrections { ){ this.sharpKernelPaths=null; this.smoothKernelPaths=null; if (this.pixelMapping == null) { // NOTE: will not notice switching sensor files ! initPixelMapping(debugLevel); } /* String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel); this.pixelMapping=new PixelMapping( sensorPaths, Loading @@ -139,6 +155,7 @@ public class EyesisCorrections { correctionsParameters.numSubCameras, // int num_channels, // 0 - any true, // boolean update_channel, // false (replace file channel with effective channel (subtract first_channel) debugLevel); */ if (all_sensors) { this.usedChannels = new boolean [this.pixelMapping.sensors.length]; for (int i = 0; i < this.usedChannels.length; i++) { Loading
src/main/java/com/elphel/imagej/correction/Eyesis_Correction.java +304 −4 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ import com.elphel.imagej.lwir.LwirReader; import com.elphel.imagej.readers.EyesisTiff; import com.elphel.imagej.tensorflow.TensorflowInferModel; import com.elphel.imagej.tileprocessor.DttRad2; import com.elphel.imagej.tileprocessor.GeometryCorrection; import com.elphel.imagej.tileprocessor.ImageDtt; import com.elphel.imagej.tileprocessor.MLStats; import com.elphel.imagej.tileprocessor.QuadCLT; Loading Loading @@ -728,6 +729,7 @@ private Panel panel1, addButton("AUX planes", panelLWIR, color_conf_process_aux); addButton("AUX ASSIGN", panelLWIR, color_process_aux); addButton("AUX OUT 3D", panelLWIR, color_process_aux); addButton("Main to AUX", panelLWIR, color_process_aux); addButton("LWIR_TEST", panelLWIR, color_conf_process); addButton("LWIR_ACQUIRE", panelLWIR, color_conf_process); Loading Loading @@ -3958,12 +3960,12 @@ private Panel panel1, IJ.showMessage("Warning",msg); return; } /* EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL, true, // true - ignore missing files true, // boolean all_sensors, COLOR_PROC_PARAMETERS.correct_vignetting); //boolean correct_vignetting */ QUAD_CLT.resetGeometryCorrection(); QUAD_CLT.initGeometryCorrection(DEBUG_LEVEL+2); Loading Loading @@ -4450,6 +4452,10 @@ private Panel panel1, return; } } @SuppressWarnings("unused") QuadCLT dbg_qc_main = QUAD_CLT; @SuppressWarnings("unused") QuadCLT dbg_qc_aux = QUAD_CLT_AUX; ///======================================== int num_infinity_corr = infinity_corr? CLT_PARAMETERS.inf_repeat : 1; Loading Loading @@ -4684,7 +4690,12 @@ private Panel panel1, EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); clt3d_aux(adjust_extrinsics, adjust_poly); return; } else if (label.equals("Main to AUX")) { DEBUG_LEVEL=MASTER_DEBUG_LEVEL; EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); mainToAux(); return; // } else if (label.equals("CLT planes")) { DEBUG_LEVEL=MASTER_DEBUG_LEVEL; EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL); Loading Loading @@ -5106,6 +5117,295 @@ private Panel panel1, // End of buttons code } } /* ======================================================================== */ public boolean mainToAux() { if (QUAD_CLT == null){ QUAD_CLT = new QuadCLT ( QuadCLT.PREFIX, PROPERTIES, EYESIS_CORRECTIONS, CORRECTION_PARAMETERS); if (DEBUG_LEVEL > 0){ System.out.println("Created new QuadCLT instance, will need to read CLT kernels"); } } if (QUAD_CLT_AUX == null){ if (EYESIS_CORRECTIONS_AUX == null) { EYESIS_CORRECTIONS_AUX = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS.getAux()); } QUAD_CLT_AUX = new QuadCLT ( QuadCLT.PREFIX_AUX, PROPERTIES, EYESIS_CORRECTIONS_AUX, CORRECTION_PARAMETERS.getAux()); if (DEBUG_LEVEL > 0){ System.out.println("Created new QuadCLT instance, will need to read CLT kernels for aux camera"); } } @SuppressWarnings("unused") QuadCLT dbg_QUAD_CLT = QUAD_CLT; @SuppressWarnings("unused") QuadCLT dbg_QUAD_CLT_AUX = QUAD_CLT_AUX; ImagePlus imp_sel = WindowManager.getCurrentImage(); if (imp_sel==null){ IJ.showMessage("Error","There are no images open\nProcess canceled"); return false; } ImageStack stack_sel = imp_sel.getStack(); String [] labels = stack_sel.getSliceLabels(); int indx = 0; for (int i = 0; i < labels.length; i++) { if (labels[i] !=null) indx++; } boolean just2 = (indx == 2) && (labels[0] != null) && (labels[1] != null); String [] choices = {"---", "disparity","strength"}; double min_strength = 0.18; // use some configurable parameters boolean use_wnd = true; boolean split_fg_bg = true; double split_fbg_rms = 0.2; // split small source samples tp FG/BG if all aux tile RMS exceeds this value GenericDialog gd = new GenericDialog("Select disparity and strength slices"); indx = 0; for (int i = 0; i < labels.length; i++) { if (labels[i] !=null) { gd.addChoice(((indx++) + 1)+": " +labels[i], choices, choices[just2 ? (i + 1) : 0]); } } gd.addMessage("--- main-to-aux depth map parameters ---"); gd.addNumericField("Minimal EO correlation strength", min_strength, 3, 6, ""); gd.addCheckbox("Use window for AUX tiles to reduce weight of the hi-res tiles near low-res tile boundaries" , use_wnd); gd.addCheckbox("Split FG and BG if hi-res disparity varies for the same low-res tile", split_fg_bg); gd.addNumericField("Aux disparity thershold to split FG and BG", split_fbg_rms, 3, 6, ""); WindowTools.addScrollBars(gd); gd.showDialog(); if (gd.wasCanceled()) return false; int [] selections = new int[indx]; indx = 0; for (int i = 0; i < selections.length; i++) { selections[i] = gd.getNextChoiceIndex(); } min_strength = gd.getNextNumber(); use_wnd = gd.getNextBoolean(); split_fg_bg = gd.getNextBoolean(); split_fbg_rms = gd.getNextNumber(); int index_disparity = -1, index_strength=-1; indx = 0; for (int i = 0; i < labels.length; i++) if (labels[i] != null) { if ((index_disparity < 0) && (selections[indx] == 1)) { index_disparity = i; } if ((index_strength < 0) && (selections[indx] == 2)) { index_strength = i; } if ((index_disparity >= 0 ) &&(index_strength >= 0 )) { break; } indx++; } int width = imp_sel.getWidth(); int height = imp_sel.getHeight(); String title = imp_sel.getTitle()+"-DS"; float [][] f_ds = new float [2][]; f_ds[0] = (float[]) stack_sel.getPixels(index_disparity+1); f_ds[1] = (float[]) stack_sel.getPixels(index_strength+1); double [][] ds = new double [2][width*height]; for (int l = 0; l < ds.length; l++) { for (int i = 0; i < ds[l].length; i++) { ds[l][i] = f_ds[l][i]; } } String [] titles = {"disparity","strength"}; (new ShowDoubleFloatArrays()) .showArrays(ds, width, height, true, title, titles); int tile_size = CLT_PARAMETERS.transform_size; int [] wh_aux = QUAD_CLT_AUX.getGeometryCorrection().getSensorWH(); int tilesX_aux = wh_aux[0] / tile_size; int tilesY_aux = wh_aux[1] / tile_size; // int num_slices = split_fg_bg? 7:2; String [] fgbg_titles = {"disparity","strength", "rms","rms-split","fg-disp","fg-str","bg-disp","bg-str"}; String [] rslt_titles = split_fg_bg ? fgbg_titles :titles; double [][] ds_aux = DepthMapMainToAux( ds, // double [][] ds, QUAD_CLT.getGeometryCorrection(), // GeometryCorrection geometryCorrection_main, QUAD_CLT_AUX.getGeometryCorrection(), // GeometryCorrection geometryCorrection_aux, CLT_PARAMETERS, min_strength, // double min_strength, use_wnd, split_fg_bg, split_fbg_rms, DEBUG_LEVEL); // int debug_level (new ShowDoubleFloatArrays()).showArrays(ds_aux, tilesX_aux, tilesY_aux, true, title+"_TOAUX", rslt_titles); return true; } public double [][] DepthMapMainToAux( double [][] ds, GeometryCorrection geometryCorrection_main, GeometryCorrection geometryCorrection_aux, CLTParameters clt_Parameters, double min_strength, boolean use_wnd, boolean split_fg_bg, double split_fbg_rms, int debug_level ){ class DS{ double disparity; // gt disparity double strength; // gt strength int tx; // gt tile x int ty; // gt tile x double fx; // fractional aux tile X (0.0..1.0) for optional window double fy; // fractional aux tile Y (0.0..1.0) for optional window // DS (double disparity, double strength){ // this.disparity = disparity; // this.strength = strength; // } DS (double disparity, double strength, int tx, int ty, double fx, double fy){ this.disparity = disparity; this.strength = strength; this.tx = tx; this.ty = ty; this.fx = fx; this.fy = fy; } @Override public String toString() { return String.format("Disparity (str) = % 6f (%5f), tx=%d ty=%d fx=%5f fy=%5f\n", disparity, strength,tx,ty,fx,fy); } } int tile_size = clt_Parameters.transform_size; int [] wh_main = geometryCorrection_main.getSensorWH(); int [] wh_aux = geometryCorrection_aux.getSensorWH(); int tilesX_main = wh_main[0] / tile_size; int tilesY_main = wh_main[1] / tile_size; int tilesX_aux = wh_aux[0] / tile_size; int tilesY_aux = wh_aux[1] / tile_size; ArrayList<ArrayList<DS>> ds_list = new ArrayList<ArrayList<DS>>(); for (int nt = 0; nt < tilesX_aux * tilesY_aux; nt++) { ds_list.add(new ArrayList<DS>()); } for (int ty = 0; ty < tilesY_main; ty++) { double centerY = ty * tile_size + tile_size/2; for (int tx = 0; tx < tilesX_main; tx++) { int nt = ty*tilesX_main + tx; double centerX = tx * tile_size + tile_size/2; double disparity = ds[0][nt]; double strength = ds[1][nt]; if ((strength >= min_strength) && !Double.isNaN(disparity)) { double [] dpxpy_aux = geometryCorrection_aux.getFromOther( geometryCorrection_main, // GeometryCorrection other_gc, centerX, // double other_px, centerY, // double other_py, disparity); // double other_disparity) double fx = dpxpy_aux[1]/tile_size; double fy = dpxpy_aux[2]/tile_size; int tx_aux = (int) Math.floor(fx); int ty_aux = (int) Math.floor(fy); fx -= tx_aux; fy -= ty_aux; if ((ty_aux >= 0) && (ty_aux < tilesY_aux) && (tx_aux >= 0) && (tx_aux < tilesX_aux)) { int nt_aux = ty_aux * tilesX_aux + tx_aux; ds_list.get(nt_aux).add(new DS(dpxpy_aux[0], strength, tx, ty, fx, fy)); } } } } // simple average (ignoring below minimal) int num_slices = split_fg_bg? 8:2; double [][] ds_aux_avg = new double [num_slices][tilesX_aux * tilesY_aux]; for (int ty = 0; ty < tilesY_aux; ty++) { for (int tx = 0; tx < tilesX_aux; tx++) { if ((ty == 4) && (tx == 12)) { System.out.println("tx = "+tx+", ty = "+ty); } int nt = ty * tilesX_aux + tx; ds_aux_avg[0][nt] = Double.NaN; ds_aux_avg[1][nt] = 0.0; if(ds_list.get(nt).isEmpty()) continue; Collections.sort(ds_list.get(nt), new Comparator<DS>() { @Override public int compare(DS lhs, DS rhs) { return rhs.disparity > lhs.disparity ? -1 : (rhs.disparity < lhs.disparity ) ? 1 : 0; } }); double sw = 0.0, swd = 0.0, swd2 = 0.0; for (DS dsi: ds_list.get(nt)) { double w = dsi.strength; if (use_wnd) { w *= Math.sin(Math.PI * (dsi.fx + 0.5/tile_size)) * Math.sin(Math.PI * (dsi.fy + 0.5/tile_size)); } sw += w; double wd = w * dsi.disparity; swd += wd; swd2 += wd * dsi.disparity; } ds_aux_avg[0][nt] = swd/sw; ds_aux_avg[1][nt] = sw/ds_list.get(nt).size(); if (split_fg_bg) { ds_aux_avg[2][nt] = Math.sqrt( (swd2 * sw - swd * swd) / (sw * sw)); ds_aux_avg[3][nt] = ds_aux_avg[2][nt]; // rms ds_aux_avg[4][nt] = ds_aux_avg[0][nt]; // fg disp ds_aux_avg[5][nt] = ds_aux_avg[1][nt]; // fg strength ds_aux_avg[6][nt] = ds_aux_avg[0][nt]; // bg disp ds_aux_avg[7][nt] = ds_aux_avg[1][nt]; // bg strength if (ds_aux_avg[2][nt] >= split_fbg_rms) { // splitting while minimizing sum of 2 squared errors double [][] swfb = new double [2][ds_list.get(nt).size() -1]; double [][] swdfb = new double [2][ds_list.get(nt).size() -1]; double [] s2fb = new double [ds_list.get(nt).size() -1]; for (int n = 0; n < s2fb.length; n++) { // split position double [] s2 = new double[2]; for (int i = 0; i <= s2fb.length; i++) { int fg = (i > n)? 1 : 0; // 0 - bg, 1 - fg DS dsi = ds_list.get(nt).get(i); double w = dsi.strength; if (use_wnd) { w *= Math.sin(Math.PI * dsi.fx) * Math.sin(Math.PI * dsi.fy); } swfb[fg][n] += w; double wd = w * dsi.disparity; swdfb[fg][n] += wd; s2[fg] += wd * dsi.disparity; } s2fb[n] = ((s2[0] * swfb[0][n] - swdfb[0][n] * swdfb[0][n]) / swfb[0][n] + (s2[1] * swfb[1][n] - swdfb[1][n] * swdfb[1][n]) / swfb[1][n]) / (swfb[0][n] + swfb[1][n]); } // now find the n with lowest s2fb and use it to split fg/bg. Could be done in a single pass, but with saved arrays // it is easier to verify int nsplit = 0; for (int i = 1; i < s2fb.length; i++) if (s2fb[i] < s2fb[nsplit]) { nsplit = i; } ds_aux_avg[3][nt] = s2fb[nsplit]; // rms split ds_aux_avg[4][nt] = swdfb[1][nsplit] / swfb[1][nsplit] ; // fg disp ds_aux_avg[5][nt] = swfb[1][nsplit]/ (s2fb.length - nsplit) ; // fg strength ds_aux_avg[6][nt] = swdfb[0][nsplit] / swfb[0][nsplit] ; // bg disp ds_aux_avg[7][nt] = swfb[0][nsplit]/ (nsplit + 1) ; // bg strength } } } } return ds_aux_avg; } //getGeometryCorrection ///data_ssd/lwir3d/results/saved/1562390490_233403/v11/ /* ======================================================================== */ public String getSaveCongigPath() { String configPath=null; Loading Loading @@ -9879,8 +10179,8 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg gd.addNumericField("JPEG scale (%)", 100* processParameters.JPEG_scale,0); gd.addCheckbox ("Save current settings with results", processParameters.saveSettings); gd.addCheckbox ("Update ImageJ status", UPDATE_STATUS); WindowTools.addScrollBars(gd); gd.addNumericField("Debug Level:", MASTER_DEBUG_LEVEL, 0); WindowTools.addScrollBars(gd); gd.showDialog(); if (gd.wasCanceled()) return false; processParameters.eyesisMode= gd.getNextBoolean(); Loading