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

next snapshot

parent f606663c
......@@ -1914,11 +1914,19 @@ 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 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);
}
......@@ -4544,7 +4547,7 @@ public class EyesisDCT {
for (int i = 0; i < setFiles.get(nSet).size(); i++){
channelFiles[fileIndices[setFiles.get(nSet).get(i)][1]] = setFiles.get(nSet).get(i);
}
ImagePlus [] imp_srcs = new ImagePlus[channelFiles.length];
double [] scaleExposures = new double[channelFiles.length];
for (int srcChannel=0; srcChannel<channelFiles.length; srcChannel++){
......@@ -4690,7 +4693,7 @@ public class EyesisDCT {
System.out.println("Processing "+fileIndices.length+" files finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
}
public void channelGainsEqualize(
boolean gain_equalize,
boolean colors_equalize,
......@@ -4725,7 +4728,7 @@ public class EyesisDCT {
System.out.println("processCLTSets(): set "+ setName + " channel "+srcChannel+
" R"+avr_pix[srcChannel][0]+" G"+avr_pix[srcChannel][1]+" B"+avr_pix[srcChannel][2]);
}
}
}
for (int j=0; j < avr_RGB.length; j++) avr_RGB[j] /= numChn;
......@@ -4760,9 +4763,9 @@ public class EyesisDCT {
}
}
}
public ImagePlus [] processCLTQuadCorr(
ImagePlus [] imp_quad, // should have properties "name"(base for saving results), "channel","path"
EyesisCorrectionParameters.CLTParameters clt_parameters,
......@@ -4814,23 +4817,66 @@ public class EyesisDCT {
int tilesY = imp_quad[0].getHeight()/clt_parameters.transform_size;
int tilesX = imp_quad[0].getWidth()/clt_parameters.transform_size;
double [][][][] clt_corr_combo = null;
// 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
// 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]
imp_quad[0].getWidth(), // final int width,
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,
clt_parameters.corr_offset,
......@@ -4840,27 +4886,69 @@ public class EyesisDCT {
clt_parameters.corr_mask,
clt_parameters.corr_normalize, // normalize correlation results by rms
clt_parameters.corr_normalize? clt_parameters.min_corr_normalized: clt_parameters.min_corr, // 0.0001; // minimal correlation value to consider valid
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
geometryCorrection, // final GeometryCorrection geometryCorrection,
clt_kernels, // final double [][][][][][] clt_kernels, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.kernel_step,
clt_parameters.transform_size,
clt_parameters.clt_window,
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileX, // final int debug_tileX,
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
threadsMax,
debugLevel);
clt_parameters.max_corr_sigma,// 1.5; // weights of points around global max to find fractional
clt_parameters.max_corr_radius,
geometryCorrection, // final GeometryCorrection geometryCorrection,
clt_kernels, // final double [][][][][][] clt_kernels, // [channel_in_quad][color][tileY][tileX][band][pixel] , size should match image (have 1 tile around)
clt_parameters.kernel_step,
clt_parameters.transform_size,
clt_parameters.clt_window,
clt_parameters.shift_x, // final int shiftX, // shift image horizontally (positive - right) - just for testing
clt_parameters.shift_y, // final int shiftY, // shift image vertically (positive - down)
clt_parameters.tileX, // final int debug_tileX,
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
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){
......@@ -4876,14 +4964,15 @@ public class EyesisDCT {
disparity_titles);
}
}
if (debugLevel > -1){
double [][] corr_rslt = new double [clt_corr_combo.length][];
String [] titles = {"combo","sum"};
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);
......@@ -4920,245 +5012,254 @@ public class EyesisDCT {
}
}
}
for (int iQuad = 0; iQuad <clt_data.length; iQuad++){
String title=name+"-"+String.format("%02d", iQuad);
String titleFull=title+"-SPLIT-D"+clt_parameters.disparity;
if (clt_parameters.gen_chn_img) {
ImagePlus [] imps_RGB = new ImagePlus[clt_data.length];
for (int iQuad = 0; iQuad < clt_data.length; iQuad++){
if (clt_parameters.corr_sigma > 0){ // no filter at all
for (int chn = 0; chn < clt_data[iQuad].length; chn++) {
image_dtt.clt_lpf(
clt_parameters.corr_sigma,
clt_data[iQuad][chn],
threadsMax,
debugLevel);
}
}
String title=name+"-"+String.format("%02d", iQuad);
String titleFull=title+"-SPLIT-D"+clt_parameters.disparity;
// 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);
}
if (debugLevel > 1){
double [][] clt = new double [clt_data[iQuad].length*4][];
for (int chn = 0; chn < clt_data[iQuad].length; chn++) {
double [][] clt_set = image_dtt.clt_dbg(
clt_data [iQuad][chn],
threadsMax,
debugLevel);
for (int ii = 0; ii < clt_set.length; ii++) clt[chn*4+ii] = clt_set[ii];
if (clt_parameters.corr_sigma > 0){ // no filter at all
for (int chn = 0; chn < clt_data[iQuad].length; chn++) {
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;
if (debugLevel > 0){
sdfa_instance.showArrays(clt,
tilesX*clt_parameters.transform_size,
tilesY*clt_parameters.transform_size,
true,
results[iQuad].getTitle()+"-CLT-D"+clt_parameters.disparity);
System.out.println("--tilesX="+tilesX);
System.out.println("--tilesY="+tilesY);
}
}
double [][] iclt_data = new double [clt_data[iQuad].length][];
for (int chn=0; chn<iclt_data.length;chn++){
iclt_data[chn] = image_dtt.iclt_2d(
clt_data[iQuad][chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
clt_parameters.transform_size, // final int
clt_parameters.clt_window, // window_type
15, // clt_parameters.iclt_mask, //which of 4 to transform back
0, // clt_parameters.dbg_mode, //which of 4 to transform back
threadsMax,
debugLevel);
if (debugLevel > 1){
double [][] clt = new double [clt_data[iQuad].length*4][];
for (int chn = 0; chn < clt_data[iQuad].length; chn++) {
double [][] clt_set = image_dtt.clt_dbg(
clt_data [iQuad][chn],
threadsMax,
debugLevel);
for (int ii = 0; ii < clt_set.length; ii++) clt[chn*4+ii] = clt_set[ii];
}
}
if (debugLevel > 0) sdfa_instance.showArrays(
iclt_data,
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
true,
results[iQuad].getTitle()+"-rbg_sigma");
if (debugLevel > 0) sdfa_instance.showArrays(iclt_data,
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
true,
results[iQuad].getTitle()+"-ICLT-RGB-D"+clt_parameters.disparity);
if (debugLevel > 0){
sdfa_instance.showArrays(clt,
tilesX*clt_parameters.transform_size,
tilesY*clt_parameters.transform_size,
true,
results[iQuad].getTitle()+"-CLT-D"+clt_parameters.disparity);
}
}
double [][] iclt_data = new double [clt_data[iQuad].length][];
for (int chn=0; chn<iclt_data.length;chn++){
iclt_data[chn] = image_dtt.iclt_2d(
clt_data[iQuad][chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
clt_parameters.transform_size, // final int
clt_parameters.clt_window, // window_type
15, // clt_parameters.iclt_mask, //which of 4 to transform back
0, // clt_parameters.dbg_mode, //which of 4 to transform back
threadsMax,
debugLevel);
// convert to ImageStack of 3 slices
String [] sliceNames = {"red", "blue", "green"};
stack = sdfa_instance.makeStack(
iclt_data,
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
sliceNames); // or use null to get chn-nn slice names
}
if (debugLevel > 0) sdfa_instance.showArrays( // -1
iclt_data,
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
true,
results[iQuad].getTitle()+"-rbg_sigma");
if (debugLevel > 0) sdfa_instance.showArrays(iclt_data,
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
true,
results[iQuad].getTitle()+"-ICLT-RGB-D"+clt_parameters.disparity);
if (debugLevel > -1){
double [] chn_avg = {0.0,0.0,0.0};
float [] pixels;
int width = stack.getWidth();
int height = stack.getHeight();
// convert to ImageStack of 3 slices
String [] sliceNames = {"red", "blue", "green"};
stack = sdfa_instance.makeStack(
iclt_data,
(tilesX + 0) * clt_parameters.transform_size,
(tilesY + 0) * clt_parameters.transform_size,
sliceNames); // or use null to get chn-nn slice names
for (int c = 0; c <3; c++){
pixels = (float[]) stack.getPixels(c+1);
for (int i = 0; i<pixels.length; i++){
chn_avg[c] += pixels[i];
if (debugLevel > -1){
double [] chn_avg = {0.0,0.0,0.0};
float [] pixels;
int width = stack.getWidth();
int height = stack.getHeight();
for (int c = 0; c <3; c++){
pixels = (float[]) stack.getPixels(c+1);
for (int i = 0; i<pixels.length; i++){
chn_avg[c] += pixels[i];
}
}
chn_avg[0] /= width*height;
chn_avg[1] /= width*height;
chn_avg[2] /= width*height;
System.out.println("Processed channels averages: R="+chn_avg[0]+", G="+chn_avg[2]+", B="+chn_avg[1]);
}
chn_avg[0] /= width*height;
chn_avg[1] /= width*height;
chn_avg[2] /= width*height;
System.out.println("Processed channels averages: R="+chn_avg[0]+", G="+chn_avg[2]+", B="+chn_avg[1]);
}
if (!this.correctionsParameters.colorProc){
results[iQuad]= new ImagePlus(titleFull, stack);
eyesisCorrections.saveAndShow(
results[iQuad],
this.correctionsParameters);
continue; // return results;
}
if (debugLevel > 1) System.out.println("before colors.1");
//Processing colors - changing stack sequence to r-g-b (was r-b-g)
if (!eyesisCorrections.fixSliceSequence(
stack,
debugLevel)){
if (debugLevel > -1) System.out.println("fixSliceSequence() returned false");
return null;
}
if (debugLevel > 1) System.out.println("before colors.2");
if (debugLevel > 1){
ImagePlus imp_dbg=new ImagePlus(imp_quad[iQuad].getTitle()+"-"+channel+"-preColors",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
this.correctionsParameters);
}
if (debugLevel > 1) System.out.println("before colors.3, scaleExposure="+scaleExposures[iQuad]+" scale = "+(255.0/eyesisCorrections.psfSubpixelShouldBe4/eyesisCorrections.psfSubpixelShouldBe4/scaleExposures[iQuad]));
CorrectionColorProc correctionColorProc=new CorrectionColorProc(eyesisCorrections.stopRequested);
double [][] yPrPb=new double [3][];
// if (dct_parameters.color_DCT){
// need to get YPbPr - not RGB here
// } else {
correctionColorProc.processColorsWeights(stack, // just gamma convert? TODO: Cleanup? Convert directly form the linear YPrPb
// 255.0/this.psfSubpixelShouldBe4/this.psfSubpixelShouldBe4, // double scale, // initial maximal pixel value (16))
// 255.0/eyesisCorrections.psfSubpixelShouldBe4/eyesisCorrections.psfSubpixelShouldBe4/scaleExposure, // double scale, // initial maximal pixel value (16))
// 255.0/2/2/scaleExposure, // double scale, // initial maximal pixel value (16))
255.0/scaleExposures[iQuad], // double scale, // initial maximal pixel value (16))
colorProcParameters,
channelGainParameters,
channel,
null, //correctionDenoise.getDenoiseMask(),
this.correctionsParameters.blueProc,
debugLevel);
if (debugLevel > 1) System.out.println("Processed colors to YPbPr, total number of slices="+stack.getSize());
if (debugLevel > 1) {
ImagePlus imp_dbg=new ImagePlus("procColors",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
this.correctionsParameters);
}
float [] fpixels;
int [] slices_YPrPb = {8,6,7};
yPrPb=new double [3][];
for (int n = 0; n < slices_YPrPb.length; n++){
fpixels = (float[]) stack.getPixels(slices_YPrPb[n]);
yPrPb[n] = new double [fpixels.length];
for (int i = 0; i < fpixels.length; i++) yPrPb[n][i] = fpixels[i];
}
if (toRGB) {
System.out.println("correctionColorProc.YPrPbToRGB");
stack = YPrPbToRGB(yPrPb,
colorProcParameters.kr, // 0.299;
colorProcParameters.kb, // 0.114;
stack.getWidth());
title=titleFull; // including "-DECONV" or "-COMBO"
titleFull=title+"-RGB-float-D"+clt_parameters.disparity;
//Trim stack to just first 3 slices
if (debugLevel > 1){ // 2){
ImagePlus imp_dbg=new ImagePlus("YPrPbToRGB",stack);
if (!this.correctionsParameters.colorProc){
results[iQuad]= new ImagePlus(titleFull, stack);
eyesisCorrections.saveAndShow(
results[iQuad],
this.correctionsParameters);
continue; // return results;
}
if (debugLevel > 1) System.out.println("before colors.1");
//Processing colors - changing stack sequence to r-g-b (was r-b-g)
if (!eyesisCorrections.fixSliceSequence(
stack,
debugLevel)){
if (debugLevel > -1) System.out.println("fixSliceSequence() returned false");
return null;
}
if (debugLevel > 1) System.out.println("before colors.2");
if (debugLevel > 1){
ImagePlus imp_dbg=new ImagePlus(imp_quad[iQuad].getTitle()+"-"+channel+"-preColors",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
this.correctionsParameters);
}
while (stack.getSize() > 3) stack.deleteLastSlice();
if (debugLevel > 1) System.out.println("Trimming color stack");
} else {
title=titleFull; // including "-DECONV" or "-COMBO"
titleFull=title+"-YPrPb-D"+clt_parameters.disparity; // including "-DECONV" or "-COMBO"
if (debugLevel > 1) System.out.println("Using full stack, including YPbPr");
}
if (debugLevel > 1) System.out.println("before colors.3, scaleExposure="+scaleExposures[iQuad]+" scale = "+(255.0/eyesisCorrections.psfSubpixelShouldBe4/eyesisCorrections.psfSubpixelShouldBe4/scaleExposures[iQuad]));
CorrectionColorProc correctionColorProc=new CorrectionColorProc(eyesisCorrections.stopRequested);
double [][] yPrPb=new double [3][];
// if (dct_parameters.color_DCT){
// need to get YPbPr - not RGB here
// } else {
correctionColorProc.processColorsWeights(stack, // just gamma convert? TODO: Cleanup? Convert directly form the linear YPrPb
// 255.0/this.psfSubpixelShouldBe4/this.psfSubpixelShouldBe4, // double scale, // initial maximal pixel value (16))
// 255.0/eyesisCorrections.psfSubpixelShouldBe4/eyesisCorrections.psfSubpixelShouldBe4/scaleExposure, // double scale, // initial maximal pixel value (16))
// 255.0/2/2/scaleExposure, // double scale, // initial maximal pixel value (16))
255.0/scaleExposures[iQuad], // double scale, // initial maximal pixel value (16))
colorProcParameters,
channelGainParameters,
channel,
null, //correctionDenoise.getDenoiseMask(),
this.correctionsParameters.blueProc,
debugLevel);
if (debugLevel > 1) System.out.println("Processed colors to YPbPr, total number of slices="+stack.getSize());
if (debugLevel > 1) {
ImagePlus imp_dbg=new ImagePlus("procColors",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
this.correctionsParameters);
}
float [] fpixels;
int [] slices_YPrPb = {8,6,7};
yPrPb=new double [3][];
for (int n = 0; n < slices_YPrPb.length; n++){
fpixels = (float[]) stack.getPixels(slices_YPrPb[n]);
yPrPb[n] = new double [fpixels.length];
for (int i = 0; i < fpixels.length; i++) yPrPb[n][i] = fpixels[i];
}
results[iQuad]= new ImagePlus(titleFull, stack);
// rotate the result
if (rotate){ // never rotate for equirectangular
stack=eyesisCorrections.rotateStack32CW(stack);
}
if (!toRGB && !this.correctionsParameters.jpeg){ // toRGB set for equirectangular
if (debugLevel > 1) System.out.println("!toRGB && !this.correctionsParameters.jpeg");
eyesisCorrections.saveAndShow(results[iQuad], this.correctionsParameters);
continue; // return result;
} else { // that's not the end result, save if required
if (debugLevel > 1) System.out.println("!toRGB && !this.correctionsParameters.jpeg - else");
eyesisCorrections.saveAndShow(results[iQuad],
eyesisCorrections.correctionsParameters,
eyesisCorrections.correctionsParameters.save32,
false,
eyesisCorrections.correctionsParameters.JPEG_quality); // save, no show
}
// convert to RGB48 (16 bits per color component)
ImagePlus imp_RGB;
stack=eyesisCorrections.convertRGB32toRGB16Stack(
stack,
rgbParameters);
if (toRGB) {
System.out.println("correctionColorProc.YPrPbToRGB");
stack = YPrPbToRGB(yPrPb,
colorProcParameters.kr, // 0.299;
colorProcParameters.kb, // 0.114;
stack.getWidth());
title=titleFull; // including "-DECONV" or "-COMBO"
titleFull=title+"-RGB-float-D"+clt_parameters.disparity;
//Trim stack to just first 3 slices
if (debugLevel > 1){ // 2){
ImagePlus imp_dbg=new ImagePlus("YPrPbToRGB",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
this.correctionsParameters);
}
while (stack.getSize() > 3) stack.deleteLastSlice();
if (debugLevel > 1) System.out.println("Trimming color stack");
} else {
title=titleFull; // including "-DECONV" or "-COMBO"
titleFull=title+"-YPrPb-D"+clt_parameters.disparity; // including "-DECONV" or "-COMBO"
if (debugLevel > 1) System.out.println("Using full stack, including YPbPr");
}
titleFull=title+"-RGB48-D"+clt_parameters.disparity;
results[iQuad]= new ImagePlus(titleFull, stack);
results[iQuad]= new ImagePlus(titleFull, stack);
// rotate the result
if (rotate){ // never rotate for equirectangular
stack=eyesisCorrections.rotateStack32CW(stack);
}
if (!toRGB && !this.correctionsParameters.jpeg){ // toRGB set for equirectangular
if (debugLevel > 1) System.out.println("!toRGB && !this.correctionsParameters.jpeg");
eyesisCorrections.saveAndShow(results[iQuad], this.correctionsParameters);
continue; // return result;
} else { // that's not the end result, save if required
if (debugLevel > 1) System.out.println("!toRGB && !this.correctionsParameters.jpeg - else");
eyesisCorrections.saveAndShow(results[iQuad],
eyesisCorrections.correctionsParameters,
eyesisCorrections.correctionsParameters.save32,
false,
eyesisCorrections.correctionsParameters.JPEG_quality); // save, no show
}
// convert to RGB48 (16 bits per color component)
// ImagePlus imp_RGB;
stack=eyesisCorrections.convertRGB32toRGB16Stack(
stack,
rgbParameters);
// ImagePlus imp_RGB24;
results[iQuad].updateAndDraw();
if (debugLevel > 1) System.out.println("result.updateAndDraw(), "+titleFull+"-RGB48");
titleFull=title+"-RGB48-D"+clt_parameters.disparity;
results[iQuad]= new ImagePlus(titleFull, stack);
CompositeImage compositeImage=eyesisCorrections.convertToComposite(results[iQuad]);
// ImagePlus imp_RGB24;
results[iQuad].updateAndDraw();
if (debugLevel > 1) System.out.println("result.updateAndDraw(), "+titleFull+"-RGB48");
if (!this.correctionsParameters.jpeg && !advanced){ // RGB48 was the end result
if (debugLevel > 1) System.out.println("if (!this.correctionsParameters.jpeg && !advanced)");
eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters);
continue; // return result;
} else { // that's not the end result, save if required
if (debugLevel > 1) System.out.println("if (!this.correctionsParameters.jpeg && !advanced) - else");
eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters, this.correctionsParameters.save16, false); // save, no show
// eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters, this.correctionsParameters.save16, true); // save, no show
}
CompositeImage compositeImage=eyesisCorrections.convertToComposite(results[iQuad]);
imp_RGB=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();
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();
if (!this.correctionsParameters.jpeg && !advanced){ // RGB48 was the end result
if (debugLevel > 1) System.out.println("if (!this.correctionsParameters.jpeg && !advanced)");
eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters);
continue; // return result;
} else { // that's not the end result, save if required
if (debugLevel > 1) System.out.println("if (!this.correctionsParameters.jpeg && !advanced) - else");
eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters, this.correctionsParameters.save16, false); // save, no show
// eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters, this.correctionsParameters.save16, true); // save, no show
}
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=imps_RGB[iQuad].getProcessor();
ip.setInterpolationMethod(ImageProcessor.BICUBIC);
ip=ip.resize((int)(ip.getWidth()*JPEG_scale),(int) (ip.getHeight()*JPEG_scale));
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,40 +1661,162 @@ 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];
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) {
tile_dct = tile_in;
} else {
// IDCT-IV should be in reversed order: CC->CC, SC->CS, CS->SC, SS->SS
int idct_mode = ((dct_mode << 1) & 2) | ((dct_mode >> 1) & 1);
tile_dct = dtt.dttt_iv (tile_in, idct_mode, dct_size);
}
tile_mdct = dtt.unfold_tile(tile_dct, dct_size, dct_mode); // mode=0 - DCCT
if ((tileY >0) && (tileX > 0) && (tileY < lastY) && (tileX < lastX)) { // fast, no extra checks
for (int i = 0; i < n2;i++){
// int start_line = ((tileY*dct_size + i) *(tilesX+1) + tileX)*dct_size;
int start_line = ((tileY*dct_size + i) * tilesX + tileX)*dct_size - offset;
for (int j = 0; j<n2;j++) {
dpixels[start_line + j] += debug_scale * tile_mdct[n2 * i + j]; // add (cc+sc+cs+ss)/4
}
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) {
tile_dct = tile_in;
} else {
// IDCT-IV should be in reversed order: CC->CC, SC->CS, CS->SC, SS->SS
int idct_mode = ((dct_mode << 1) & 2) | ((dct_mode >> 1) & 1);
tile_dct = dtt.dttt_iv (tile_in, idct_mode, dct_size);
}
} 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*dct_size + i) * tilesX + tileX)*dct_size - offset;
tile_mdct = dtt.unfold_tile(tile_dct, dct_size, dct_mode); // mode=0 - DCCT
if ((tileY >0) && (tileX > 0) && (tileY < lastY) && (tileX < lastX)) { // fast, no extra checks
for (int i = 0; i < n2;i++){
// int start_line = ((tileY*dct_size + i) *(tilesX+1) + tileX)*dct_size;
int start_line = ((tileY*dct_size + i) * tilesX + tileX)*dct_size - offset;
for (int j = 0; j<n2;j++) {
if ( ((tileX > 0) && (tileX < lastX)) ||
((tileX == 0) && (j >= n_half)) ||
((tileX == lastX) && (j < (n2 - n_half)))) {
dpixels[start_line + j] += debug_scale * tile_mdct[n2 * i + j]; // add (cc+sc+cs+ss)/4
dpixels[start_line + j] += debug_scale * tile_mdct[n2 * i + j]; // add (cc+sc+cs+ss)/4
}
}
} 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*dct_size + i) * tilesX + tileX)*dct_size - offset;
for (int j = 0; j<n2;j++) {
if ( ((tileX > 0) && (tileX < lastX)) ||
((tileX == 0) && (j >= n_half)) ||
((tileX == lastX) && (j < (n2 - n_half)))) {
dpixels[start_line + j] += debug_scale * tile_mdct[n2 * i + j]; // add (cc+sc+cs+ss)/4
}
}
}
}
}
}
}
}
}
};
}
startAndJoin(threads);
}
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);
}
}
}
}
}
......@@ -1700,6 +1828,9 @@ public class ImageDtt {
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,9 +2080,11 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
for (int n = 0; n < 4; n++){
for (int i = 0; i < filter.length; i++){
clt_data[tileY][tileX][n][i] *= filter[i];
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];
}
}
}
}
......@@ -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,12 +2272,21 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
for (int i = 0; i < corr_size;i++){
System.arraycopy(corr_data[tileY][tileX], corr_size* i, corr_data_out, ((tileY*tile_size + i) *tilesX + tileX)*tile_size , corr_size);
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++){
corr_data_out[((tileY*tile_size + corr_size) *tilesX + tileX)*tile_size+i] = border_contrast*((i & 1) - 0.5);
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++){
corr_data_out[((tileY*tile_size + corr_size) *tilesX + tileX)*tile_size+i] = border_contrast*((i & 1) - 0.5);
}
}
}
}
......@@ -2151,20 +2295,26 @@ 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,20 +2340,22 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
for (int pair = 0; pair< pairs; pair++) {
for (int nColor = 0; nColor < colors; nColor++) {
int indx = pair*colors+nColor;
for (int i = 0; i < corr_size;i++){
System.arraycopy(
corr_data[tileY][tileX][pair][nColor],
corr_size* i,
corr_data_out[indx],
((tileY*tile_size + i) *tilesX + tileX)*tile_size ,
corr_size);
corr_data_out[indx][((tileY*tile_size + i) *tilesX + tileX)*tile_size+corr_size] = border_contrast*((i & 1) - 0.5);
}
for (int i = 0; i < tile_size; i++){
corr_data_out[indx][((tileY*tile_size + corr_size) *tilesX + tileX)*tile_size+i] = border_contrast*((i & 1) - 0.5);
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;
for (int i = 0; i < corr_size;i++){
System.arraycopy(
corr_data[tileY][tileX][pair][nColor],
corr_size* i,
corr_data_out[indx],
((tileY*tile_size + i) *tilesX + tileX)*tile_size ,
corr_size);
corr_data_out[indx][((tileY*tile_size + i) *tilesX + tileX)*tile_size+corr_size] = border_contrast*((i & 1) - 0.5);
}
for (int i = 0; i < tile_size; i++){
corr_data_out[indx][((tileY*tile_size + corr_size) *tilesX + tileX)*tile_size+i] = border_contrast*((i & 1) - 0.5);
}
}
}
}
......
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