Commit 238bf728 authored by Andrey Filippov's avatar Andrey Filippov

next snapshot

parent f606663c
......@@ -1914,12 +1914,20 @@ public class EyesisCorrectionParameters {
public int tile_task_op = 0xff; // bitmask of operation modes applied to tiles (0 - nothing), bits TBD later
// +(0..f) - images, +(00.f0) - process pairs +256 - force disparity when combining images
// window to process tiles;
// window to process tiles (later arbitrary masks will be generated to follow particular stages);
public int tile_task_wl = 0; //
public int tile_task_wt = 0; //
public int tile_task_ww = 324; //
public int tile_task_wh = 242; //
public double diff_thershold = 5.0; // RMS difference from average to discard channel (~ 1.0 - 1/255 full scale image)
public boolean diff_gauss = true; // when averaging images, use gaussian around average as weight (false - sharp all/nothing)
public boolean sharp_alpha = false; // combining mode for alpha channel: false - treat as RGB, true - apply center 8x8 only
public boolean gen_chn_img = false; // generate shifted channel images
public boolean show_nonoverlap = true; // show result RGBA before overlap combined (first channels, then RGBA combined?)
public boolean show_overlap = true; // show result RGBA (first channels, then RGBA combined?)
......@@ -1943,7 +1951,6 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"novignetting_r", this.novignetting_r+"");
properties.setProperty(prefix+"novignetting_g", this.novignetting_g+"");
properties.setProperty(prefix+"novignetting_b", this.novignetting_b+"");
properties.setProperty(prefix+"scale_r", this.scale_r+"");
properties.setProperty(prefix+"scale_g", this.scale_g+"");
properties.setProperty(prefix+"scale_b", this.scale_b+"");
......@@ -1964,6 +1971,17 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"max_corr_sigma", this.max_corr_sigma +"");
properties.setProperty(prefix+"max_corr_radius", this.max_corr_radius +"");
properties.setProperty(prefix+"corr_border_contrast", this.corr_border_contrast +"");
properties.setProperty(prefix+"tile_task_op", this.tile_task_op+"");
properties.setProperty(prefix+"tile_task_wl", this.tile_task_wl+"");
properties.setProperty(prefix+"tile_task_wt", this.tile_task_wt+"");
properties.setProperty(prefix+"tile_task_ww", this.tile_task_ww+"");
properties.setProperty(prefix+"tile_task_wh", this.tile_task_wh+"");
properties.setProperty(prefix+"diff_thershold", this.diff_thershold +"");
properties.setProperty(prefix+"diff_gauss", this.diff_gauss+"");
properties.setProperty(prefix+"sharp_alpha", this.sharp_alpha+"");
properties.setProperty(prefix+"gen_chn_img", this.gen_chn_img+"");
properties.setProperty(prefix+"show_nonoverlap", this.show_nonoverlap+"");
properties.setProperty(prefix+"show_overlap", this.show_overlap+"");
}
public void getProperties(String prefix,Properties properties){
......@@ -2005,6 +2023,18 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"max_corr_sigma")!=null) this.max_corr_sigma=Double.parseDouble(properties.getProperty(prefix+"max_corr_sigma"));
if (properties.getProperty(prefix+"max_corr_radius")!=null) this.max_corr_radius=Double.parseDouble(properties.getProperty(prefix+"max_corr_radius"));
if (properties.getProperty(prefix+"corr_border_contrast")!=null) this.corr_border_contrast=Double.parseDouble(properties.getProperty(prefix+"corr_border_contrast"));
if (properties.getProperty(prefix+"tile_task_op")!=null) this.tile_task_op=Integer.parseInt(properties.getProperty(prefix+"tile_task_op"));
if (properties.getProperty(prefix+"tile_task_wl")!=null) this.tile_task_wl=Integer.parseInt(properties.getProperty(prefix+"tile_task_wl"));
if (properties.getProperty(prefix+"tile_task_wt")!=null) this.tile_task_wt=Integer.parseInt(properties.getProperty(prefix+"tile_task_wt"));
if (properties.getProperty(prefix+"tile_task_ww")!=null) this.tile_task_ww=Integer.parseInt(properties.getProperty(prefix+"tile_task_ww"));
if (properties.getProperty(prefix+"tile_task_wh")!=null) this.tile_task_wh=Integer.parseInt(properties.getProperty(prefix+"tile_task_wh"));
if (properties.getProperty(prefix+"diff_thershold")!=null) this.diff_thershold=Double.parseDouble(properties.getProperty(prefix+"diff_thershold"));
if (properties.getProperty(prefix+"diff_gauss")!=null) this.diff_gauss=Boolean.parseBoolean(properties.getProperty(prefix+"v"));
if (properties.getProperty(prefix+"sharp_alpha")!=null) this.sharp_alpha=Boolean.parseBoolean(properties.getProperty(prefix+"sharp_alpha"));
if (properties.getProperty(prefix+"gen_chn_img")!=null) this.gen_chn_img=Boolean.parseBoolean(properties.getProperty(prefix+"gen_chn_img"));
if (properties.getProperty(prefix+"show_nonoverlap")!=null)this.show_nonoverlap=Boolean.parseBoolean(properties.getProperty(prefix+"show_nonoverlap"));
if (properties.getProperty(prefix+"show_overlap")!=null) this.show_overlap=Boolean.parseBoolean(properties.getProperty(prefix+"show_overlap"));
}
public boolean showDialog() {
......@@ -2047,6 +2077,18 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Sigma for weights of points around global max to find fractional", this.max_corr_sigma, 3);
gd.addNumericField("Maximal distance from int max to consider", this.max_corr_radius, 3);
gd.addNumericField("Contrast of dotted border on correlation results", this.corr_border_contrast, 6);
gd.addMessage("--- tiles tasks ---");
gd.addNumericField("Tile operations bits: +(0..f) - images, +(00.f0) - process pairs +256, ... ", this.tile_task_op, 0);
gd.addNumericField("Tile operations window left (in 8x8 tiles)", this.tile_task_wl, 0);
gd.addNumericField("Tile operations window top", this.tile_task_wt, 0);
gd.addNumericField("Tile operations window width", this.tile_task_ww, 0);
gd.addNumericField("Tile operations window height", this.tile_task_wh, 0);
gd.addNumericField("RMS difference from average to discard channel (255 full scale image)", this.diff_thershold, 4);
gd.addCheckbox ("Gaussian as weight when averaging images (false - sharp all/nothing)", this.diff_gauss);
gd.addCheckbox ("Alpha channel: use center 8x8 (unchecked - treat same as RGB)", this.sharp_alpha);
gd.addCheckbox ("Generate shifted channel images", this.gen_chn_img);
gd.addCheckbox ("Show result RGBA before overlap combined", this.show_nonoverlap);
gd.addCheckbox ("Show result RGBA ", this.show_overlap);
WindowTools.addScrollBars(gd);
gd.showDialog();
......@@ -2090,7 +2132,17 @@ public class EyesisCorrectionParameters {
this.max_corr_sigma= gd.getNextNumber();
this.max_corr_radius= gd.getNextNumber();
this.corr_border_contrast= gd.getNextNumber();
this.tile_task_op= (int) gd.getNextNumber();
this.tile_task_wl= (int) gd.getNextNumber();
this.tile_task_wt= (int) gd.getNextNumber();
this.tile_task_ww= (int) gd.getNextNumber();
this.tile_task_wh= (int) gd.getNextNumber();
this.diff_thershold= gd.getNextNumber();
this.diff_gauss= gd.getNextBoolean();
this.sharp_alpha= gd.getNextBoolean();
this.gen_chn_img= gd.getNextBoolean();
this.show_nonoverlap= gd.getNextBoolean();
this.show_overlap= gd.getNextBoolean();
return true;
}
}
......
......@@ -2920,6 +2920,7 @@ public class EyesisDCT {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_data[chn],
clt_parameters.transform_size,
threadsMax,
debugLevel);
}
......@@ -3612,6 +3613,7 @@ public class EyesisDCT {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_data[chn],
clt_parameters.transform_size,
threadsMax,
debugLevel);
}
......@@ -4237,6 +4239,7 @@ public class EyesisDCT {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_data[iQuad][chn],
clt_parameters.transform_size,
threadsMax,
debugLevel);
}
......@@ -4814,22 +4817,65 @@ public class EyesisDCT {
int tilesY = imp_quad[0].getHeight()/clt_parameters.transform_size;
int tilesX = imp_quad[0].getWidth()/clt_parameters.transform_size;
// temporary setting up tile task file (one integer per tile, bitmask
// for testing defined for a window, later the tiles to process will be calculated based on previous passes results
int [][] tile_op = new int [tilesY][tilesX]; // all zero
int txl = clt_parameters.tile_task_wl;
int txr = txl + clt_parameters.tile_task_wl;
int tyt = clt_parameters.tile_task_wl;
int tyb = tyt + clt_parameters.tile_task_wh;
if (txl < 0) txl = 0;
else if (txl >= tilesX) txl = tilesX - 1;
if (txr <= txl) txr = txl + 1;
else if (txr > tilesX) txr = tilesX;
if (tyt < 0) tyt = 0;
else if (tyt >= tilesY) tyt = tilesY - 1;
if (tyb <= tyt) tyb = tyt + 1;
else if (tyb > tilesY) tyb = tilesY;
for (int i = tyt; i < tyb; i++) {
for (int j = txl; j < txr; j++) {
tile_op[i][j] = clt_parameters.tile_task_op;
}
}
//TODO: Add array of default disparity - use for combining images in force disparity mode (no correlation), when disparity is predicted from other tiles
double [][][][] clt_corr_combo = null;
double [][][][][] clt_corr_partial = null;
double [][][][] texture_tiles = null; // [tilesY][tilesX]["RGBA".length()][]; // tiles will be 16x16, 2 visualizaion mode full 16 or overlapped
// undecided, so 2 modes of combining alpha - same as rgb, or use center tile only
if (clt_parameters.correlate){
clt_corr_combo = new double [2][tilesY][tilesX][];
texture_tiles = new double [tilesY][tilesX]["RGBA".length()][];
for (int i = 0; i < tilesY; i++){
for (int j = 0; j < tilesX; j++){
clt_corr_combo[0][i][j] = null;
clt_corr_combo[1][i][j] = null;
texture_tiles[i][j] = null;
}
}
if (clt_parameters.corr_keep){
clt_corr_partial = new double [tilesY][tilesX][][][];
for (int i = 0; i < tilesY; i++){
for (int j = 0; j < tilesX; j++){
clt_corr_partial[i][j] = null;
}
}
}
}
double [][] disparity_map = new double [8][]; //[0] -residual disparity, [1] - orthogonal (just for debugging)
double [][][][][][] clt_data = image_dtt.clt_aberrations_quad_corr(
tile_op, // per-tile operation bit codes
clt_parameters.disparity, // final double disparity,
double_stacks, // final double [][][] imade_data, // first index - number of image in a quad
// correlation results - final and partial
clt_corr_combo, // [tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
clt_corr_partial, // [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
disparity_map, // [2][tilesY * tilesX]
texture_tiles, // [tilesY][tilesX]["RGBA".length()][];
imp_quad[0].getWidth(), // final int width,
clt_parameters.fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
clt_parameters.corr_sym,
......@@ -4853,14 +4899,56 @@ public class EyesisDCT {
clt_parameters.tileY, // final int debug_tileY,
(clt_parameters.dbg_mode & 64) != 0, // no fract shift
(clt_parameters.dbg_mode & 128) != 0, // no convolve
// (clt_parameters.dbg_mode & 256) != 0, // transpose convolve
// (clt_parameters.dbg_mode & 256) != 0, // transpose convolve
threadsMax,
debugLevel);
System.out.println("clt_data.length="+clt_data.length+" clt_data[0].length="+clt_data[0].length
+" clt_data[0][0].length="+clt_data[0][0].length+" clt_data[0][0][0].length="+
clt_data[0][0][0].length+" clt_data[0][0][0][0].length="+clt_data[0][0][0][0].length+
" clt_data[0][0][0][0][0].length="+clt_data[0][0][0][0][0].length);
clt_data[0][0][0].length);
// +" clt_data[0][0][0][0].length="+clt_data[0][0][0][0].length+
// " clt_data[0][0][0][0][0].length="+clt_data[0][0][0][0][0].length);
// visualize texture tiles as RGBA slices
double [][] texture_nonoverlap = null;
double [][] texture_overlap = null;
String [] rgba_titles = {"red","green","blue","alpha"};
if (texture_tiles != null){
if (clt_parameters.show_nonoverlap){
texture_nonoverlap = image_dtt.combineRGBATiles(
texture_tiles, // array [tilesY][tilesX][4][4*transform_size] or [tilesY][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.disparity,
rgba_titles );
}
if (clt_parameters.show_overlap){
texture_overlap = image_dtt.combineRGBATiles(
texture_tiles, // array [tilesY][tilesX][4][4*transform_size] or [tilesY][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);
sdfa_instance.showArrays(
texture_overlap,
tilesX * clt_parameters.transform_size,
tilesY * clt_parameters.transform_size,
true,
name + "-TXTOL-D"+clt_parameters.disparity,
rgba_titles );
}
}
// visualize correlation results
if (clt_corr_combo!=null){
if (disparity_map != null){
......@@ -4884,6 +4972,7 @@ public class EyesisDCT {
for (int i = 0; i<corr_rslt.length; i++) {
corr_rslt[i] = image_dtt.corr_dbg(
clt_corr_combo[i],
2*clt_parameters.transform_size - 1,
clt_parameters.corr_border_contrast,
threadsMax,
debugLevel);
......@@ -4898,7 +4987,7 @@ public class EyesisDCT {
titles );
}
if (debugLevel > -1){
if (debugLevel > 0){ // -1
if (clt_corr_partial!=null){
String [] allColorNames = {"red","blue","green","combo"};
String [] titles = new String[clt_corr_partial.length];
......@@ -4907,6 +4996,9 @@ public class EyesisDCT {
}
double [][] corr_rslt_partial = image_dtt.corr_partial_dbg(
clt_corr_partial,
2*clt_parameters.transform_size - 1, //final int corr_size,
4, // final int pairs,
4, // final int colors,
clt_parameters.corr_border_contrast,
threadsMax,
debugLevel);
......@@ -4921,8 +5013,9 @@ public class EyesisDCT {
}
}
for (int iQuad = 0; iQuad <clt_data.length; iQuad++){
if (clt_parameters.gen_chn_img) {
ImagePlus [] imps_RGB = new ImagePlus[clt_data.length];
for (int iQuad = 0; iQuad < clt_data.length; iQuad++){
String title=name+"-"+String.format("%02d", iQuad);
String titleFull=title+"-SPLIT-D"+clt_parameters.disparity;
......@@ -4932,13 +5025,14 @@ public class EyesisDCT {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_data[iQuad][chn],
clt_parameters.transform_size,
threadsMax,
debugLevel);
}
}
// int tilesY = imp_quad[iQuad].getHeight()/clt_parameters.transform_size;
// int tilesX = imp_quad[iQuad].getWidth()/clt_parameters.transform_size;
// int tilesY = imp_quad[iQuad].getHeight()/clt_parameters.transform_size;
// int tilesX = imp_quad[iQuad].getWidth()/clt_parameters.transform_size;
if (debugLevel > 0){
System.out.println("--tilesX="+tilesX);
System.out.println("--tilesY="+tilesY);
......@@ -4973,7 +5067,7 @@ public class EyesisDCT {
debugLevel);
}
if (debugLevel > 0) sdfa_instance.showArrays(
if (debugLevel > 0) sdfa_instance.showArrays( // -1
iclt_data,
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
......@@ -5108,7 +5202,7 @@ public class EyesisDCT {
eyesisCorrections.correctionsParameters.JPEG_quality); // save, no show
}
// convert to RGB48 (16 bits per color component)
ImagePlus imp_RGB;
// ImagePlus imp_RGB;
stack=eyesisCorrections.convertRGB32toRGB16Stack(
stack,
rgbParameters);
......@@ -5132,33 +5226,40 @@ public class EyesisDCT {
// eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters, this.correctionsParameters.save16, true); // save, no show
}
imp_RGB=eyesisCorrections.convertRGB48toRGB24(
imps_RGB[iQuad]=eyesisCorrections.convertRGB48toRGB24(
stack,
title+"-RGB24-D"+clt_parameters.disparity,
0, 65536, // r range 0->0, 65536->256
0, 65536, // g range
0, 65536);// b range
if (JPEG_scale!=1.0){
ImageProcessor ip=imp_RGB.getProcessor();
ImageProcessor ip=imps_RGB[iQuad].getProcessor();
ip.setInterpolationMethod(ImageProcessor.BICUBIC);
ip=ip.resize((int)(ip.getWidth()*JPEG_scale),(int) (ip.getHeight()*JPEG_scale));
imp_RGB= new ImagePlus(imp_RGB.getTitle(),ip);
imp_RGB.updateAndDraw();
imps_RGB[iQuad]= new ImagePlus(imps_RGB[iQuad].getTitle(),ip);
imps_RGB[iQuad].updateAndDraw();
}
if (iQuad <0) eyesisCorrections.saveAndShow(imps_RGB[iQuad], this.correctionsParameters); // individual images (just commented out)
} // and generating shifted channle images
// combine to a sliced color image
int [] slice_seq = {0,1,3,2}; //clockwise
int width = imps_RGB[0].getWidth();
int height = imps_RGB[0].getHeight();
ImageStack array_stack=new ImageStack(width,height);
for (int i = 0; i<slice_seq.length; i++){
if (imps_RGB[slice_seq[i]] != null) {
array_stack.addSlice("port_"+slice_seq[i], imps_RGB[slice_seq[i]].getProcessor().getPixels());
} else {
array_stack.addSlice("port_"+slice_seq[i], results[slice_seq[i]].getProcessor().getPixels());
}
eyesisCorrections.saveAndShow(imp_RGB, this.correctionsParameters);
}
ImagePlus imp_stack = new ImagePlus(name+"-SHIFTED-D"+clt_parameters.disparity, array_stack);
imp_stack.getProcessor().resetMinAndMax();
imp_stack.updateAndDraw();
//imp_stack.getProcessor().resetMinAndMax();
//imp_stack.show();
eyesisCorrections.saveAndShow(imp_stack, this.correctionsParameters);
}
return results;
}
}
......@@ -3968,6 +3968,7 @@ private Panel panel1,
image_dtt.clt_lpf( // filter in-place
CLT_PARAMETERS.corr_sigma, // final double sigma,
clt_corr[chn], // final double [][][][] clt_data,
CLT_PARAMETERS.transform_size,
THREADS_MAX, // maximal number of threads to launch
DEBUG_LEVEL); // globalDebugLevel)
}
......@@ -4018,11 +4019,12 @@ private Panel panel1,
THREADS_MAX,
DEBUG_LEVEL);
}
if (DEBUG_LEVEL > -1){
if (DEBUG_LEVEL > 0){ //============== -1 =================
double [][] corr_rslt = new double [clt_corr.length][];
for (int chn = 0; chn < clt_corr.length; chn++) {
corr_rslt[chn] = image_dtt.corr_dbg(
corr_tiles[chn],
2*CLT_PARAMETERS.transform_size - 1,
CLT_PARAMETERS.corr_border_contrast,
THREADS_MAX,
DEBUG_LEVEL);
......
import java.util.concurrent.atomic.AtomicInteger;
import ij.IJ;
import ij.ImageStack;
/**
......@@ -893,6 +894,7 @@ public class ImageDtt {
}
public double [][][][][][] clt_aberrations_quad_corr(
final int [][] tile_op, // [tilesY][tilesX] - what to do - 0 - nothing for this tile
final double disparity,
final double [][][] image_data, // first index - number of image in a quad
// correlation results - final and partial
......@@ -904,6 +906,8 @@ public class ImageDtt {
// [tilesY][tilesX] should be set by caller
final double [][] disparity_map, // [8][tilesY][tilesX], only [6][] is needed on input or null - do nat calculate
// last 2 - contrast, avg/ "geometric average)
final double [][][][] texture_tiles, // [tilesY][tilesX]["RGBA".length()][];
final int width,
final double corr_fat_zero, // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
final boolean corr_sym,
......@@ -938,8 +942,8 @@ public class ImageDtt {
final int tilesX=width/transform_size;
final int tilesY=height/transform_size;
final int nTilesInChn=tilesX*tilesY;
// final int nTiles=tilesX*tilesY*nChn;
final double [][][][][][] clt_data = new double[quad][nChn][tilesY][tilesX][4][];
// final double [][][][][][] clt_data = new double[quad][nChn][tilesY][tilesX][4][];
final double [][][][][][] clt_data = new double[quad][nChn][tilesY][tilesX][][];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final double [] col_weights= new double [numcol]; // colors are RBG
......@@ -1047,6 +1051,7 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTilesInChn; nTile = ai.getAndIncrement()) {
tileY = nTile /tilesX;
tileX = nTile % tilesX;
if (tile_op[tileY][tileX] == 0) continue; // nothing to do for this tile
for (int chn = 0; chn <numcol; chn++) {
......@@ -1066,6 +1071,7 @@ public class ImageDtt {
}
for (int i = 0; i < quad; i++) {
clt_data[i][chn][tileY][tileX] = new double [4][];
fract_shiftsXY[i] = extract_correct_tile( // return a pair of resudual offsets
image_data[i],
width, // image width
......@@ -1655,6 +1661,7 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < tiles_list[nser.get()].length; nTile = ai.getAndIncrement()) {
tileX = tiles_list[nser.get()][nTile][0];
tileY = tiles_list[nser.get()][nTile][1];
if (dct_data[tileY][tileX] != null){
for (int dct_mode = 0; dct_mode < 4; dct_mode++) if (((1 << dct_mode) & debug_mask) != 0) {
System.arraycopy(dct_data[tileY][tileX][dct_mode], 0, tile_in, 0, tile_in.length);
if ((debug_mode & 1) != 0) {
......@@ -1693,6 +1700,7 @@ public class ImageDtt {
}
}
}
}
};
}
startAndJoin(threads);
......@@ -1700,6 +1708,129 @@ public class ImageDtt {
return dpixels;
}
public double [][] combineRGBATiles(
final double [][][][] texture_tiles, // array [tilesY][tilesX][4][4*transform_size] or [tilesY][tilesX]{null}
final int transform_size,
final boolean overlap, // when false - output each tile as 16x16, true - overlap to make 8x8
final boolean sharp_alpha, // combining mode for alpha channel: false - treat as RGB, true - apply center 8x8 only
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=texture_tiles.length;
final int tilesX=texture_tiles[0].length;
final int width= (overlap?1:2)*tilesX * transform_size;
final int height= (overlap?1:2)*tilesY * transform_size;
if (globalDebugLevel > 0) {
System.out.println("iclt_2d():tilesX= "+tilesX);
System.out.println("iclt_2d():tilesY= "+tilesY);
System.out.println("iclt_2d():width= "+width);
System.out.println("iclt_2d():height= "+height);
System.out.println("iclt_2d():overlap= "+overlap);
System.out.println("iclt_2d():sharp_alpha= "+sharp_alpha);
}
final double [][] dpixels = new double["RGBA".length()][width*height]; // assuming java initializes them to 0
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger nser = new AtomicInteger(0);
final int [][][] tiles_list = new int[4][][];
for (int n=0; n<4; n++){
int nx = (tilesX + 1 - (n &1)) / 2;
int ny = (tilesY + 1 - ((n>>1) & 1)) / 2;
tiles_list[n] = new int [nx*ny][2];
int indx = 0;
for (int i = 0;i < ny; i++) for (int j = 0; j < nx; j++){
tiles_list[n][indx][0]=2*j+(n &1);
tiles_list[n][indx++][1]=2*i+((n>>1) & 1);
}
}
for (int n=0; n<4; n++){
nser.set(n);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int tileY,tileX;
int n2 = transform_size * 2;
int n_half = transform_size / 2;
int lastY = tilesY-1;
int lastX = tilesX-1;
int offset = n_half * (transform_size * tilesX) + n_half;
for (int nTile = ai.getAndIncrement(); nTile < tiles_list[nser.get()].length; nTile = ai.getAndIncrement()) {
tileX = tiles_list[nser.get()][nTile][0];
tileY = tiles_list[nser.get()][nTile][1];
double [][] texture_tile =texture_tiles[tileY][tileX];
if (texture_tile != null) {
if (overlap) {
if ((tileY >0) && (tileX > 0) && (tileY < lastY) && (tileX < lastX)) { // fast, no extra checks
for (int i = 0; i < n2;i++){
int start_line = ((tileY*transform_size + i) * tilesX + tileX)*transform_size - offset;
for (int chn = 0; chn < texture_tile.length; chn++) {
if ((chn < 3) || !sharp_alpha) {
for (int j = 0; j<n2;j++) {
dpixels[chn][start_line + j] += texture_tile[chn][n2 * i + j];
}
} else if ((i >= n_half) && (i < (n2-n_half))) {
for (int j = n_half; j < (n2 - n_half); j++) {
dpixels[chn][start_line + j] += texture_tile[chn][n2 * i + j];
}
}
}
}
} else { // be careful with margins
for (int i = 0; i < n2;i++){
if ( ((tileY > 0) && (tileY < lastY)) ||
((tileY == 0) && (i >= n_half)) ||
((tileY == lastY) && (i < (n2 - n_half)))) {
int start_line = ((tileY*transform_size + i) * tilesX + tileX)*transform_size - offset;
for (int chn = 0; chn < texture_tile.length; chn++) {
if ((chn < 3) || !sharp_alpha) {
for (int j = 0; j<n2;j++) {
if ( ((tileX > 0) && (tileX < lastX)) ||
((tileX == 0) && (j >= n_half)) ||
((tileX == lastX) && (j < (n2 - n_half)))) {
dpixels[chn][start_line + j] += texture_tile[chn][n2 * i + j];
}
}
} else if ((i >= n_half) && (i < (n2-n_half))) {
for (int j = n_half; j < (n2 - n_half); j++) {
if ( ((tileX > 0) && (tileX < lastX)) ||
((tileX == 0) && (j >= n_half)) ||
((tileX == lastX) && (j < (n2 - n_half)))) {
dpixels[chn][start_line + j] += texture_tile[chn][n2 * i + j];
}
}
}
}
}
}
}
} else { //if (overlap) - just copy tiles w/o overlapping
for (int i = 0; i < n2;i++){
for (int chn = 0; chn < texture_tile.length; chn++) {
System.arraycopy(
texture_tile[chn],
i * n2,
dpixels[chn],
(tileY * n2 + i)* width + tileX*n2,
n2);
}
}
}
}
}
}
};
}
startAndJoin(threads);
}
return dpixels;
}
public double [][][][] clt_shiftXY(
final double [][][][] dct_data, // array [tilesY][tilesX][4][dct_size*dct_size]
final int dct_size,
......@@ -1885,13 +2016,14 @@ public class ImageDtt {
public void clt_lpf(
final double sigma,
final double [][][][] clt_data,
final int dct_size,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=clt_data.length;
final int tilesX=clt_data[0].length;
final int nTiles=tilesX*tilesY;
final int dct_size = (int) Math.round(Math.sqrt(clt_data[0][0][0].length));
// final int dct_size = (int) Math.round(Math.sqrt(clt_data[0][0][0].length));
final int dct_len = dct_size*dct_size;
final double [] filter_direct= new double[dct_len];
if (sigma == 0) {
......@@ -1948,6 +2080,7 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
if (clt_data[tileY][tileX] != null) {
for (int n = 0; n < 4; n++){
for (int i = 0; i < filter.length; i++){
clt_data[tileY][tileX][n][i] *= filter[i];
......@@ -1955,6 +2088,7 @@ public class ImageDtt {
}
}
}
}
};
}
startAndJoin(threads);
......@@ -2110,6 +2244,7 @@ public class ImageDtt {
// extract correlation result in linescan order (for visualization)
public double [] corr_dbg(
final double [][][] corr_data,
final int corr_size,
final double border_contrast,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
......@@ -2117,7 +2252,7 @@ public class ImageDtt {
final int tilesY=corr_data.length;
final int tilesX=corr_data[0].length;
final int nTiles=tilesX*tilesY;
final int corr_size = (int) Math.round(Math.sqrt(corr_data[0][0].length));
// final int corr_size = (int) Math.round(Math.sqrt(corr_data[0][0].length));
final int tile_size = corr_size+1;
final int corr_len = corr_size*corr_size;
......@@ -2137,8 +2272,16 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
if ((corr_data[tileY][tileX] != null) && (corr_data[tileY][tileX].length > 0)) {
for (int i = 0; i < corr_size;i++){
try {
System.arraycopy(corr_data[tileY][tileX], corr_size* i, corr_data_out, ((tileY*tile_size + i) *tilesX + tileX)*tile_size , corr_size);
} catch (Exception e){
System.out.println("corr_data[tileY][tileX].length = "+corr_data[tileY][tileX].length+
" corr_size = "+corr_size+" i ="+i+" tile_size="+tile_size);
continue;
}
corr_data_out[((tileY*tile_size + i) *tilesX + tileX)*tile_size+corr_size] = border_contrast*((i & 1) - 0.5);
}
for (int i = 0; i < tile_size; i++){
......@@ -2146,25 +2289,32 @@ public class ImageDtt {
}
}
}
}
};
}
startAndJoin(threads);
return corr_data_out;
}
// extract correlation result in linescan order (for visualization)
public double [][] corr_partial_dbg(
final double [][][][][] corr_data,
final int corr_size,
final int pairs,
final int colors,
final double border_contrast,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=corr_data.length;
final int tilesX=corr_data[0].length;
final int pairs= corr_data[0][0].length;
final int colors=corr_data[0][0][0].length;
final int nTiles=tilesX*tilesY;
final int corr_size = (int) Math.round(Math.sqrt(corr_data[0][0][0][0].length));
// final int corr_size = (int) Math.round(Math.sqrt(corr_data[0][0][0][0].length));
// final int pairs= corr_data[0][0].length;
// final int colors=corr_data[0][0][0].length;
final int tile_size = corr_size+1;
final int corr_len = corr_size*corr_size;
......@@ -2190,6 +2340,7 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
if ((corr_data[tileY][tileX] != null) && (corr_data[tileY][tileX].length > 0)) {
for (int pair = 0; pair< pairs; pair++) {
for (int nColor = 0; nColor < colors; nColor++) {
int indx = pair*colors+nColor;
......@@ -2209,6 +2360,7 @@ public class ImageDtt {
}
}
}
}
};
}
startAndJoin(threads);
......
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