Commit 42bc2c68 authored by Andrey Filippov's avatar Andrey Filippov

adding tile assignment to surfaces costs

parent 076baece
......@@ -69,6 +69,67 @@ public class CLTPass3d{
{
return this.tileProcessor;
}
public double [][][][] getTextureTiles()
{
return texture_tiles;
}
public double [][] getTileRBGA(
int num_layers)
{
if (texture_tiles == null) return null;
int tilesY = texture_tiles.length;
int tilesX = 0;
int nl = 0;
for (int ty = 0; ty < tilesY; ty++){
if (texture_tiles[ty] != null){
tilesX = texture_tiles[ty].length;
for (int tx = 0; tx < tilesX; tx++){
if (texture_tiles[ty][tx] != null){
nl = texture_tiles[ty][tx].length;
break;
}
}
if (nl > 0) break;
}
if (nl > 0) break;
}
if (num_layers > nl) num_layers = nl;
int numTiles = tilesX * tilesY;
double [] scales = new double [num_layers];
for (int n = 0; n < num_layers; n++){
if (n < 3) scales[n] = 1.0/255.0; // R,B,G
else if (n == 3) scales[n] = 1.0; //alpha
else if (n < 8) scales[n] = 1.0; // ports 0..3
else scales[n] = 1.0/255.0; // RBG rms, in 1/255 units, but small
}
double [][] tileTones = new double [num_layers][numTiles];
for (int ty = 0; ty < tilesY; ty++ ) if (texture_tiles[ty] != null){
for (int tx = 0; tx < tilesX; tx++ ) if (texture_tiles[ty][tx] != null) {
int indx = ty * tilesX + tx;
for (int n = 0; n < num_layers; n++) if (texture_tiles[ty][tx][n] != null){
double s = 0.0;
for (int i = 0; i < texture_tiles[ty][tx][n].length; i++){
s += texture_tiles[ty][tx][n][i];
}
s /= (texture_tiles[ty][tx][n].length/4); // overlapping tiles
s *= scales[n];
tileTones[n][indx] = s;
}
}
}
return tileTones;
}
public String getTextureName()
{
if (texture != null) {
return texture;
} else {
return "null-texture-name";
}
}
public void updateSelection(){ // add updating border tiles?
int tilesX = tileProcessor.getTilesX();
int tilesY = tileProcessor.getTilesY();
......
......@@ -3196,7 +3196,7 @@ public class QuadCLT {
double [][][][] clt_corr_combo = null;
double [][][][][] clt_corr_partial = null; // [tp.tilesY][tp.tilesX][pair][color][(2*transform_size-1)*(2*transform_size-1)]
double [][] clt_mismatch = null; // [3*4][tp.tilesY * tp.tilesX] // transpose unapplied
double [][][][] texture_tiles = null; // [tp.tilesY][tp.tilesX]["RGBA".length()][]; // tiles will be 16x16, 2 visualizaion mode full 16 or overlapped
double [][][][] texture_tiles = null; // [tp.tilesY][tp.tilesX]["RGBA".length()][]; // tiles will be 16x16, 2 visualization mode full 16 or overlapped
// undecided, so 2 modes of combining alpha - same as rgb, or use center tile only
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
......
This diff is collapsed.
......@@ -43,7 +43,11 @@ public class TileNeibs{
public int opposite(int dir){
return (dir + dirs / 2) % dirs;
}
int getLength(){
return sizeX * sizeY;
}
/**
* Get x,y pair from index
* @param indx element index
......@@ -64,9 +68,15 @@ public class TileNeibs{
*/
int getIndex(int x, int y){
if ((x < 0) || (y < 0) || (x >= sizeX) || (y >= sizeY)) return -1;
return y * sizeX + x;
}
int getIndex(int [] xy){
if ((xy[0] < 0) || (xy[1] < 0) || (xy[0] >= sizeX) || (xy[1] >= sizeY)) return -1;
return xy[1] * sizeX + xy[0];
}
/**
* Get 2d element index after step N, NE, ... NW. Returns -1 if leaving array
* @param indx start index
......@@ -78,7 +88,11 @@ public class TileNeibs{
int y = indx / sizeX;
int x = indx % sizeX;
if (dir < 0) return indx;
switch (dir % dirs){
if (dir > 8) {
System.out.println("getNeibIndex(): indx="+indx+", dir="+dir);
}
// switch (dir % dirs){
switch (dir){
case 0: return (y == 0) ? -1 : (indx - sizeX);
case 1: return ((y == 0) || ( x == (sizeX - 1))) ? -1 : (indx - sizeX + 1);
case 2: return ( ( x == (sizeX - 1))) ? -1 : (indx + 1);
......
......@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Arrays;
//import java.util.concurrent.atomic.AtomicInteger;
public class TileProcessor {
public ArrayList <CLTPass3d> clt_3d_passes = null;
public int clt_3d_passes_size = 0; //clt_3d_passes size after initial processing
......@@ -3136,17 +3137,139 @@ public class TileProcessor {
if (tileSurface == null){
return false;
}
/*
tileSurface.testSimpleConnected(
230, // clt_parameters.tileX,
131);//clt_parameters.tileY);
*/
// show testure_tiles
double [][][][] texture_tiles = scan_prev.getTextureTiles();
ImageDtt image_dtt = new ImageDtt();
double [][][] dispStrength = st.getDisparityStrengths(
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
boolean [][] tileSel = st.getMeasurementSelections(
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
if (texture_tiles != null){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
double [][] texture_nonoverlap = null;
double [][] texture_overlap = null;
String [] rgba_titles = {"red","blue","green","alpha"};
String [] rgba_weights_titles = {"red","blue","green","alpha","port0","port1","port2","port3","r-rms","b-rms","g-rms","w-rms"};
String name = scan_prev.getTextureName();
boolean show_nonoverlap = false; // true; // clt_parameters.show_nonoverlap
boolean show_overlap = false; //true; // clt_parameters.show_overlap
boolean show_rgba_color = false; //true; // clt_parameters.show_rgba_color
if (show_nonoverlap){
texture_nonoverlap = image_dtt.combineRGBATiles(
texture_tiles, // array [tp.tilesY][tp.tilesX][4][4*transform_size] or [tp.tilesY][tp.tilesX]{null}
clt_parameters.transform_size,
false, // when false - output each tile as 16x16, true - overlap to make 8x8
clt_parameters.sharp_alpha, // combining mode for alpha channel: false - treat as RGB, true - apply center 8x8 only
threadsMax, // maximal number of threads to launch
debugLevel);
sdfa_instance.showArrays(
texture_nonoverlap,
tilesX * (2 * clt_parameters.transform_size),
tilesY * (2 * clt_parameters.transform_size),
true,
name + "-TXTNOL-D",
(clt_parameters.keep_weights?rgba_weights_titles:rgba_titles));
}
if (show_overlap || show_rgba_color){
int alpha_index = 3;
texture_overlap = image_dtt.combineRGBATiles(
texture_tiles, // array [tp.tilesY][tp.tilesX][4][4*transform_size] or [tp.tilesY][tp.tilesX]{null}
clt_parameters.transform_size,
true, // when false - output each tile as 16x16, true - overlap to make 8x8
clt_parameters.sharp_alpha, // combining mode for alpha channel: false - treat as RGB, true - apply center 8x8 only
threadsMax, // maximal number of threads to launch
debugLevel);
if (clt_parameters.alpha1 > 0){ // negative or 0 - keep alpha as it was
double scale = (clt_parameters.alpha1 > clt_parameters.alpha0) ? (1.0/(clt_parameters.alpha1 - clt_parameters.alpha0)) : 0.0;
for (int i = 0; i < texture_overlap[alpha_index].length; i++){
double d = texture_overlap[alpha_index][i];
if (d >=clt_parameters.alpha1) d = 1.0;
else if (d <=clt_parameters.alpha0) d = 0.0;
else d = scale * (d- clt_parameters.alpha0);
texture_overlap[alpha_index][i] = d;
}
}
if (show_overlap) {
sdfa_instance.showArrays(
texture_overlap,
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
true,
name + "-TXTOL-D",
(clt_parameters.keep_weights?rgba_weights_titles:rgba_titles));
}
/*
if (clt_parameters.show_rgba_color) {
// for now - use just RGB. Later add oprion for RGBA
double [][] texture_rgb = {texture_overlap[0],texture_overlap[1],texture_overlap[2]};
double [][] texture_rgba = {texture_overlap[0],texture_overlap[1],texture_overlap[2],texture_overlap[3]};
// ImagePlus img_texture =
linearStackToColor(
clt_parameters,
colorProcParameters,
rgbParameters,
name+"-texture", // String name,
"-D"+clt_parameters.disparity, //String suffix, // such as disparity=...
toRGB,
!this.correctionsParameters.jpeg, // boolean bpp16, // 16-bit per channel color mode for result
true, // boolean saveShowIntermediate, // save/show if set globally
true, // boolean saveShowFinal, // save/show result (color image?)
((clt_parameters.alpha1 > 0)? texture_rgba: texture_rgb),
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
1.0, // double scaleExposure, // is it needed?
debugLevel );
}
*/
}
double [][] tiles_tone = scan_prev.getTileRBGA(
12); // int num_layers);
sdfa_instance.showArrays(
tiles_tone,
tilesX,
tilesY,
true,
name + "tiles_tone",
(clt_parameters.keep_weights?rgba_weights_titles:rgba_titles));
}
TileAssignment ta = new TileAssignment(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
tileSurface, // TileSurface ts,
scan_prev, // CLTPass3d p3d,
// tileSel, // boolean[][] tile_sel,
dispStrength, // double [][][] dispStrength,
Double.NaN, // double kR,
Double.NaN, // double kB,
Double.NaN); // double fatZero)
ta.showToneDiffWeights3();
ta.showToneDiffWeights1();
// }
// end of show testure_tiles
/*
tileSurface.testSimpleConnected(
230, // clt_parameters.tileX,
131);//clt_parameters.tileY);
*/
// Reset/initialize assignments - if not done so yet or specifically requested
boolean first_run = !tileSurface.isInit() || clt_parameters.tsReset;
......@@ -3195,7 +3318,7 @@ public class TileProcessor {
(clt_parameters.tsEnGrow? growMaxDiffNear: null), // final double [] maxDiffNear, // null
clt_parameters.plDispNorm, // final double dispNorm, // disparity normalize (proportionally scale down disparity difference if above
dispStrength, // final double [][][] dispStrength,
2, // -1, // debugLevel, // final int debugLevel)
debugLevel, // 2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
System.out.print("growWeakAssigned():");
......@@ -3205,7 +3328,8 @@ public class TileProcessor {
int [] stats_planes = tileSurface.assignPlanesTiles(
true, // final boolean force,
tile_layers_planes, //final int [][] tileLayers,
st.planes_mod, // final TilePlanes.PlaneData[][] planes,
st.planes_mod, // final TilePlanes.PlaneData[][] planes
clt_parameters.tsNoEdge , // final boolean noEdge,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3369,7 +3493,14 @@ public class TileProcessor {
opinions, // int [][][] opinions_in,
tile_assignments); // final int [][][] tileAssignments)
int [][] tile_layers_surf = ta.imgToSurf(tile_layers);
ta.showTileCost(tile_layers_surf);
ta.showTileCosts(tile_layers_surf);
TileAssignment.TACosts [] ta_stats = ta.statTileCosts(tile_layers_surf);
for (int i = 0; i < ta_stats.length; i++){
System.out.println(ta_stats[i].toString());
}
tileSurface.setTileLayers(tile_layers);
......
......@@ -105,11 +105,36 @@ public class TileSurface {
this.t_dirs8 = tdirs;
}
public int getThreadsMax(){
return this.threadsMax;
}
public int getSTilesX(){
return stilesX;
}
public int getSTilesY(){
return stilesY;
}
public int getSuperTileSize(){
return superTileSize;
}
public int [][] getTileLayers()
{
return this.tileLayers;
}
public int getImageTilesX(){
return imageTilesX;
}
public int getImageTilesY(){
return imageTilesY;
}
public TileData [][] getTileData(){
return this.tileData;
}
public int [][] getTileLayersCopy()
{
......@@ -155,6 +180,31 @@ public class TileSurface {
return this.parent_plane;
}
*/
public String getNeibString()
{
String s = "[";
for (int dir = 0; dir < 8; dir++){
s += (neighbors[dir]>=0) ? neighbors[dir]:"x";
if (dir < 7) s += ", ";
}
s+= "] ";
return s;
}
public String toString()
{
String s = " ";
s += getNeibString();
s += String.format( "index=%2d(%2d) parent = %3d:%1d disp=%8.5f weight=%8.5f",
new_index, indx,
parent_nsTile, parent_layer, disp_strength[0], disp_strength[1]);
return s;
}
public void setParentTileLayer (int parent_nsTile, int parent_layer)
{
this.parent_nsTile = parent_nsTile;
......@@ -2069,7 +2119,7 @@ public class TileSurface {
* @param dbg_Y debug tile Y coordinate
* @return
*/
public int [] assignTilesToSingleCandidate( // not used
public int [] assignTilesToSingleCandidate_old( // not used
final boolean noEdge,
final double maxDiff,
final double minDiffOther,
......@@ -2077,8 +2127,6 @@ public class TileSurface {
final double maxStrength,
final int moveDirs, // 1 increase disparity, 2 - decrease disparity, 3 - both directions
final double dispNorm, // disparity normalize (proportionally scale down disparity difference if above
// final int [][] tileLayers,
// final TileData [][] tileData,
final double [][][] dispStrength,
final int debugLevel,
final int dbg_X,
......@@ -2217,7 +2265,7 @@ public class TileSurface {
public int [][] getConsensusAssignment(
final int min_agree,
int [][][] opinions_in,
int [][][] opinions_in, // options contain 1-based surface indices
final int [][][] tileAssignments)
{
final int imgTiles = imageTilesX * imageTilesY;
......@@ -2241,7 +2289,7 @@ public class TileSurface {
System.out.println("getConsensusAssignment(): nTile="+nTile);
}
int num_agree = 0;
ArrayList <Integer> alts = new ArrayList <Integer>();
ArrayList <Integer> alts = new ArrayList <Integer>(); // elements are 1-based surfaces
for (int n = 0; n < num_in; n++)if (tileAssignments[n] != null){
int surf1 = tileAssignments[n][ml][nTile];
if (surf1 != 0){
......@@ -2279,6 +2327,7 @@ public class TileSurface {
* Assign tiles that were used to generate planes. Only tiles in the center (non-overlapping) part of the supertile
* @param force re-assign tile if it was already assigned
* @param tileLayers
* @param noEdge do not assign tiles to the surface edges (can not add border later)
* @param debugLevel
* @param dbg_X
* @param dbg_Y
......@@ -2289,6 +2338,7 @@ public class TileSurface {
final boolean force,
final int [][] tileLayers,
final TilePlanes.PlaneData[][] planes,
final boolean noEdge,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -2335,9 +2385,10 @@ public class TileSurface {
int ns = -1;
for (int ml = 0; ml < meas_sel.length; ml++) if (meas_sel[ml] != null){
if (meas_sel[ml][st_index]){
int nSurfTile = -1;
if (ns < 0){ // find for the first used ml, if there are more - they will reuse
nTile = (superTileSize * sty + dy) * imageTilesX + (superTileSize * stx + dx);
int nSurfTile = getSurfaceTileIndex(nTile);
nSurfTile = getSurfaceTileIndex(nTile);
for (int i = 0; i < tileData[nSurfTile].length; i ++){
if ( (tileData[nSurfTile][i].getParentNsTile() == nsTile) &&
(tileData[nSurfTile][i].getParentLayer() == np)) {
......@@ -2359,9 +2410,24 @@ public class TileSurface {
(superTileSize * sty + dy)+")");
}
}
if ((ns >= 0) && (force || (tileLayers[ml][nTile] == 0))) {
tileLayers[ml][nTile] = ns + 1;
stats_all[numThread][NEW_ASSIGNED] ++;
boolean bad_edge = noEdge;
if (bad_edge) {
bad_edge = false;
int []neibs = tileData[nSurfTile][ns].getNeighbors();
for (int i = 0; i < neibs.length; i++) if (neibs[i] < 0) {
bad_edge = true;
break;
}
}
if (bad_edge) {
stats_all[numThread][NO_SURF] ++;
tileLayers[ml][nTile] = IMPOSSIBLE;
} else {
tileLayers[ml][nTile] = ns + 1;
stats_all[numThread][NEW_ASSIGNED] ++;
}
}
}
}
......@@ -2560,8 +2626,10 @@ public class TileSurface {
// calculate index in tileData (has different dimensions - TODO: trim?
int nSurfTile1 = getSurfaceTileIndex(nTile1);
int ns1 = neibs[dir];
System.out.println("growWeakAssigned(): nTile="+pTile.x+" ns="+pTile.y+" dir = "+dir+
" nSurfTile="+nSurfTile+" nSurfTile1="+nSurfTile1+" ns1="+ns1);
if (debugLevel > 0) {
System.out.println("growWeakAssigned(): nTile="+pTile.x+" ns="+pTile.y+" dir = "+dir+
" nSurfTile="+nSurfTile+" nSurfTile1="+nSurfTile1+" ns1="+ns1);
}
boolean bad_edge = noEdge;
if (bad_edge) {
bad_edge = false;
......@@ -3750,7 +3818,7 @@ public class TileSurface {
if (nl1 < 0){
if (debugLevel >-1) {
System.out.println("growClusterOnce(): Expected 8 neighbors for tile nSurfTile0="+
nSurfTile0+" neibs["+dir+"] = "+nl1);
nSurfTile0+":"+nl0+" neibs["+dir+"] = "+nl1);
}
} else {
int neTile1 = tnWindow.getNeibIndex(neTile0, dir);
......@@ -4176,7 +4244,7 @@ public class TileSurface {
if (nl1 < 0){
if (debugLevel >-1) {
System.out.println("growEachCluster(): Expected 8 neighbors for tile nSurfTile0="+
nSurfTile0+" neibs["+dir+"] = "+nl1);
nSurfTile0+":"+nl0+" neibs["+dir+"] = "+nl1);
}
int nTile1 = tnImage.getNeibIndex(nTile0, dir);
if (nTile1 >= 0) {
......
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