Commit 7c36f258 authored by Andrey Filippov's avatar Andrey Filippov

implemented (I)CLT and shift

parent 122aa397
......@@ -44,10 +44,10 @@ public class DttRad2 {
double [] hwindow = null; // half window
int [][] fold_index = null; // index of the source item in 2nx2n array input to mdct_2d.
// First index (0..n^2-1) index in the folded array (dct-iV input)
// Second index(0..3) - item to add (2 vertiacl, 2 - horizontal)
double [][] fold_k = null; // Matching fold_index items. Each is a product of 2 window coefficients and sign
// Second index(0..3) - item to add (2 vertical, 2 - horizontal)
double [][][] fold_k = null; // First index - mode: 0 - CC 1: SC, 2: CS, 3: SS. Other indices matching fold_index items. Each is a product of 2 window coefficients and sign
int [] unfold_index = null; // index for each element of idct(2nx2n)
double [] unfold_k = null; // Matching unfold_index items. Each is a product of 2 window coefficients and sign
double [][] unfold_k = null; // First index - mode: 0 - CC 1: SC, 2: CS, 3: SS. Other indices matching unfold_index items. Each is a product of 2 window coefficients and sign
public DttRad2 (int maxN){ // n - maximal
setup_arrays(maxN); // always setup arrays for fast calculations
......@@ -87,25 +87,31 @@ public class DttRad2 {
// For index in dct-iv input (0..n-1) get 2 variants of index in mdct input array (0..2*n-1)
// second index : 0 - index in X array 2*n long
// 1 - window index (0..n-1), [0] - minimal, [n-1] - max
// 2 - sign of the term
// 2 - sign of the C term (-~c - d, +a -~b)
// 3 - sign of the S term (+~c - d, +a +~b)
private int [][] get_fold_indices(int x, int n){
int n1 = n>>1;
int [][] ind = new int[2][3];
int [][] ind = new int[2][4];
if (x <n1) {
ind[0][0] = n + n1 - x - 1; // -cR
ind[0][0] = n + n1 - x - 1; // C: -cR, S: +cR
ind[0][1] = n1 + x;
ind[0][2] = -1;
ind[1][0] = n + n1 + x; // -d
ind[0][3] = 1;
ind[1][0] = n + n1 + x; // C: -d, S: -d
ind[1][1] = n1 - x - 1;
ind[1][2] = -1;
ind[1][3] = -1;
} else {
x-=n1;
ind[0][0] = x; // +a
ind[0][0] = x; // C: +a, S: +a
ind[0][1] = x;
ind[0][2] = 1;
ind[1][0] = n - x - 1; // -bR
ind[0][3] = 1;
ind[1][0] = n - x - 1; // C: -bR, S: +bR
ind[1][1] = n - x - 1;
ind[1][2] = -1;
ind[1][3] = 1;
}
return ind;
......@@ -114,49 +120,57 @@ public class DttRad2 {
private void set_fold_2d(int n){ // n - DCT and window size
if ((fold_index != null) && (fold_index.length == n*n)) return;
fold_index = new int[n*n][4];
fold_k = new double[n*n][4];
fold_k = new double[4][n*n][4];
int [] vert_ind = new int[2];
double [] vert_k = new double[2];
double [][] vert_k = new double[2][2];
int [] hor_ind = new int[2];
double [] hor_k = new double[2];
double [][] hor_k = new double[2][2];
int [][] fi;
int n2 = 2*n;
for (int i = 0; i < n; i++ ){
fi = get_fold_indices(i,n);
vert_ind[0] = fi[0][0];
vert_ind[1] = fi[1][0];
vert_k[0] = fi[0][2] * hwindow[fi[0][1]];
vert_k[1] = fi[1][2] * hwindow[fi[1][1]];
vert_k[0][0] = fi[0][2] * hwindow[fi[0][1]]; // use cosine sign
vert_k[0][1] = fi[1][2] * hwindow[fi[1][1]]; // use cosine sign
vert_k[1][0] = fi[0][3] * hwindow[fi[0][1]]; // use sine sign
vert_k[1][1] = fi[1][3] * hwindow[fi[1][1]]; // use sine sign
for (int j = 0; j < n; j++ ){
fi = get_fold_indices(j,n);
hor_ind[0] = fi[0][0];
hor_ind[1] = fi[1][0];
hor_k[0] = fi[0][2] * hwindow[fi[0][1]];
hor_k[1] = fi[1][2] * hwindow[fi[1][1]];
hor_k[0][0] = fi[0][2] * hwindow[fi[0][1]]; // use cosine sign
hor_k[0][1] = fi[1][2] * hwindow[fi[1][1]]; // use cosine sign
hor_k[1][0] = fi[0][3] * hwindow[fi[0][1]]; // use sine sign
hor_k[1][1] = fi[1][3] * hwindow[fi[1][1]]; // use sine sign
int indx = n*i + j;
for (int k = 0; k<4;k++) {
fold_index[indx][k] = n2 * vert_ind[(k>>1) & 1] + hor_ind[k & 1];
fold_k[indx][k] = vert_k[(k>>1) & 1] * hor_k[k & 1];
}
for (int mode = 0; mode<4; mode++){
for (int k = 0; k<4;k++) {
fold_k[mode][indx][k] = vert_k[(mode>>1) &1][(k>>1) & 1] * hor_k[mode &1][k & 1];
}
}
}
}
if (n < 8) {
for (int i = 0; i < n; i++ ){
fi = get_fold_indices(i,n);
System.out.println(i+"->"+String.format("[%2d % 2d % 2d] [%2d %2d %2d] %f %f",
fi[0][0],fi[0][1],fi[0][2],
fi[1][0],fi[1][1],fi[1][2], hwindow[fi[0][1]], hwindow[fi[1][1]]));
System.out.println(i+"->"+String.format("?[%2d %2d %2d %2d] [%2d %2d %2d %2d] %f %f",
fi[0][0],fi[0][1],fi[0][2],fi[0][3],
fi[1][0],fi[1][1],fi[1][2],fi[1][3], hwindow[fi[0][1]], hwindow[fi[1][1]]));
}
}
}
public double [][] get_fold_2d(
public double [][][] get_fold_2d(
double scale_hor,
double scale_vert)
{
return get_fold_2d( this.N, scale_hor, scale_vert);
}
public double [][] get_fold_2d(
public double [][][] get_fold_2d(
int n,
double scale_hor,
double scale_vert
......@@ -173,37 +187,53 @@ public class DttRad2 {
hwindow_h[i] = (ah > (Math.PI/2))? 0.0: Math.cos(ah);
hwindow_v[i] = (av > (Math.PI/2))? 0.0: Math.cos(av);
}
double [][] fold_sk = new double[n*n][4];
int [] vert_ind = new int[2];
double [] vert_k = new double[2];
int [] hor_ind = new int[2];
double [] hor_k = new double[2];
double [][][] fold_sk = new double[2][n*n][4];
int [] vert_ind = new int[2];
double [][] vert_k = new double[2][2];
int [] hor_ind = new int[2];
double [][] hor_k = new double[2][2];
int [][] fi;
for (int i = 0; i < n; i++ ){
fi = get_fold_indices(i,n);
vert_ind[0] = fi[0][0];
vert_ind[1] = fi[1][0];
vert_k[0] = fi[0][2] * hwindow_v[fi[0][1]];
vert_k[1] = fi[1][2] * hwindow_v[fi[1][1]];
// vert_k[0] = fi[0][2] * hwindow_v[fi[0][1]];
// vert_k[1] = fi[1][2] * hwindow_v[fi[1][1]];
vert_k[0][0] = fi[0][2] * hwindow_v[fi[0][1]]; // use cosine sign
vert_k[0][1] = fi[1][2] * hwindow_v[fi[1][1]]; // use cosine sign
vert_k[1][0] = fi[0][3] * hwindow_v[fi[0][1]]; // use sine sign
vert_k[1][1] = fi[1][3] * hwindow_v[fi[1][1]]; // use sine sign
for (int j = 0; j < n; j++ ){
fi = get_fold_indices(j,n);
hor_ind[0] = fi[0][0];
hor_ind[1] = fi[1][0];
hor_k[0] = fi[0][2] * hwindow_h[fi[0][1]];
hor_k[1] = fi[1][2] * hwindow_h[fi[1][1]];
// hor_k[0] = fi[0][2] * hwindow_h[fi[0][1]];
// hor_k[1] = fi[1][2] * hwindow_h[fi[1][1]];
hor_k[0][0] = fi[0][2] * hwindow_h[fi[0][1]]; // use cosine sign
hor_k[0][1] = fi[1][2] * hwindow_h[fi[1][1]]; // use cosine sign
hor_k[1][0] = fi[0][3] * hwindow_h[fi[0][1]]; // use sine sign
hor_k[1][1] = fi[1][3] * hwindow_h[fi[1][1]]; // use sine sign
int indx = n*i + j;
for (int k = 0; k<4;k++) {
fold_sk[indx][k] = vert_k[(k>>1) & 1] * hor_k[k & 1];
// for (int k = 0; k<4;k++) {
// fold_sk[indx][k] = vert_k[(k>>1) & 1] * hor_k[k & 1];
// }
for (int mode = 0; mode<4; mode++){
for (int k = 0; k<4;k++) {
fold_sk[mode][indx][k] = vert_k[(mode>>1) &1][(k>>1) & 1] * hor_k[mode &1][k & 1];
}
}
}
}
return fold_sk;
}
/*
// return index+1 and sign for 1-d imdct. x is index (0..2*n-1) of the imdct array, value is sign * (idct_index+1),
// where idct_index (0..n-1) is index in the dct-iv array
private int get_unfold_index(int x, int n){
private int get_unfold_index_signes(int x, int n){
int n1 = n>>1;
int segm = x / n1;
x = x % n1;
......@@ -218,7 +248,7 @@ public class DttRad2 {
private void set_unfold_2d(int n){ // n - DCT size
if ((unfold_index != null) && (unfold_index.length == 4*n*n)) return;
unfold_index = new int[4*n*n];
unfold_k = new double[4*n*n];
unfold_k = new double[4][4*n*n];
int n2 = 2*n;
for (int i = 0; i < 2*n; i++ ){
int index_vert = get_unfold_index(i,n);
......@@ -253,6 +283,52 @@ public class DttRad2 {
}
}
}
*/
// return index and two signs (c,s) for 1-d imdct. x is index (0..2*n-1) of the imdct array, value is sign * (idct_index+1),
// where idct_index (0..n-1) is index in the dct-iv array
private int [] get_unfold_index_signs(int x, int n){
int n1 = n>>1;
int segm = x / n1;
x = x % n1;
int [] is2 = new int[3];
switch (segm){
case 0: is2[0] = x + n1; is2[1]= 1; is2[2] = 1; return is2; // return 1+ (x + n1);
case 1: is2[0] = n - x - 1; is2[1]= -1; is2[2] = 1; return is2; // return -(n - x);
case 2: is2[0] = n1 - x - 1; is2[1]= -1; is2[2] = 1; return is2; // return -(n1 - x);
case 3: is2[0] = x; is2[1]= -1; is2[2] = -1; return is2; // return -(1 + x);
}
return null; //should never happen
}
private void set_unfold_2d(int n){ // n - DCT size
if ((unfold_index != null) && (unfold_index.length == 4*n*n)) return;
unfold_index = new int[4*n*n];
unfold_k = new double[4][4*n*n];
int n2 = 2*n;
for (int i = 0; i < 2*n; i++ ){
int [] is2_vert = get_unfold_index_signs(i,n);
double [] k_vert = {is2_vert[1]*hwindow[(i < n)?i:n2 -i -1], is2_vert[2]*hwindow[(i < n)?i:n2 -i -1]};
int index_vert = is2_vert[0] * n;
for (int j = 0; j < 2*n; j++ ){
int [] is2_hor = get_unfold_index_signs(j,n);
int index_hor = is2_hor[0];
double [] k_hor = {is2_hor[1] * hwindow[(j < n)?j:n2 -j -1], is2_hor[2] * hwindow[(j < n)?j:n2 -j -1]};
unfold_index[n2*i+j]=(index_vert+index_hor);
for (int mode = 0; mode < 4; mode++){
unfold_k[mode][n2*i+j] = k_vert[(mode>>1) &1]*k_hor[mode &1];
}
if (n < 8) System.out.print(String.format("%4d", unfold_index[n2*i+j]));
}
if (n < 8) System.out.println();
}
if (n < 8) {
for (int i = 0; i < 2*n; i++ ){
System.out.println(i+"=>"+get_unfold_index_signs(i,n)[0]+", "+get_unfold_index_signs(i,n)[1]+", "+get_unfold_index_signs(i,n)[2]);
}
}
}
public double [] dttt_iv(double [] x){
return dttt_iv(x, 0, 1 << (ilog2(x.length)/2));
......@@ -398,11 +474,11 @@ public class DttRad2 {
}
// Convert 2nx2n overlapping tile to n*n for dct-iv
public double [] fold_tile(double [] x) { // x should be 2n*2n
public double [] fold_tile(double [] x, int mode) { // x should be 2n*2n
return fold_tile(x, 1 << (ilog2(x.length/4)/2));
}
public double [] fold_tile(double [] x, int n) { // x should be 2n*2n
return fold_tile(x,n,this.fold_k);
public double [] fold_tile(double [] x, int n, int mode) { // x should be 2n*2n
return fold_tile(x,n, mode,this.fold_k);
// double [] y = new double [n*n];
// for (int i = 0; i<y.length;i++) {
// y[i] = 0;
......@@ -416,27 +492,35 @@ public class DttRad2 {
public double [] fold_tile(
double [] x,
int n,
double [][] fold_k
int mode, //////
double [][][] fold_k
) { // x should be 2n*2n
double [] y = new double [n*n];
for (int i = 0; i<y.length;i++) {
y[i] = 0;
for (int k = 0; k < 4; k++){
y[i] += x[fold_index[i][k]] * fold_k[i][k];
y[i] += x[fold_index[i][k]] * fold_k[mode][i][k];
}
}
return y;
}
public double [] unfold_tile(double [] x) { // x should be n*n
return unfold_tile(x, 1 << (ilog2(x.length)/2));
public double [] unfold_tile(
double [] x, // x should be n*n
int mode)
{
return unfold_tile(x, 1 << (ilog2(x.length)/2), mode);
}
public double [] unfold_tile(double [] x, int n) { // x should be 2n*2n
public double [] unfold_tile(
double [] x, // x should be 2n*2n
int n,
int mode)
{
double [] y = new double [4*n*n];
for (int i = 0; i<y.length;i++) {
y[i] = unfold_k[i]* x[unfold_index[i]];
y[i] = unfold_k[mode][i]* x[unfold_index[i]];
}
return y;
}
......
......@@ -1766,6 +1766,64 @@ public class EyesisCorrectionParameters {
this.addBottom=Integer.parseInt(properties.getProperty(prefix+"addBottom"));
}
}
public static class CLTParameters {
public int transform_size = 8; //
public int clt_window = 1; // currently only 3 types of windows - 0 (none), 1 and 2
public double shift_x = 0.0;
public double shift_y = 0.0;
public int iclt_mask = 15; // which transforms to combine
public int tileX = 258; // number of kernel tile (0..163)
public int tileY = 133; // number of kernel tile (0..122)
public int dbg_mode = 0; // 0 - normal, +1 - no DCT/IDCT
public CLTParameters(){}
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"transform_size",this.transform_size+"");
properties.setProperty(prefix+"clt_window", this.clt_window+"");
properties.setProperty(prefix+"shift_x", this.shift_x+"");
properties.setProperty(prefix+"shift_y", this.shift_y+"");
properties.setProperty(prefix+"iclt_mask", this.iclt_mask+"");
properties.setProperty(prefix+"tileX", this.tileX+"");
properties.setProperty(prefix+"tileY", this.tileY+"");
properties.setProperty(prefix+"dbg_mode", this.dbg_mode+"");
}
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"transform_size")!=null) this.transform_size=Integer.parseInt(properties.getProperty(prefix+"transform_size"));
if (properties.getProperty(prefix+"clt_window")!=null) this.clt_window=Integer.parseInt(properties.getProperty(prefix+"clt_window"));
if (properties.getProperty(prefix+"shift_x")!=null) this.shift_x=Double.parseDouble(properties.getProperty(prefix+"shift_x"));
if (properties.getProperty(prefix+"shift_y")!=null) this.shift_y=Double.parseDouble(properties.getProperty(prefix+"shift_y"));
if (properties.getProperty(prefix+"iclt_mask")!=null) this.iclt_mask=Integer.parseInt(properties.getProperty(prefix+"iclt_mask"));
if (properties.getProperty(prefix+"tileX")!=null) this.tileX=Integer.parseInt(properties.getProperty(prefix+"tileX"));
if (properties.getProperty(prefix+"tileY")!=null) this.tileY=Integer.parseInt(properties.getProperty(prefix+"tileY"));
if (properties.getProperty(prefix+"dbg_mode")!=null) this.dbg_mode=Integer.parseInt(properties.getProperty(prefix+"dbg_mode"));
}
public boolean showDialog() {
GenericDialog gd = new GenericDialog("Set DCT parameters");
gd.addNumericField("DCT size", this.transform_size, 0);
gd.addNumericField("Lapped transform window type (0- rectangular, 1 - sinus)", this.clt_window, 0);
gd.addNumericField("shift_x", this.shift_x, 4);
gd.addNumericField("shift_y", this.shift_y, 4);
gd.addNumericField("Bit mask - which of 4 transforms to combine after iclt", this.iclt_mask, 0);
gd.addNumericField("Tile X to extract (0..163)", this.tileX, 0);
gd.addNumericField("Tile Y to extract (0..122)", this.tileY, 0);
gd.addNumericField("dbg_mode: 0 - normal, +1 - no DCT/IDCT, just fold", this.dbg_mode, 0);
WindowTools.addScrollBars(gd);
gd.showDialog();
if (gd.wasCanceled()) return false;
this.transform_size= (int) gd.getNextNumber();
this.clt_window= (int) gd.getNextNumber();
this.shift_x = gd.getNextNumber();
this.shift_y = gd.getNextNumber();
this.iclt_mask= (int) gd.getNextNumber();
this.tileX= (int) gd.getNextNumber();
this.tileY= (int) gd.getNextNumber();
this.dbg_mode= (int) gd.getNextNumber();
return true;
}
}
public static class DCTParameters {
public int dct_size = 8; //
public int asym_size = 15; //
......
......@@ -65,7 +65,19 @@ public class Eyesis_Correction extends PlugInFrame implements ActionListener {
*
*/
private static final long serialVersionUID = -1507307664341265263L;
private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPostProcessing1,panelPostProcessing2,panelPostProcessing3,panelDct1;
private Panel panel1,
panel2,
panel3,
panel4,
panel5,
panel5a,
panel6,
panel7,
panelPostProcessing1,
panelPostProcessing2,
panelPostProcessing3,
panelDct1,
panelClt1;
JP46_Reader_camera JP4_INSTANCE=null;
// private deBayerScissors debayer_instance;
......@@ -95,6 +107,8 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
8 // seed_size
);
public static EyesisCorrectionParameters.CLTParameters CLT_PARAMETERS = new EyesisCorrectionParameters.CLTParameters();
public static EyesisDCT EYESIS_DCT = null;
public static EyesisCorrectionParameters.DebayerParameters DEBAYER_PARAMETERS = new EyesisCorrectionParameters.DebayerParameters(
......@@ -350,7 +364,7 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
instance = this;
addKeyListener(IJ.getInstance());
int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0) + (DCT_MODE?1:0);
int menuRows=4 + (ADVANCED_MODE?4:0) + (MODE_3D?3:0) + (DCT_MODE?2:0);
setLayout(new GridLayout(menuRows, 1));
panel6 = new Panel();
......@@ -467,6 +481,18 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
addButton("DCT process files", panelDct1, color_process);
add(panelDct1);
}
if (DCT_MODE) {
panelClt1 = new Panel();
panelClt1.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Setup CLT parameters", panelClt1, color_configure);
addButton("Select CLT image", panelClt1, color_configure);
addButton("CLT stack", panelClt1, color_process);
addButton("CLT test 1", panelClt1, color_process);
addButton("CLT test 2", panelClt1, color_process);
addButton("CLT test 3", panelClt1, color_process);
addButton("CLT test 4", panelClt1, color_process);
add(panelClt1);
}
pack();
GUI.center(this);
......@@ -3061,8 +3087,8 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
}
}
mxt[tileN] = tile.clone();
mxtf[tileN] = dtt.fold_tile (tile, n);
mxtfu[tileN] = dtt.unfold_tile (mxtf[tileN], n);
mxtf[tileN] = dtt.fold_tile (tile, n, 0); // DCCT
mxtfu[tileN] = dtt.unfold_tile (mxtf[tileN], n,0); // DCCT
mycc[tileN] = dtt.dttt_iv (mxtf[tileN], 0, n);
// mysc[tileN] = dtt.dttt_iv (mxtf[tileN], 1, n); // x - sin, y - cos
......@@ -3077,7 +3103,7 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
}
}
myt [tileN] = dtt.dttt_iv (myccx[tileN], 0, n);
imyt[tileN] = dtt.unfold_tile (myt [tileN], n); // each tile - imdct
imyt[tileN] = dtt.unfold_tile (myt [tileN], n, 0); // DCCT, each tile - imdct
for (int iy=0;iy<n2;iy++){
for (int ix=0;ix<n2;ix++){
......@@ -3583,6 +3609,150 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
// EyesisCorrectionParameters.DCTParameters dCTParameters,
// int srcKernelSize,
EYESIS_DCT.showKernels(); // show restored kernels
/* ======================================================================== */
} else if (label.equals("Setup CLT parameters")) {
CLT_PARAMETERS.showDialog();
return;
/* ======================================================================== */
// public ImagePlus DBG_IMP = null;
} else if (label.equals("Select CLT image")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
// process selected image stack
ImagePlus imp_src = WindowManager.getCurrentImage();
if (imp_src==null){
IJ.showMessage("Error","JP4 image or Bayer image stack required");
return;
}
if (imp_src.getStackSize()<3){ // convert JP4 to image stack
EyesisCorrectionParameters.SplitParameters split_parameters = new EyesisCorrectionParameters.SplitParameters(
1, // oversample;
// Add just for mdct (N/2)
CLT_PARAMETERS.transform_size/2, // addLeft
CLT_PARAMETERS.transform_size/2, // addTop
CLT_PARAMETERS.transform_size/2, // addRight
CLT_PARAMETERS.transform_size/2 // addBottom
);
ImageStack sourceStack= bayerToStack(imp_src, // source Bayer image, linearized, 32-bit (float))
split_parameters);
DBG_IMP = new ImagePlus(imp_src.getTitle()+"-SPIT", sourceStack);
if (DEBUG_LEVEL > 1) {
DBG_IMP.getProcessor().resetMinAndMax();
DBG_IMP.show();
}
} else {
DBG_IMP = imp_src;
}
/* ======================================================================== */
} else if (label.equals("CLT stack")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!CLT_PARAMETERS.showDialog()) return;
// process selected image stack
if (DBG_IMP == null) {
ImagePlus imp_src = WindowManager.getCurrentImage();
if (imp_src==null){
IJ.showMessage("Error","JP4 image or Bayer image stack required");
return;
}
// ImagePlus imp2;
if (imp_src.getStackSize()<3){ // convert JP4 to image stack
EyesisCorrectionParameters.SplitParameters split_parameters = new EyesisCorrectionParameters.SplitParameters(
1, // oversample;
CLT_PARAMETERS.transform_size/2, // addLeft
CLT_PARAMETERS.transform_size/2, // addTop
CLT_PARAMETERS.transform_size/2, // addRight
CLT_PARAMETERS.transform_size/2 // addBottom
);
ImageStack sourceStack= bayerToStack(imp_src, // source Bayer image, linearized, 32-bit (float))
split_parameters);
DBG_IMP = new ImagePlus(imp_src.getTitle()+"-SPIT", sourceStack);
DBG_IMP.getProcessor().resetMinAndMax();
DBG_IMP.show();
} else {
DBG_IMP = imp_src;
}
}
ImageDtt image_dtt = new ImageDtt();
double [][][][][] clt_data = image_dtt.cltStack(
DBG_IMP.getStack(),
0, // CLT_PARAMETERS.kernel_chn,
CLT_PARAMETERS,
THREADS_MAX, DEBUG_LEVEL, UPDATE_STATUS);
/*
for (int chn = 0; chn < clt_data.length; chn++) {
image_dtt.dct_lpf(
CLT_PARAMETERS.dbg_sigma,
clt_data[chn],
THREADS_MAX, DEBUG_LEVEL);
}
*/
int tilesY = DBG_IMP.getHeight()/CLT_PARAMETERS.transform_size - 1;
int tilesX = DBG_IMP.getWidth()/CLT_PARAMETERS.transform_size - 1;
System.out.println("'CLT stack': tilesX="+tilesX);
System.out.println("'CLT stack': tilesY="+tilesY);
double [][] clt = new double [clt_data.length*4][];
for (int chn = 0; chn < clt_data.length; chn++) {
double [][] clt_set = image_dtt.clt_dbg(
clt_data [chn],
THREADS_MAX,
DEBUG_LEVEL);
for (int ii = 0; ii < clt_set.length; ii++) clt[chn*4+ii] = clt_set[ii];
}
// System.out.println("dct_dc.length="+dct_dc.length+" dct_ac.length="+dct_ac.length);
if (DEBUG_LEVEL > 0){
SDFA_INSTANCE.showArrays(clt,
tilesX*CLT_PARAMETERS.transform_size,
tilesY*CLT_PARAMETERS.transform_size,
true,
DBG_IMP.getTitle()+"-CLT+"+CLT_PARAMETERS.iclt_mask);
}
if ((CLT_PARAMETERS.shift_x != 0) || (CLT_PARAMETERS.shift_y !=0)){
for (int chn = 0; chn < clt_data.length; chn++) {
clt_data[chn] = image_dtt.clt_shiftXY(
clt_data[chn], // final double [][][][] dct_data, // array [tilesY][tilesX][4][dct_size*dct_size]
CLT_PARAMETERS.transform_size, // final int dct_size,
CLT_PARAMETERS.shift_x, // final double shiftX,
CLT_PARAMETERS.shift_y, // final double shiftY,
(CLT_PARAMETERS.dbg_mode >> 2) & 3, // swap order hor/vert
THREADS_MAX, // maximal number of threads to launch
DEBUG_LEVEL); // globalDebugLevel)
}
}
double [][] iclt_data = new double [clt_data.length][];
for (int chn=0; chn<iclt_data.length;chn++){
iclt_data[chn] = image_dtt.iclt_2d(
clt_data[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
CLT_PARAMETERS.iclt_mask, //which of 4 to transform back
CLT_PARAMETERS.dbg_mode, //which of 4 to transform back
THREADS_MAX, // maximal number of threads to launch
DEBUG_LEVEL); // globalDebugLevel)
}
SDFA_INSTANCE.showArrays(
iclt_data,
(tilesX + 1) * CLT_PARAMETERS.transform_size,
(tilesY + 1) * CLT_PARAMETERS.transform_size,
true,
DBG_IMP.getTitle()+"-ICLT-"+CLT_PARAMETERS.iclt_mask);
return;
// End of buttons code
}
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
......@@ -4183,6 +4353,7 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
properties.setProperty("UPDATE_STATUS", UPDATE_STATUS+ "");
SPLIT_PARAMETERS.setProperties("SPLIT_PARAMETERS.", properties);
DCT_PARAMETERS.setProperties("DCT_PARAMETERS.", properties);
CLT_PARAMETERS.setProperties("CLT_PARAMETERS.", properties);
DEBAYER_PARAMETERS.setProperties("DEBAYER_PARAMETERS.", properties);
NONLIN_PARAMETERS.setProperties("NONLIN_PARAMETERS.", properties);
COLOR_PROC_PARAMETERS.setProperties("COLOR_PROC_PARAMETERS.", properties);
......@@ -4205,6 +4376,7 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
UPDATE_STATUS= Boolean.parseBoolean(properties.getProperty("UPDATE_STATUS"));
SPLIT_PARAMETERS.getProperties("SPLIT_PARAMETERS.", properties);
DCT_PARAMETERS.getProperties("DCT_PARAMETERS.", properties);
CLT_PARAMETERS.getProperties("CLT_PARAMETERS.", properties);
DEBAYER_PARAMETERS.getProperties("DEBAYER_PARAMETERS.", properties);
NONLIN_PARAMETERS.getProperties("NONLIN_PARAMETERS.", properties);
COLOR_PROC_PARAMETERS.getProperties("COLOR_PROC_PARAMETERS.", properties);
......
......@@ -51,7 +51,7 @@ public class ImageDtt {
// Extract float pixels from inage stack, convert each to double
EyesisDCT.DCTKernels dct_kernels = null;
dct_kernels = eyesisDCT.kernels[subcamera];
dct_kernels = ((eyesisDCT==null) || (eyesisDCT.kernels==null))?null:eyesisDCT.kernels[subcamera];
if (dct_kernels == null){
System.out.println("No DCT kernels available for subcamera # "+subcamera);
} else if (debugLevel>0){
......@@ -269,7 +269,7 @@ public class ImageDtt {
System.arraycopy(dpixels, (tileY*width+tileX)*dct_size + i*width, tile_in, i*n2, n2);
}
}
tile_folded=dtt.fold_tile(tile_in, dct_size);
tile_folded=dtt.fold_tile(tile_in, dct_size, 0); // DCCT
tile_out=dtt.dttt_iv (tile_folded, dct_mode, dct_size);
if ((dct_kernels != null) && !skip_sym){ // convolve in frequency domain with sym_kernel
double s0 =0;
......@@ -586,7 +586,6 @@ public class ImageDtt {
// Restore DC
public double [] lapped_idct(
// final double [][][] dctdc_data, // array [tilesY][tilesX][dct_size*dct_size+1] - last element is DC value
final double [][][] dct_data, // array [tilesY][tilesX][dct_size*dct_size]
......@@ -642,7 +641,7 @@ public class ImageDtt {
tileY = tiles_list[nser.get()][nTile][1];
System.arraycopy(dct_data[tileY][tileX], 0, tile_in, 0, tile_in.length);
tile_dct=dtt.dttt_iv (tile_in, 0, dct_size);
tile_out=dtt.unfold_tile(tile_dct, dct_size);
tile_out=dtt.unfold_tile(tile_dct, dct_size, 0); // mpode=0 - DCCT
for (int i = 0; i < n2;i++){
int start_line = ((tileY*dct_size + i) *(tilesX+1) + tileX)*dct_size;
for (int j = 0; j<n2;j++) {
......@@ -657,7 +656,402 @@ public class ImageDtt {
}
return dpixels;
}
// perform 2d clt, result is [tileY][tileX][cc_sc_cs_ss][index_in_tile]
public double [][][][] clt_2d(
final double [] dpixels,
final int width,
final int dct_size,
final int window_type,
final int debug_tileX,
final int debug_tileY,
final int debug_mode,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int height=dpixels.length/width;
final int tilesX=width/dct_size-1;
final int tilesY=height/dct_size-1;
final int nTiles=tilesX*tilesY;
final double [][][][] dct_data = new double[tilesY][tilesX][4][dct_size*dct_size];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
for (int dct_mode = 0; dct_mode < dct_data[tileY][tileX].length; dct_mode++){
for (int i=0; i<dct_data[tileY][tileX][dct_mode].length;i++) {
dct_data[tileY][tileX][dct_mode][i]= 0.0; // actually not needed, Java initializes arrays
}
}
}
}
double [] dc = new double [dct_size*dct_size];
for (int i = 0; i<dc.length; i++) dc[i] = 1.0;
DttRad2 dtt0 = new DttRad2(dct_size);
dtt0.set_window(window_type);
if (globalDebugLevel > 0) {
System.out.println("clt_2d(): width="+width+" height="+height+" dct_size="+dct_size+
" debug_tileX="+debug_tileX+" debug_tileY="+debug_tileY+" globalDebugLevel="+globalDebugLevel);
}
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
DttRad2 dtt = new DttRad2(dct_size);
dtt.set_window(window_type);
double [] tile_in = new double[4*dct_size * dct_size];
double [][] tile_folded = new double[4][];
double [][] tile_out = new double[4][]; // = new double[dct_size * dct_size];
int tileY,tileX;
int n2 = dct_size * 2;
// showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
for (int i = 0; i < n2;i++){
System.arraycopy(dpixels, (tileY*width+tileX)*dct_size + i*width, tile_in, i*n2, n2);
}
for (int dct_mode = 0; dct_mode <4; dct_mode++) {
tile_folded[dct_mode] = dtt.fold_tile(tile_in, dct_size, dct_mode); // DCCT, DSCT, DCST, DSST
if ((debug_mode & 1) != 0) {
tile_out[dct_mode] = tile_folded[dct_mode];
} else {
tile_out[dct_mode] = dtt.dttt_iv (tile_folded[dct_mode], dct_mode, dct_size);
}
System.arraycopy(tile_out[dct_mode], 0, dct_data[tileY][tileX][dct_mode], 0, tile_out[dct_mode].length);
}
if ((globalDebugLevel > 0) && (debug_tileX == tileX) && (debug_tileY == tileY)) {
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(tile_in, n2, n2, "tile_in_x"+tileX+"_y"+tileY);
String [] titles = {"CC","SC","CS","SS"};
sdfa_instance.showArrays(tile_folded, dct_size, dct_size, true, "folded_x"+tileX+"_y"+tileY, titles);
sdfa_instance.showArrays(tile_out, dct_size, dct_size, true, "clt_x"+tileX+"_y"+tileY, titles);
}
}
}
};
}
startAndJoin(threads);
return dct_data;
}
public double [] iclt_2d(
final double [][][][] dct_data, // array [tilesY][tilesX][4][dct_size*dct_size]
final int dct_size,
final int window_type,
final int debug_mask, // which transforms to combine
final int debug_mode, // skip idct - just unfold
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=dct_data.length;
final int tilesX=dct_data[0].length;
final int width= (tilesX+1)*dct_size;
final int height= (tilesY+1)*dct_size;
final double debug_scale = 1.0 /((debug_mask & 1) + ((debug_mask >> 1) & 1) + ((debug_mask >> 2) & 1) + ((debug_mask >> 3) & 1));
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():debug_mask= "+debug_mask);
System.out.println("iclt_2d():debug_scale= "+debug_scale);
}
final double [] dpixels = new double[width*height];
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 i=0; i<dpixels.length;i++) dpixels[i]= 0;
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() {
DttRad2 dtt = new DttRad2(dct_size);
dtt.set_window(window_type);
double [] tile_in = new double [dct_size * dct_size];
double [] tile_dct;
double [] tile_mdct;
int tileY,tileX;
int n2 = dct_size * 2;
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
for (int i = 0; i < n2;i++){
int start_line = ((tileY*dct_size + i) *(tilesX+1) + tileX)*dct_size;
for (int j = 0; j<n2;j++) {
dpixels[start_line + j] += debug_scale * tile_mdct[n2 * i + j]; // add (cc+sc+cs+ss)/4
}
}
}
}
}
};
}
startAndJoin(threads);
}
return dpixels;
}
public double [][][][] clt_shiftXY(
final double [][][][] dct_data, // array [tilesY][tilesX][4][dct_size*dct_size]
final int dct_size,
final double shiftX,
final double shiftY,
final int dbg_swap_mode,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=dct_data.length;
final int tilesX=dct_data[0].length;
final int nTiles = tilesY* tilesX;
final int width= (tilesX+1)*dct_size;
final int height= (tilesY+1)*dct_size;
if (globalDebugLevel > 0) {
System.out.println("clt_shift():tilesX= "+tilesX);
System.out.println("clt_shift():tilesY= "+tilesY);
System.out.println("clt_shift():width= "+width);
System.out.println("clt_shift():height= "+height);
System.out.println("clt_shift():shiftX= "+shiftX);
System.out.println("clt_shift():shiftY= "+shiftY);
}
final double [] cos_hor = new double [dct_size*dct_size];
final double [] sin_hor = new double [dct_size*dct_size];
final double [] cos_vert = new double [dct_size*dct_size];
final double [] sin_vert = new double [dct_size*dct_size];
for (int i = 0; i < dct_size; i++){
double ch = Math.cos((i+0.5)*Math.PI*shiftX/dct_size);
double sh = Math.sin((i+0.5)*Math.PI*shiftX/dct_size);
double cv = Math.cos((i+0.5)*Math.PI*shiftY/dct_size);
double sv = Math.sin((i+0.5)*Math.PI*shiftY/dct_size);
for (int j = 0; j < dct_size; j++){
int ih = dct_size * j + i;
int iv = dct_size * i + j;
cos_hor[ih] = ch;
sin_hor[ih] = sh;
cos_vert[iv] = cv;
sin_vert[iv] = sv;
}
}
if (globalDebugLevel > 0){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
String [] titles = {"cos_hor","sin_hor","cos_vert","sin_vert"};
double [][] cs_dbg = {cos_hor, sin_hor, cos_vert, sin_vert};
sdfa_instance.showArrays(cs_dbg, dct_size, dct_size, true, "shift_cos_sin", titles);
}
final double [][][][] rslt = new double[dct_data.length][dct_data[0].length][dct_data[0][0].length][dct_data[0][0][0].length];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int tileY,tileX;
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
// Horizontal shift
if (dbg_swap_mode == 1) {
for (int i = 0; i < cos_hor.length; i++) {
rslt[tileY][tileX][0][i] = dct_data[tileY][tileX][0][i] * cos_vert[i] - dct_data[tileY][tileX][1][i] * sin_vert[i];
rslt[tileY][tileX][1][i] = dct_data[tileY][tileX][1][i] * cos_vert[i] + dct_data[tileY][tileX][0][i] * sin_vert[i] ;
rslt[tileY][tileX][2][i] = dct_data[tileY][tileX][2][i] * cos_vert[i] - dct_data[tileY][tileX][3][i] * sin_vert[i];
rslt[tileY][tileX][3][i] = dct_data[tileY][tileX][3][i] * cos_vert[i] + dct_data[tileY][tileX][2][i] * sin_vert[i] ;
}
// Vertical shift (in-place)
for (int i = 0; i < cos_hor.length; i++) {
double tmp = rslt[tileY][tileX][0][i] * cos_hor[i] - rslt[tileY][tileX][2][i] * sin_hor[i];
rslt[tileY][tileX][2][i] = rslt[tileY][tileX][2][i] * cos_hor[i] + rslt[tileY][tileX][0][i] * sin_hor[i];
rslt[tileY][tileX][0][i] = tmp;
tmp = rslt[tileY][tileX][1][i] * cos_hor[i] - rslt[tileY][tileX][3][i] * sin_hor[i];
rslt[tileY][tileX][3][i] = rslt[tileY][tileX][3][i] * cos_hor[i] + rslt[tileY][tileX][1][i] * sin_hor[i];
rslt[tileY][tileX][1][i] = tmp;
}
} else if (dbg_swap_mode == 0) {
// Horizontal shift
for (int i = 0; i < cos_hor.length; i++) {
rslt[tileY][tileX][0][i] = dct_data[tileY][tileX][0][i] * cos_hor[i] - dct_data[tileY][tileX][1][i] * sin_hor[i];
rslt[tileY][tileX][1][i] = dct_data[tileY][tileX][1][i] * cos_hor[i] + dct_data[tileY][tileX][0][i] * sin_hor[i];
rslt[tileY][tileX][2][i] = dct_data[tileY][tileX][2][i] * cos_hor[i] - dct_data[tileY][tileX][3][i] * sin_hor[i];
rslt[tileY][tileX][3][i] = dct_data[tileY][tileX][3][i] * cos_hor[i] + dct_data[tileY][tileX][2][i] * sin_hor[i];
}
// Vertical shift (in-place)
for (int i = 0; i < cos_hor.length; i++) {
double tmp = rslt[tileY][tileX][0][i] * cos_vert[i] - rslt[tileY][tileX][2][i] * sin_vert[i];
rslt[tileY][tileX][2][i] = rslt[tileY][tileX][2][i] * cos_vert[i] + rslt[tileY][tileX][0][i] * sin_vert[i];
rslt[tileY][tileX][0][i] = tmp;
tmp = rslt[tileY][tileX][1][i] * cos_vert[i] - rslt[tileY][tileX][3][i] * sin_vert[i];
rslt[tileY][tileX][3][i] = rslt[tileY][tileX][3][i] * cos_vert[i] + rslt[tileY][tileX][1][i] * sin_vert[i];
rslt[tileY][tileX][1][i] = tmp;
}
} else if (dbg_swap_mode == 3) {
for (int i = 0; i < cos_hor.length; i++) {
rslt[tileY][tileX][0][i] = dct_data[tileY][tileX][0][i] * cos_vert[i] - dct_data[tileY][tileX][1][i] * sin_vert[i];
rslt[tileY][tileX][1][i] = dct_data[tileY][tileX][1][i] * cos_vert[i] + dct_data[tileY][tileX][0][i] * sin_vert[i];
rslt[tileY][tileX][2][i] = dct_data[tileY][tileX][2][i] * cos_vert[i] + dct_data[tileY][tileX][3][i] * sin_vert[i];
rslt[tileY][tileX][3][i] = dct_data[tileY][tileX][3][i] * cos_vert[i] - dct_data[tileY][tileX][2][i] * sin_vert[i];
}
// Vertical shift (in-place)
for (int i = 0; i < cos_hor.length; i++) {
double tmp = rslt[tileY][tileX][0][i] * cos_hor[i] - rslt[tileY][tileX][2][i] * sin_hor[i];
rslt[tileY][tileX][2][i] = rslt[tileY][tileX][2][i] * cos_hor[i] + rslt[tileY][tileX][0][i] * sin_hor[i];
rslt[tileY][tileX][0][i] = tmp;
tmp = rslt[tileY][tileX][1][i] * cos_hor[i] + rslt[tileY][tileX][3][i] * sin_hor[i];
rslt[tileY][tileX][3][i] = rslt[tileY][tileX][3][i] * cos_hor[i] - rslt[tileY][tileX][1][i] * sin_hor[i];
rslt[tileY][tileX][1][i] = tmp;
}
} else if (dbg_swap_mode == 2) {
// Horizontal shift
for (int i = 0; i < cos_hor.length; i++) {
rslt[tileY][tileX][0][i] = dct_data[tileY][tileX][0][i] * cos_hor[i] - dct_data[tileY][tileX][1][i] * sin_hor[i];
rslt[tileY][tileX][1][i] = dct_data[tileY][tileX][1][i] * cos_hor[i] + dct_data[tileY][tileX][0][i] * sin_hor[i];
rslt[tileY][tileX][2][i] = dct_data[tileY][tileX][2][i] * cos_hor[i] + dct_data[tileY][tileX][3][i] * sin_hor[i];
rslt[tileY][tileX][3][i] = dct_data[tileY][tileX][3][i] * cos_hor[i] - dct_data[tileY][tileX][2][i] * sin_hor[i];
}
// Vertical shift (in-place)
for (int i = 0; i < cos_hor.length; i++) {
double tmp = rslt[tileY][tileX][0][i] * cos_vert[i] - rslt[tileY][tileX][2][i] * sin_vert[i];
rslt[tileY][tileX][2][i] = rslt[tileY][tileX][2][i] * cos_vert[i] + rslt[tileY][tileX][0][i] * sin_vert[i];
rslt[tileY][tileX][0][i] = tmp;
tmp = rslt[tileY][tileX][1][i] * cos_vert[i] + rslt[tileY][tileX][3][i] * sin_vert[i];
rslt[tileY][tileX][3][i] = rslt[tileY][tileX][3][i] * cos_vert[i] - rslt[tileY][tileX][1][i] * sin_vert[i];
rslt[tileY][tileX][1][i] = tmp;
}
}
}
}
};
}
startAndJoin(threads);
return rslt;
}
public double [][][][][] cltStack(
final ImageStack imageStack,
final int subcamera, //
final EyesisCorrectionParameters.CLTParameters cltParameters, //
// final EyesisDCT eyesisDCT,
final int threadsMax, // maximal step in pixels on the maxRadius for 1 angular step (i.e. 0.5)
final int debugLevel,
final boolean updateStatus) // update status info
{
if (imageStack==null) return null;
final int imgWidth=imageStack.getWidth();
final int nChn=imageStack.getSize();
double [][][][][] dct_data = new double [nChn][][][][];
float [] fpixels;
int i,chn; //tileX,tileY;
/* find number of the green channel - should be called "green", if none - use last */
// Extract float pixels from inage stack, convert each to double
// EyesisDCT.DCTKernels dct_kernels = null;
// dct_kernels = eyesisDCT.kernels[subcamera];
// if (dct_kernels == null){
// System.out.println("No DCT kernels available for subcamera # "+subcamera);
// } else if (debugLevel>0){
// System.out.println("Using DCT kernels for subcamera # "+subcamera);
// }
// if (dctParameters.kernel_chn >=0 ){
// dct_kernels = eyesisDCT.kernels[dctParameters.kernel_chn];
// }
for (chn=0;chn<nChn;chn++) {
fpixels= (float[]) imageStack.getPixels(chn+1);
double[] dpixels = new double[fpixels.length];
for (i = 0; i <fpixels.length;i++) dpixels[i] = fpixels[i];
// convert each to DCT tiles
dct_data[chn] = clt_2d(
dpixels,
imgWidth,
cltParameters.transform_size,
cltParameters.clt_window,
cltParameters.tileX, // debug_tileX,
cltParameters.tileY, // debug_tileY,
cltParameters.dbg_mode, // debug_mode,
threadsMax, // maximal number of threads to launch
debugLevel);
}
return dct_data;
}
// extract DCT transformed parameters in linescan order (for visualization)
public double [][] clt_dbg(
final double [][][][] dct_data,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=dct_data.length;
final int tilesX=dct_data[0].length;
final int nTiles=tilesX*tilesY;
final int dct_size = (int) Math.round(Math.sqrt(dct_data[0][0][0].length));
final int dct_len = dct_size*dct_size;
final double [][] dct_data_out = new double[4][tilesY*tilesX*dct_len];
System.out.println("clt_dbg(): tilesY="+tilesY+", tilesX="+tilesX+", dct_size="+dct_size+", dct_len="+dct_len+", dct_data_out[0].length="+dct_data_out[0].length);
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int n=0; n<dct_data_out.length;n++) for (int i=0; i<dct_data_out[n].length;i++) dct_data_out[n][i]= 0;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int tileY,tileX;
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
for (int n=0; n<dct_data_out.length;n++) {
for (int i = 0; i < dct_size;i++){
System.arraycopy(dct_data[tileY][tileX][n], dct_size* i, dct_data_out[n], ((tileY*dct_size + i) *tilesX + tileX)*dct_size , dct_size);
}
}
}
}
};
}
startAndJoin(threads);
return dct_data_out;
}
public double [][][][] mdctScale(
final ImageStack imageStack,
final int subcamera, //
......@@ -755,7 +1149,7 @@ public class ImageDtt {
double [] tile_folded;
double [] tile_out; // = new double[dct_size * dct_size];
int tileY,tileX;
double [][] fold_k = dtt.get_fold_2d(
double [][][] fold_k = dtt.get_fold_2d(
// int n,
scale_hor,
scale_vert
......@@ -770,7 +1164,7 @@ public class ImageDtt {
for (int i = 0; i < n2;i++){
System.arraycopy(dpixels, (tileY*width+tileX)*src_size + i*width, tile_in, i*n2, n2);
}
tile_folded=dtt.fold_tile(tile_in, dct_size, fold_k);
tile_folded=dtt.fold_tile(tile_in, dct_size, 0, fold_k); // DCCT
tile_out=dtt.dttt_iv (tile_folded, dct_mode, dct_size);
// if ((tileY == debug_tileY) && (tileX == debug_tileX) && (color == 2)) {
......
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