Commit 5e4e5577 authored by Andrey Filippov's avatar Andrey Filippov

added absolute contrast

parent 29e261ef
...@@ -8,11 +8,18 @@ public class ItemMatch { ...@@ -8,11 +8,18 @@ public class ItemMatch {
public double [] combo_pxy; // combo image {pixel_x, pixel_y} public double [] combo_pxy; // combo image {pixel_x, pixel_y}
public double [] lla; // add later public double [] lla; // add later
public HashMap<String, ItemPatternMatch> pattern_matches = new HashMap<String, ItemPatternMatch>(); public HashMap<String, ItemPatternMatch> pattern_matches = new HashMap<String, ItemPatternMatch>();
public double abs_contrast = 0;
public ItemMatch (double [] combo_pxy) { public ItemMatch (double [] combo_pxy) {
this.combo_pxy = combo_pxy; this.combo_pxy = combo_pxy;
} }
public void setAbsoluteContrast(double contrast) {
abs_contrast = contrast; // only for main scene
}
public double getAbsoluteContrast() {
return abs_contrast;
}
public double [] getXY() { public double [] getXY() {
return combo_pxy; return combo_pxy;
} }
......
...@@ -30,7 +30,7 @@ public class ItemPatternMatch { ...@@ -30,7 +30,7 @@ public class ItemPatternMatch {
best_sub = sub; best_sub = sub;
} }
public int getBestSub() { public int getBestSub() { // 1 - full, > 1 - partial
return best_sub; return best_sub;
} }
......
...@@ -1772,6 +1772,12 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1772,6 +1772,12 @@ public class OrthoMapsCollection implements Serializable{
double scale_warp = 1.0; // use 4? double scale_warp = 1.0; // use 4?
int extr_size = 128; int extr_size = 128;
boolean remove_dc = true; boolean remove_dc = true;
// creating filters for absolute contrast calculation (main scene only)
double abs_edge_frac = 0.25;
double abs_oversize = 1.8;
int abs_mode = 1; // 0 - keep, 1 keep type and if half +/-1, 2 - keep type, 3 - any
boolean abs_invert = true; // center has lower value than around
double abs_outliers_frac = 0.3;
// filters // filters
boolean filt_keep = false; // list filtered out, but actually keep them boolean filt_keep = false; // list filtered out, but actually keep them
...@@ -1789,13 +1795,15 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1789,13 +1795,15 @@ public class OrthoMapsCollection implements Serializable{
double filt_height = 0.2; // allow extra negative offset parallel to image offset, corresponding to object above ground double filt_height = 0.2; // allow extra negative offset parallel to image offset, corresponding to object above ground
// double [] filt_full_half_frac = {0.7, 0.5}; // second probably not needed, it is for main // double [] filt_full_half_frac = {0.7, 0.5}; // second probably not needed, it is for main
double [] filt_full_half_frac = {0.675, 0.5}; // second probably not needed, it is for main double [] filt_full_half_frac = {0.675, 0.5}; // second probably not needed, it is for main
double filt_abs_contrast = 50.0;
int debugLevel = 1; int debugLevel = 1;
GenericJTabbedDialog gd = new GenericJTabbedDialog("Correlate two images with patterns",1200,1100); GenericJTabbedDialog gd = new GenericJTabbedDialog("Correlate two images with patterns",1200,1100);
gd.addTab("General","General parameters");
gd.addStringField ("Object type", object_type, 20,"Object type/name.");
gd.addNumericField("Minimal correlation, first", min_corrs[0], 5,7,"","Minimal correlation value to keep, first scene."); gd.addNumericField("Minimal correlation, first", min_corrs[0], 5,7,"","Minimal correlation value to keep, first scene.");
gd.addNumericField("Minimal correlation, second", min_corrs[1], 5,7,"","Minimal correlation value to keep, second scene."); gd.addNumericField("Minimal correlation, second", min_corrs[1], 5,7,"","Minimal correlation value to keep, second scene.");
// gd.addNumericField("Maximal peak area, first", max_area[0], 5,7,"","Maximal cross-section area of the peak at certain height.");
// gd.addNumericField("Maximal peak area, second", max_area[1], 5,7,"","Maximal cross-section area of the peak at certain height.");
gd.addNumericField("Phase correlation main", phaseCoeff[0], 3,7,"","1.0 - pure phase correlation, 0.0 - regular correlation."); gd.addNumericField("Phase correlation main", phaseCoeff[0], 3,7,"","1.0 - pure phase correlation, 0.0 - regular correlation.");
gd.addNumericField("Phase correlation other", phaseCoeff[1], 3,7,"","1.0 - pure phase correlation, 0.0 - regular correlation."); gd.addNumericField("Phase correlation other", phaseCoeff[1], 3,7,"","1.0 - pure phase correlation, 0.0 - regular correlation.");
gd.addNumericField("Minimal relative full correlation", min_corr_full_rel, 5,7,"","Minimal relative correlation value with full circular pattern to keep."); gd.addNumericField("Minimal relative full correlation", min_corr_full_rel, 5,7,"","Minimal relative correlation value with full circular pattern to keep.");
...@@ -1806,11 +1814,18 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1806,11 +1814,18 @@ public class OrthoMapsCollection implements Serializable{
gd.addNumericField("Correlation size", corr_size, 0,4,"pix", "Should be power of 2."); gd.addNumericField("Correlation size", corr_size, 0,4,"pix", "Should be power of 2.");
gd.addNumericField("Adversarial distance", adv_radius, 1,6,"pix", "Suppress weaker if they have closer strong ones."); gd.addNumericField("Adversarial distance", adv_radius, 1,6,"pix", "Suppress weaker if they have closer strong ones.");
gd.addNumericField("Search other scene max", search_radius, 1,6,"pix", "Search for other scene max from the main one."); gd.addNumericField("Search other scene max", search_radius, 1,6,"pix", "Search for other scene max from the main one.");
gd.addStringField ("Object type", object_type, 20,"Object type/name.");
gd.addNumericField("Scale warp", scale_warp, 1,6,"x", "Scale second image warping."); gd.addNumericField("Scale warp", scale_warp, 1,6,"x", "Scale second image warping.");
gd.addNumericField("Extract object size", extr_size, 0,4,"", "Size of square object image to extract."); gd.addNumericField("Extract object size", extr_size, 0,4,"", "Size of square object image to extract.");
gd.addCheckbox ("Remove DC", remove_dc, "Remove DC in extracted object images."); gd.addCheckbox ("Remove DC", remove_dc, "Remove DC in extracted object images.");
gd.addMessage("--- Filtering results ---"); gd.addTab("Absolute Contrast","Preparing absolute contrast measurements for the main scene");
gd.addNumericField("Edge cutt-off fraction (<0.5)", abs_edge_frac, 5,7,"","Used for extracting inner and outer zones from tha existing patterns.");
gd.addNumericField("Radius of outer ring to pattern radius",abs_oversize, 5,7,"","Outer ring external radius as a mupltile of the pattern radius.");
gd.addNumericField("Update subpattern mode", abs_mode, 0,4,"", "0 - keep, 1 keep type and if half, only change by +/-1, 2 - keep type, 3 - any.");
gd.addCheckbox ("Cold center", abs_invert, "Center pattern values are lower than around.");
gd.addNumericField("Outlier fraction when averaging", abs_outliers_frac, 5,7,"","Discard this fraction of pixels in inner and outer zones when averaging.");
gd.addTab("Filters","Filtering results to reduce false positives");
gd.addCheckbox ("Keep filtered out", filt_keep, "List filtered out, but actaually keep them."); gd.addCheckbox ("Keep filtered out", filt_keep, "List filtered out, but actaually keep them.");
gd.addCheckbox ("Apply filters at once", filt_atonce, "If false, first filter by main scene only, do not process secondary scene if main failed."); gd.addCheckbox ("Apply filters at once", filt_atonce, "If false, first filter by main scene only, do not process secondary scene if main failed.");
gd.addNumericField("Peak hight fraction", filt_frac_max, 5,7,"","Fraction of the peak hight for eigenvlues (radius and elongation)."); gd.addNumericField("Peak hight fraction", filt_frac_max, 5,7,"","Fraction of the peak hight for eigenvlues (radius and elongation).");
...@@ -1832,16 +1847,14 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1832,16 +1847,14 @@ public class OrthoMapsCollection implements Serializable{
gd.addNumericField("Maximal object height", filt_height, 5,7,"m", "Maximal object height to allow extra offset."); gd.addNumericField("Maximal object height", filt_height, 5,7,"m", "Maximal object height to allow extra offset.");
gd.addNumericField("Full/half corr minimal ratio, main",filt_full_half_frac[0], 5,7,"","Minimal correlation with full pattern strength ratio to correlation with a half-pattern."); gd.addNumericField("Full/half corr minimal ratio, main",filt_full_half_frac[0], 5,7,"","Minimal correlation with full pattern strength ratio to correlation with a half-pattern.");
gd.addNumericField("Full/half corr minimal ratio, other",filt_full_half_frac[1], 5,7,"","Minimal correlation with full pattern strength ratio to correlation with a half-pattern."); gd.addNumericField("Full/half corr minimal ratio, other",filt_full_half_frac[1], 5,7,"","Minimal correlation with full pattern strength ratio to correlation with a half-pattern.");
gd.addNumericField("Minimal absolute contrast", filt_abs_contrast, 5,7,"","Minimal absolute difference between center and peripheral areas of the main scene objects.");
// //
gd.addNumericField("Debug level", debugLevel, 0,4,"", "Debug level."); gd.addNumericField("Debug level", debugLevel, 0,4,"", "Debug level.");
gd.showDialog(); gd.showDialog();
if (gd.wasCanceled()) return null; if (gd.wasCanceled()) return null;
object_type= gd.getNextString();
min_corrs[0]= gd.getNextNumber(); min_corrs[0]= gd.getNextNumber();
min_corrs[1]= gd.getNextNumber(); min_corrs[1]= gd.getNextNumber();
// max_area[0]= gd.getNextNumber();
// max_area[1]= gd.getNextNumber();
phaseCoeff[0]= gd.getNextNumber(); phaseCoeff[0]= gd.getNextNumber();
phaseCoeff[1]= gd.getNextNumber(); phaseCoeff[1]= gd.getNextNumber();
min_corr_full_rel= gd.getNextNumber(); min_corr_full_rel= gd.getNextNumber();
...@@ -1852,11 +1865,16 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1852,11 +1865,16 @@ public class OrthoMapsCollection implements Serializable{
corr_size= (int) gd.getNextNumber(); corr_size= (int) gd.getNextNumber();
adv_radius= gd.getNextNumber(); adv_radius= gd.getNextNumber();
search_radius= gd.getNextNumber(); search_radius= gd.getNextNumber();
object_type= gd.getNextString();
scale_warp = gd.getNextNumber(); scale_warp = gd.getNextNumber();
extr_size= (int) gd.getNextNumber(); extr_size= (int) gd.getNextNumber();
remove_dc= gd.getNextBoolean(); remove_dc= gd.getNextBoolean();
abs_edge_frac = gd.getNextNumber();
abs_oversize = gd.getNextNumber();
abs_mode = (int) gd.getNextNumber();
abs_invert = gd.getNextBoolean();
abs_outliers_frac = gd.getNextNumber();
filt_keep= gd.getNextBoolean(); filt_keep= gd.getNextBoolean();
filt_atonce= gd.getNextBoolean(); filt_atonce= gd.getNextBoolean();
filt_frac_max= gd.getNextNumber(); filt_frac_max= gd.getNextNumber();
...@@ -1878,6 +1896,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1878,6 +1896,7 @@ public class OrthoMapsCollection implements Serializable{
filt_height = gd.getNextNumber(); filt_height = gd.getNextNumber();
filt_full_half_frac[0]=gd.getNextNumber(); filt_full_half_frac[0]=gd.getNextNumber();
filt_full_half_frac[1]=gd.getNextNumber(); filt_full_half_frac[1]=gd.getNextNumber();
filt_abs_contrast= gd.getNextNumber();
debugLevel= (int) gd.getNextNumber(); debugLevel= (int) gd.getNextNumber();
...@@ -1885,6 +1904,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1885,6 +1904,7 @@ public class OrthoMapsCollection implements Serializable{
indices, // int [] indices, // null or which indices to use (normally just 2 for pairwise comparison) indices, // int [] indices, // null or which indices to use (normally just 2 for pairwise comparison)
affines, // double [][][] affines, // null or [indices.length][2][3] affines, // double [][][] affines, // null or [indices.length][2][3]
warp, // FineXYCorr warp); warp, // FineXYCorr warp);
object_type, // String object_type,
min_corrs, // double [] min_corrs, // one per min_corrs, // double [] min_corrs, // one per
phaseCoeff, // double [] phaseCoeff phaseCoeff, // double [] phaseCoeff
min_corr_full_rel, // double min_corr_full_rel, min_corr_full_rel, // double min_corr_full_rel,
...@@ -1894,10 +1914,14 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1894,10 +1914,14 @@ public class OrthoMapsCollection implements Serializable{
corr_size, // int corr_size, corr_size, // int corr_size,
adv_radius, // double adv_radius, // adv_radius, // double adv_radius, //
search_radius, // double search_radius, // search_radius, // double search_radius, //
object_type, // String object_type,
scale_warp, // double scale_warp, scale_warp, // double scale_warp,
extr_size, // int extr_size, extr_size, // int extr_size,
remove_dc, // boolean remove_dc, remove_dc, // boolean remove_dc,
abs_edge_frac, // double abs_edge_frac, // = 0.25;
abs_oversize, // double abs_oversize, // = 1.8;
abs_mode, // int abs_mode, // = 1; // 0 - keep, 1 keep type and if half +/-1, 2 - keep type, 3 - any
abs_invert, // boolean abs_invert, // = true; // center has lower value than around
abs_outliers_frac, // double abs_outliers_frac,
filt_keep, // boolean filt_keep, filt_keep, // boolean filt_keep,
filt_atonce, // boolean filt_atonce, filt_atonce, // boolean filt_atonce,
filt_frac_max, // double frac_max, // measure are at fraction of max filt_frac_max, // double frac_max, // measure are at fraction of max
...@@ -1908,6 +1932,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1908,6 +1932,7 @@ public class OrthoMapsCollection implements Serializable{
filt_dist, // double [] filt_dist, filt_dist, // double [] filt_dist,
filt_height, // double filt_height, filt_height, // double filt_height,
filt_full_half_frac, // double [] filt_full_half_frac, filt_full_half_frac, // double [] filt_full_half_frac,
filt_abs_contrast, // double filt_abs_contrast, // = 50.0;
debugLevel); // int debugLevel) debugLevel); // int debugLevel)
} }
...@@ -1915,6 +1940,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1915,6 +1940,7 @@ public class OrthoMapsCollection implements Serializable{
int [] indices, // null or which indices to use (normally just 2 for pairwise comparison) int [] indices, // null or which indices to use (normally just 2 for pairwise comparison)
double [][][] affines, // null or [indices.length][2][3] double [][][] affines, // null or [indices.length][2][3]
FineXYCorr warp, // use for a single pair only FineXYCorr warp, // use for a single pair only
String object_type,
double [] min_corrs, // one per double [] min_corrs, // one per
double [] phaseCoeff, // one per double [] phaseCoeff, // one per
double min_corr_full_rel, double min_corr_full_rel,
...@@ -1924,10 +1950,14 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1924,10 +1950,14 @@ public class OrthoMapsCollection implements Serializable{
int corr_size, int corr_size,
double adv_radius, // double adv_radius, //
double search_radius, // look for other scene max within this distance from main double search_radius, // look for other scene max within this distance from main
String object_type,
double scale_warp, double scale_warp,
int extr_size, int extr_size,
boolean remove_dc, boolean remove_dc,
double abs_edge_frac, // = 0.25;
double abs_oversize, // = 1.8;
int abs_mode, // = 1; // 0 - keep, 1 keep type and if half +/-1, 2 - keep type, 3 - any
boolean abs_invert, // = true; // center has lower value than around
double abs_outliers_frac,
boolean filt_keep, boolean filt_keep,
boolean filt_atonce, boolean filt_atonce,
double frac_max, // measure are at fraction of max double frac_max, // measure are at fraction of max
...@@ -1938,6 +1968,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1938,6 +1968,7 @@ public class OrthoMapsCollection implements Serializable{
double [] filt_dist, double [] filt_dist,
double filt_height, double filt_height,
double [] filt_full_half_frac, double [] filt_full_half_frac,
double filt_abs_contrast, // = 50.0;
int debugLevel) { int debugLevel) {
warp.scale_warp = scale_warp; warp.scale_warp = scale_warp;
int corr_radius = (int) (Math.sqrt(0.5)* adv_radius) -1 ; int corr_radius = (int) (Math.sqrt(0.5)* adv_radius) -1 ;
...@@ -2001,8 +2032,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2001,8 +2032,7 @@ public class OrthoMapsCollection implements Serializable{
// double [][][] extr_corr_best = new double [indices.length][][]; // only for main - already combined // double [][][] extr_corr_best = new double [indices.length][][]; // only for main - already combined
double [][][] extr_corr_half = new double [indices.length][][]; double [][][] extr_corr_half = new double [indices.length][][];
double [][][][] filter_data = new double [indices.length][][][]; // [scene][max][0-full, 1 - half][0- max, 1 - area, 2 - distance] double [][][][] filter_data = new double [indices.length][][][]; // [scene][max][0-full, 1 - half][0- max, 1 - area, 2 - distance]
int [] best_patt_indx; // int [] best_patt_indx;
for (int scene_num = 0; scene_num < indices.length; scene_num++) { // will probably just use first one, second - derivative for (int scene_num = 0; scene_num < indices.length; scene_num++) { // will probably just use first one, second - derivative
gops[scene_num] = GroundObjectPattern.getPattern( gops[scene_num] = GroundObjectPattern.getPattern(
object_type, // String object_type, object_type, // String object_type,
...@@ -2070,15 +2100,13 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2070,15 +2100,13 @@ public class OrthoMapsCollection implements Serializable{
} }
} }
if (scene_num == 0) { if (scene_num == 0) {
double oversize = 1.8; boolean debug = debugLevel > 1;
double edge_frac = 0.25;
icorr_patterns[scene_num] = OrthoMap.getIntPatterns( icorr_patterns[scene_num] = OrthoMap.getIntPatterns(
corr_patterns[scene_num], // double [][] patterns, corr_patterns[scene_num], // double [][] patterns,
edge_frac, // double edge_frac, // 0.15 abs_edge_frac, // double edge_frac, // 0.15
oversize, // double oversize, abs_oversize, // double oversize,
true); // boolean debug); debug); // boolean debug);
} }
} }
// Splitting - above done for both scenes, below - just for the main one // Splitting - above done for both scenes, below - just for the main one
for (int scene_num = 0; scene_num < indices.length; scene_num++) { // will probably just use first one, second - derivative for (int scene_num = 0; scene_num < indices.length; scene_num++) { // will probably just use first one, second - derivative
...@@ -2229,7 +2257,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2229,7 +2257,7 @@ public class OrthoMapsCollection implements Serializable{
i, i,
icenter_xy[0],icenter_xy[1], icenter_xy[0],icenter_xy[1],
match.getMatchValue(gops[scene_num],sort_pattern_index), match.getMatchValue(gops[scene_num],sort_pattern_index),
match.getPatternMatch(gops[scene_num]).getBestSub())); match.getPatternMatch(gops[scene_num]).getBestSub())); // 1-based
for (int j = 0; j < match_values.length; j++) if (j != sort_pattern_index) { for (int j = 0; j < match_values.length; j++) if (j != sort_pattern_index) {
System.out.print(String.format(" %8.5f",match_values[j])); System.out.print(String.format(" %8.5f",match_values[j]));
if (j == (match_values.length-1)) { if (j == (match_values.length-1)) {
...@@ -2252,12 +2280,12 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2252,12 +2280,12 @@ public class OrthoMapsCollection implements Serializable{
filter_data[scene_num] = new double[match_sort.size()][2][]; // [scene][max][0-full, 1 - half][0- max, 1 - area, 2 - distance] filter_data[scene_num] = new double[match_sort.size()][2][]; // [scene][max][0-full, 1 - half][0- max, 1 - area, 2 - distance]
extr_corr[scene_num] = new double [match_sort.size()][]; // extracted_objects[scene_num].length][]; extr_corr[scene_num] = new double [match_sort.size()][]; // extracted_objects[scene_num].length][];
extr_corr_half[scene_num] = new double [match_sort.size()][]; // extracted_objects[scene_num].length][]; extr_corr_half[scene_num] = new double [match_sort.size()][]; // extracted_objects[scene_num].length][];
best_patt_indx = new int [match_sort.size()]; /// best_patt_indx = new int [match_sort.size()];
for (int mn=0; mn < match_sort.size(); mn++) { for (int mn=0; mn < match_sort.size(); mn++) {
int indx =match_sort.get(mn); int indx =match_sort.get(mn);
ItemMatch match = matches_list.get(indx); ItemMatch match = matches_list.get(indx);
int best_patt = match.getPatternMatch(gops[scene_num]).getBestSub() - 1; int best_patt = match.getPatternMatch(gops[scene_num]).getBestSub() - 1;
best_patt_indx[mn] = best_patt; /// best_patt_indx[mn] = best_patt;
double [] center_xy = match.getXY(); double [] center_xy = match.getXY();
extr_corr[scene_num][mn] = ObjectLocation.extractObjectImage( extr_corr[scene_num][mn] = ObjectLocation.extractObjectImage(
center_xy, // double [] center_xy, center_xy, // double [] center_xy,
...@@ -2294,7 +2322,35 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2294,7 +2322,35 @@ public class OrthoMapsCollection implements Serializable{
frac_max, // double frac_max) frac_max, // double frac_max)
filt_other_rad, // double other_radius, filt_other_rad, // double other_radius,
debugLevel); // final int debugLevel) { debugLevel); // final int debugLevel) {
// extract main scene data, needed for the absolute contrast calculations, no display
showExtractedImages( // scene_num == 0 here
null, // ortho_maps[indices[scene_num]].getName()+"-prefilter", // String prefix
scene_num, //int scene_num,
sort_pattern_index, // int sort_pattern_index,
extr_size, // int extr_size,
gops[scene_num], // GroundObjectPattern gop,
matches_list, // ArrayList <ItemMatch> matches_list,
match_sort, // ArrayList<Integer> match_sort,
extracted_objects, // double[][][] extracted_objects, // may be null - will not be generated
null, // extract_display, // double[][][] extract_display, // may be null - will not be displayed
dmulti, // double[][] dmulti,
width, // int width,
remove_dc, // boolean remove_dc,
null, // imps_extracted, //ImagePlus[] imps_extracted, // may be null - will not be displayed
debugLevel); // int debugLevel
} }
// calculate absolute contrasts for all patterns, update best_sub modes: 0 - keep, 1 - keep type, 2 keep type and if half +/-1
setAbsoluteContrasts(
abs_mode, // int mode, // 0 - keep, 1 keep type and if half +/-1, 2 - keep type, 3 - any
abs_invert, // boolean neg_better, // more negative is difference - stronger result
abs_outliers_frac, // double outliers_frac,
gops[scene_num], // GroundObjectPattern gop,
matches_list, // ArrayList <ItemMatch> matches_list,
match_sort, // ArrayList<Integer> match_sort,
extracted_objects[scene_num], //double[][] extracted_objects, // for this scene
icorr_patterns[scene_num], // int [][] ipatterns,
debugLevel); // int debugLevel
double [] scene_xy_offset = {centers[1][0]-centers[0][0],centers[1][1]-centers[0][1]}; double [] scene_xy_offset = {centers[1][0]-centers[0][0],centers[1][1]-centers[0][1]};
boolean [] removed = null; boolean [] removed = null;
double scene_agl = gops[1].getAGL(); // second scene agl double scene_agl = gops[1].getAGL(); // second scene agl
...@@ -2311,7 +2367,8 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2311,7 +2367,8 @@ public class OrthoMapsCollection implements Serializable{
filt_dist, // double [] filt_dist, filt_dist, // double [] filt_dist,
filt_height, // double filt_height, filt_height, // double filt_height,
filt_full_half_frac,// double [] filt_full_half_frac, filt_full_half_frac,// double [] filt_full_half_frac,
best_patt_indx, // int [] best_patt_indx, filt_abs_contrast, // double filt_abs_contrast,
gops[scene_num], // GroundObjectPattern gop,
filt_other_frac, // double [] filt_other_frac, // null - disable, for all full (round) patterns. filt_other_frac, // double [] filt_other_frac, // null - disable, for all full (round) patterns.
filter_data, // double [][][][] filter_data, filter_data, // double [][][][] filter_data,
zoom_level, // int zoom_level, zoom_level, // int zoom_level,
...@@ -2327,7 +2384,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2327,7 +2384,7 @@ public class OrthoMapsCollection implements Serializable{
extr_corr[sn] = removeFilteredOut (extr_corr[sn], removed); extr_corr[sn] = removeFilteredOut (extr_corr[sn], removed);
extr_corr_half[sn] = removeFilteredOut (extr_corr_half[sn], removed); extr_corr_half[sn] = removeFilteredOut (extr_corr_half[sn], removed);
} }
best_patt_indx = removeFilteredOut(best_patt_indx, removed); // best_patt_indx = removeFilteredOut(best_patt_indx, removed);
removed = new boolean [match_sort.size()]; removed = new boolean [match_sort.size()];
} }
...@@ -2366,18 +2423,36 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2366,18 +2423,36 @@ public class OrthoMapsCollection implements Serializable{
imps_extracted_corr, // ImagePlus[] imps_extracted_corr, // may be null - will not be displayed imps_extracted_corr, // ImagePlus[] imps_extracted_corr, // may be null - will not be displayed
imps_extracted_corr_half); // ImagePlus[] imps_extracted_corr_half imps_extracted_corr_half); // ImagePlus[] imps_extracted_corr_half
} }
double [] abs_contrast = new double [match_sort.size()]; // print updated table after some scenes may be removed by the filter
double outliers_frac = 0.3; System.out.println("\nAfter first scene filtering:");
System.out.print(String.format("%4s: %9s %8s %8s %3s"," # ", " x/y ", " best ","contrast","sub"));
for (int j = 0; j < (corrs_out[scene_num].length + 1); j++) if (j != sort_pattern_index) {
System.out.print(String.format(" %8s ","match_"+j));
}
System.out.println();
for (int i = 0; i < match_sort.size(); i++) { for (int i = 0; i < match_sort.size(); i++) {
int indx =match_sort.get(i); int indx =match_sort.get(i);
ItemMatch match = matches_list.get(indx); ItemMatch match = matches_list.get(indx);
int best_patt= match.getPatternMatch(gops[scene_num]).getBestSub(); double [] match_values = match.getMatchValues(gops[scene_num]);
abs_contrast[i] = OrthoMap.getAbsoluteContrast( int [] icenter_xy = match.getIntXY();
extracted_objects[scene_num][i], // double [] data, System.out.print(String.format("%4d: %4d/%4d %8.5f %8.3f %3d",
icorr_patterns[scene_num][best_patt-1], //int [] ipattern, i,
outliers_frac, // double outliers_frac, icenter_xy[0],icenter_xy[1],
true); // boolean debug); match.getMatchValue(gops[scene_num],sort_pattern_index),
match.getAbsoluteContrast(),
match.getPatternMatch(gops[scene_num]).getBestSub())); // 1-based
for (int j = 0; j < match_values.length; j++) if (j != sort_pattern_index) {
System.out.print(String.format(" %8.5f",match_values[j]));
if (j == (match_values.length-1)) {
System.out.println();
} else {
System.out.print(",");
}
} }
}
// Correlate second scene only for selected fragments // Correlate second scene only for selected fragments
for (int scene_other = 1; scene_other < indices.length; scene_other++) { // normally just 1 for (int scene_other = 1; scene_other < indices.length; scene_other++) { // normally just 1
filter_data[scene_other] = new double[match_sort.size()][2][]; // [scene][max][0-full, 1 - half][0- max, 1 - area, 2 - distance] filter_data[scene_other] = new double[match_sort.size()][2][]; // [scene][max][0-full, 1 - half][0- max, 1 - area, 2 - distance]
...@@ -2465,7 +2540,8 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2465,7 +2540,8 @@ public class OrthoMapsCollection implements Serializable{
filt_dist, // double [] filt_dist, filt_dist, // double [] filt_dist,
filt_height, // double filt_height, filt_height, // double filt_height,
filt_full_half_frac,// double [] filt_other_frac, // null - disable, for all full (round) patterns. filt_full_half_frac,// double [] filt_other_frac, // null - disable, for all full (round) patterns.
best_patt_indx, // int [] best_patt_indx, filt_abs_contrast, // double filt_abs_contrast,
gops[scene_num], // GroundObjectPattern gop,
filt_other_frac, // double [] filt_other_frac, // null - disable, for all full (round) patterns. filt_other_frac, // double [] filt_other_frac, // null - disable, for all full (round) patterns.
filter_data, // double [][][][] filter_data, filter_data, // double [][][][] filter_data,
zoom_level, // int zoom_level, zoom_level, // int zoom_level,
...@@ -2482,7 +2558,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2482,7 +2558,7 @@ public class OrthoMapsCollection implements Serializable{
extr_corr[sn] = removeFilteredOut (extr_corr[sn], removed); extr_corr[sn] = removeFilteredOut (extr_corr[sn], removed);
extr_corr_half[sn] = removeFilteredOut (extr_corr_half[sn], removed); extr_corr_half[sn] = removeFilteredOut (extr_corr_half[sn], removed);
} }
best_patt_indx = removeFilteredOut(best_patt_indx, removed); // best_patt_indx = removeFilteredOut(best_patt_indx, removed);
removed = new boolean [match_sort.size()]; removed = new boolean [match_sort.size()];
} }
...@@ -2541,7 +2617,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2541,7 +2617,7 @@ public class OrthoMapsCollection implements Serializable{
System.out.println("Second image is offset by dx="+scene_xy_offset[0]+", dy="+scene_xy_offset[1]+", dist="+ System.out.println("Second image is offset by dx="+scene_xy_offset[0]+", dy="+scene_xy_offset[1]+", dist="+
Math.sqrt(scene_xy_offset[0]*scene_xy_offset[0]+scene_xy_offset[1]*scene_xy_offset[1])+" pix"); Math.sqrt(scene_xy_offset[0]*scene_xy_offset[0]+scene_xy_offset[1]*scene_xy_offset[1])+" pix");
System.out.println("Updated object list with main scene peak areas and secondary scene maximums, areas and maximum distances from the main"); System.out.println("Updated object list with main scene peak areas and secondary scene maximums, areas and maximum distances from the main");
System.out.print(String.format("%4s: %9s %8s %3s"," # ", " x/y ", " best ","sub")); System.out.print(String.format("%4s: %9s %8s %8s %3s"," # ", " x/y ", " best ","contrast","sub"));
for (int j = 0; j < (corrs_out[scene_num].length + 1); j++) if (j != sort_pattern_index) { for (int j = 0; j < (corrs_out[scene_num].length + 1); j++) if (j != sort_pattern_index) {
System.out.print(String.format(" %8s ","match_"+j)); System.out.print(String.format(" %8s ","match_"+j));
} }
...@@ -2556,11 +2632,12 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2556,11 +2632,12 @@ public class OrthoMapsCollection implements Serializable{
ItemMatch match = matches_list.get(indx); ItemMatch match = matches_list.get(indx);
double [] match_values = match.getMatchValues(gops[scene_num]); double [] match_values = match.getMatchValues(gops[scene_num]);
int [] icenter_xy = match.getIntXY(); int [] icenter_xy = match.getIntXY();
System.out.print(String.format("%4d: %4d/%4d %8.5f %3d", System.out.print(String.format("%4d: %4d/%4d %8.5f %8.3f %3d",
i, i,
icenter_xy[0],icenter_xy[1], icenter_xy[0],icenter_xy[1],
match.getMatchValue(gops[scene_num],sort_pattern_index), match.getMatchValue(gops[scene_num],sort_pattern_index),
match.getPatternMatch(gops[scene_num]).getBestSub())); match.getAbsoluteContrast(),
match.getPatternMatch(gops[scene_num]).getBestSub())); // 1-based
for (int j = 0; j < match_values.length; j++) if (j != sort_pattern_index) { for (int j = 0; j < match_values.length; j++) if (j != sort_pattern_index) {
System.out.print(String.format(" %8.5f",match_values[j])); System.out.print(String.format(" %8.5f",match_values[j]));
if (j != (match_values.length-1)) { if (j != (match_values.length-1)) {
...@@ -2826,7 +2903,9 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2826,7 +2903,9 @@ public class OrthoMapsCollection implements Serializable{
double [] filt_dist, double [] filt_dist,
double filt_height, double filt_height,
double [] filt_full_half_frac, double [] filt_full_half_frac,
int [] best_patt_indx, double filt_abs_contrast,
GroundObjectPattern gop,
// int [] best_patt_indx,
double [] filt_other_frac, // null - disable, for all full (round) patterns. double [] filt_other_frac, // null - disable, for all full (round) patterns.
double [][][][] filter_data, double [][][][] filter_data,
int zoom_level, int zoom_level,
...@@ -2849,11 +2928,22 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2849,11 +2928,22 @@ public class OrthoMapsCollection implements Serializable{
ItemMatch match = matches_list.get(indx); ItemMatch match = matches_list.get(indx);
int [] ixy = match.getIntXY(); int [] ixy = match.getIntXY();
String name = ixy[0]+"/"+ixy[1]; String name = ixy[0]+"/"+ixy[1];
boolean is_partial = best_patt_indx[mn] != 0; // only apply to combined full/half correlations, just full may have nearby maximums near the same size double abs_contrast = match.getAbsoluteContrast();
int best_patt= match.getPatternMatch(gop).getBestSub(); // 1-based
// boolean is_partial = best_patt_indx[mn] != 0; // only apply to combined full/half correlations, just full may have nearby maximums near the same size
boolean is_partial = best_patt != 1; // only apply to combined full/half correlations, just full may have nearby maximums near the same size
double [] strength_full_half_ratio = new double[2]; double [] strength_full_half_ratio = new double[2];
for (int scene_num = 0; scene_num < 2; scene_num++) if (filter_data[scene_num] != null){ for (int scene_num = 0; scene_num < 2; scene_num++) if (filter_data[scene_num] != null){
strength_full_half_ratio[scene_num] = filter_data[scene_num][mn][0][0] / filter_data[scene_num][mn][1][0]; strength_full_half_ratio[scene_num] = filter_data[scene_num][mn][0][0] / filter_data[scene_num][mn][1][0];
} }
if (abs_contrast < filt_abs_contrast) {
System.out.println(name+": filtered out by "+NAME_MO[0]+" scene because its absolute contrast = "+
abs_contrast+ " < "+filt_abs_contrast);
if (!remove[mn]) num_removed++;
remove[mn] = true;
}
for (int hf = 0; hf < 2; hf++) { for (int hf = 0; hf < 2; hf++) {
for (int scene_num = 0; scene_num < 2; scene_num++) if (filt_main_other[scene_num]){ for (int scene_num = 0; scene_num < 2; scene_num++) if (filt_main_other[scene_num]){
if (Double.isNaN(filter_data[scene_num][mn][hf][0])) { if (Double.isNaN(filter_data[scene_num][mn][hf][0])) {
...@@ -2927,7 +3017,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2927,7 +3017,7 @@ public class OrthoMapsCollection implements Serializable{
} }
if (is_partial && (filt_other_frac != null) && (hf > 0) && (near_max_frac > filt_other_frac[scene_num])) { if (is_partial && (filt_other_frac != null) && (hf > 0) && (near_max_frac > filt_other_frac[scene_num])) {
System.out.println(name+": filtered out by "+NAME_MO[scene_num]+ System.out.println(name+": filtered out by "+NAME_MO[scene_num]+
" because it matches partial pattern and combined full/partial correlation has a near peak "+ " because it matches partial pattern ("+best_patt+") and combined full/partial correlation has a near peak "+
near_max_frac+" > "+ filt_other_frac[scene_num]+" of the used peak."); near_max_frac+" > "+ filt_other_frac[scene_num]+" of the used peak.");
if (!remove[mn]) num_removed++; if (!remove[mn]) num_removed++;
remove[mn] = true; remove[mn] = true;
...@@ -2962,6 +3052,115 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -2962,6 +3052,115 @@ public class OrthoMapsCollection implements Serializable{
return remove; return remove;
} }
/**
* Set absolute contrasts for each object, optionally changing sub-pattern index. Absolute contrast
* is a difference between average (w/o outliers) data value in zone1 (center area of the pattern) and
* the ring around it (zone2).
* On return the matches_list data is modified - absolute contrasts are set, and best_pattern may be
* updated.
* @param mode Update of the best sub-pattern index:
* 0 - keep current
* 1 - keep type (full/half) and allow half direction to change by -1,0, or +1
* 2 - keep type (full/half)
* 3 - no restrictions - find the best sub-pattern index from scratch.
* @param neg_better center lower (colder) than around
* @param outliers_frac fraction of outliers to remove while calculating averages
* @param gop GroundObjectPattern instance used
* @param matches_list list of pattern matches
* @param match_sort sorted list of indices in pattern matches list, so the first is the best match.
* @param extracted_objects square arrays for each of the object, so the center of objects is in the
* center of the square.
* @param ipatterns integer square patterns with the same dimensions as the extracted_objects. Value
* 0 - do not use this pixel, 1 - Zone1 (inside the pattern), 2 - Zone2 - reference ring around
* the pattern.
* @param debugLevel debug level. >0 - dispaly images, >-4 - print.
* @return true
*/
public static boolean setAbsoluteContrasts(
int mode, // 0 - keep, 1 keep type and if half +/-1, 2 - keep type, 3 - any
boolean neg_better, // more negative is difference - stronger result
double outliers_frac,
GroundObjectPattern gop,
ArrayList <ItemMatch> matches_list,
ArrayList<Integer> match_sort,
double[][] extracted_objects, // for this scene
int [][] ipatterns,
int debugLevel
) {
boolean debug = debugLevel > 1;
for (int mn=0; mn < match_sort.size(); mn++) {
if (debugLevel > 1) {
System.out.println("setAbsoluteContrasts(): Calculating absolute contrast for match #"+mn);
}
int indx =match_sort.get(mn);
ItemMatch match = matches_list.get(indx);
boolean [] try_sub = new boolean [ipatterns.length];
int best_patt= match.getPatternMatch(gop).getBestSub() - 1; // 0-based
int num_halves = ipatterns.length - 1; // == 8
switch (mode) {
case 0: try_sub[best_patt] = true; break; // only one
case 1: // keep type and +-1 for direction
if (best_patt == 0) {
try_sub[0] = true;
} else {
for (int offs = -1; offs <= 1 ; offs++) {
int i = best_patt+offs;
if (i < 1) {
i += num_halves;
} else if (i > num_halves) {
i -= num_halves;
}
try_sub[i] = true;
}
}
break;
case 2: // keep type
if (best_patt == 0) {
try_sub[0] = true;
} else {
for (int i = 1; i < try_sub.length; i++) {
try_sub[i] = true;
}
}
break;
case 3: // any
for (int i = 0; i < try_sub.length; i++) {
try_sub[i] = true;
}
break;
}
double [] dir_contrasts = new double [try_sub.length];
int best_index = -1;
for (int i = 0; i < try_sub.length; i++) if (try_sub[i]) {
dir_contrasts[i]= OrthoMap.getAbsoluteContrast(
extracted_objects[mn], // double [] data,
ipatterns[i], // int [] ipattern,
outliers_frac, // double outliers_frac,
debug); // boolean debug)
if (neg_better) {
dir_contrasts[i] *= -1;
}
if (dir_contrasts[i] > 0) {
if ((best_index < 0) || (dir_contrasts[i] > dir_contrasts[best_index])) {
best_index = i;
}
}
}
if (best_index != best_patt) {
if (debugLevel > -3) {
System.out.println("setAbsoluteContrasts(): updating best pattern index for match #"
+mn+". Was (1 for full):"+(best_patt+1)+", new is "+(best_index + 1));
}
match.getPatternMatch(gop).setBestSub(best_index + 1);
}
match.setAbsoluteContrast(dir_contrasts[best_index]); // the higher the better
if (debugLevel > -3) {
System.out.println("setAbsoluteContrasts(): Set absolute contrast for match #"+mn+" = "+dir_contrasts[best_index]);
}
}
return true;
}
...@@ -3024,7 +3223,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -3024,7 +3223,7 @@ public class OrthoMapsCollection implements Serializable{
} }
} }
} }
if ((debugLevel > 0) && (imps_extracted != null) && (extract_display != null)) { if ((debugLevel > 0) && (imps_extracted != null) && (extract_display != null) && (prefix != null)) {
String [] extr_titles = new String [match_sort.size()]; String [] extr_titles = new String [match_sort.size()];
for (int mn=0; mn < match_sort.size(); mn++) { for (int mn=0; mn < match_sort.size(); mn++) {
int indx =match_sort.get(mn); int indx =match_sort.get(mn);
...@@ -3073,7 +3272,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -3073,7 +3272,7 @@ public class OrthoMapsCollection implements Serializable{
int indx =match_sort.get(mn); int indx =match_sort.get(mn);
ItemMatch match = matches_list.get(indx); ItemMatch match = matches_list.get(indx);
int [] ixy = match.getIntXY(); int [] ixy = match.getIntXY();
int best_patt = match.getPatternMatch(gop).getBestSub() - 1; int best_patt = match.getPatternMatch(gop).getBestSub() - 1; // 0-based
extr_titles_full[mn] = ixy[0]+"/"+ ixy[1]; extr_titles_full[mn] = ixy[0]+"/"+ ixy[1];
extr_titles_half[mn] = extr_titles_full[mn]+":"+best_patt; extr_titles_half[mn] = extr_titles_full[mn]+":"+best_patt;
} }
......
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