Loading src/main/java/com/elphel/imagej/common/GenericJTabbedDialog.java +25 −0 Original line number Diff line number Diff line Loading @@ -216,6 +216,31 @@ public class GenericJTabbedDialog implements ActionListener { inp_units.putClientProperty("type", "combo"); // combo.setPreferredSize(new Dimension(200)); // combo.setSize(200, combo.getPreferredSize().height); // combo.setMaximumSize(20); // combo.getPreferredSize() ); inp_units.setLayout(new FlowLayout(FlowLayout.LEFT)); addLine(label, inp_units, tooltip); } public void addChoice(String label, String[] items, String defaultItem, String tooltip, int count) { int index = 0; if (defaultItem != null) { for (int i = 0; i < items.length; i++) if (items[i].equals(defaultItem)) { index = i; break; } } JComboBox<String> combo = new JComboBox<String>(items); combo.setSelectedIndex(index); JPanel inp_units = new JPanel(false); inp_units.add(combo); inp_units.putClientProperty("type", "combo"); if (count > 0) { combo.setMaximumRowCount(count); } // combo.setPreferredSize(new Dimension(200)); // combo.setSize(200, combo.getPreferredSize().height); // combo.setMaximumSize(20); // combo.getPreferredSize() ); inp_units.setLayout(new FlowLayout(FlowLayout.LEFT)); Loading src/main/java/com/elphel/imagej/orthomosaic/ComboMatch.java +145 −109 Original line number Diff line number Diff line Loading @@ -48,6 +48,11 @@ public class ComboMatch { GPUTileProcessor gpu_tile_processor, // initialized by the caller boolean extract_objects, int debugLevel) { boolean create_kernels = debugLevel>1000; if (create_kernels) { OrthoMap.combineKernels(); return true; } GPU_TILE_PROCESSOR = gpu_tile_processor; PairwiseOrthoMatch pairwiseOrthoMatch = null; String [] pair_names = new String[2]; Loading Loading @@ -797,29 +802,46 @@ public class ComboMatch { String [] choices = getPairChoices( available_pairs, // int [][] pairs, names); // String [] names) String [] choices_all = new String[choices.length+1]; System.arraycopy(choices, 0, choices_all, 0, choices.length); choices_all[choices_all.length-1] = "--- select a single image ---"; GenericJTabbedDialog gdc = new GenericJTabbedDialog("Select image pair",1200,400); gdc.addChoice("Operation:", choices, choices[choices.length-1]); int num_choice_lines = 50; gdc.addChoice("Image pair:", choices_all, choices_all[choices.length], // -1], "Select processed image pair or request a single image selection", num_choice_lines); gdc.showDialog(); if (gdc.wasCanceled()) return false; int pair= gdc.getNextChoiceIndex(); if (pair >= choices.length) { int default_choice = 0; int num_scene_lines = 50; String scene_name = maps_collection.selectOneScene( default_choice, // int default_choice, num_scene_lines); // int num_choice_lines) if (scene_name == null) { return false; } gpu_spair = new String[] {scene_name}; } else { gpu_spair = new String[] { maps_collection.ortho_maps[available_pairs[pair][0]].getName(), maps_collection.ortho_maps[available_pairs[pair][1]].getName()}; } } int [] gpu_pair = new int[gpu_spair.length]; int min_zoom_lev = maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(); int max_zoom_lev = maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(); for (int i = 0; i < gpu_pair.length; i++) { gpu_pair[i] = maps_collection.getIndex(gpu_spair[i]); min_zoom_lev = Math.min(min_zoom_lev, maps_collection.ortho_maps[gpu_pair[i]].getOriginalZoomLevel()); max_zoom_lev = Math.max(max_zoom_lev, maps_collection.ortho_maps[gpu_pair[i]].getOriginalZoomLevel()); } int min_zoom_lev = Math.min( maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(), maps_collection.ortho_maps[gpu_pair[1]].getOriginalZoomLevel()); int max_zoom_lev = Math.max( maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(), maps_collection.ortho_maps[gpu_pair[1]].getOriginalZoomLevel()); int initial_zoom = max_zoom_lev - 4; // another algorithm? System.out.println("Setting up GPU"); if (GPU_QUAD_AFFINE == null) { try { Loading @@ -836,13 +858,23 @@ public class ComboMatch { return false; } // final int debugLevel); } double [][] affine0 = {{1,0,0},{0,1,0}}; // will always stay the same double [][] affine1 = null; if (gpu_spair.length < 2) { System.out.println("Selected a single image"); double [][][] affines = {affine0}; // or use affine1 = null as second? if (pattern_match) { ImagePlus imp_pat_match = maps_collection.patternMatchDualWrap ( gpu_pair, // int [] indices, // null or which indices to use (normally just 2 for pairwise comparison) affines, // double [][][] affines, // null or [indices.length][2][3] null); // warp); // FineXYCorr warp) // imp_pat_match.show(); } double [][] affine0 = {{1,0,0},{0,1,0}}; // will always stay the same } else { pairwiseOrthoMatch = maps_collection.ortho_maps[gpu_pair[0]].getMatch( maps_collection.ortho_maps[gpu_pair[1]].getName()); double [][] affine1 = null; if (pairwiseOrthoMatch == null) { System.out.println("No correlation data is available for pairs "+gpu_spair[0]+ " - "+gpu_spair[1]+" need to implement/search reverse, a spiral search or restart command"); Loading Loading @@ -908,6 +940,9 @@ public class ComboMatch { System.out.println(); } } if (pattern_match) { ImagePlus imp_pat_match = maps_collection.patternMatchDualWrap ( gpu_pair, // int [] indices, // null or which indices to use (normally just 2 for pairwise comparison) Loading @@ -934,6 +969,7 @@ public class ComboMatch { } } } } if (save_collection) { try { maps_collection.writeOrthoMapsCollection(orthoMapsCollection_path); Loading Loading @@ -1132,8 +1168,8 @@ adjusted affines[1] for a pair: 1694564291_293695/1694564778_589341 pairs, // int [][] pairs, scene_names); // String [] names) GenericJTabbedDialog gds = new GenericJTabbedDialog("Select image pair",1200,400); gds.addChoice("Operation:", choices, choices[choices.length-1]); GenericJTabbedDialog gds = new GenericJTabbedDialog("Select image pair from the image",1200,400); gds.addChoice("Image pair in the marked image:", choices, choices[choices.length-1]); gds.showDialog(); if (gds.wasCanceled()) return null; pair= gds.getNextChoiceIndex(); Loading src/main/java/com/elphel/imagej/orthomosaic/OrthoMap.java +233 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import ij.ImageStack; import ij.Prefs; import ij.gui.PointRoi; import ij.gui.Roi; import ij.io.FileSaver; import ij.plugin.filter.AVI_Writer; import ij.plugin.filter.GaussianBlur; import ij.process.ColorProcessor; Loading Loading @@ -1808,9 +1809,217 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ } return point_arr; } ///media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/ /* /media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/kernel_25_50.tiff /media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/kernel_50_100.tiff /media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/kernel_50_75.tiff */ public static void combineKernels() { // specific hard-wired kernels String kernels_dir = "/media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/"; String kernel_25_50_after = "kernel_25_50_after.tiff"; /* String kernel_25_50 = "kernel_25_50.tiff"; String kernel_50_75 = "kernel_50_75.tiff"; String kernel_50_100 = "kernel_50_100.tiff"; String kernel_25_75 = "kernel_25_75.tiff"; String kernel_25_100 = "kernel_25_100.tiff"; */ String [] kernels_paths = { kernels_dir+kernel_25_50_after}; // // kernels_dir+kernel_25_50, // kernels_dir+kernel_50_75, // kernels_dir+kernel_50_100}; double [][] kernels_data = new double [kernels_paths.length][]; for (int n = 0; n < kernels_data.length; n++) { ImagePlus imp = new ImagePlus(kernels_paths[n]); float [] pixels = (float []) imp.getProcessor().getPixels(); kernels_data[n] = new double [pixels.length]; for (int i = 0; i < pixels.length; i++) { kernels_data[n][i] = pixels[i]; } } ArrayList<Double> scale_list = new ArrayList<Double>(); for (double scale = 1.5; scale < 3.0; scale += 0.05) { scale_list.add(scale); } for (double scale = 3.0; scale <= 4.5; scale += 0.1) { scale_list.add(scale); } for (double scale:scale_list) { double [] dkernel_scaled = scaleKernel(scale, kernels_data[0]); int size = (int) Math.sqrt(dkernel_scaled.length); String title = String.format("kernel_25x%4.2f.tiff",scale); ImagePlus imp_kernel = ShowDoubleFloatArrays.makeArrays( dkernel_scaled, size, size, title); // imp_kernel.show(); String kpath = kernels_dir+title; FileSaver imp_kernel_fs = new FileSaver(imp_kernel); imp_kernel_fs.saveAsTiff(kpath); // imp_kernel// } /* double [] dkernel_25_75 = combineKernels( kernels_data[0], scaleKernel(2, kernels_data[1])); double [] dkernel_25_100 = combineKernels( kernels_data[0], scaleKernel(2, kernels_data[2])); double [] dkernel_25_50_2x = scaleKernel(2, kernels_data[0]); double [] dkernel_25_50_3x = scaleKernel(3, kernels_data[0]); double [] dkernel_25_50_4x = scaleKernel(4, kernels_data[0]); int size_25_75 = (int) Math.sqrt(dkernel_25_75.length); int size_25_100 = (int) Math.sqrt(dkernel_25_100.length); ImagePlus [] imp_kernel = new ImagePlus[5]; imp_kernel[0] = ShowDoubleFloatArrays.makeArrays( dkernel_25_75, size_25_75, size_25_75, kernel_25_75); imp_kernel[1] = ShowDoubleFloatArrays.makeArrays( dkernel_25_100, size_25_100, size_25_100, kernel_25_100); imp_kernel[2] = ShowDoubleFloatArrays.makeArrays( dkernel_25_50_2x, (int) Math.sqrt(dkernel_25_50_2x.length), (int) Math.sqrt(dkernel_25_50_2x.length), "kernel_25_50_2x"); imp_kernel[3] = ShowDoubleFloatArrays.makeArrays( dkernel_25_50_3x, (int) Math.sqrt(dkernel_25_50_3x.length), (int) Math.sqrt(dkernel_25_50_3x.length), "kernel_25_50_3x"); imp_kernel[4] = ShowDoubleFloatArrays.makeArrays( dkernel_25_50_4x, (int) Math.sqrt(dkernel_25_50_4x.length), (int) Math.sqrt(dkernel_25_50_4x.length), "kernel_25_50_4x"); imp_kernel[0].show(); imp_kernel[1].show(); imp_kernel[2].show(); imp_kernel[3].show(); imp_kernel[4].show(); */ System.out.println("combineKernels(): Created kernels"); } /* public static double [] scaleKernel( int scale, // normally is exactly twice double [] kernel1) { int kernel_size1 = (int) Math.sqrt(kernel1.length); int radius1 = (kernel_size1 - 1)/2; int radius = scale * radius1; int kernel_size = 2 * radius + 1; double [] kernel = new double [kernel_size*kernel_size]; double rscale = 1.0/scale; for (int dy = -radius; dy <= radius; dy++) { int y = radius + dy; double y_in = radius1 + dy*rscale; int iy0 = (int) Math.floor(y_in); double fy = y_in-iy0; int iy1 = Math.min(iy0+1, kernel_size1-1); for (int dx = -radius; dx <= radius; dx++) { int x = radius + dx; double x_in = radius1 + dx*rscale; int ix0 = (int) Math.floor(x_in); double fx = x_in-ix0; int ix1 = Math.min(ix0+1, kernel_size1-1); kernel[y*kernel_size + x] = (1-fy)*(1-fx)*kernel1[iy0*kernel_size1+ix0]+ (1-fy)*( fx)*kernel1[iy0*kernel_size1+ix1]+ ( fy)*(1-fx)*kernel1[iy1*kernel_size1+ix0]+ ( fy)*( fx)*kernel1[iy1*kernel_size1+ix1]; } } return kernel; } */ public static double [] scaleKernel( double scale, // normally is exactly twice double [] kernel1) { int kernel_size1 = (int) Math.sqrt(kernel1.length); int radius1 = (kernel_size1 - 1)/2; int radius = (int) Math.floor(scale * radius1); int kernel_size = 2 * radius + 1; double [] kernel = new double [kernel_size*kernel_size]; double rscale = 1.0/scale; for (int dy = -radius; dy <= radius; dy++) { int y = radius + dy; double y_in = radius1 + dy*rscale; int iy0 = (int) Math.floor(y_in); double fy = y_in-iy0; int iy1 = Math.min(iy0+1, kernel_size1-1); for (int dx = -radius; dx <= radius; dx++) { int x = radius + dx; double x_in = radius1 + dx*rscale; int ix0 = (int) Math.floor(x_in); double fx = x_in-ix0; int ix1 = Math.min(ix0+1, kernel_size1-1); kernel[y*kernel_size + x] = (1-fy)*(1-fx)*kernel1[iy0*kernel_size1+ix0]+ (1-fy)*( fx)*kernel1[iy0*kernel_size1+ix1]+ ( fy)*(1-fx)*kernel1[iy1*kernel_size1+ix0]+ ( fy)*( fx)*kernel1[iy1*kernel_size1+ix1]; } } // normalize result double s = 0; for (int i = 0; i < kernel.length; i++) s+= kernel[i]; System.out.println("scaleKernel(): s="+s); double k = 1/s; for (int i = 0; i < kernel.length; i++) kernel[i] *= k; return kernel; } public static double [] combineKernels( double [] kernel1, double [] kernel2) { int kernel_size1 = (int) Math.sqrt(kernel1.length); int kernel_size2 = (int) Math.sqrt(kernel2.length); int kernel_radius1 = (kernel_size1 - 1)/2; int kernel_radius2 = (kernel_size2 - 1)/2; int kernel_radius = kernel_radius1 + kernel_radius2; int kernel_size = 2*kernel_radius + 1; double [] kernel = new double [kernel_size * kernel_size]; int indx_tl = kernel_radius2 * (kernel_size + 1); for (int y = 0; y < kernel_size1; y++) { System.arraycopy( kernel1, y* kernel_size1, kernel, indx_tl + y * kernel_size, kernel_size1); } kernel = convolveWithKernel( kernel, // final double [] data, kernel2, // final double [] kernel, kernel_size); // final int width); // normalize result double s = 0; for (int i = 0; i < kernel.length; i++) s+= kernel[i]; System.out.println("combineKernels(): s="+s); double k = 1/s; for (int i = 0; i < kernel.length; i++) kernel[i] *= k; return kernel; } public static double [] convolveWithKernel( final double [] data, final double [] kernel, Loading Loading @@ -1864,6 +2073,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ * @param ipattern square pattern array corresponding to data. 1 means * average (w/o outliers) and add, 2 - average and subtract * @param outliers_frac - fraction of outliers to remove while averaging * @param masked_data null or double[data.length] - will return a copy of data * with NaN for all unused for averaging * @param debug show debug images * @return difference between average in-pattern (1) and outside (2) average * values Loading @@ -1872,6 +2083,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ double [] data, int [] ipattern, double outliers_frac, double [] masked_data, // null or double [data.length] to return masked data boolean debug) { if (debug) { int size = (int) Math.sqrt(data.length); Loading Loading @@ -1925,6 +2137,15 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ } } } if (masked_data != null) { Arrays.fill(masked_data, Double.NaN); for (int n = 0; n < lists.size(); n++) { ArrayList<Integer> list = lists.get(n); for (Integer i: list) { masked_data[i] = data[i]; } } } if (debug) { int [] ipattern1 = new int [ipattern.length]; for (int n = 0; n < lists.size(); n++) { Loading Loading @@ -4074,7 +4295,9 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ final int dbg_pix0= 1439210; // -2827822; // 3649679;// #3 final int dbg_pix2 = 1442449; // -2831060; final int dbg_pix3 = 1439211; // 2827822; final int dbg_x = 1445; final int dbg_y = 2338; final int dbg_tolerance = 10; for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { Loading @@ -4097,6 +4320,15 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ break is_max; } } if (dbg_tolerance >= 0) { int dbg_px = ipix % width; int dbg_py = ipix / width; if ((Math.abs(dbg_px-dbg_x) <= dbg_tolerance) || (Math.abs(dbg_py-dbg_y) <= dbg_tolerance)) { System.out.println("combineDirCorrs(): ipix="+ipix+ ", dbg_px="+dbg_px+", dbg_py="+dbg_py); System.out.println(); } } // compare with others in adversarial radius, if equal - use higher index ipix for (int dy = -iradius; dy <= iradius; dy++) { for (int dx = -iradius; dx <= iradius; dx++) { Loading Loading
src/main/java/com/elphel/imagej/common/GenericJTabbedDialog.java +25 −0 Original line number Diff line number Diff line Loading @@ -216,6 +216,31 @@ public class GenericJTabbedDialog implements ActionListener { inp_units.putClientProperty("type", "combo"); // combo.setPreferredSize(new Dimension(200)); // combo.setSize(200, combo.getPreferredSize().height); // combo.setMaximumSize(20); // combo.getPreferredSize() ); inp_units.setLayout(new FlowLayout(FlowLayout.LEFT)); addLine(label, inp_units, tooltip); } public void addChoice(String label, String[] items, String defaultItem, String tooltip, int count) { int index = 0; if (defaultItem != null) { for (int i = 0; i < items.length; i++) if (items[i].equals(defaultItem)) { index = i; break; } } JComboBox<String> combo = new JComboBox<String>(items); combo.setSelectedIndex(index); JPanel inp_units = new JPanel(false); inp_units.add(combo); inp_units.putClientProperty("type", "combo"); if (count > 0) { combo.setMaximumRowCount(count); } // combo.setPreferredSize(new Dimension(200)); // combo.setSize(200, combo.getPreferredSize().height); // combo.setMaximumSize(20); // combo.getPreferredSize() ); inp_units.setLayout(new FlowLayout(FlowLayout.LEFT)); Loading
src/main/java/com/elphel/imagej/orthomosaic/ComboMatch.java +145 −109 Original line number Diff line number Diff line Loading @@ -48,6 +48,11 @@ public class ComboMatch { GPUTileProcessor gpu_tile_processor, // initialized by the caller boolean extract_objects, int debugLevel) { boolean create_kernels = debugLevel>1000; if (create_kernels) { OrthoMap.combineKernels(); return true; } GPU_TILE_PROCESSOR = gpu_tile_processor; PairwiseOrthoMatch pairwiseOrthoMatch = null; String [] pair_names = new String[2]; Loading Loading @@ -797,29 +802,46 @@ public class ComboMatch { String [] choices = getPairChoices( available_pairs, // int [][] pairs, names); // String [] names) String [] choices_all = new String[choices.length+1]; System.arraycopy(choices, 0, choices_all, 0, choices.length); choices_all[choices_all.length-1] = "--- select a single image ---"; GenericJTabbedDialog gdc = new GenericJTabbedDialog("Select image pair",1200,400); gdc.addChoice("Operation:", choices, choices[choices.length-1]); int num_choice_lines = 50; gdc.addChoice("Image pair:", choices_all, choices_all[choices.length], // -1], "Select processed image pair or request a single image selection", num_choice_lines); gdc.showDialog(); if (gdc.wasCanceled()) return false; int pair= gdc.getNextChoiceIndex(); if (pair >= choices.length) { int default_choice = 0; int num_scene_lines = 50; String scene_name = maps_collection.selectOneScene( default_choice, // int default_choice, num_scene_lines); // int num_choice_lines) if (scene_name == null) { return false; } gpu_spair = new String[] {scene_name}; } else { gpu_spair = new String[] { maps_collection.ortho_maps[available_pairs[pair][0]].getName(), maps_collection.ortho_maps[available_pairs[pair][1]].getName()}; } } int [] gpu_pair = new int[gpu_spair.length]; int min_zoom_lev = maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(); int max_zoom_lev = maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(); for (int i = 0; i < gpu_pair.length; i++) { gpu_pair[i] = maps_collection.getIndex(gpu_spair[i]); min_zoom_lev = Math.min(min_zoom_lev, maps_collection.ortho_maps[gpu_pair[i]].getOriginalZoomLevel()); max_zoom_lev = Math.max(max_zoom_lev, maps_collection.ortho_maps[gpu_pair[i]].getOriginalZoomLevel()); } int min_zoom_lev = Math.min( maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(), maps_collection.ortho_maps[gpu_pair[1]].getOriginalZoomLevel()); int max_zoom_lev = Math.max( maps_collection.ortho_maps[gpu_pair[0]].getOriginalZoomLevel(), maps_collection.ortho_maps[gpu_pair[1]].getOriginalZoomLevel()); int initial_zoom = max_zoom_lev - 4; // another algorithm? System.out.println("Setting up GPU"); if (GPU_QUAD_AFFINE == null) { try { Loading @@ -836,13 +858,23 @@ public class ComboMatch { return false; } // final int debugLevel); } double [][] affine0 = {{1,0,0},{0,1,0}}; // will always stay the same double [][] affine1 = null; if (gpu_spair.length < 2) { System.out.println("Selected a single image"); double [][][] affines = {affine0}; // or use affine1 = null as second? if (pattern_match) { ImagePlus imp_pat_match = maps_collection.patternMatchDualWrap ( gpu_pair, // int [] indices, // null or which indices to use (normally just 2 for pairwise comparison) affines, // double [][][] affines, // null or [indices.length][2][3] null); // warp); // FineXYCorr warp) // imp_pat_match.show(); } double [][] affine0 = {{1,0,0},{0,1,0}}; // will always stay the same } else { pairwiseOrthoMatch = maps_collection.ortho_maps[gpu_pair[0]].getMatch( maps_collection.ortho_maps[gpu_pair[1]].getName()); double [][] affine1 = null; if (pairwiseOrthoMatch == null) { System.out.println("No correlation data is available for pairs "+gpu_spair[0]+ " - "+gpu_spair[1]+" need to implement/search reverse, a spiral search or restart command"); Loading Loading @@ -908,6 +940,9 @@ public class ComboMatch { System.out.println(); } } if (pattern_match) { ImagePlus imp_pat_match = maps_collection.patternMatchDualWrap ( gpu_pair, // int [] indices, // null or which indices to use (normally just 2 for pairwise comparison) Loading @@ -934,6 +969,7 @@ public class ComboMatch { } } } } if (save_collection) { try { maps_collection.writeOrthoMapsCollection(orthoMapsCollection_path); Loading Loading @@ -1132,8 +1168,8 @@ adjusted affines[1] for a pair: 1694564291_293695/1694564778_589341 pairs, // int [][] pairs, scene_names); // String [] names) GenericJTabbedDialog gds = new GenericJTabbedDialog("Select image pair",1200,400); gds.addChoice("Operation:", choices, choices[choices.length-1]); GenericJTabbedDialog gds = new GenericJTabbedDialog("Select image pair from the image",1200,400); gds.addChoice("Image pair in the marked image:", choices, choices[choices.length-1]); gds.showDialog(); if (gds.wasCanceled()) return null; pair= gds.getNextChoiceIndex(); Loading
src/main/java/com/elphel/imagej/orthomosaic/OrthoMap.java +233 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import ij.ImageStack; import ij.Prefs; import ij.gui.PointRoi; import ij.gui.Roi; import ij.io.FileSaver; import ij.plugin.filter.AVI_Writer; import ij.plugin.filter.GaussianBlur; import ij.process.ColorProcessor; Loading Loading @@ -1808,9 +1809,217 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ } return point_arr; } ///media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/ /* /media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/kernel_25_50.tiff /media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/kernel_50_100.tiff /media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/kernel_50_75.tiff */ public static void combineKernels() { // specific hard-wired kernels String kernels_dir = "/media/elphel/SSD3-4GB/lwir16-proc/ortho_videos/kernels/"; String kernel_25_50_after = "kernel_25_50_after.tiff"; /* String kernel_25_50 = "kernel_25_50.tiff"; String kernel_50_75 = "kernel_50_75.tiff"; String kernel_50_100 = "kernel_50_100.tiff"; String kernel_25_75 = "kernel_25_75.tiff"; String kernel_25_100 = "kernel_25_100.tiff"; */ String [] kernels_paths = { kernels_dir+kernel_25_50_after}; // // kernels_dir+kernel_25_50, // kernels_dir+kernel_50_75, // kernels_dir+kernel_50_100}; double [][] kernels_data = new double [kernels_paths.length][]; for (int n = 0; n < kernels_data.length; n++) { ImagePlus imp = new ImagePlus(kernels_paths[n]); float [] pixels = (float []) imp.getProcessor().getPixels(); kernels_data[n] = new double [pixels.length]; for (int i = 0; i < pixels.length; i++) { kernels_data[n][i] = pixels[i]; } } ArrayList<Double> scale_list = new ArrayList<Double>(); for (double scale = 1.5; scale < 3.0; scale += 0.05) { scale_list.add(scale); } for (double scale = 3.0; scale <= 4.5; scale += 0.1) { scale_list.add(scale); } for (double scale:scale_list) { double [] dkernel_scaled = scaleKernel(scale, kernels_data[0]); int size = (int) Math.sqrt(dkernel_scaled.length); String title = String.format("kernel_25x%4.2f.tiff",scale); ImagePlus imp_kernel = ShowDoubleFloatArrays.makeArrays( dkernel_scaled, size, size, title); // imp_kernel.show(); String kpath = kernels_dir+title; FileSaver imp_kernel_fs = new FileSaver(imp_kernel); imp_kernel_fs.saveAsTiff(kpath); // imp_kernel// } /* double [] dkernel_25_75 = combineKernels( kernels_data[0], scaleKernel(2, kernels_data[1])); double [] dkernel_25_100 = combineKernels( kernels_data[0], scaleKernel(2, kernels_data[2])); double [] dkernel_25_50_2x = scaleKernel(2, kernels_data[0]); double [] dkernel_25_50_3x = scaleKernel(3, kernels_data[0]); double [] dkernel_25_50_4x = scaleKernel(4, kernels_data[0]); int size_25_75 = (int) Math.sqrt(dkernel_25_75.length); int size_25_100 = (int) Math.sqrt(dkernel_25_100.length); ImagePlus [] imp_kernel = new ImagePlus[5]; imp_kernel[0] = ShowDoubleFloatArrays.makeArrays( dkernel_25_75, size_25_75, size_25_75, kernel_25_75); imp_kernel[1] = ShowDoubleFloatArrays.makeArrays( dkernel_25_100, size_25_100, size_25_100, kernel_25_100); imp_kernel[2] = ShowDoubleFloatArrays.makeArrays( dkernel_25_50_2x, (int) Math.sqrt(dkernel_25_50_2x.length), (int) Math.sqrt(dkernel_25_50_2x.length), "kernel_25_50_2x"); imp_kernel[3] = ShowDoubleFloatArrays.makeArrays( dkernel_25_50_3x, (int) Math.sqrt(dkernel_25_50_3x.length), (int) Math.sqrt(dkernel_25_50_3x.length), "kernel_25_50_3x"); imp_kernel[4] = ShowDoubleFloatArrays.makeArrays( dkernel_25_50_4x, (int) Math.sqrt(dkernel_25_50_4x.length), (int) Math.sqrt(dkernel_25_50_4x.length), "kernel_25_50_4x"); imp_kernel[0].show(); imp_kernel[1].show(); imp_kernel[2].show(); imp_kernel[3].show(); imp_kernel[4].show(); */ System.out.println("combineKernels(): Created kernels"); } /* public static double [] scaleKernel( int scale, // normally is exactly twice double [] kernel1) { int kernel_size1 = (int) Math.sqrt(kernel1.length); int radius1 = (kernel_size1 - 1)/2; int radius = scale * radius1; int kernel_size = 2 * radius + 1; double [] kernel = new double [kernel_size*kernel_size]; double rscale = 1.0/scale; for (int dy = -radius; dy <= radius; dy++) { int y = radius + dy; double y_in = radius1 + dy*rscale; int iy0 = (int) Math.floor(y_in); double fy = y_in-iy0; int iy1 = Math.min(iy0+1, kernel_size1-1); for (int dx = -radius; dx <= radius; dx++) { int x = radius + dx; double x_in = radius1 + dx*rscale; int ix0 = (int) Math.floor(x_in); double fx = x_in-ix0; int ix1 = Math.min(ix0+1, kernel_size1-1); kernel[y*kernel_size + x] = (1-fy)*(1-fx)*kernel1[iy0*kernel_size1+ix0]+ (1-fy)*( fx)*kernel1[iy0*kernel_size1+ix1]+ ( fy)*(1-fx)*kernel1[iy1*kernel_size1+ix0]+ ( fy)*( fx)*kernel1[iy1*kernel_size1+ix1]; } } return kernel; } */ public static double [] scaleKernel( double scale, // normally is exactly twice double [] kernel1) { int kernel_size1 = (int) Math.sqrt(kernel1.length); int radius1 = (kernel_size1 - 1)/2; int radius = (int) Math.floor(scale * radius1); int kernel_size = 2 * radius + 1; double [] kernel = new double [kernel_size*kernel_size]; double rscale = 1.0/scale; for (int dy = -radius; dy <= radius; dy++) { int y = radius + dy; double y_in = radius1 + dy*rscale; int iy0 = (int) Math.floor(y_in); double fy = y_in-iy0; int iy1 = Math.min(iy0+1, kernel_size1-1); for (int dx = -radius; dx <= radius; dx++) { int x = radius + dx; double x_in = radius1 + dx*rscale; int ix0 = (int) Math.floor(x_in); double fx = x_in-ix0; int ix1 = Math.min(ix0+1, kernel_size1-1); kernel[y*kernel_size + x] = (1-fy)*(1-fx)*kernel1[iy0*kernel_size1+ix0]+ (1-fy)*( fx)*kernel1[iy0*kernel_size1+ix1]+ ( fy)*(1-fx)*kernel1[iy1*kernel_size1+ix0]+ ( fy)*( fx)*kernel1[iy1*kernel_size1+ix1]; } } // normalize result double s = 0; for (int i = 0; i < kernel.length; i++) s+= kernel[i]; System.out.println("scaleKernel(): s="+s); double k = 1/s; for (int i = 0; i < kernel.length; i++) kernel[i] *= k; return kernel; } public static double [] combineKernels( double [] kernel1, double [] kernel2) { int kernel_size1 = (int) Math.sqrt(kernel1.length); int kernel_size2 = (int) Math.sqrt(kernel2.length); int kernel_radius1 = (kernel_size1 - 1)/2; int kernel_radius2 = (kernel_size2 - 1)/2; int kernel_radius = kernel_radius1 + kernel_radius2; int kernel_size = 2*kernel_radius + 1; double [] kernel = new double [kernel_size * kernel_size]; int indx_tl = kernel_radius2 * (kernel_size + 1); for (int y = 0; y < kernel_size1; y++) { System.arraycopy( kernel1, y* kernel_size1, kernel, indx_tl + y * kernel_size, kernel_size1); } kernel = convolveWithKernel( kernel, // final double [] data, kernel2, // final double [] kernel, kernel_size); // final int width); // normalize result double s = 0; for (int i = 0; i < kernel.length; i++) s+= kernel[i]; System.out.println("combineKernels(): s="+s); double k = 1/s; for (int i = 0; i < kernel.length; i++) kernel[i] *= k; return kernel; } public static double [] convolveWithKernel( final double [] data, final double [] kernel, Loading Loading @@ -1864,6 +2073,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ * @param ipattern square pattern array corresponding to data. 1 means * average (w/o outliers) and add, 2 - average and subtract * @param outliers_frac - fraction of outliers to remove while averaging * @param masked_data null or double[data.length] - will return a copy of data * with NaN for all unused for averaging * @param debug show debug images * @return difference between average in-pattern (1) and outside (2) average * values Loading @@ -1872,6 +2083,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ double [] data, int [] ipattern, double outliers_frac, double [] masked_data, // null or double [data.length] to return masked data boolean debug) { if (debug) { int size = (int) Math.sqrt(data.length); Loading Loading @@ -1925,6 +2137,15 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ } } } if (masked_data != null) { Arrays.fill(masked_data, Double.NaN); for (int n = 0; n < lists.size(); n++) { ArrayList<Integer> list = lists.get(n); for (Integer i: list) { masked_data[i] = data[i]; } } } if (debug) { int [] ipattern1 = new int [ipattern.length]; for (int n = 0; n < lists.size(); n++) { Loading Loading @@ -4074,7 +4295,9 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ final int dbg_pix0= 1439210; // -2827822; // 3649679;// #3 final int dbg_pix2 = 1442449; // -2831060; final int dbg_pix3 = 1439211; // 2827822; final int dbg_x = 1445; final int dbg_y = 2338; final int dbg_tolerance = 10; for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { Loading @@ -4097,6 +4320,15 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ break is_max; } } if (dbg_tolerance >= 0) { int dbg_px = ipix % width; int dbg_py = ipix / width; if ((Math.abs(dbg_px-dbg_x) <= dbg_tolerance) || (Math.abs(dbg_py-dbg_y) <= dbg_tolerance)) { System.out.println("combineDirCorrs(): ipix="+ipix+ ", dbg_px="+dbg_px+", dbg_py="+dbg_py); System.out.println(); } } // compare with others in adversarial radius, if equal - use higher index ipix for (int dy = -iradius; dy <= iradius; dy++) { for (int dx = -iradius; dx <= iradius; dx++) { Loading