Commit 98b0dee4 authored by Andrey Filippov's avatar Andrey Filippov

more on tile assignments

parent 42bc2c68
...@@ -2351,6 +2351,15 @@ public class EyesisCorrectionParameters { ...@@ -2351,6 +2351,15 @@ public class EyesisCorrectionParameters {
public int tsConsensAgree = 1; // Minimal number of assignments to agree public int tsConsensAgree = 1; // Minimal number of assignments to agree
// Tile assignment parameters // Tile assignment parameters
public double taMinFgBg = 0.1; // Minimal foreground/ background separation to look for weak FG edge
public double taMinFgEdge = 0.2; // Minimal foreground edge strength (stronger edges will have proportionally smaller costs)
public double taMinColSep = 0.05; // Minimal surface separation that requires color change
public double taMinColDiff = 0.01; // Minimal color variation (larger proportionally reduces cost)
public double taOutlier = 1.0; // Disparity difference limit
public double taDiffPwr = 0.25; // Strength power when calculating disparity error
public double taBestPwr = 0.0; // Strength power when calculating disparity error over best
public double taDiff9Pwr = 0.5; // Strength power when calculating disparity error for group of 9
public double taCostEmpty = 1.0; // Cost of a tile that is not assigned public double taCostEmpty = 1.0; // Cost of a tile that is not assigned
public double taCostNoLink = 1.0; // Cost of a tile not having any neighbor in particular direction public double taCostNoLink = 1.0; // Cost of a tile not having any neighbor in particular direction
public double taCostSwitch = 1.0; // Cost of a tile switching to a neighbor that does not have a link public double taCostSwitch = 1.0; // Cost of a tile switching to a neighbor that does not have a link
...@@ -2362,6 +2371,16 @@ public class EyesisCorrectionParameters { ...@@ -2362,6 +2371,16 @@ public class EyesisCorrectionParameters {
public double taCostFlaps = 1.0; // Cost of using supertile "flaps" (not in the center 8x8 tiles area) public double taCostFlaps = 1.0; // Cost of using supertile "flaps" (not in the center 8x8 tiles area)
public double taCostMismatch = 1.0; // Cost of a measurement layer not having same layer in the same location or near public double taCostMismatch = 1.0; // Cost of a measurement layer not having same layer in the same location or near
public boolean taEnEmpty = true; // Enable cost of a tile that is not assigned
public boolean taEnNoLink = true; // Enable cost of a tile not having any neighbor in particular direction
public boolean taEnSwitch = true; // Enable cost of a tile switching to a neighbor that does not have a link
public boolean taEnColor = true; // Enable cost of a tile switching to a disconnected neighbor divided by a color mismatch
public boolean taEnDiff = true; // Enable cost of a weighted normalized tile disparity error
public boolean taEnDiffBest = true; // Enable cost of a weighted normalized tile disparity error above best surface
public boolean taEnDiff9 = true; // Enable cost of a weighted normalized tile disparity error for tile and 8 neighbors (DC)
public boolean taEnWeakFgnd = true; // Enable cost of a weak foreground edge
public boolean taEnFlaps = true; // Enable cost of using supertile "flaps" (not in the center 8x8 tiles area)
public boolean taEnMismatch = false; // Enable cost of a measurement layer not having same layer in the same location or near
...@@ -2791,6 +2810,15 @@ public class EyesisCorrectionParameters { ...@@ -2791,6 +2810,15 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"tsConsensMode", this.tsConsensMode +""); properties.setProperty(prefix+"tsConsensMode", this.tsConsensMode +"");
properties.setProperty(prefix+"tsConsensAgree", this.tsConsensAgree +""); properties.setProperty(prefix+"tsConsensAgree", this.tsConsensAgree +"");
properties.setProperty(prefix+"taMinFgBg", this.taMinFgBg +"");
properties.setProperty(prefix+"taMinFgEdge", this.taMinFgEdge +"");
properties.setProperty(prefix+"taMinColSep", this.taMinColSep +"");
properties.setProperty(prefix+"taMinColDiff", this.taMinColDiff +"");
properties.setProperty(prefix+"taOutlier", this.taOutlier +"");
properties.setProperty(prefix+"taDiffPwr", this.taDiffPwr +"");
properties.setProperty(prefix+"taBestPwr", this.taBestPwr +"");
properties.setProperty(prefix+"taDiff9Pwr", this.taDiff9Pwr +"");
properties.setProperty(prefix+"taCostEmpty", this.taCostEmpty +""); properties.setProperty(prefix+"taCostEmpty", this.taCostEmpty +"");
properties.setProperty(prefix+"taCostNoLink", this.taCostNoLink +""); properties.setProperty(prefix+"taCostNoLink", this.taCostNoLink +"");
properties.setProperty(prefix+"taCostSwitch", this.taCostSwitch +""); properties.setProperty(prefix+"taCostSwitch", this.taCostSwitch +"");
...@@ -2802,6 +2830,18 @@ public class EyesisCorrectionParameters { ...@@ -2802,6 +2830,18 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"taCostFlaps", this.taCostFlaps +""); properties.setProperty(prefix+"taCostFlaps", this.taCostFlaps +"");
properties.setProperty(prefix+"taCostMismatch", this.taCostMismatch +""); properties.setProperty(prefix+"taCostMismatch", this.taCostMismatch +"");
properties.setProperty(prefix+"taEnEmpty", this.taEnEmpty +"");
properties.setProperty(prefix+"taEnNoLink", this.taEnNoLink +"");
properties.setProperty(prefix+"taEnSwitch", this.taEnSwitch +"");
properties.setProperty(prefix+"taEnColor", this.taEnColor +"");
properties.setProperty(prefix+"taEnDiff", this.taEnDiff +"");
properties.setProperty(prefix+"taEnDiffBest", this.taEnDiffBest +"");
properties.setProperty(prefix+"taEnDiff9", this.taEnDiff9 +"");
properties.setProperty(prefix+"taEnWeakFgnd", this.taEnWeakFgnd +"");
properties.setProperty(prefix+"taEnFlaps", this.taEnFlaps +"");
properties.setProperty(prefix+"taEnMismatch", this.taEnMismatch +"");
properties.setProperty(prefix+"dbg_migrate", this.dbg_migrate+""); properties.setProperty(prefix+"dbg_migrate", this.dbg_migrate+"");
properties.setProperty(prefix+"show_ortho_combine", this.show_ortho_combine+""); properties.setProperty(prefix+"show_ortho_combine", this.show_ortho_combine+"");
...@@ -3222,6 +3262,15 @@ public class EyesisCorrectionParameters { ...@@ -3222,6 +3262,15 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"tsConsensMode")!=null) this.tsConsensMode=Integer.parseInt(properties.getProperty(prefix+"tsConsensMode")); if (properties.getProperty(prefix+"tsConsensMode")!=null) this.tsConsensMode=Integer.parseInt(properties.getProperty(prefix+"tsConsensMode"));
if (properties.getProperty(prefix+"tsConsensAgree")!=null) this.tsConsensAgree=Integer.parseInt(properties.getProperty(prefix+"tsConsensAgree")); if (properties.getProperty(prefix+"tsConsensAgree")!=null) this.tsConsensAgree=Integer.parseInt(properties.getProperty(prefix+"tsConsensAgree"));
if (properties.getProperty(prefix+"taMinFgBg")!=null) this.taMinFgBg=Double.parseDouble(properties.getProperty(prefix+"taMinFgBg"));
if (properties.getProperty(prefix+"taMinFgEdge")!=null) this.taMinFgEdge=Double.parseDouble(properties.getProperty(prefix+"taMinFgEdge"));
if (properties.getProperty(prefix+"taMinColSep")!=null) this.taMinColSep=Double.parseDouble(properties.getProperty(prefix+"taMinColSep"));
if (properties.getProperty(prefix+"taMinColDiff")!=null) this.taMinColDiff=Double.parseDouble(properties.getProperty(prefix+"taMinColDiff"));
if (properties.getProperty(prefix+"taOutlier")!=null) this.taOutlier=Double.parseDouble(properties.getProperty(prefix+"taOutlier"));
if (properties.getProperty(prefix+"taDiffPwr")!=null) this.taDiffPwr=Double.parseDouble(properties.getProperty(prefix+"taDiffPwr"));
if (properties.getProperty(prefix+"taBestPwr")!=null) this.taBestPwr=Double.parseDouble(properties.getProperty(prefix+"taBestPwr"));
if (properties.getProperty(prefix+"taDiff9Pwr")!=null) this.taDiff9Pwr=Double.parseDouble(properties.getProperty(prefix+"taDiff9Pwr"));
if (properties.getProperty(prefix+"taCostEmpty")!=null) this.taCostEmpty=Double.parseDouble(properties.getProperty(prefix+"taCostEmpty")); if (properties.getProperty(prefix+"taCostEmpty")!=null) this.taCostEmpty=Double.parseDouble(properties.getProperty(prefix+"taCostEmpty"));
if (properties.getProperty(prefix+"taCostNoLink")!=null) this.taCostNoLink=Double.parseDouble(properties.getProperty(prefix+"taCostNoLink")); if (properties.getProperty(prefix+"taCostNoLink")!=null) this.taCostNoLink=Double.parseDouble(properties.getProperty(prefix+"taCostNoLink"));
if (properties.getProperty(prefix+"taCostSwitch")!=null) this.taCostSwitch=Double.parseDouble(properties.getProperty(prefix+"taCostSwitch")); if (properties.getProperty(prefix+"taCostSwitch")!=null) this.taCostSwitch=Double.parseDouble(properties.getProperty(prefix+"taCostSwitch"));
...@@ -3233,6 +3282,18 @@ public class EyesisCorrectionParameters { ...@@ -3233,6 +3282,18 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"taCostFlaps")!=null) this.taCostFlaps=Double.parseDouble(properties.getProperty(prefix+"taCostFlaps")); if (properties.getProperty(prefix+"taCostFlaps")!=null) this.taCostFlaps=Double.parseDouble(properties.getProperty(prefix+"taCostFlaps"));
if (properties.getProperty(prefix+"taCostMismatch")!=null) this.taCostMismatch=Double.parseDouble(properties.getProperty(prefix+"taCostMismatch")); if (properties.getProperty(prefix+"taCostMismatch")!=null) this.taCostMismatch=Double.parseDouble(properties.getProperty(prefix+"taCostMismatch"));
if (properties.getProperty(prefix+"taEnEmpty")!=null) this.taEnEmpty=Boolean.parseBoolean(properties.getProperty(prefix+"taEnEmpty"));
if (properties.getProperty(prefix+"taEnNoLink")!=null) this.taEnNoLink=Boolean.parseBoolean(properties.getProperty(prefix+"taEnNoLink"));
if (properties.getProperty(prefix+"taEnSwitch")!=null) this.taEnSwitch=Boolean.parseBoolean(properties.getProperty(prefix+"taEnSwitch"));
if (properties.getProperty(prefix+"taEnColor")!=null) this.taEnColor=Boolean.parseBoolean(properties.getProperty(prefix+"taEnColor"));
if (properties.getProperty(prefix+"taEnDiff")!=null) this.taEnDiff=Boolean.parseBoolean(properties.getProperty(prefix+"taEnDiff"));
if (properties.getProperty(prefix+"taEnDiffBest")!=null) this.taEnDiffBest=Boolean.parseBoolean(properties.getProperty(prefix+"taEnDiffBest"));
if (properties.getProperty(prefix+"taEnDiff9")!=null) this.taEnDiff9=Boolean.parseBoolean(properties.getProperty(prefix+"taEnDiff9"));
if (properties.getProperty(prefix+"taEnWeakFgnd")!=null) this.taEnWeakFgnd=Boolean.parseBoolean(properties.getProperty(prefix+"taEnWeakFgnd"));
if (properties.getProperty(prefix+"taEnFlaps")!=null) this.taEnFlaps=Boolean.parseBoolean(properties.getProperty(prefix+"taEnFlaps"));
if (properties.getProperty(prefix+"taEnMismatch")!=null) this.taEnMismatch=Boolean.parseBoolean(properties.getProperty(prefix+"taEnMismatch"));
if (properties.getProperty(prefix+"dbg_migrate")!=null) this.dbg_migrate=Boolean.parseBoolean(properties.getProperty(prefix+"dbg_migrate")); if (properties.getProperty(prefix+"dbg_migrate")!=null) this.dbg_migrate=Boolean.parseBoolean(properties.getProperty(prefix+"dbg_migrate"));
if (properties.getProperty(prefix+"show_ortho_combine")!=null) this.show_ortho_combine=Boolean.parseBoolean(properties.getProperty(prefix+"show_ortho_combine")); if (properties.getProperty(prefix+"show_ortho_combine")!=null) this.show_ortho_combine=Boolean.parseBoolean(properties.getProperty(prefix+"show_ortho_combine"));
...@@ -3685,6 +3746,15 @@ public class EyesisCorrectionParameters { ...@@ -3685,6 +3746,15 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Minimal number of assignments to agree", this.tsConsensAgree, 0); gd.addNumericField("Minimal number of assignments to agree", this.tsConsensAgree, 0);
gd.addMessage ("--- Tile assignment parameters ---"); gd.addMessage ("--- Tile assignment parameters ---");
gd.addNumericField("Minimal foreground/ background separation to look for weak FG edge", this.taMinFgBg, 6);
gd.addNumericField("Minimal foreground edge strength (stronger edges will have proportionally smaller costs)", this.taMinFgEdge, 6);
gd.addNumericField("Minimal surface separation that requires color change", this.taMinColSep, 6);
gd.addNumericField("Minimal color variation (larger proportionally reduces cost)", this.taMinColDiff, 6);
gd.addNumericField("Disparity difference limit (to handle outliers)", this.taOutlier, 6);
gd.addNumericField("Strength power when calculating disparity error", this.taDiffPwr, 6);
gd.addNumericField("Strength power when calculating disparity error over best", this.taBestPwr, 6);
gd.addNumericField("Strength power when calculating disparity error for group of 9", this.taDiff9Pwr, 6);
gd.addNumericField("Cost of a tile that is not assigned", this.taCostEmpty, 6); gd.addNumericField("Cost of a tile that is not assigned", this.taCostEmpty, 6);
gd.addNumericField("Cost of a tile not having any neighbor in particular direction", this.taCostNoLink, 6); gd.addNumericField("Cost of a tile not having any neighbor in particular direction", this.taCostNoLink, 6);
gd.addNumericField("Cost of a tile switching to a neighbor that does not have a link", this.taCostSwitch, 6); gd.addNumericField("Cost of a tile switching to a neighbor that does not have a link", this.taCostSwitch, 6);
...@@ -3696,6 +3766,17 @@ public class EyesisCorrectionParameters { ...@@ -3696,6 +3766,17 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Cost of using supertile \"flaps\" (not in the center 8x8 tiles area)", this.taCostFlaps, 6); gd.addNumericField("Cost of using supertile \"flaps\" (not in the center 8x8 tiles area)", this.taCostFlaps, 6);
gd.addNumericField("Cost of a measurement layer not having same layer in the same location or near", this.taCostMismatch, 6); gd.addNumericField("Cost of a measurement layer not having same layer in the same location or near", this.taCostMismatch, 6);
gd.addCheckbox ("Cost of a tile that is not assigned", this.taEnEmpty);
gd.addCheckbox ("Cost of a tile not having any neighbor in particular direction", this.taEnNoLink);
gd.addCheckbox ("Cost of a tile switching to a neighbor that does not have a link", this.taEnSwitch);
gd.addCheckbox ("Cost of a tile switching to a disconnected neighbor divided by a color", this.taEnColor);
gd.addCheckbox ("Cost of a weighted normalized tile disparity error", this.taEnDiff);
gd.addCheckbox ("Cost of a weighted normalized tile disparity error above best surface", this.taEnDiffBest);
gd.addCheckbox ("Cost of a weighted normalized tile disparity error for tile and 8 neighbors (DC)",this.taEnDiff9);
gd.addCheckbox ("Cost of a weak foreground edge", this.taEnWeakFgnd);
gd.addCheckbox ("Cost of using supertile \"flaps\" (not in the center 8x8 tiles area)", this.taEnFlaps);
gd.addCheckbox ("Cost of a measurement layer not having same layer in the same location or near", this.taEnMismatch);
gd.addCheckbox ("Test new mode after migration", this.dbg_migrate); gd.addCheckbox ("Test new mode after migration", this.dbg_migrate);
gd.addMessage ("--- Other debug images ---"); gd.addMessage ("--- Other debug images ---");
...@@ -4124,6 +4205,15 @@ public class EyesisCorrectionParameters { ...@@ -4124,6 +4205,15 @@ public class EyesisCorrectionParameters {
this.tsConsensMode = (int) gd.getNextNumber(); this.tsConsensMode = (int) gd.getNextNumber();
this.tsConsensAgree = (int) gd.getNextNumber(); this.tsConsensAgree = (int) gd.getNextNumber();
this.taMinFgBg= gd.getNextNumber();
this.taMinFgEdge= gd.getNextNumber();
this.taMinColSep= gd.getNextNumber();
this.taMinColDiff= gd.getNextNumber();
this.taOutlier= gd.getNextNumber();
this.taDiffPwr= gd.getNextNumber();
this.taBestPwr= gd.getNextNumber();
this.taDiff9Pwr= gd.getNextNumber();
this.taCostEmpty= gd.getNextNumber(); this.taCostEmpty= gd.getNextNumber();
this.taCostNoLink= gd.getNextNumber(); this.taCostNoLink= gd.getNextNumber();
this.taCostSwitch= gd.getNextNumber(); this.taCostSwitch= gd.getNextNumber();
...@@ -4135,6 +4225,17 @@ public class EyesisCorrectionParameters { ...@@ -4135,6 +4225,17 @@ public class EyesisCorrectionParameters {
this.taCostFlaps= gd.getNextNumber(); this.taCostFlaps= gd.getNextNumber();
this.taCostMismatch= gd.getNextNumber(); this.taCostMismatch= gd.getNextNumber();
this.taEnEmpty= gd.getNextBoolean();
this.taEnNoLink= gd.getNextBoolean();
this.taEnSwitch= gd.getNextBoolean();
this.taEnColor= gd.getNextBoolean();
this.taEnDiff= gd.getNextBoolean();
this.taEnDiffBest= gd.getNextBoolean();
this.taEnDiff9= gd.getNextBoolean();
this.taEnWeakFgnd= gd.getNextBoolean();
this.taEnFlaps= gd.getNextBoolean();
this.taEnMismatch= gd.getNextBoolean();
this.dbg_migrate= gd.getNextBoolean(); this.dbg_migrate= gd.getNextBoolean();
this.show_ortho_combine= gd.getNextBoolean(); this.show_ortho_combine= gd.getNextBoolean();
...@@ -4199,6 +4300,15 @@ public class EyesisCorrectionParameters { ...@@ -4199,6 +4300,15 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Minimal number of assignments to agree", this.tsConsensAgree, 0); gd.addNumericField("Minimal number of assignments to agree", this.tsConsensAgree, 0);
gd.addMessage ("--- Tile assignment parameters ---"); gd.addMessage ("--- Tile assignment parameters ---");
gd.addNumericField("Minimal foreground/ background separation to look for weak FG edge", this.taMinFgBg, 6);
gd.addNumericField("Minimal foreground edge strength (stronger edges will have proportionally smaller costs)", this.taMinFgEdge, 6);
gd.addNumericField("Minimal surface separation that requires color change", this.taMinColSep, 6);
gd.addNumericField("Minimal color variation (larger proportionally reduces cost)", this.taMinColDiff, 6);
gd.addNumericField("Disparity difference limit (to handle outliers)", this.taOutlier, 6);
gd.addNumericField("Strength power when calculating disparity error", this.taDiffPwr, 6);
gd.addNumericField("Strength power when calculating disparity error over best", this.taBestPwr, 6);
gd.addNumericField("Strength power when calculating disparity error for group of 9", this.taDiff9Pwr, 6);
gd.addNumericField("Cost of a tile that is not assigned", this.taCostEmpty, 6); gd.addNumericField("Cost of a tile that is not assigned", this.taCostEmpty, 6);
gd.addNumericField("Cost of a tile not having any neighbor in particular direction", this.taCostNoLink, 6); gd.addNumericField("Cost of a tile not having any neighbor in particular direction", this.taCostNoLink, 6);
gd.addNumericField("Cost of a tile switching to a neighbor that does not have a link", this.taCostSwitch, 6); gd.addNumericField("Cost of a tile switching to a neighbor that does not have a link", this.taCostSwitch, 6);
...@@ -4210,6 +4320,17 @@ public class EyesisCorrectionParameters { ...@@ -4210,6 +4320,17 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Cost of using supertile \"flaps\" (not in the center 8x8 tiles area)", this.taCostFlaps, 6); gd.addNumericField("Cost of using supertile \"flaps\" (not in the center 8x8 tiles area)", this.taCostFlaps, 6);
gd.addNumericField("Cost of a measurement layer not having same layer in the same location or near", this.taCostMismatch, 6); gd.addNumericField("Cost of a measurement layer not having same layer in the same location or near", this.taCostMismatch, 6);
gd.addCheckbox ("Cost of a tile that is not assigned", this.taEnEmpty);
gd.addCheckbox ("Cost of a tile not having any neighbor in particular direction", this.taEnNoLink);
gd.addCheckbox ("Cost of a tile switching to a neighbor that does not have a link", this.taEnSwitch);
gd.addCheckbox ("Cost of a tile switching to a disconnected neighbor divided by a color", this.taEnColor);
gd.addCheckbox ("Cost of a weighted normalized tile disparity error", this.taEnDiff);
gd.addCheckbox ("Cost of a weighted normalized tile disparity error above best surface", this.taEnDiffBest);
gd.addCheckbox ("Cost of a weighted normalized tile disparity error for tile and 8 neighbors (DC)",this.taEnDiff9);
gd.addCheckbox ("Cost of a weak foreground edge", this.taEnWeakFgnd);
gd.addCheckbox ("Cost of using supertile \"flaps\" (not in the center 8x8 tiles area)", this.taEnFlaps);
gd.addCheckbox ("Cost of a measurement layer not having same layer in the same location or near", this.taEnMismatch);
WindowTools.addScrollBars(gd); WindowTools.addScrollBars(gd);
gd.showDialog(); gd.showDialog();
if (gd.wasCanceled()) return false; if (gd.wasCanceled()) return false;
...@@ -4255,6 +4376,15 @@ public class EyesisCorrectionParameters { ...@@ -4255,6 +4376,15 @@ public class EyesisCorrectionParameters {
this.tsConsensMode = (int) gd.getNextNumber(); this.tsConsensMode = (int) gd.getNextNumber();
this.tsConsensAgree = (int) gd.getNextNumber(); this.tsConsensAgree = (int) gd.getNextNumber();
this.taMinFgBg= gd.getNextNumber();
this.taMinFgEdge= gd.getNextNumber();
this.taMinColSep= gd.getNextNumber();
this.taMinColDiff= gd.getNextNumber();
this.taOutlier= gd.getNextNumber();
this.taDiffPwr= gd.getNextNumber();
this.taBestPwr= gd.getNextNumber();
this.taDiff9Pwr= gd.getNextNumber();
this.taCostEmpty= gd.getNextNumber(); this.taCostEmpty= gd.getNextNumber();
this.taCostNoLink= gd.getNextNumber(); this.taCostNoLink= gd.getNextNumber();
this.taCostSwitch= gd.getNextNumber(); this.taCostSwitch= gd.getNextNumber();
...@@ -4265,6 +4395,18 @@ public class EyesisCorrectionParameters { ...@@ -4265,6 +4395,18 @@ public class EyesisCorrectionParameters {
this.taCostWeakFgnd= gd.getNextNumber(); this.taCostWeakFgnd= gd.getNextNumber();
this.taCostFlaps= gd.getNextNumber(); this.taCostFlaps= gd.getNextNumber();
this.taCostMismatch= gd.getNextNumber(); this.taCostMismatch= gd.getNextNumber();
this.taEnEmpty= gd.getNextBoolean();
this.taEnNoLink= gd.getNextBoolean();
this.taEnSwitch= gd.getNextBoolean();
this.taEnColor= gd.getNextBoolean();
this.taEnDiff= gd.getNextBoolean();
this.taEnDiffBest= gd.getNextBoolean();
this.taEnDiff9= gd.getNextBoolean();
this.taEnWeakFgnd= gd.getNextBoolean();
this.taEnFlaps= gd.getNextBoolean();
this.taEnMismatch= gd.getNextBoolean();
return true; return true;
} }
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
import java.awt.Point; import java.awt.Point;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
//import ij.IJ; //import ij.IJ;
...@@ -51,10 +52,14 @@ public class TileAssignment { ...@@ -51,10 +52,14 @@ public class TileAssignment {
// from clt_parameters // from clt_parameters
private double dispNorm; private double dispNorm;
private TACosts cost_coeff; private TACosts cost_coeff;
private double minFgBg = 0.1; // Minimal foreground/ background separation to look for weak FG edge private double minFgBg; // = 0.1; // Minimal foreground/ background separation to look for weak FG edge
private double minFgEdge = 0.2; // Minimal foreground edge strength (stronger edges will have proportionally smaller costs) private double minFgEdge; // = 0.2; // Minimal foreground edge strength (stronger edges will have proportionally smaller costs)
private double minColSep = 0.05; // Minimal surface separation that requires color change private double minColSep; // = 0.05; // Minimal surface separation that requires color change
private double minColDiff = 0.01; // Minimal surface separation that requires color change private double minColDiff; // = 0.01; // Minimal color variation (larger proportionally reduces cost)
private double dispOutlier; // = 1.0; // Disparity difference limit (to handle outliers)
private double strengthDiffPwr; // = 0.25; // Strength power when calculating disparity error
private double strengthBestPwr; // = 0.0; // Strength power when calculating disparity error over best
private double strengthDiff9Pwr; // = 0.5; // Strength power when calculating disparity error for group of 9
static double [] NEIB_WEIGHTS = {0.5,0.25, 0.5, 0.25, 0.5,0.25, 0.5, 0.25, 1.0}; static double [] NEIB_WEIGHTS = {0.5,0.25, 0.5, 0.25, 0.5,0.25, 0.5, 0.25, 1.0};
...@@ -76,15 +81,15 @@ public class TileAssignment { ...@@ -76,15 +81,15 @@ public class TileAssignment {
public TACosts (int mode) public TACosts (int mode)
{ {
this.empty = 1.0; this.empty = 1.0/0.35833; // 0.71715;
this.nolink = 1.0/1.50705; this.nolink = 1.0/0.83739; // 0.95952; // 1.50705;
this.swtch = 1.0/0.59474; this.swtch = 1.0/0.07604; // 0.05172; // 0.59474;
this.color = 1.0/2.25763; this.color = 1.0/0.21458; // 0.19294; // 2.25763;
this.diff = 1.0/1.94213; this.diff = 1.0/0.11879; // 0.11039; // 1.94213;
this.diff_best = 1.0/0.06731; this.diff_best = 1.0/0.02831; // 0.00628; // 0.06731;
this.diff9 = 1.0/1.09087; this.diff9 = 1.0/0.04064; // 0.01350; // 1.09087;
this.weak_fgnd = 1.0/0.22250; this.weak_fgnd = 1.0/1.177746; // 0.02172; // 0.01726; // 0.22250;
this.flaps = 1.0/0.07229; this.flaps = 1.0/0.1; // 0.00056; // 0.07229;
this.ml_mismatch = 1.0; this.ml_mismatch = 1.0;
// ml_mismatch not yet implemented - is it needed - maybe some see-through data appears on one layer only // ml_mismatch not yet implemented - is it needed - maybe some see-through data appears on one layer only
} }
...@@ -94,16 +99,16 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -94,16 +99,16 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
*/ */
public TACosts (EyesisCorrectionParameters.CLTParameters clt_parameters) public TACosts (EyesisCorrectionParameters.CLTParameters clt_parameters)
{ {
this.empty = clt_parameters.taCostEmpty; this.empty = clt_parameters.taEnEmpty? clt_parameters.taCostEmpty : 0.0;
this.nolink = clt_parameters.taCostNoLink; this.nolink = clt_parameters.taEnNoLink? clt_parameters.taCostNoLink : 0.0;
this.swtch = clt_parameters.taCostSwitch; this.swtch = clt_parameters.taEnSwitch? clt_parameters.taCostSwitch : 0.0;
this.color = clt_parameters.taCostColor; this.color = clt_parameters.taEnColor? clt_parameters.taCostColor : 0.0;
this.diff = clt_parameters.taCostDiff; this.diff = clt_parameters.taEnDiff? clt_parameters.taCostDiff : 0.0;
this.diff_best = clt_parameters.taCostDiffBest; this.diff_best = clt_parameters.taEnDiffBest? clt_parameters.taCostDiffBest : 0.0;
this.diff9 = clt_parameters.taCostDiff9; this.diff9 = clt_parameters.taEnDiff9? clt_parameters.taCostDiff9 : 0.0;
this.weak_fgnd = clt_parameters.taCostWeakFgnd; this.weak_fgnd = clt_parameters.taEnWeakFgnd? clt_parameters.taCostWeakFgnd : 0.0;
this.flaps = clt_parameters.taCostFlaps; this.flaps = clt_parameters.taEnFlaps? clt_parameters.taCostFlaps : 0.0;
this.ml_mismatch = clt_parameters.taCostMismatch; this.ml_mismatch = clt_parameters.taEnMismatch? clt_parameters.taCostMismatch : 0.0;
// ml_mismatch not yet implemented - is it needed - maybe some see-through data appears on one layer only // ml_mismatch not yet implemented - is it needed - maybe some see-through data appears on one layer only
} }
...@@ -248,7 +253,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -248,7 +253,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
this.surfTilesX = ts.getSTilesX() * ts.getSuperTileSize(); this.surfTilesX = ts.getSTilesX() * ts.getSuperTileSize();
this.surfTilesY = ts.getSTilesY() * ts.getSuperTileSize(); this.surfTilesY = ts.getSTilesY() * ts.getSuperTileSize();
this.imgTilesX = ts.getImageTilesX(); this.imgTilesX = ts.getImageTilesX();
this.imgTilesY = ts.getImageTilesX(); this.imgTilesY = ts.getImageTilesY();
this.tnImage = new TileNeibs(imgTilesX, imgTilesY); this.tnImage = new TileNeibs(imgTilesX, imgTilesY);
this.tnSurface = new TileNeibs(surfTilesX, surfTilesY); this.tnSurface = new TileNeibs(surfTilesX, surfTilesY);
setDispStrength(dispStrength); setDispStrength(dispStrength);
...@@ -259,8 +264,22 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -259,8 +264,22 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
public void copyParams(EyesisCorrectionParameters.CLTParameters clt_parameters) public void copyParams(EyesisCorrectionParameters.CLTParameters clt_parameters)
{ {
this.dispNorm = clt_parameters.plDispNorm; this.dispNorm = clt_parameters.plDispNorm;
cost_coeff = new TACosts (clt_parameters); this.minFgBg = clt_parameters.taMinFgBg;
cost_coeff.mul(new TACosts (0)); // make average ~=1.0 for each used component this.minFgEdge = clt_parameters.taMinFgEdge;
this.minColSep = clt_parameters.taMinColSep;
this.minColDiff = clt_parameters.taMinColDiff;
this.dispOutlier = clt_parameters.taOutlier;
this.strengthDiffPwr = clt_parameters.taDiffPwr;
this.strengthBestPwr = clt_parameters.taBestPwr;
this.strengthDiff9Pwr = clt_parameters.taDiff9Pwr;
this.cost_coeff = new TACosts (clt_parameters);
this.cost_coeff.mul(new TACosts (0)); // make average ~=1.0 for each used component
} }
public void setDispStrength( public void setDispStrength(
double [][][] ds) double [][][] ds)
...@@ -277,6 +296,14 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -277,6 +296,14 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
} }
} }
public int getSurfTilesX(){
return surfTilesX;
}
public int getSurfTilesY(){
return surfTilesY;
}
// private int surfTilesX;
// private int surfTilesY;
public void setTones(CLTPass3d p3d) public void setTones(CLTPass3d p3d)
...@@ -453,7 +480,8 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -453,7 +480,8 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
} }
} }
/** /**
* Get signed normalized difference from the measured disparity to the selected surface * Get signed normalized difference from the measured disparity to the selected surface,
* limit it to +/-dispOutlier to reduce cost of the outliers
* @param ml measured layer (combo, quad, hor, vert) * @param ml measured layer (combo, quad, hor, vert)
* @param nSurfTile tile index in surface array (includes full supertiles) * @param nSurfTile tile index in surface array (includes full supertiles)
* @param ns number of the surface * @param ns number of the surface
...@@ -476,6 +504,8 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -476,6 +504,8 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
if (d_av > dispNorm){ if (d_av > dispNorm){
diff *= dispNorm/d_av; diff *= dispNorm/d_av;
} }
if (diff > dispOutlier) diff = dispOutlier;
else if (diff < -dispOutlier) diff = -dispOutlier;
return diff; return diff;
} }
...@@ -491,6 +521,11 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -491,6 +521,11 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
int nSurfTile) int nSurfTile)
{ {
double best = Double.NaN; double best = Double.NaN;
if ((ts.getTileData() == null) || (ts.getTileData()[nSurfTile] == null)){
// System.out.println("dispDiffBest("+ml+","+nSurfTile+")");
return best;
}
for (int ns = 0; ns < ts.getTileData()[nSurfTile].length; ns++){ for (int ns = 0; ns < ts.getTileData()[nSurfTile].length; ns++){
double diff = dispDiff(ml, nSurfTile, ns); double diff = dispDiff(ml, nSurfTile, ns);
double adiff = Math.abs(diff); double adiff = Math.abs(diff);
...@@ -514,7 +549,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -514,7 +549,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
{ {
double worst = Double.NaN; double worst = Double.NaN;
if ((ts.getTileData() == null) || (ts.getTileData()[nSurfTile] == null)){ if ((ts.getTileData() == null) || (ts.getTileData()[nSurfTile] == null)){
System.out.println("dispDiffWorst("+ml+","+nSurfTile+")"); // System.out.println("dispDiffWorst("+ml+","+nSurfTile+")");
return worst; return worst;
} }
for (int ns = 0; ns < ts.getTileData()[nSurfTile].length; ns++){ for (int ns = 0; ns < ts.getTileData()[nSurfTile].length; ns++){
...@@ -583,13 +618,17 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -583,13 +618,17 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
return costs; return costs;
} }
public void showTileCost(int [][] tileLayers) public void showTileCost(
String prefix,
int [][] tileLayers)
{ {
double [] composite_costs = calcTileCosts(tileLayers); double [] composite_costs = calcTileCosts(tileLayers);
(new showDoubleFloatArrays()).showArrays(composite_costs, surfTilesX, surfTilesY, "composite_costs"); (new showDoubleFloatArrays()).showArrays(composite_costs, surfTilesX, surfTilesY, prefix+"composite_costs");
} }
public void showTileCosts(int [][] tileLayers) public void showTileCosts(
String prefix,
int [][] tileLayers)
{ {
String [] titles = (new TACosts()).getTitles(); String [] titles = (new TACosts()).getTitles();
int num_stiles = surfTilesX*surfTilesY; int num_stiles = surfTilesX*surfTilesY;
...@@ -621,7 +660,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -621,7 +660,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
cost_components[i][nSurfTile] = costs[i]; cost_components[i][nSurfTile] = costs[i];
} }
} }
(new showDoubleFloatArrays()).showArrays(cost_components, surfTilesX, surfTilesY, true, "cost_components", titles); (new showDoubleFloatArrays()).showArrays(cost_components, surfTilesX, surfTilesY, true, prefix+"cost_components", titles);
} }
...@@ -756,6 +795,11 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -756,6 +795,11 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
double strength = dispStrength[ml][nSurfTile][1]; double strength = dispStrength[ml][nSurfTile][1];
strength = Math.max(strength, minFgEdge); strength = Math.max(strength, minFgEdge);
costs.weak_fgnd += minFgEdge / strength; costs.weak_fgnd += minFgEdge / strength;
} else if (disp_diff < -minFgBg) {
double [] dsmeas_other = dispStrength[ml][nSurfTiles[dir]];
double strength = (dsmeas_other != null)? dsmeas_other[1]: 0.0; // measured strength on the other end or 0.0 if nothing there
strength = Math.max(strength, minFgEdge);
costs.weak_fgnd += minFgEdge / strength;
} }
if (Math.abs(disp_diff) > minColSep){ if (Math.abs(disp_diff) > minColSep){
double col_diff = tone_diff_weight[nSurfTile][dir][0]; double col_diff = tone_diff_weight[nSurfTile][dir][0];
...@@ -772,7 +816,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -772,7 +816,7 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
} //for (int ml = 0; ml < around.length; ml++) if ((around[ml] != null) && (around[ml][8] > 0)) } //for (int ml = 0; ml < around.length; ml++) if ((around[ml] != null) && (around[ml][8] > 0))
double disp_diff_lpf = 0.0, disp_diff_weight = 0.0; // calculate LPF of the disparity signed error over all ML and 9 cells double disp_diff_lpf = 0.0, disp_diff_weight = 0.0; // calculate LPF of the disparity signed error over all ML and 9 cells
double disp_diff2 = 0.0, disp_weight = 0.0; // calculate disparity error in the center, weighted double disp_diff2 = 0.0, disp_weight = 0.0; // calculate disparity error in the center, weighted
double disp_diff_over_best = 0.0; // calculate disparity error in the center, weighted double disp_diff_over_best = 0.0, disp_weight_best = 0.0; // calculate disparity error in the center, weighted
for (int ml = 0; ml < around.length; ml++) if (around[ml] != null){ for (int ml = 0; ml < around.length; ml++) if (around[ml] != null){
double diff=0.0, weight=0.0; double diff=0.0, weight=0.0;
for (int dir = 0; dir < 9; dir++){ for (int dir = 0; dir < 9; dir++){
...@@ -787,16 +831,42 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -787,16 +831,42 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
nSurfTiles[dir]); // int nSurfTile, nSurfTiles[dir]); // int nSurfTile,
} }
if (dispStrength[ml][nSurfTile] != null) { // not a bug if (dispStrength[ml][nSurfTile] != null) { // not a bug
weight = dispStrength[ml][nSurfTile][1] * NEIB_WEIGHTS[dir]; if (strengthDiff9Pwr > 0.0) {
weight = dispStrength[ml][nSurfTile][1];
if (strengthDiff9Pwr != 1.0) {
weight = Math.pow(weight, strengthDiff9Pwr);
}
} else {
weight = 1.0;
}
weight *= NEIB_WEIGHTS[dir];
disp_diff_lpf += diff * weight; disp_diff_lpf += diff * weight;
disp_diff_weight += weight; disp_diff_weight += weight;
// } else { // } else {
// System.out.println("getTileCosts() BUG, nSurfTile="+nSurfTile); // System.out.println("getTileCosts() BUG, nSurfTile="+nSurfTile);
} }
} }
// now diff, weight are for the center // now diff is for the center, weight needs to be re-calculated
if (strengthDiffPwr > 0.0) {
weight = dispStrength[ml][nSurfTile][1];
if (strengthDiffPwr != 1.0) {
weight = Math.pow(weight, strengthDiffPwr);
}
} else {
weight = 1.0;
}
disp_diff2 += diff * diff * weight; disp_diff2 += diff * diff * weight;
disp_weight += weight; disp_weight += weight;
// and once more for the disparity over best
if (strengthBestPwr > 0.0) {
weight = dispStrength[ml][nSurfTile][1];
if (strengthBestPwr != 1.0) {
weight = Math.pow(weight, strengthBestPwr);
}
} else {
weight = 1.0;
}
disp_diff_over_best += (Math.abs(diff) - dispDiffBest( ml, nSurfTiles[8])) * weight; // this one - not squared disp_diff_over_best += (Math.abs(diff) - dispDiffBest( ml, nSurfTiles[8])) * weight; // this one - not squared
} }
...@@ -826,6 +896,9 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -826,6 +896,9 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
int [][] tileLayersSurf = new int[tileLayersImg.length][]; int [][] tileLayersSurf = new int[tileLayersImg.length][];
for (int ml = 0; ml < tileLayersImg.length; ml++) if (tileLayersImg[ml] != null){ for (int ml = 0; ml < tileLayersImg.length; ml++) if (tileLayersImg[ml] != null){
tileLayersSurf[ml] = new int [tnSurface.getLength()]; tileLayersSurf[ml] = new int [tnSurface.getLength()];
for (int i = 0; i < tileLayersSurf[ml].length; i++){
tileLayersSurf[ml][i] = -1;
}
for (int nTile = 0; nTile < tileLayersImg[ml].length; nTile++){ for (int nTile = 0; nTile < tileLayersImg[ml].length; nTile++){
int nSurfTile = tnSurface.getIndex(tnImage.getXY(nTile)); int nSurfTile = tnSurface.getIndex(tnImage.getXY(nTile));
if (nSurfTile >= 0) { if (nSurfTile >= 0) {
...@@ -842,13 +915,226 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch ...@@ -842,13 +915,226 @@ diff_best= 0.06731 diff9= 1.09087 weak_fgnd= 0.22250 flaps= 0.07229 ml_mismatch
int [][] tileLayersImg = new int[tileLayersSurf.length][]; int [][] tileLayersImg = new int[tileLayersSurf.length][];
for (int ml = 0; ml < tileLayersSurf.length; ml++) if (tileLayersSurf[ml] != null){ for (int ml = 0; ml < tileLayersSurf.length; ml++) if (tileLayersSurf[ml] != null){
tileLayersImg[ml] = new int [tnImage.getLength()]; tileLayersImg[ml] = new int [tnImage.getLength()];
for (int i = 0; i < tileLayersImg[ml].length; i++){
tileLayersImg[ml][i] = -1;
}
for (int nSurfTile = 0; nSurfTile < tileLayersSurf[ml].length; nSurfTile++){ for (int nSurfTile = 0; nSurfTile < tileLayersSurf[ml].length; nSurfTile++){
int nImgTile = tnImage.getIndex(tnSurface.getXY(nSurfTile)); int nImgTile = tnImage.getIndex(tnSurface.getXY(nSurfTile));
if (nImgTile >= 0) { if (nImgTile >= 0) {
tileLayersSurf[ml][nImgTile] = tileLayersImg[ml][nSurfTile]; tileLayersImg[ml][nImgTile] = tileLayersSurf[ml][nSurfTile];
} }
} }
} }
return tileLayersSurf; return tileLayersImg;
}
public void optimizeAssignment(
final boolean noEdge,
final int [][] tileLayers,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int step = 3;
final int tries = 1000;
// final int dbg_tile = dbg_X + dbg_Y * surfTilesX;
final int dbg_tile = 27083; // 44493;
final int num_tiles = surfTilesX * surfTilesY;
final int [][] tile_indices = new int [step*step][];
for (int sty = 0; sty < step; sty ++){
int num_y = (surfTilesY + step -1 - sty) / step;
for (int stx = 0; stx < step; stx ++){
int num_x = (surfTilesX + step -1 - stx) / step;
int indx1 = sty * step + stx;
int l = num_y * num_x;
tile_indices[indx1] = new int [l];
int indx2 = 0;
for (int y = 0; y < num_y; y++){
for (int x = 0; x < num_x; x++){
tile_indices[indx1][indx2++] = (sty + step * y) * surfTilesX + (stx + step * x);
}
}
}
}
final Thread[] threads = ImageDtt.newThreadArray((debugLevel > 1)? 1 : ts.getThreadsMax());
final int numThreads = threads.length;
final int [] improved = new int [numThreads];
final AtomicInteger ai_numThread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger ai_series = new AtomicInteger(0);
final AtomicBoolean [] dirty = new AtomicBoolean[surfTilesX * surfTilesY];
for (int nSurfTile = 0; nSurfTile < dirty.length; nSurfTile++){
boolean valid_tile = false; // bad may be only some ml?
for (int ml = 0; ml < tileLayers.length; ml++) if ((tileLayers[ml] != null) && (tileLayers[ml][nSurfTile] >= 0)){
valid_tile = true;
break;
}
if (valid_tile) dirty[nSurfTile] = new AtomicBoolean(true);
}
final boolean [][] bad_surface = new boolean[num_tiles][];
final TileSurface.TileData [][] tileData = ts.getTileData();
if (noEdge) {
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nSurfTile = ai.getAndIncrement(); nSurfTile < num_tiles; nSurfTile = ai.getAndIncrement()) {
if (tileData[nSurfTile] != null){
bad_surface[nSurfTile] = new boolean [tileData[nSurfTile].length];
for (int ns = 0; ns < tileData[nSurfTile].length; ns++) {
int []neibs = tileData[nSurfTile][ns].getNeighbors();
for (int i = 0; i < neibs.length; i++){
if (neibs[i] < 0){
bad_surface[nSurfTile][ns] = true;
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
for (int nTry = 0 ; nTry < tries; nTry++) {
for (int i = 0; i < improved.length; i++) improved[i] = 0;
int this_improved = 0;
for (int nSeries = 0; nSeries < tile_indices.length; nSeries++) {
final int fnSeries = nSeries;
ai.set(0);
ai_numThread.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int numThread = ai_numThread.getAndIncrement(); // unique number of thread to write to rslt_diffs[numThread]
for (int iTile = ai.getAndIncrement(); iTile < tile_indices[fnSeries].length; iTile = ai.getAndIncrement()) {
int nSurfTile = tile_indices[fnSeries][iTile];
int dl = ((debugLevel > 1) && (nSurfTile == dbg_tile)) ? 3: debugLevel;
if (dl > 2){
System.out.println("optimizeAssignment(), nSurfTile = "+nSurfTile+" dl = "+dl);
}
// if (dirty[nSurfTile].get()) {
if ((dirty[nSurfTile] != null) && dirty[nSurfTile].getAndSet(false)) {
int num_surf = tileData[nSurfTile].length;
int lowest_surf = 0;
for (; lowest_surf < num_surf; lowest_surf ++){
if ((bad_surface[nSurfTile] != null) && !bad_surface[nSurfTile][lowest_surf]) {
break;
}
}
if (lowest_surf >= num_surf) {
continue; // no valid surfaces at this location
}
double best_cost = cost_coeff.dotProd(getTileCosts(
nSurfTile, // int nSurfTile,
tileLayers, // int [][] tileLayers,
null)); // HashMap<Point,Integer> replacements);
// int [] initial_indices = tileLayers[nSurfTile].clone();
int [] initial_indices = new int [valid_ml.length]; // 1-based
for (int ml = 0; ml < valid_ml.length; ml ++ ){
if (tileLayers[ml] != null) {
initial_indices[ml] = tileLayers[ml][nSurfTile]; // 1-based
}
}
int [] best_surf = null;
int [] surfaces = null; // new int [valid_ml.length];
int max_reset = 0; // = valid_ml.length; // maximal ml to reset
while (true) {
if (surfaces == null) {
surfaces = new int [valid_ml.length];
for (int ml = 0; ml < valid_ml.length; ml ++){
if (!valid_ml[ml] || (tileLayers[ml][nSurfTile] < 0)) {
surfaces[ml] = -1;
}
}
max_reset = valid_ml.length;
} else { // find ml to increase surface
for (max_reset = 0; max_reset < surfaces.length; max_reset++) if (surfaces[max_reset] >= 0){
for (surfaces[max_reset]++; surfaces[max_reset] < num_surf; surfaces[max_reset]++) {
if ((bad_surface[nSurfTile] == null) || !bad_surface[nSurfTile][surfaces[max_reset]]) {
break;
}
}
if (surfaces[max_reset] < num_surf) break;
}
if (max_reset >= surfaces.length){
break; // while (true) {
}
}
// reset all surfaces[] with indices < max_reset to lowest
for (int ml = 0; ml < max_reset; ml++ ) if (valid_ml[ml] && (surfaces[ml] >= 0)){
surfaces[ml] = lowest_surf;
}
// now surfaces[] contain next combination of surfaces to try
// tileLayers[nSurfTile] = surfaces;
for (int ml = 0; ml < valid_ml.length; ml ++ ){
if (tileLayers[ml] != null) {
tileLayers[ml][nSurfTile] = surfaces[ml] + 1; // 1-based from 0-based
}
}
double cost = cost_coeff.dotProd(getTileCosts( //
nSurfTile, // int nSurfTile,
tileLayers, // int [][] tileLayers,
null)); // HashMap<Point,Integer> replacements);
if (cost < best_cost) {
best_cost = cost;
best_surf = surfaces.clone();
}
} // while (true)
if (best_surf != null){ // update
// tileLayers[nSurfTile] = best_surf;
for (int ml = 0; ml < valid_ml.length; ml ++ ){
if (tileLayers[ml] != null) {
tileLayers[ml][nSurfTile] = best_surf[ml] + 1; // 1-based from 0-based
}
}
for (int dir = 0; dir <8; dir++) {
int nSurfTile1 = tnSurface.getNeibIndex(nSurfTile, dir);
if ((nSurfTile1 >= 0) && (dirty[nSurfTile1] != null)){
dirty[nSurfTile1].set(true);
}
improved[numThread]++;
}
} else { // restore initial data
// tileLayers[nSurfTile] = initial_indices;
for (int ml = 0; ml < valid_ml.length; ml ++ ){
if (tileLayers[ml] != null) {
tileLayers[ml][nSurfTile] = initial_indices[ml]; // 1-based from 1-based
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (debugLevel > -1){
int num_better = 0;
for (int i = 0; i < improved.length; i++){
num_better += improved[i];
}
System.out.println("optimizeAssignment(): pass = "+nTry+ ":"+nSeries+" improved:" + (num_better - this_improved));
this_improved = num_better;
}
} // for (int nSeries = 0; nSeries < tile_indices.length; nSeries++) {
// should be checked only after all series (now 9 passes) are finished - if anything was added - continue
int num_improved = 0;
for (int i = 0; i < improved.length; i++){
num_improved += improved[i];
}
if (debugLevel > -1){
System.out.println("optimizeAssignment(): pass = "+nTry+ " improved:"+num_improved);
}
if (num_improved == 0) break;
}
} }
} }
...@@ -3494,14 +3494,53 @@ public class TileProcessor { ...@@ -3494,14 +3494,53 @@ public class TileProcessor {
tile_assignments); // final int [][][] tileAssignments) tile_assignments); // final int [][][] tileAssignments)
int [][] tile_layers_surf = ta.imgToSurf(tile_layers); int [][] tile_layers_surf = ta.imgToSurf(tile_layers);
ta.showTileCost(tile_layers_surf); if (debugLevel > -1) {
ta.showTileCosts(tile_layers_surf); double [][] dbg_tls = new double [tile_layers_surf.length][];
for (int ml = 0; ml < tile_layers_surf.length; ml++) if (tile_layers_surf[ml] != null){
dbg_tls[ml] = new double [tile_layers_surf[ml].length];
for (int i = 0; i < tile_layers_surf[ml].length; i++){
dbg_tls[ml][i] = tile_layers_surf[ml][i];
}
}
(new showDoubleFloatArrays()).showArrays(dbg_tls, ta.getSurfTilesX(), ta.getSurfTilesY(), true, "tile_layers_surf");
}
ta.showTileCost("before_",tile_layers_surf);
ta.showTileCosts("before_",tile_layers_surf);
TileAssignment.TACosts [] ta_stats = ta.statTileCosts(tile_layers_surf); TileAssignment.TACosts [] ta_stats = ta.statTileCosts(tile_layers_surf);
for (int i = 0; i < ta_stats.length; i++){ for (int i = 0; i < ta_stats.length; i++){
System.out.println(ta_stats[i].toString()); System.out.println(ta_stats[i].toString());
} }
ta.optimizeAssignment(
clt_parameters.tsNoEdge , // final boolean noEdge,
tile_layers_surf, // final int [][] tileLayers,
2, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel > -1) {
double [][] dbg_tls = new double [tile_layers_surf.length][];
for (int ml = 0; ml < tile_layers_surf.length; ml++) if (tile_layers_surf[ml] != null){
dbg_tls[ml] = new double [tile_layers_surf[ml].length];
for (int i = 0; i < tile_layers_surf[ml].length; i++){
dbg_tls[ml][i] = tile_layers_surf[ml][i];
}
}
(new showDoubleFloatArrays()).showArrays(dbg_tls, ta.getSurfTilesX(), ta.getSurfTilesY(), true, "optimized_tile_layers_surf");
}
ta.showTileCost("after_",tile_layers_surf);
ta.showTileCosts("after_",tile_layers_surf);
ta_stats = ta.statTileCosts(tile_layers_surf);
System.out.println("Optimized:");
for (int i = 0; i < ta_stats.length; i++){
System.out.println(ta_stats[i].toString());
}
tile_layers = ta.surfToImg(tile_layers_surf);
//==============
tileSurface.setTileLayers(tile_layers); tileSurface.setTileLayers(tile_layers);
......
...@@ -2304,7 +2304,7 @@ public class TileSurface { ...@@ -2304,7 +2304,7 @@ public class TileSurface {
} }
} }
} }
if ((alts.size() > 1) || (num_agree < min_agree)){ if (((alts.size() > 1) || (num_agree < min_agree)) && (consensus[ml][nTile] > 0)){
consensus[ml][nTile] = 0; // not assigned consensus[ml][nTile] = 0; // not assigned
} }
if (!alts.isEmpty()){ if (!alts.isEmpty()){
......
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