Commit b15f9feb authored by Andrey Filippov's avatar Andrey Filippov

Merge remote-tracking branch 'origin/dct'

parents c7e1de46 7c36f258
......@@ -12003,7 +12003,11 @@ if (MORE_BUTTONS) {
int loopDebugLevel){
boolean noMove=false;
if (newMotorPos==null) {
try {
newMotorPos=focusingMotors.readElphel10364Motors().clone();
} catch (Exception e){
System.out.println("moveAndMaybeProbe(): Failed to read motors");
}
justMove=true;
noMove=true;
}
......@@ -12098,7 +12102,11 @@ if (MORE_BUTTONS) {
// System.out.println(">"+focusingMotors.historySize()+": "+focusingMotors.curpos[0]+", "+focusingMotors.curpos[1]+", "+focusingMotors.curpos[2]);
boolean noMove=false;
if (newMotorPos==null) {
try {
newMotorPos=focusingMotors.readElphel10364Motors().clone();
} catch (Exception e){
System.out.println("moveMeasureAndSave(): motors unreachable.");
}
noMove=true;
}
if (!noMove)focusingMotors.moveElphel10364Motors(
......@@ -2671,7 +2671,7 @@ public class CalibrationHardwareInterface {
}
boolean result=commandToDevice(command);
updateCurrents();
if (result) updateCurrents();
return result;
}
......@@ -2718,7 +2718,8 @@ public class CalibrationHardwareInterface {
String msg = e1.getMessage();
if (msg==null || msg.equals("")) msg = ""+e1;
IJ.showMessage("Error",msg);
throw new IllegalArgumentException (msg);
return false;
// throw new IllegalArgumentException (msg);
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
return false;
......@@ -3471,7 +3472,9 @@ public class CalibrationHardwareInterface {
IJ.showStatus("");
String error = e1.getMessage();
if (error==null || error.equals("")) error = ""+e1;
IJ.showMessage("commandElphel10364Motors ERRROR", ""+error);
System.out.println("commandElphel10364Motors ERRROR: "+error);
// *********** Temporary removed message box (usually "HOST UNREACHABLE") *************
// IJ.showMessage("commandElphel10364Motors ERRROR", ""+error);
return null;
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
......@@ -6529,7 +6532,9 @@ if (debugLevel>=debugThreshold) System.out.println(i+" "+diff[0]+" "+diff[1]+" "
}
public double distFromProbed(int [] position){
double minDist=Double.NaN;
if (this.history.size() <1) return Double.NaN;
if (position==null) position= this.history.get(this.history.size()-1).motorsPos;
if (this.history.size()>0){
for (int i=0;i<this.history.size();i++) if (this.history.get(i).isProbed) {
int [] probedPosition=this.history.get(i).motorsPos;
......
......@@ -1691,16 +1691,26 @@ import org.apache.commons.configuration.XMLConfiguration;
if (gridImages!=null) {
// this.pathName=""; // modified, keep the path anyway
// overwrite saved paths with the provided images, number of images{ should match
if (this.gIP.length!=gridImages.length){
String msg="Number of provided images ("+gridImages.length+") does not match parameters restored from the "+pathname+" ("+this.gIP.length+")";
IJ.showMessage("Error",msg);
throw new IllegalArgumentException (msg);
}
if (this.gIP.length == gridImages.length){
for (int i=0;i<this.gIP.length;i++){
this.gIP[i].gridImage=gridImages[i];
this.gIP[i].path=null; // not needed, just in case
this.gIP[i].enabled=true;// enable all (actually just one) acquired images
}
} else {
String msg="Number of provided images ("+gridImages.length+") does not match parameters restored from the "+pathname+" ("+this.gIP.length+")";
IJ.showMessage("Error",msg);
// throw new IllegalArgumentException (msg);
for (int i=0; i<this.gIP.length ; i++){
this.gIP[i].path=null; // not needed, just in case
this.gIP[i].enabled=true;// enable all (actually just one) acquired images
if (i < gridImages.length) {
this.gIP[i].gridImage=gridImages[i];
} else {
this.gIP[i].gridImage=null;
}
}
}
// setGridImages(gridImages);
}
readAllGrids(patternParameters); // prepare grid parameters for LMA
......@@ -2080,7 +2090,7 @@ import org.apache.commons.configuration.XMLConfiguration;
imp_grid=this.gIP[numGridImg].gridImage;
} else {
if (this.updateStatus) IJ.showStatus("Reading grid file "+(fileNumber+1)+" (of "+(numImages)+"): "+this.gIP[fileNumber].path);
if (this.debugLevel>1) System.out.print(fileNumber+" ("+this.gIP[fileNumber].getStationNumber()+"): "+this.gIP[fileNumber].path);
if (this.debugLevel>-1) System.out.print(fileNumber+" ("+this.gIP[fileNumber].getStationNumber()+"): "+this.gIP[fileNumber].path);
imp_grid=opener.openImage("", this.gIP[fileNumber].path); // or (path+filenames[nFile])
if (imp_grid==null) {
String msg="Failed to read grid file "+this.gIP[fileNumber].path;
......
......@@ -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,45 +120,120 @@ 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(
double scale_hor,
double scale_vert)
{
return get_fold_2d( this.N, scale_hor, scale_vert);
}
public double [][][] get_fold_2d(
int n,
double scale_hor,
double scale_vert
){ // n - DCT and window size
// if ((fold_index != null) && (fold_index.length == n*n)) return;
// fold_index = new int[n*n][4];
double [] hwindow_h = new double[n];
double [] hwindow_v = new double[n];
double f = Math.PI/(2.0*n);
for (int i = 0; i < n; i++ ) {
double ah = f*scale_hor * (n-i-0.5);
double av = f*scale_vert * (n-i-0.5);
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[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][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][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 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;
......@@ -167,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);
......@@ -202,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));
......@@ -347,28 +474,53 @@ 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
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;
// for (int k = 0; k < 4; k++){
// y[i] += x[fold_index[i][k]] * fold_k[i][k];
// }
// }
// return y;
}
public double [] fold_tile(
double [] x,
int n,
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;
}
......
......@@ -102,7 +102,7 @@ public class EyesisCorrectionParameters {
public boolean planeAsJPEG= true; // save de-warped image as JPEG (only if equirectangularFormat==0)
// public String equirectangularSuffixA="A.eqr-tiff"; // or the roll-over part
public String resultsDirectory="";
public boolean removeUnusedSensorData=true;
public boolean removeUnusedSensorData=false;
public int exposureCorrectionMode=2; // - 0 - none, 1 - absolute, 2 - relative
public double referenceExposure=0.0003; // 3/10000 sec, used in absolute mode only
public double relativeExposure=0.5; // 0.0 - use shortest (darken), 1.0 - use longest (brighten)
......@@ -1772,6 +1772,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; //
......@@ -1791,6 +1849,9 @@ public class EyesisCorrectionParameters {
public double dbg_x1 = -1.3;
public double dbg_y1 = 2.0;
public double dbg_sigma = 0.8;
public double dbg_src_size = 8.0; // trying to slightly scale in dct space. == dct = 1:1, dct+1.0 - shrink dct(dct+1.0)
public double dbg_scale = 1.0; // Should ==DCT_PARAMETERS.dct_size / DCT_PARAMETERS.dbg_src_size
public double dbg_fold_scale = 1.0; // Modifies window during MDCT->DCT-IV folding
public String dbg_mask = ".........:::::::::.........:::::::::......*..:::::*:::.........:::::::::.........";
public int dbg_mode = 1; // 0 - old LMA, 1 - new LMA - *** not used anymore ***
public int dbg_window_mode = 1; // 0 - none, 1 - square, 2 - sin 3 - sin^2 Now _should_ be square !!!
......@@ -1801,16 +1862,26 @@ public class EyesisCorrectionParameters {
public double decimateSigma = -1.0; // special mode for 2:1 deciamtion
public int tileX = 82; // number of kernel tile (0..163)
public int tileY = 62; // number of kernel tile (0..122)
public boolean subtract_dc = false;//subtract/restore dc
public int kernel_chn = -1; // camera channel calibration to use for aberration correction ( < 0 - no correction)
public boolean normalize = true; //normalize both sym and asym kernels (asym to have sum==1, sym to have sum = dct_size
public boolean normalize_sym = true; //normalize sym kernels separately
public boolean normalize = true; // normalize both sym and asym kernels (asym to have sum==1, sym to have sum = dct_size
public boolean normalize_sym = true; // normalize sym kernels separately
public boolean antiwindow = false; // divide symmetrical kernel by a window function
public boolean skip_sym = false; // do not apply symmetrical correction
public boolean convolve_direct = false; // do not apply symmetrical correction
// colors should be balanced before DCT color conversion!
public double novignetting_r = 0.2644; // reg gain in the center of sensor calibration R (instead of vignetting)
public double novignetting_g = 0.3733; // green gain in the center of sensor calibration G
public double novignetting_b = 0.2034; // blue gain in the center of sensor calibration B
public double scale_r = 1.0; // extra gain correction after vignetting or nonvignetting, before other processing
public double scale_g = 1.0;
public double scale_b = 1.0;
public double vignetting_max = 0.4; // value in vignetting data to correspond to 1x in the kernel
public double vignetting_range = 5.0; // do not try to correct vignetting less than vignetting_max/vignetting_range
public boolean post_debayer = false; // perform de-bayer after aberrations in pixel domain
public boolean color_DCT = true; // false - use old color processing mode
public double sigma_rb = 0.9; // additional (to G) blur for R and B
public double sigma_y = 0.7; // blur for G contribution to Y
......@@ -1868,6 +1939,9 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"dbg_x1", this.dbg_x1+"");
properties.setProperty(prefix+"dbg_y1", this.dbg_y1+"");
properties.setProperty(prefix+"dbg_sigma", this.dbg_sigma+"");
properties.setProperty(prefix+"dbg_src_size",this.dbg_src_size+"");
properties.setProperty(prefix+"dbg_scale", this.dbg_scale+"");
properties.setProperty(prefix+"dbg_fold_scale", this.dbg_fold_scale+"");
properties.setProperty(prefix+"dbg_mask", this.dbg_mask+"");
properties.setProperty(prefix+"dbg_mode", this.dbg_mode+"");
properties.setProperty(prefix+"dbg_window_mode", this.dbg_window_mode+"");
......@@ -1877,27 +1951,32 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"decimateSigma", this.decimateSigma+"");
properties.setProperty(prefix+"tileX", this.tileX+"");
properties.setProperty(prefix+"tileY", this.tileY+"");
properties.setProperty(prefix+"subtract_dc", this.subtract_dc+"");
properties.setProperty(prefix+"kernel_chn", this.kernel_chn+"");
properties.setProperty(prefix+"normalize", this.normalize+"");
properties.setProperty(prefix+"normalize_sym", this.normalize_sym+"");
properties.setProperty(prefix+"antiwindow", this.antiwindow+"");
properties.setProperty(prefix+"skip_sym", this.skip_sym+"");
properties.setProperty(prefix+"convolve_direct", this.convolve_direct+"");
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+"");
properties.setProperty(prefix+"vignetting_max", this.vignetting_max+"");
properties.setProperty(prefix+"vignetting_range", this.vignetting_range+"");
properties.setProperty(prefix+"post_debayer", this.post_debayer+"");
properties.setProperty(prefix+"color_DCT", this.color_DCT+"");
properties.setProperty(prefix+"sigma_rb", this.sigma_rb+"");
properties.setProperty(prefix+"sigma_y", this.sigma_y+"");
properties.setProperty(prefix+"sigma_color", this.sigma_color+"");
properties.setProperty(prefix+"line_thershold", this.line_thershold+"");
properties.setProperty(prefix+"nonlin", this.nonlin+"");
properties.setProperty(prefix+"nonlin_max_y", this.nonlin_max_y+"");
properties.setProperty(prefix+"nonlin_max_c", this.nonlin_max_c+"");
properties.setProperty(prefix+"nonlin_y", this.nonlin_y+"");
properties.setProperty(prefix+"nonlin_c", this.nonlin_c+"");
properties.setProperty(prefix+"nonlin_corn", this.nonlin_corn+"");
properties.setProperty(prefix+"denoise", this.denoise+"");
properties.setProperty(prefix+"denoise_y", this.denoise_y+"");
properties.setProperty(prefix+"denoise_c", this.denoise_c+"");
......@@ -1926,6 +2005,9 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"dbg_x1")!=null) this.dbg_x1=Double.parseDouble(properties.getProperty(prefix+"dbg_x1"));
if (properties.getProperty(prefix+"dbg_y1")!=null) this.dbg_y1=Double.parseDouble(properties.getProperty(prefix+"dbg_y1"));
if (properties.getProperty(prefix+"dbg_sigma")!=null) this.dbg_sigma=Double.parseDouble(properties.getProperty(prefix+"dbg_sigma"));
if (properties.getProperty(prefix+"dbg_src_size")!=null) this.dbg_src_size=Double.parseDouble(properties.getProperty(prefix+"dbg_src_size"));
if (properties.getProperty(prefix+"dbg_scale")!=null) this.dbg_scale=Double.parseDouble(properties.getProperty(prefix+"dbg_scale"));
if (properties.getProperty(prefix+"dbg_fold_scale")!=null) this.dbg_fold_scale=Double.parseDouble(properties.getProperty(prefix+"dbg_fold_scale"));
if (properties.getProperty(prefix+"dbg_mask")!=null) this.dbg_mask=properties.getProperty(prefix+"dbg_mask");
if (properties.getProperty(prefix+"dbg_mode")!=null) this.dbg_mode=Integer.parseInt(properties.getProperty(prefix+"dbg_mode"));
if (properties.getProperty(prefix+"centerWindowToTarget")!=null) this.centerWindowToTarget=Boolean.parseBoolean(properties.getProperty(prefix+"centerWindowToTarget"));
......@@ -1935,27 +2017,32 @@ public class EyesisCorrectionParameters {
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_window_mode")!=null) this.dbg_window_mode=Integer.parseInt(properties.getProperty(prefix+"dbg_window_mode"));
if (properties.getProperty(prefix+"subtract_dc")!=null) this.subtract_dc=Boolean.parseBoolean(properties.getProperty(prefix+"subtract_dc"));
if (properties.getProperty(prefix+"kernel_chn")!=null) this.kernel_chn=Integer.parseInt(properties.getProperty(prefix+"kernel_chn"));
if (properties.getProperty(prefix+"normalize")!=null) this.normalize=Boolean.parseBoolean(properties.getProperty(prefix+"normalize"));
if (properties.getProperty(prefix+"normalize_sym")!=null) this.normalize_sym=Boolean.parseBoolean(properties.getProperty(prefix+"normalize_sym"));
if (properties.getProperty(prefix+"antiwindow")!=null) this.antiwindow=Boolean.parseBoolean(properties.getProperty(prefix+"antiwindow"));
if (properties.getProperty(prefix+"skip_sym")!=null) this.skip_sym=Boolean.parseBoolean(properties.getProperty(prefix+"skip_sym"));
if (properties.getProperty(prefix+"convolve_direct")!=null) this.convolve_direct=Boolean.parseBoolean(properties.getProperty(prefix+"convolve_direct"));
if (properties.getProperty(prefix+"novignetting_r")!=null) this.novignetting_r=Double.parseDouble(properties.getProperty(prefix+"novignetting_r"));
if (properties.getProperty(prefix+"novignetting_g")!=null) this.novignetting_g=Double.parseDouble(properties.getProperty(prefix+"novignetting_g"));
if (properties.getProperty(prefix+"novignetting_b")!=null) this.novignetting_b=Double.parseDouble(properties.getProperty(prefix+"novignetting_b"));
if (properties.getProperty(prefix+"scale_r")!=null) this.scale_r=Double.parseDouble(properties.getProperty(prefix+"scale_r"));
if (properties.getProperty(prefix+"scale_g")!=null) this.scale_g=Double.parseDouble(properties.getProperty(prefix+"scale_g"));
if (properties.getProperty(prefix+"scale_b")!=null) this.scale_b=Double.parseDouble(properties.getProperty(prefix+"scale_b"));
if (properties.getProperty(prefix+"vignetting_max")!=null) this.vignetting_max=Double.parseDouble(properties.getProperty(prefix+"vignetting_max"));
if (properties.getProperty(prefix+"vignetting_range")!=null) this.vignetting_range=Double.parseDouble(properties.getProperty(prefix+"vignetting_range"));
if (properties.getProperty(prefix+"post_debayer")!=null) this.post_debayer=Boolean.parseBoolean(properties.getProperty(prefix+"post_debayer"));
if (properties.getProperty(prefix+"color_DCT")!=null) this.color_DCT=Boolean.parseBoolean(properties.getProperty(prefix+"color_DCT"));
if (properties.getProperty(prefix+"sigma_rb")!=null) this.sigma_rb=Double.parseDouble(properties.getProperty(prefix+"sigma_rb"));
if (properties.getProperty(prefix+"sigma_y")!=null) this.sigma_y=Double.parseDouble(properties.getProperty(prefix+"sigma_y"));
if (properties.getProperty(prefix+"sigma_color")!=null) this.sigma_color=Double.parseDouble(properties.getProperty(prefix+"sigma_color"));
if (properties.getProperty(prefix+"line_thershold")!=null) this.line_thershold=Double.parseDouble(properties.getProperty(prefix+"line_thershold"));
if (properties.getProperty(prefix+"nonlin")!=null) this.nonlin=Boolean.parseBoolean(properties.getProperty(prefix+"nonlin"));
if (properties.getProperty(prefix+"nonlin_max_y")!=null) this.nonlin_max_y=Double.parseDouble(properties.getProperty(prefix+"nonlin_max_y"));
if (properties.getProperty(prefix+"nonlin_max_c")!=null) this.nonlin_max_c=Double.parseDouble(properties.getProperty(prefix+"nonlin_max_c"));
if (properties.getProperty(prefix+"nonlin_y")!=null) this.nonlin_y=Double.parseDouble(properties.getProperty(prefix+"nonlin_y"));
if (properties.getProperty(prefix+"nonlin_c")!=null) this.nonlin_c=Double.parseDouble(properties.getProperty(prefix+"nonlin_c"));
if (properties.getProperty(prefix+"nonlin_corn")!=null) this.nonlin_corn=Double.parseDouble(properties.getProperty(prefix+"nonlin_corn"));
if (properties.getProperty(prefix+"denoise")!=null) this.denoise=Boolean.parseBoolean(properties.getProperty(prefix+"denoise"));
if (properties.getProperty(prefix+"denoise_y")!=null) this.denoise_y=Double.parseDouble(properties.getProperty(prefix+"denoise_y"));
if (properties.getProperty(prefix+"denoise_c")!=null) this.denoise_c=Double.parseDouble(properties.getProperty(prefix+"denoise_c"));
......@@ -1983,24 +2070,34 @@ public class EyesisCorrectionParameters {
gd.addNumericField("dbg_x1", this.dbg_x1, 2);
gd.addNumericField("dbg_y1", this.dbg_y1, 2);
gd.addNumericField("dbg_sigma", this.dbg_sigma, 3);
gd.addNumericField("== dct_size = 1:1, dct+1.0 - shrink dct(dct+1.0)", this.dbg_src_size, 3);
gd.addNumericField("Should ==DCT_PARAMETERS.dct_size / DCT_PARAMETERS.dbg_src_size", this.dbg_scale, 3);
gd.addNumericField("Modifies window during MDCT->DCT-IV folding", this.dbg_fold_scale, 3);
gd.addStringField ("Debug mask (anything but * is false)", this.dbg_mask, 100);
gd.addNumericField("LMA implementation: 0 - old, 1 - new", this.dbg_mode, 0);
gd.addNumericField("Convolution window: 0 - none, 1 - square, 2 - sin, 3 - sin^2", this.dbg_window_mode, 0);
gd.addNumericField("Convolution window: 0 - none, [1 - square], 2 - sin, 3 - sin^2", this.dbg_window_mode, 0);
gd.addCheckbox ("Center convolution window around target kernel center", this.centerWindowToTarget);
gd.addNumericField("Color channel to extract kernel (<0 - use synthetic)", this.color_channel, 0);
gd.addNumericField("Convolution kernel decimation (original is normally 2x)", this.decimation, 0);
gd.addNumericField("Smooth convolution kernel before decimation", this.decimateSigma, 3);
gd.addNumericField("Tile X to extract (0..163)", this.tileX, 0);
gd.addNumericField("Tile Y to extract (0..122)", this.tileY, 0);
gd.addCheckbox ("Subtract avarege before dct, restore after idct", this.subtract_dc);
gd.addNumericField("Calibration channel to use for aberration ( <0 - no correction)",this.kernel_chn, 0);
gd.addCheckbox ("Normalize both sym and asym kernels ", this.normalize);
gd.addCheckbox ("Normalize sym kernels separately", this.normalize_sym);
gd.addCheckbox ("Divide symmetrical kernel by a window function", this.antiwindow);
gd.addCheckbox ("Do not apply symmetrical (DCT) correction ", this.skip_sym);
gd.addCheckbox ("Convolve directly with symmetrical kernel (debug feature) ", this.convolve_direct);
gd.addNumericField("Value (max) in vignetting data to correspond to 1x in the kernel",this.vignetting_max, 3);
gd.addNumericField("Do not try to correct vignetting smaller than this fraction of max",this.vignetting_range, 3);
gd.addCheckbox ("Use DCT-base color conversion", this.color_DCT );
gd.addNumericField("Reg gain in the center of sensor calibration R (instead of vignetting)",this.novignetting_r, 4);
gd.addNumericField("Green gain in the center of sensor calibration G (instead of vignetting)",this.novignetting_g, 4);
gd.addNumericField("Blue gain in the center of sensor calibration B (instead of vignetting)",this.novignetting_b, 4);
gd.addNumericField("Extra red correction to compensate for light temperature", this.scale_r, 4);
gd.addNumericField("Extra green correction to compensate for light temperature", this.scale_g, 4);
gd.addNumericField("Extra blue correction to compensate for light temperature", this.scale_b, 4);
gd.addNumericField("Value (max) in vignetting data to correspond to 1x in the kernel", this.vignetting_max, 3);
gd.addNumericField("Do not try to correct vignetting smaller than this fraction of max", this.vignetting_range, 3);
gd.addCheckbox ("Perform de-bayer after aberrations in pixel domain", this.post_debayer );
gd.addCheckbox ("Use DCT-based color conversion (false - just LPF RGB with dbg_sigma)",this.color_DCT );
gd.addNumericField("Gaussian sigma to apply to R and B (in addition to G), pix", this.sigma_rb, 3);
gd.addNumericField("Gaussian sigma to apply to Y in the MDCT domain, pix", this.sigma_y, 3);
gd.addNumericField("Gaussian sigma to apply to Pr and Pb in the MDCT domain, pix", this.sigma_color, 3);
......@@ -2040,6 +2137,9 @@ public class EyesisCorrectionParameters {
this.dbg_x1= gd.getNextNumber();
this.dbg_y1= gd.getNextNumber();
this.dbg_sigma= gd.getNextNumber();
this.dbg_src_size= gd.getNextNumber();
this.dbg_scale= gd.getNextNumber();
this.dbg_fold_scale= gd.getNextNumber();
this.dbg_mask= gd.getNextString();
this.dbg_mode= (int) gd.getNextNumber();
this.dbg_window_mode= (int) gd.getNextNumber();
......@@ -2049,14 +2149,24 @@ public class EyesisCorrectionParameters {
this.decimateSigma= gd.getNextNumber();
this.tileX= (int) gd.getNextNumber();
this.tileY= (int) gd.getNextNumber();
this.subtract_dc= gd.getNextBoolean();
this.kernel_chn= (int) gd.getNextNumber();
this.normalize= gd.getNextBoolean();
this.normalize_sym= gd.getNextBoolean();
this.antiwindow= gd.getNextBoolean();
this.skip_sym= gd.getNextBoolean();
this.convolve_direct= gd.getNextBoolean();
this.novignetting_r= gd.getNextNumber();
this.novignetting_g= gd.getNextNumber();
this.novignetting_b= gd.getNextNumber();
this.scale_r= gd.getNextNumber();
this.scale_g= gd.getNextNumber();
this.scale_b= gd.getNextNumber();
this.vignetting_max= gd.getNextNumber();
this.vignetting_range= gd.getNextNumber();
this.post_debayer= gd.getNextBoolean();
this.color_DCT= gd.getNextBoolean();
this.sigma_rb= gd.getNextNumber();
this.sigma_y= gd.getNextNumber();
......
......@@ -107,16 +107,6 @@ public class EyesisCorrections {
//if ((this.debugLevel>1) && (correctionsParameters.sourcePaths!=null) && (correctionsParameters.sourcePaths.length>0)) {
if ((this.debugLevel>101) && (correctionsParameters.sourcePaths!=null) && (correctionsParameters.sourcePaths.length>0)) {
testFF(correctionsParameters.sourcePaths[0]);
// this.channelVignettingCorrection[srcChannel]=this.pixelMapping.getBayerFlatFieldFloat(
/*
SDFA_INSTANCE.showArrays(
this.channelVignettingCorrection,
this.channelWidthHeight[srcChannel][0],
this.channelWidthHeight[srcChannel][1],
true,
"Flat-Field");
//LENS_DISTORTIONS.displayGridTitles());
*/
}
}
......
......@@ -30,7 +30,6 @@ import ij.ImagePlus;
import ij.ImageStack;
import ij.Prefs;
import ij.io.FileSaver;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;
......@@ -220,16 +219,7 @@ public class EyesisDCT {
final int preTargetSize = 4 * dct_size;
final int targetSize = 2 * dct_size; // normally 16
final double [] anitperiodic_window = createAntiperiodicWindow(dct_size);
/*
final int vgn_step = dct_kernel.img_step/vign_decimation;
final int vgn_width = vign_width/vign_decimation;
final int vgn_height = vign_height/vign_decimation;
final int vgn_left = (vign_width - (dct_kernel.img_step * (kernelNumHor-1)))/(2* vign_decimation); // in decimated pixels
final int vgn_top = (vign_height -(dct_kernel.img_step * (kernelNumVert-1)))/(2* vign_decimation); // in decimated pixels
final double vgn_max = dct_parameters.vignetting_max;
final double vgn_min = vgn_max/dct_parameters.vignetting_range;
*/
final int chn_green = 2; // all others multiply by 4 as there 1 in 4 Bayer for those, green - by 2
// final int chn_green = 2; // all others multiply by 4 as there 1 in 4 Bayer for those, green - by 2
final long startTime = System.nanoTime();
System.out.println("calculateDCTKernel():numberOfKernels="+numberOfKernels);
for (int ithread = 0; ithread < threads.length; ithread++) {
......@@ -239,15 +229,11 @@ public class EyesisDCT {
if (dct_parameters.decimateSigma > 0) gb=new DoubleGaussianBlur();
float [] kernelPixels= null; // will be initialized at first use NOT yet?
double [] kernel= new double[kernelSize*kernelSize];
// int targetSize = dct_parameters.asym_size + 2 * dct_parameters.dct_size - 2;
double [] pre_target_kernel= new double [preTargetSize * preTargetSize]; // before made antiperiodic
double [] target_kernel = new double [targetSize * targetSize]; // strictly antiperiodic in both x and y directions
FactorConvKernel factorConvKernel = new FactorConvKernel();
factorConvKernel.setDebugLevel (0); // globalDebugLevel);
// factorConvKernel.setTargetWindowMode (dct_parameters.dbg_window_mode, dct_parameters.centerWindowToTarget);
factorConvKernel.setTargetWindowMode (dct_parameters.centerWindowToTarget);
factorConvKernel.numIterations = dct_parameters.LMA_steps;
factorConvKernel.setAsymCompactness (dct_parameters.compactness, dct_parameters.asym_tax_free);
......@@ -255,27 +241,10 @@ public class EyesisDCT {
factorConvKernel.setDCWeight (dct_parameters.dc_weight);
int chn,tileY,tileX;
// int chn0=-1;
// int i;
// double sum;
for (int nTile = ai.getAndIncrement(); nTile < numberOfKernels; nTile = ai.getAndIncrement()) {
chn=nTile/numberOfKernelsInChn;
tileY =(nTile % numberOfKernelsInChn)/kernelNumHor;
tileX = nTile % kernelNumHor;
/*
if (vignetting != null){
int vh = vgn_left + vgn_step * tileX;
if (vh < 0) vh = 0;
if (vh >= vgn_width) vh = vgn_width -1;
int vv = vgn_top + vgn_step * tileY;
if (vv < 0) vv = 0;
if (vv >= vgn_height) vh = vgn_height -1;
kscale = vignetting[chn][vv*vgn_width+vh];
if (kscale < vgn_min) kscale = vgn_min;
}
kscale = vgn_max/kscale * ((chn == chn_green)? 2:4);
*/
//// kscale = (chn == chn_green)? 2:4;
if (tileX==0) {
if (updateStatus) IJ.showStatus("Processing kernels, channel "+(chn+1)+" of "+nChn+", row "+(tileY+1)+" of "+kernelNumVert);
if (globalDebugLevel>2) System.out.println("Processing kernels, channel "+(chn+1)+" of "+nChn+", row "+(tileY+1)+" of "+kernelNumVert+" : "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
......@@ -339,22 +308,13 @@ public class EyesisDCT {
double [] asym_kernel = factorConvKernel.getAsymKernel();
int sym_kernel_inc_index = kernelNumHor * dct_parameters.dct_size;
int sym_kernel_start_index = (sym_kernel_inc_index * tileY + tileX) * dct_parameters.dct_size;
// int indx = 0;
for (int i = 0; i<dct_parameters.dct_size;i++){
System.arraycopy(
sym_kernel,
i * dct_parameters.dct_size,
dct_kernel.sym_kernels[chn],
sym_kernel_start_index + i * sym_kernel_inc_index,
dct_parameters.dct_size);
/*
int dst_start = sym_kernel_start_index + i * sym_kernel_inc_index;
for (int j = 0; j < dct_parameters.dct_size; j++){
dct_kernel.sym_kernels[chn][dst_start++] = sym_kernel[indx++];
}
*/
}
int asym_kernel_inc_index = kernelNumHor * dct_parameters.asym_size;
int asym_kernel_start_index = (asym_kernel_inc_index * tileY + tileX)* dct_parameters.asym_size;
......@@ -374,7 +334,6 @@ public class EyesisDCT {
if (globalDebugLevel > 1) System.out.println("Threads done at "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
System.out.println("1.Threads done at "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
/* prepare result stack to return */
// ImageStack outStack=new ImageStack(kernelNumHor,kernelNumVert);
return dct_kernel;
}
//processChannelImage
......@@ -408,8 +367,6 @@ public class EyesisDCT {
final int kernelWidth=kernelStack.getWidth();
final int kernelNumHor=kernelWidth/kernelSize;
// final int kernelNumVert=kernelStack.getHeight()/kernelSize;
// final int nChn=kernelStack.getSize();
double [] kernel = new double [kernelSize*kernelSize];
extractOneKernel((float[]) kernelStack.getPixels(chn+1), // array of combined square kernels, each
kernel, // will be filled, should have correct size before call
......@@ -418,8 +375,6 @@ public class EyesisDCT {
yTile);
return kernel;
}
//imp2.getStack()
// to be used in threaded method
private void extractOneKernel(float [] pixels, // array of combined square kernels, each
double [] kernel, // will be filled, should have correct size before call
......@@ -440,6 +395,7 @@ public class EyesisDCT {
int base=(yTile*pixelsWidth+xTile)*size;
for (i=0;i<size;i++) for (j=0;j<size;j++) kernel [i*size+j]=pixels[base+i*pixelsWidth+j];
}
public double [] reformatKernel(
double [] src_kernel,// will be blured in-place
int src_size, // typical 64
......@@ -602,6 +558,10 @@ public class EyesisDCT {
}
}
}
public void resetDCTKernels()
{
kernels = null;
}
public boolean readDCTKernels(
EyesisCorrectionParameters.DCTParameters dct_parameters,
......@@ -611,7 +571,7 @@ public class EyesisDCT {
int debugLevel
){
String [] symKernelPaths = correctionsParameters.selectDCTChannelFiles(
// 0, // 0 - sharp, 1 - smooth
// 0, // 0 - sharp, 1 - smooth
eyesisCorrections.usedChannels.length, // numChannels, // number of channels
eyesisCorrections.debugLevel);
if (symKernelPaths==null) return false;
......@@ -637,7 +597,7 @@ public class EyesisDCT {
DttRad2 dtt = new DttRad2(dct_parameters.dct_size);
for (int chn=0;chn<eyesisCorrections.usedChannels.length;chn++){
// if (eyesisCorrections.usedChannels[chn] && (symKernelPaths[chn]!=null) && (kernels[chn]==null)){
// if (eyesisCorrections.usedChannels[chn] && (symKernelPaths[chn]!=null) && (kernels[chn]==null)){
if (eyesisCorrections.usedChannels[chn] && (symKernelPaths[chn]!=null)){
ImagePlus imp_kernel_sym=new ImagePlus(symKernelPaths[chn]);
if (imp_kernel_sym.getStackSize()<3) {
......@@ -684,11 +644,9 @@ public class EyesisDCT {
int sym_width = kernels[chn].numHor * dct_size;
int sym_height = kernels[chn].sym_kernels[0].length /sym_width;
int asym_nonzero =kernels[chn].asym_nonzero;
// sdfa_instance.showArrays(kernels[chn].sym_kernels, sym_width, sym_height, true, symKernelPaths[chn]);
int asym_width = kernels[chn].numHor * kernels[chn].asym_size;
int asym_height = kernels[chn].asym_kernels[0].length /asym_width;
// sdfa_instance.showArrays(kernels[chn].asym_kernels, asym_width, asym_height, true, asymKernelPaths[chn]);
int numHor = kernels[chn].numHor;
int numVert = kernels[chn].sym_kernels[0].length / (dct_size * dct_size * numHor);
kernels[chn].st_kernels = new double [nColors][numVert][numHor][dct_size * dct_size];
......@@ -706,6 +664,13 @@ public class EyesisDCT {
norm_sym_weights[i*dct_size+j] = d;
}
}
double [] inv_window = new double [dct_size*dct_size];
for (int i = 0; i < dct_size; i++){
for (int j = 0; j < dct_size; j++){
double d = 1.0 / (Math.cos(Math.PI*i/(2*dct_size))*Math.cos(Math.PI*j/(2*dct_size)));
inv_window[i*dct_size+j] = d;
}
}
if (debugLevel>0) {
System.out.println("readDCTKernels() debugLevel = "+debugLevel+
......@@ -751,22 +716,24 @@ public class EyesisDCT {
System.out.println("i="+i+", sum="+scale_asym);
}
}
} else {
scale_asym = 1.0;
}
// Compensate for Bayer pattern where there are twice less R,B than G
double k = ((nc == 2)? 1.0:2.0) / scale_asym;
for (int i = 0; i < kernels[chn].asym_val[nc][tileY][tileX].length;i++){
// kernels[chn].asym_val[nc][tileY][tileX][i] /= scale_asym;
// kernels[chn].asym_val[nc][tileY][tileX][i] /= scale_asym;
kernels[chn].asym_val[nc][tileY][tileX][i] *= k; // includes correction for different number of pixels in r,b(1/4) and G (2/4)
}
if ((debugLevel>0) && (tileY==67) && (tileX==125)) {
System.out.println("nc="+nc+" sum="+scale_asym+", normalized:");
if ((debugLevel > 0) && (tileY==67) && (tileX==125)) {
System.out.println("nc="+nc+" sum="+scale_asym+", k="+k +", k*scale_asym="+(k*scale_asym)+", normalized:");
for (int i=0; i<kernels[chn].asym_indx[nc][tileY][tileX].length; i++){
System.out.println("kernels["+chn+"].asym_val["+nc+"]["+tileY+"]["+tileX+"]["+i+"]="+kernels[chn].asym_val[nc][tileY][tileX][i]);
System.out.println("kernels["+chn+"].asym_indx["+nc+"]["+tileY+"]["+tileX+"]["+i+"]="+kernels[chn].asym_indx[nc][tileY][tileX][i]);
}
}
} else {
scale_asym = 1.0;
}
// extract DCT (symmetrical) kernels
int sym_kernel_start_index = (sym_kernel_inc_index * tileY + tileX) * dct_size;
......@@ -778,6 +745,15 @@ public class EyesisDCT {
i * dct_size,
dct_size);
}
// sym_kernel pre-compensation for window function
if (dct_parameters.antiwindow) {
for (int i=0; i < kernels[chn].st_kernels[nc][tileY][tileX].length;i++) {
kernels[chn].st_kernels[nc][tileY][tileX][i] *= inv_window[i];
}
}
if (scale_asym != 1.0){
for (int i=0; i < kernels[chn].st_kernels[nc][tileY][tileX].length;i++) {
kernels[chn].st_kernels[nc][tileY][tileX][i] *= scale_asym;
......@@ -813,10 +789,10 @@ public class EyesisDCT {
kernels[chn].st_kernels[nc][tileY][tileX][i] *= dct_size;
}
// kernels[chn].st_kernels[nc][tileY][tileX]= dtt.dttt_iii(kernels[chn].st_kernels[nc][tileY][tileX]);
// kernels[chn].st_kernels[nc][tileY][tileX]= dtt.dttt_iii(kernels[chn].st_kernels[nc][tileY][tileX]);
kernels[chn].st_kernels[nc][tileY][tileX]= dtt.dttt_iiie(kernels[chn].st_kernels[nc][tileY][tileX]);
}
// System.out.println("tileY="+tileY);
// System.out.println("tileY="+tileY);
}
}
// Debug will be removed later, the
......@@ -832,10 +808,10 @@ public class EyesisDCT {
}
public void showKernels(){
// System.out.println("showKernels(): kernels.length="+kernels.length);
// System.out.println("showKernels(): kernels.length="+kernels.length);
for (int chn=0;chn < kernels.length; chn++){
if (kernels[chn]!=null){
// System.out.println("showKernels("+chn+")");
// System.out.println("showKernels("+chn+")");
showKernels(chn);
}
}
......@@ -849,7 +825,7 @@ public class EyesisDCT {
int asym_size= kernels[chn].asym_size;
int sym_width = numHor * dct_size;
int sym_height = numVert * dct_size;
// int asym_nonzero =kernels[chn].asym_nonzero;
// int asym_nonzero =kernels[chn].asym_nonzero;
int asym_width = numHor * kernels[chn].asym_size;
int asym_height = numVert * kernels[chn].asym_size;
kernels[chn].sym_kernels = new double [nColors][sym_width*sym_height];
......@@ -925,13 +901,13 @@ public class EyesisDCT {
kernels[chn].sym_direct = null; // not needed anymore
}
// public boolean isChannelEnabled(int channel){
// return ((channel>=0) && (channel<this.usedChannels.length) && this.usedChannels[channel]);
// }
// public boolean isChannelEnabled(int channel){
// return ((channel>=0) && (channel<this.usedChannels.length) && this.usedChannels[channel]);
// }
public void processDCTChannelImages(
// EyesisCorrectionParameters.SplitParameters splitParameters,
// EyesisCorrectionParameters.SplitParameters splitParameters,
EyesisCorrectionParameters.DCTParameters dct_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
EyesisCorrectionParameters.NonlinParameters nonlinParameters,
......@@ -955,6 +931,7 @@ public class EyesisDCT {
int [] channels={correctionsParameters.getChannelFromSourceTiff(sourceFiles[nFile])};
if (correctionsParameters.isJP4()){
int subCamera= channels[0]- correctionsParameters.firstSubCamera; // to match those in the sensor files
// removeUnusedSensorData should be off!?
channels=this.eyesisCorrections.pixelMapping.channelsForSubCamera(subCamera);
}
if (channels!=null){
......@@ -993,7 +970,7 @@ public class EyesisDCT {
for (int iImage=0;iImage<fileIndices.length;iImage++){
int nFile=fileIndices[iImage][0];
ImagePlus imp_src=null;
// int srcChannel=correctionsParameters.getChannelFromSourceTiff(sourceFiles[nFile]);
// int srcChannel=correctionsParameters.getChannelFromSourceTiff(sourceFiles[nFile]);
int srcChannel=fileIndices[iImage][1];
if (correctionsParameters.isJP4()){
int subchannel=eyesisCorrections.pixelMapping.getSubChannel(srcChannel);
......@@ -1017,23 +994,23 @@ public class EyesisDCT {
// do we need to add any properties?
} else {
imp_src=new ImagePlus(sourceFiles[nFile]);
// (new JP46_Reader_camera(false)).decodeProperiesFromInfo(imp_src); // decode existent properties from info
// (new JP46_Reader_camera(false)).decodeProperiesFromInfo(imp_src); // decode existent properties from info
eyesisCorrections.JP4_INSTANCE.decodeProperiesFromInfo(imp_src); // decode existent properties from info
if (debugLevel>0) System.out.println("Processing "+sourceFiles[nFile]);
}
double scaleExposure=1.0;
if (!Double.isNaN(referenceExposures[nFile]) && (imp_src.getProperty("EXPOSURE")!=null)){
scaleExposure=referenceExposures[nFile]/Double.parseDouble((String) imp_src.getProperty("EXPOSURE"));
// imp_src.setProperty("scaleExposure", scaleExposure); // it may already have channel
// imp_src.setProperty("scaleExposure", scaleExposure); // it may already have channel
if (debugLevel>0) System.out.println("Will scale intensity (to compensate for exposure) by "+scaleExposure);
}
imp_src.setProperty("name", correctionsParameters.getNameFromSourceTiff(sourceFiles[nFile]));
imp_src.setProperty("channel", srcChannel); // it may already have channel
imp_src.setProperty("path", sourceFiles[nFile]); // it may already have channel
// ImagePlus result=processChannelImage( // returns ImagePlus, but it already should be saved/shown
// ImagePlus result=processChannelImage( // returns ImagePlus, but it already should be saved/shown
processDCTChannelImage( // returns ImagePlus, but it already should be saved/shown
imp_src, // should have properties "name"(base for saving results), "channel","path"
// splitParameters,
// splitParameters,
dct_parameters,
debayerParameters,
nonlinParameters,
......@@ -1052,19 +1029,22 @@ public class EyesisDCT {
}
//pixelMapping
Runtime.getRuntime().gc();
if (debugLevel>0) System.out.println("Processing image "+(iImage+1)+" (of "+fileIndices.length+") finished at "+
if (debugLevel >-1) System.out.println("Processing image "+(iImage+1)+" (of "+fileIndices.length+") finished at "+
IJ.d2s(0.000000001*(System.nanoTime()-this.startTime),3)+" sec, --- Free memory="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
if (eyesisCorrections.stopRequested.get()>0) {
System.out.println("User requested stop");
return;
}
}
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 ImagePlus processDCTChannelImage(
ImagePlus imp_src, // should have properties "name"(base for saving results), "channel","path"
// EyesisCorrectionParameters.SplitParameters splitParameters, // will not be used !
// EyesisCorrectionParameters.SplitParameters splitParameters, // will not be used !
EyesisCorrectionParameters.DCTParameters dct_parameters,
EyesisCorrectionParameters.DebayerParameters debayerParameters,
EyesisCorrectionParameters.NonlinParameters nonlinParameters,
......@@ -1123,7 +1103,35 @@ public class EyesisDCT {
if (d > max_vign_corr) d = max_vign_corr;
pixels[i]*=d;
}
// Scale here, combine with vignetting later?
int width = imp_src.getWidth();
int height = imp_src.getHeight();
for (int y = 0; y < height-1; y+=2){
for (int x = 0; x < width-1; x+=2){
pixels[y*width+x ] *= dct_parameters.scale_g;
pixels[y*width+x+width+1] *= dct_parameters.scale_g;
pixels[y*width+x +1] *= dct_parameters.scale_r;
pixels[y*width+x+width ] *= dct_parameters.scale_b;
}
}
} else { // assuming GR/BG pattern
System.out.println("Applying fixed color gain correction parameters: Gr="+
dct_parameters.novignetting_r+", Gg="+dct_parameters.novignetting_g+", Gb="+dct_parameters.novignetting_b);
float [] pixels=(float []) imp_src.getProcessor().getPixels();
int width = imp_src.getWidth();
int height = imp_src.getHeight();
double kr = dct_parameters.scale_r/dct_parameters.novignetting_r;
double kg = dct_parameters.scale_g/dct_parameters.novignetting_g;
double kb = dct_parameters.scale_b/dct_parameters.novignetting_b;
for (int y = 0; y < height-1; y+=2){
for (int x = 0; x < width-1; x+=2){
pixels[y*width+x ] *= kg;
pixels[y*width+x+width+1] *= kg;
pixels[y*width+x +1] *= kr;
pixels[y*width+x+width ] *= kb;
}
}
}
String title=name+"-"+String.format("%02d", channel);
ImagePlus result=imp_src;
......@@ -1147,27 +1155,54 @@ public class EyesisDCT {
result, // source Bayer image, linearized, 32-bit (float))
splitParameters);
String titleFull=title+"-SPLIT";
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/4;
chn_avg[1] /= width*height/4;
chn_avg[2] /= width*height/2;
System.out.println("Split channels averages: R="+chn_avg[0]+", G="+chn_avg[2]+", B="+chn_avg[1]);
}
if (!this.correctionsParameters.debayer) {
result= new ImagePlus(titleFull, stack);
eyesisCorrections.saveAndShow(result, this.correctionsParameters);
return result;
}
// =================
// =================
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
if (debugLevel > 0) {
System.out.println("Showing image BEFORE_PROC");
ImagePlus imp_dbg= new ImagePlus("BEFORE_PROC",stack);
imp_dbg.getProcessor().resetMinAndMax();
imp_dbg.updateAndDraw();
imp_dbg.show();
}
if (this.correctionsParameters.deconvolve) { // process with DCT, otherwise use simple debayer
ImageDtt image_dtt = new ImageDtt();
double [][][][] dctdc_data = image_dtt.mdctDcStack(
double [][][][] dct_data = image_dtt.mdctStack(
stack,
channel,
dct_parameters,
this,
threadsMax,
debugLevel,
updateStatus);
System.out.println("dctdc_data.length="+dctdc_data.length+" dctdc_data[0].length="+dctdc_data[0].length
+" dctdc_data[0][0].length="+dctdc_data[0][0].length+" dctdc_data[0][0][0].length="+dctdc_data[0][0][0].length);
System.out.println("dct_data.length="+dct_data.length+" dct_data[0].length="+dct_data[0].length
+" dct_data[0][0].length="+dct_data[0][0].length+" dct_data[0][0][0].length="+dct_data[0][0][0].length);
if (dct_parameters.color_DCT){ // convert RBG -> YPrPb
dctdc_data = image_dtt.dct_color_convert(
dctdc_data,
dct_data = image_dtt.dct_color_convert(
dct_data,
colorProcParameters.kr,
colorProcParameters.kb,
dct_parameters.sigma_rb, // blur of channels 0,1 (r,b) in addition to 2 (g)
......@@ -1176,68 +1211,55 @@ public class EyesisDCT {
threadsMax,
debugLevel);
} else { // just LPF RGB
for (int chn = 0; chn < dctdc_data.length; chn++) {
if (dct_parameters.dbg_sigma > 0){ // no filter at all
for (int chn = 0; chn < dct_data.length; chn++) {
image_dtt.dct_lpf(
dct_parameters.dbg_sigma,
dctdc_data[chn],
dct_data[chn],
threadsMax,
debugLevel);
}
}
}
int tilesY = stack.getHeight()/dct_parameters.dct_size - 1;
int tilesX = stack.getWidth()/dct_parameters.dct_size - 1;
if (debugLevel>0){
if (debugLevel > 0){
System.out.println("--tilesX="+tilesX);
System.out.println("--tilesY="+tilesY);
}
double [][] dct_dc = new double [dctdc_data.length][];
double [][] dct_ac = new double [dctdc_data.length][];
for (int chn = 0; chn < dct_dc.length; chn++) {
if (!dct_parameters.color_DCT){ // convert RBG -> YPrPb
dct_dc[chn] = image_dtt.lapped_dct_dcac(
false, // out_ac, // false - output DC, true - output AC
dctdc_data [chn],
threadsMax,
debugLevel);
}
dct_ac[chn] = image_dtt.lapped_dct_dcac(
true, // out_ac, // false - output DC, true - output AC
dctdc_data [chn],
if (debugLevel > 1){
double [][] dct = new double [dct_data.length][];
for (int chn = 0; chn < dct.length; chn++) {
dct[chn] = image_dtt.lapped_dct_dbg(
dct_data [chn],
threadsMax,
debugLevel);
}
// System.out.println("dct_dc.length="+dct_dc.length+" dct_ac.length="+dct_ac.length);
if (debugLevel > 0){
sdfa_instance.showArrays(dct_ac,
sdfa_instance.showArrays(dct,
tilesX*dct_parameters.dct_size,
tilesY*dct_parameters.dct_size,
true,
result.getTitle()+"-DCT_AC");
if (!dct_parameters.color_DCT){ // convert RBG -> YPrPb
sdfa_instance.showArrays(dct_dc,
tilesX,
tilesY,
true,
result.getTitle()+"-DCT_DC");
result.getTitle()+"-DCT");
}
}
double [][] idct_data = new double [dctdc_data.length][];
double [][] idct_data = new double [dct_data.length][];
for (int chn=0; chn<idct_data.length;chn++){
idct_data[chn] = image_dtt.lapped_idctdc(
dctdc_data[chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
idct_data[chn] = image_dtt.lapped_idct(
dct_data[chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
dct_parameters.dct_size, // final int
dct_parameters.dct_window, //window_type
threadsMax,
debugLevel);
}
if (dct_parameters.color_DCT){ // convert RBG -> YPrPb
sdfa_instance.showArrays(
if (debugLevel > 0) sdfa_instance.showArrays(
idct_data,
(tilesX + 1) * dct_parameters.dct_size,
(tilesY + 1) * dct_parameters.dct_size,
true,
result.getTitle()+"-IDCTDC-YPrPb");
result.getTitle()+"-IDCT-YPrPb");
if (dct_parameters.nonlin && ((dct_parameters.nonlin_y != 0.0) || (dct_parameters.nonlin_c != 0.0))) {
System.out.println("Applying edge emphasis, nonlin_y="+dct_parameters.nonlin_y+
", nonlin_c="+dct_parameters.nonlin_c+", nonlin_corn="+dct_parameters.nonlin_corn);
......@@ -1254,9 +1276,9 @@ public class EyesisDCT {
(dct_parameters.denoise? dct_parameters.denoise_c:0.0), // final double denoise_c, // = 1.0; // maximal total smoothing of the color differences post-kernel (will compete with edge emphasis)
dct_parameters.denoise_y_corn, // final double denoise_y_corn, // = 0.5; // weight of the 4 corner pixels during denoise y (relative to 4 straight)
dct_parameters.denoise_c_corn, // final double denoise_c_corn, // = 0.5; // weight of the 4 corner pixels during denoise y (relative to 4 straight)
threadsMax, // final int threadsMax, // maximal number of threads to launch
dct_parameters.dct_size, //, // final int threadsMax, // maximal number of threads to launch
debugLevel); // final int globalDebugLevel)
sdfa_instance.showArrays(
if (debugLevel > 0) sdfa_instance.showArrays(
idct_data,
(tilesX + 1) * dct_parameters.dct_size,
(tilesY + 1) * dct_parameters.dct_size,
......@@ -1271,14 +1293,44 @@ public class EyesisDCT {
(tilesX + 1) * dct_parameters.dct_size);
} else {
System.out.println("Bypassing nonlinear correction");
if (dct_parameters.post_debayer){ // post_debayer
if (debugLevel > -1) System.out.println("Applying post-debayer");
if (debugLevel > -1) sdfa_instance.showArrays(
idct_data,
(tilesX + 1) * dct_parameters.dct_size,
(tilesY + 1) * dct_parameters.dct_size,
true,
result.getTitle()+"-rbg_before");
idct_data = post_debayer( // debayer in pixel domain after aberration correction
idct_data, // final double [][] rbg, // yPrPb,
(tilesX + 1) * dct_parameters.dct_size, // final int width,
dct_parameters.dct_size, // final int step, // just for multi-threading efficiency?
dct_parameters.dct_size, // final int threadsMax, // maximal number of threads to launch
debugLevel); // final int globalDebugLevel)
// add here YPrPb conversion, then edge_emphasis
if (debugLevel > -1) sdfa_instance.showArrays(
idct_data,
(tilesX + 1) * dct_parameters.dct_size,
(tilesY + 1) * dct_parameters.dct_size,
true,
result.getTitle()+"-rbg_after");
} else {
if (debugLevel > -1) System.out.println("Applyed LPF, sigma = "+dct_parameters.dbg_sigma);
if (debugLevel > -1) sdfa_instance.showArrays(
idct_data,
(tilesX + 1) * dct_parameters.dct_size,
(tilesY + 1) * dct_parameters.dct_size,
true,
result.getTitle()+"-rbg_sigma");
}
}
sdfa_instance.showArrays(idct_data,
if (debugLevel > 0) sdfa_instance.showArrays(idct_data,
(tilesX + 1) * dct_parameters.dct_size,
(tilesY + 1) * dct_parameters.dct_size,
true,
result.getTitle()+"-IDCTDC-RGB");
result.getTitle()+"-IDCT-RGB");
// convert to ImageStack of 3 slices
String [] sliceNames = {"red", "blue", "green"};
......@@ -1290,9 +1342,26 @@ public class EyesisDCT {
} else { // if (this.correctionsParameters.deconvolve) - here use a simple debayer
System.out.println("Bypassing DCTR-based aberration correction");
System.out.println("Bypassing DCT-based aberration correction");
debayer_rbg(stack, 0.25); // simple standard 3x3 kernel debayer
}
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]);
}
if (!this.correctionsParameters.colorProc){
result= new ImagePlus(titleFull, stack);
......@@ -1301,7 +1370,7 @@ public class EyesisDCT {
this.correctionsParameters);
return result;
}
System.out.println("before colors.1");
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,
......@@ -1309,14 +1378,14 @@ public class EyesisDCT {
if (debugLevel > -1) System.out.println("fixSliceSequence() returned false");
return null;
}
System.out.println("before colors.2");
if (debugLevel > -1){
if (debugLevel > 1) System.out.println("before colors.2");
if (debugLevel > 1){
ImagePlus imp_dbg=new ImagePlus(imp_src.getTitle()+"-"+channel+"-preColors",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
this.correctionsParameters);
}
System.out.println("before colors.3, scaleExposure="+scaleExposure+" scale = "+(255.0/eyesisCorrections.psfSubpixelShouldBe4/eyesisCorrections.psfSubpixelShouldBe4/scaleExposure));
if (debugLevel > 1) System.out.println("before colors.3, scaleExposure="+scaleExposure+" scale = "+(255.0/eyesisCorrections.psfSubpixelShouldBe4/eyesisCorrections.psfSubpixelShouldBe4/scaleExposure));
CorrectionColorProc correctionColorProc=new CorrectionColorProc(eyesisCorrections.stopRequested);
double [][] yPrPb=new double [3][];
// if (dct_parameters.color_DCT){
......@@ -1333,8 +1402,8 @@ public class EyesisDCT {
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 > 0){
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,
......@@ -1348,17 +1417,6 @@ public class EyesisDCT {
yPrPb[n] = new double [fpixels.length];
for (int i = 0; i < fpixels.length; i++) yPrPb[n][i] = fpixels[i];
}
// }
/*
String [] slice_names_YPrPb={"Y","Pr","Pb"};
sdfa_instance.showArrays(idct_data,
stack.getWidth(), // (tilesX + 1) * dct_parameters.dct_size,
stack.getHeight(), // (tilesY + 1) * dct_parameters.dct_size,
true,
result.getTitle()+"-YPrPb",
slice_names_YPrPb);
*/
if (toRGB) {
System.out.println("correctionColorProc.YPrPbToRGB");
......@@ -1367,40 +1425,29 @@ public class EyesisDCT {
colorProcParameters.kb, // 0.114;
stack.getWidth());
/*
correctionColorProc.YPrPbToRGB(stack,
colorProcParameters.kr, // 0.299;
colorProcParameters.kb, // 0.114;
colorProcParameters.useFirstY?9:8, // int sliceY,
6, // int slicePr,
7// int slicePb
);
*/
title=titleFull; // including "-DECONV" or "-COMBO"
titleFull=title+"-RGB-float";
//Trim stack to just first 3 slices
if (debugLevel > 0){ // 2){
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");
if (debugLevel > 1) System.out.println("Trimming color stack");
} else {
title=titleFull; // including "-DECONV" or "-COMBO"
titleFull=title+"-YPrPb"; // including "-DECONV" or "-COMBO"
if (debugLevel > -1) System.out.println("Using full stack, including YPbPr");
if (debugLevel > 1) System.out.println("Using full stack, including YPbPr");
}
result= new ImagePlus(titleFull, stack);
// Crop image to match original one (scaled to oversampling)
if (crop){ // always crop if equirectangular
System.out.println("cropping");
if (debugLevel > 1) System.out.println("cropping");
stack = eyesisCorrections.cropStack32(stack,splitParameters);
if (debugLevel > -1) { // 2){
if (debugLevel > 2) { // 2){
ImagePlus imp_dbg=new ImagePlus("cropped",stack);
eyesisCorrections.saveAndShow(
imp_dbg,
......@@ -1412,11 +1459,11 @@ public class EyesisDCT {
stack=eyesisCorrections.rotateStack32CW(stack);
}
if (!toRGB && !this.correctionsParameters.jpeg){ // toRGB set for equirectangular
System.out.println("!toRGB && !this.correctionsParameters.jpeg");
if (debugLevel > 1) System.out.println("!toRGB && !this.correctionsParameters.jpeg");
eyesisCorrections.saveAndShow(result, this.correctionsParameters);
return result;
} else { // that's not the end result, save if required
System.out.println("!toRGB && !this.correctionsParameters.jpeg - else");
if (debugLevel > 1) System.out.println("!toRGB && !this.correctionsParameters.jpeg - else");
eyesisCorrections.saveAndShow(result,
eyesisCorrections.correctionsParameters,
eyesisCorrections.correctionsParameters.save32,
......@@ -1433,16 +1480,16 @@ public class EyesisDCT {
result= new ImagePlus(titleFull, stack);
// ImagePlus imp_RGB24;
result.updateAndDraw();
System.out.println("result.updateAndDraw(), "+titleFull+"-RGB48");
if (debugLevel > 1) System.out.println("result.updateAndDraw(), "+titleFull+"-RGB48");
CompositeImage compositeImage=eyesisCorrections.convertToComposite(result);
if (!this.correctionsParameters.jpeg && !advanced){ // RGB48 was the end result
System.out.println("if (!this.correctionsParameters.jpeg && !advanced)");
if (debugLevel > 1) System.out.println("if (!this.correctionsParameters.jpeg && !advanced)");
eyesisCorrections.saveAndShow(compositeImage, this.correctionsParameters);
return result;
} else { // that's not the end result, save if required
System.out.println("if (!this.correctionsParameters.jpeg && !advanced) - else");
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
}
......@@ -1511,7 +1558,7 @@ public class EyesisDCT {
int width
) {
int length = yPrPb[0].length;
// int height = length/width;
// int height = length/width;
double [][]rbg = new double[3][length];
double Kg=1.0-Kr-Kb;
......@@ -1539,6 +1586,69 @@ public class EyesisDCT {
}
public double [][] post_debayer( // debayer in pixel domain after aberration correction
final double [][] rbg, // yPrPb,
final int width,
final int step, // just for multi-threading efficiency?
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final double [][] rbg_new = new double [rbg.length][rbg[0].length];
final int height = rbg[0].length/width;
final int tilesY = (height + step - 1) / step;
final int tilesX = (width + step - 1) / step;
final int nTiles=tilesX*tilesY;
final double [] kern_g={
0.0, 0.125, 0.0 ,
0.125, 0.5, 0.125,
0.0, 0.125, 0.0 };
final double [] kern_rb={
0.0625, 0.125, 0.0625,
0.125, 0.25, 0.125,
0.0625, 0.125, 0.0625};
final double [][] kerns = {kern_rb,kern_rb,kern_g};
final int [] neib_indices = {-width-1,-width,-width+1,-1,0,1,width-1,width,width+1};
final Thread[] threads = ImageDtt.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;
double [] neibs = new double[9]; // pixels around current, first Y, then each color diff
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
int y1 = (tileY +1) * step;
if (y1 > height) y1 = height;
int x1 = (tileX +1) * step;
if (x1 > width) x1 = width;
for (int y = tileY * step; y < y1; y++) {
for (int x = tileX * step; x < x1; x++) {
int indx = y*width + x;
for (int n = 0; n < rbg.length; n++) {
rbg_new[n][indx] = rbg[n][indx]; // default - just copy old value
}
if ((y > 0) && (y < (height - 1)) && (x > 0) && (x < (width - 1))) { // only correct those not on the edge
for (int n = 0; n < rbg.length; n++) {
rbg_new[n][indx] = 0.0;
for (int i = 0; i < neibs.length; i++){
rbg_new[n][indx] += kerns[n][i]*rbg[n][indx+neib_indices[i]];
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return rbg_new;
}
public double [][] edge_emphasis(
final double [][] yPrPb,
final int width,
......@@ -1716,6 +1826,9 @@ public class EyesisDCT {
ImageDtt.startAndJoin(threads);
return yPrPb_new;
}
public void debayer_rbg(
ImageStack stack_rbg){
debayer_rbg(stack_rbg, 1.0);
......
......@@ -70,7 +70,19 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
String prefsPath;
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;
......@@ -100,6 +112,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(
......@@ -383,7 +397,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));
>>>>>>> origin/dct
......@@ -490,8 +504,8 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
panelDct1.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("DCT test 1", panelDct1, color_process);
addButton("select MDCT image", panelDct1, color_configure);
addButton("MDCT scale", panelDct1, color_process);
addButton("MDCT stack", panelDct1, color_process);
addButton("MDCT DC stack", panelDct1, color_process);
addButton("DCT test 3", panelDct1, color_process);
addButton("DCT test 4", panelDct1, color_process);
addButton("Test Kernel Factorization", panelDct1, color_process);
......@@ -499,10 +513,23 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
addButton("Select kernels image", panelDct1, color_configure);
addButton("Create DCT kernels", panelDct1, color_process);
addButton("Read DCT kernels", panelDct1, color_process);
addButton("Reset DCT kernels", panelDct1, color_stop);
addButton("Setup DCT parameters", panelDct1, color_configure);
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();
>>>>>>> origin/dct
......@@ -2661,18 +2688,18 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
DBG_IMP = imp_src;
}
/* ======================================================================== */
} else if (label.equals("MDCT stack")) {
} else if (label.equals("MDCT scale")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!DCT_PARAMETERS.showDialog()) return;
// process selected image stack
// 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;
// ImagePlus imp2;
if (imp_src.getStackSize()<3){ // convert JP4 to image stack
EyesisCorrectionParameters.SplitParameters split_parameters = new EyesisCorrectionParameters.SplitParameters(
......@@ -2693,25 +2720,58 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
} else {
DBG_IMP = imp_src;
}
}
ImageDtt image_dtt = new ImageDtt();
double [][] dct_data = image_dtt.mdctStack(DBG_IMP.getStack(),
double [][][][] dctdc_data = image_dtt.mdctScale(
DBG_IMP.getStack(),
DCT_PARAMETERS.kernel_chn,
DCT_PARAMETERS,
THREADS_MAX, DEBUG_LEVEL, UPDATE_STATUS);
int tilesY = DBG_IMP.getHeight()/DCT_PARAMETERS.dct_size - 1;
int tilesX = DBG_IMP.getWidth()/DCT_PARAMETERS.dct_size - 1;
for (int chn = 0; chn < dctdc_data.length; chn++) {
image_dtt.dct_scale(
DCT_PARAMETERS.dbg_scale, // DCT_PARAMETERS.dct_size / DCT_PARAMETERS.dbg_src_size , //final double scale_hor, // < 1.0 - enlarge in dct domain (shrink in time/space)
DCT_PARAMETERS.dbg_scale, //DCT_PARAMETERS.dct_size / DCT_PARAMETERS.dbg_src_size, // final double scale_vert, // < 1.0 - enlarge in dct domain (shrink in time/space)
DCT_PARAMETERS.normalize, // final boolean normalize, // preserve weighted dct values
dctdc_data[chn], // final double [][][] dct_data,
DCT_PARAMETERS.tileX,
DCT_PARAMETERS.tileY,
THREADS_MAX, DEBUG_LEVEL);
}
for (int chn = 0; chn < dctdc_data.length; chn++) {
image_dtt.dct_lpf(
DCT_PARAMETERS.dbg_sigma,
dctdc_data[chn],
THREADS_MAX, DEBUG_LEVEL);
}
// int tilesY = DBG_IMP.getHeight()/DCT_PARAMETERS.dct_size - 1;
// int tilesX = DBG_IMP.getWidth()/DCT_PARAMETERS.dct_size - 1;
int tilesY = dctdc_data[0].length;
int tilesX = dctdc_data[0][0].length;
System.out.println("tilesX="+tilesX);
System.out.println("tilesY="+tilesY);
SDFA_INSTANCE.showArrays(dct_data,
double [][] dct = new double [dctdc_data.length][];
for (int chn = 0; chn < dct.length; chn++) {
dct[chn] = image_dtt.lapped_dct_dbg(
dctdc_data [chn],
THREADS_MAX,
DEBUG_LEVEL);
}
// System.out.println("dct_dc.length="+dct_dc.length+" dct_ac.length="+dct_ac.length);
if (DEBUG_LEVEL > 0){
SDFA_INSTANCE.showArrays(dct,
tilesX*DCT_PARAMETERS.dct_size,
tilesY*DCT_PARAMETERS.dct_size,
true,
DBG_IMP.getTitle()+"-DCT");
double [][] idct_data = new double [dct_data.length][];
}
double [][] idct_data = new double [dctdc_data.length][];
for (int chn=0; chn<idct_data.length;chn++){
idct_data[chn] = image_dtt.lapped_idct(
dct_data[chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
tilesX*DCT_PARAMETERS.dct_size, // dct_width,
dctdc_data[chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
DCT_PARAMETERS.dct_size, // final int
DCT_PARAMETERS.dct_window, //window_type
THREADS_MAX, // maximal number of threads to launch
......@@ -2721,10 +2781,12 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
(tilesX + 1) * DCT_PARAMETERS.dct_size,
(tilesY + 1) * DCT_PARAMETERS.dct_size,
true,
DBG_IMP.getTitle()+"-IDCT");
DBG_IMP.getTitle()+"-IDCTDC");
return;
/* ======================================================================== */
} else if (label.equals("MDCT DC stack")) {
} else if (label.equals("MDCT stack")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
// IJ.showMessage("DCT test 1");
if (!DCT_PARAMETERS.showDialog()) return;
......@@ -2759,8 +2821,9 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
}
ImageDtt image_dtt = new ImageDtt();
double [][][][] dctdc_data = image_dtt.mdctDcStack(
double [][][][] dctdc_data = image_dtt.mdctStack(
DBG_IMP.getStack(),
DCT_PARAMETERS.kernel_chn,
DCT_PARAMETERS,
EYESIS_DCT,
THREADS_MAX, DEBUG_LEVEL, UPDATE_STATUS);
......@@ -2777,36 +2840,24 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
int tilesX = DBG_IMP.getWidth()/DCT_PARAMETERS.dct_size - 1;
System.out.println("tilesX="+tilesX);
System.out.println("tilesY="+tilesY);
double [][] dct_dc = new double [dctdc_data.length][];
double [][] dct_ac = new double [dctdc_data.length][];
for (int chn = 0; chn < dct_dc.length; chn++) {
dct_dc[chn] = image_dtt.lapped_dct_dcac(
false, // out_ac, // false - output DC, true - output AC
dctdc_data [chn],
THREADS_MAX,
DEBUG_LEVEL);
dct_ac[chn] = image_dtt.lapped_dct_dcac(
true, // out_ac, // false - output DC, true - output AC
double [][] dct = new double [dctdc_data.length][];
for (int chn = 0; chn < dct.length; chn++) {
dct[chn] = image_dtt.lapped_dct_dbg(
dctdc_data [chn],
THREADS_MAX,
DEBUG_LEVEL);
}
// System.out.println("dct_dc.length="+dct_dc.length+" dct_ac.length="+dct_ac.length);
if (DEBUG_LEVEL > 0){
SDFA_INSTANCE.showArrays(dct_ac,
SDFA_INSTANCE.showArrays(dct,
tilesX*DCT_PARAMETERS.dct_size,
tilesY*DCT_PARAMETERS.dct_size,
true,
DBG_IMP.getTitle()+"-DCT_AC");
SDFA_INSTANCE.showArrays(dct_dc,
tilesX,
tilesY,
true,
DBG_IMP.getTitle()+"-DCT_DC");
DBG_IMP.getTitle()+"-DCT");
}
double [][] idct_data = new double [dctdc_data.length][];
for (int chn=0; chn<idct_data.length;chn++){
idct_data[chn] = image_dtt.lapped_idctdc(
idct_data[chn] = image_dtt.lapped_idct(
dctdc_data[chn], // scanline representation of dcd data, organized as dct_size x dct_size tiles
DCT_PARAMETERS.dct_size, // final int
DCT_PARAMETERS.dct_window, //window_type
......@@ -3070,8 +3121,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
......@@ -3086,7 +3137,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++){
......@@ -3537,14 +3588,15 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
EYESIS_DCT.createDCTKernels(
DCT_PARAMETERS,
/*
EYESIS_CORRECTIONS.pixelMapping,
*/
CONVOLVE_FFT_SIZE/2,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
//"Reset DCT kernels"
} else if (label.equals("Reset DCT kernels")) {
if (EYESIS_DCT != null){
EYESIS_DCT.resetDCTKernels();
}
} else if (label.equals("Read DCT kernels")) {
if (!DCT_PARAMETERS.showDialog()) return;
if (EYESIS_DCT == null){
......@@ -3591,6 +3643,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;
......@@ -4191,6 +4387,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);
......@@ -4213,6 +4410,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);
......
......@@ -31,175 +31,9 @@ public class ImageDtt {
}
public double [][] mdctStack(
final ImageStack imageStack,
final EyesisCorrectionParameters.DCTParameters dctParameters, //
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
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] =lapped_dct(
dpixels,
imgWidth,
dctParameters.dct_size,
0, // dct_mode, // 0: dct/dct, 1: dct/dst, 2: dst/dct, 3: dst/dst
dctParameters.dct_window, // final int window_type,
threadsMax, // maximal number of threads to launch
debugLevel);
}
return dct_data;
}
public double [] lapped_dct(
final double [] dpixels,
final int width,
final int dct_size,
final int dct_mode, // 0: dct/dct, 1: dct/dst, 2: dst/dct, 3: dst/dst
final int window_type,
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*dct_size*dct_size];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int i=0; i<dct_data.length;i++) dct_data[i]= 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[4*dct_size * dct_size];
double [] tile_folded;
double [] tile_out; // = new double[dct_size * dct_size];
int tileY,tileX;
int n2 = dct_size * 2;
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);
}
// tile_out=dtt.mdct_2d(tile_in, dct_mode, dct_size);
tile_folded=dtt.fold_tile(tile_in, dct_size);
tile_out=dtt.dttt_iv (tile_folded, dct_mode, dct_size);
for (int i = 0; i < dct_size;i++){
System.arraycopy(tile_out, dct_size* i, dct_data, ((tileY*dct_size + i) *tilesX + tileX)*dct_size , dct_size);
}
}
}
};
}
startAndJoin(threads);
return dct_data;
}
public double [] lapped_idct(
final double [] dct_data, // scanline representation of dcd data, organized as dct_size x dct_size tiles
final int dct_width,
final int dct_size,
final int window_type,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesX=dct_width/dct_size;
final int tilesY=dct_data.length/(dct_width*dct_size);
final int width= (tilesX+1)*dct_size;
final int height= (tilesY+1)*dct_size;
if (globalDebugLevel > 0) {
System.out.println("lapped_idct():dct_width="+dct_width);
System.out.println("lapped_idct():tilesX= "+tilesX);
System.out.println("lapped_idct():tilesY= "+tilesY);
System.out.println("lapped_idct():width= "+width);
System.out.println("lapped_idct():height= "+height);
double debug0 = 0.0;
for (int i=0;i<dct_data.length;i++){
debug0 +=dct_data[i]*dct_data[i];
}
debug0 = Math.sqrt(debug0)/dct_data.length;
System.out.println("lapped_idct():debug0= "+debug0+" (dct_data.length= "+dct_data.length+")");
}
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; // = new double[dct_size * dct_size];
double [] tile_out; // = new double[4*dct_size * dct_size];
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 i = 0; i < dct_size;i++){
System.arraycopy(dct_data, (tileY*dct_width+tileX)*dct_size + i*dct_width, tile_in, dct_size*i, dct_size);
}
tile_dct=dtt.dttt_iv (tile_in, 0, dct_size);
tile_out=dtt.unfold_tile(tile_dct, dct_size);
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] += tile_out[n2 * i + j]; // +1.0;
}
}
}
}
};
}
startAndJoin(threads);
}
return dpixels;
}
public double [][][][] mdctDcStack(
public double [][][][] mdctStack(
final ImageStack imageStack,
final int subcamera, //
final EyesisCorrectionParameters.DCTParameters dctParameters, //
final EyesisDCT eyesisDCT,
final int threadsMax, // maximal step in pixels on the maxRadius for 1 angular step (i.e. 0.5)
......@@ -210,27 +44,32 @@ public class ImageDtt {
if (imageStack==null) return null;
final int imgWidth=imageStack.getWidth();
final int nChn=imageStack.getSize();
double [][][][] dctdc_data = new double [nChn][][][];
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;
if (dctParameters.kernel_chn >=0 ){
dct_kernels = eyesisDCT.kernels[dctParameters.kernel_chn];
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){
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
dctdc_data[chn] =lapped_dctdc(
dct_data[chn] =lapped_dct(
dpixels,
imgWidth,
dctParameters.dct_size,
dctParameters.subtract_dc,
0, // dct_mode, // 0: dct/dct, 1: dct/dst, 2: dst/dct, 3: dst/dst
dctParameters.dct_window, // final int window_type,
chn,
......@@ -243,15 +82,13 @@ public class ImageDtt {
threadsMax, // maximal number of threads to launch
debugLevel);
}
return dctdc_data;
return dct_data;
}
// extract DC, result is an array [tilesY][tilesX][dct_size*dct_size+1] - last element is DC value
public double [][][] lapped_dctdc(
public double [][][] lapped_dct(
final double [] dpixels,
final int width,
final int dct_size,
final boolean subtract_dc,
final int dct_mode, // 0: dct/dct, 1: dct/dst, 2: dst/dct, 3: dst/dst
final int window_type,
final int color,
......@@ -269,12 +106,12 @@ public class ImageDtt {
final int tilesX=width/dct_size-1;
final int tilesY=height/dct_size-1;
final int nTiles=tilesX*tilesY;
final double [][][] dctdc_data = new double[tilesY][tilesX][dct_size*dct_size+1];
final double [][][] dct_data = new double[tilesY][tilesX][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 i=0; i<dctdc_data[tileY][tileX].length;i++) dctdc_data[tileY][tileX][i]= 0.0; // actually not needed, Java initializes arrays
for (int i=0; i<dct_data[tileY][tileX].length;i++) dct_data[tileY][tileX][i]= 0.0; // actually not needed, Java initializes arrays
}
}
double [] dc = new double [dct_size*dct_size];
......@@ -308,10 +145,8 @@ public class ImageDtt {
double [] tile_out; // = new double[dct_size * dct_size];
int tileY,tileX;
int n2 = dct_size * 2;
double dc;
double [] tile_out_copy = null;
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;
......@@ -434,16 +269,8 @@ 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);
dc = 0.0;
if (subtract_dc) {
for (int i = 0; i < tile_folded.length; i++) dc+=tile_folded[i];
dc /= tile_folded.length;
for (int i = 0; i < tile_folded.length; i++) tile_folded[i] -= dc;
}
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;
......@@ -512,32 +339,30 @@ public class ImageDtt {
System.out.println("s0="+s0+" s1="+s1+" s2="+s2+" s3="+s3);
}
}
System.arraycopy(tile_out, 0, dctdc_data[tileY][tileX], 0, tile_out.length);
dctdc_data[tileY][tileX][tile_out.length] = dc;
System.arraycopy(tile_out, 0, dct_data[tileY][tileX], 0, tile_out.length);
}
}
};
}
startAndJoin(threads);
return dctdc_data;
return dct_data;
}
// extract DC or AC components in linescan order (for visualization)
public double [] lapped_dct_dcac(
final boolean out_ac, // false - output DC, true - output AC
final double [][][] dctdc_data,
// extract DCT transformed parameters in linescan order (for visualization)
public double [] lapped_dct_dbg(
final double [][][] dct_data,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=dctdc_data.length;
final int tilesX=dctdc_data[0].length;
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(dctdc_data[0][0].length-1));
final int dct_size = (int) Math.round(Math.sqrt(dct_data[0][0].length));
final int dct_len = dct_size*dct_size;
final double [] dct_data = new double[tilesY*tilesX*(out_ac?dct_len:1)];
final double [] dct_data_out = new double[tilesY*tilesX*dct_len];
final Thread[] threads = newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int i=0; i<dct_data.length;i++) dct_data[i]= 0;
for (int i=0; i<dct_data_out.length;i++) dct_data_out[i]= 0;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
......@@ -546,31 +371,27 @@ public class ImageDtt {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
if (out_ac) {
for (int i = 0; i < dct_size;i++){
System.arraycopy(dctdc_data[tileY][tileX], dct_size* i, dct_data, ((tileY*dct_size + i) *tilesX + tileX)*dct_size , dct_size);
}
} else {
dct_data[tileY *tilesX + tileX] = dctdc_data[tileY][tileX][dct_len];
System.arraycopy(dct_data[tileY][tileX], dct_size* i, dct_data_out, ((tileY*dct_size + i) *tilesX + tileX)*dct_size , dct_size);
}
}
}
};
}
startAndJoin(threads);
return dct_data;
return dct_data_out;
}
public void dct_lpf(
final double sigma,
final double [][][] dctdc_data,
final double [][][] dct_data,
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=dctdc_data.length;
final int tilesX=dctdc_data[0].length;
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(dctdc_data[0][0].length-1));
final int dct_size = (int) Math.round(Math.sqrt(dct_data[0][0].length));
final int dct_len = dct_size*dct_size;
final double [] filter_direct= new double[dct_len];
if (sigma == 0) {
......@@ -598,19 +419,19 @@ public class ImageDtt {
filter_direct[i] /= sum;
}
if (globalDebugLevel > -1) {
if (globalDebugLevel > 0) {
for (int i=0; i<filter_direct.length;i++){
System.out.println("dct_lpf_psf() "+i+": "+filter_direct[i]);
}
}
DttRad2 dtt = new DttRad2(dct_size);
// final double [] filter= dtt.dttt_iii(filter_direct);
final double [] filter= dtt.dttt_iiie(filter_direct);
final double [] dbg_filter= dtt.dttt_ii(filter);
for (int i=0; i < filter.length;i++) filter[i] *= dct_size;
// for (int i=0; i < filter.length;i++) filter[i] *= dct_size;
for (int i=0; i < filter.length;i++) filter[i] *= 2*dct_size;
if (globalDebugLevel > -1) {
if (globalDebugLevel > 0) {
for (int i=0; i<filter.length;i++){
System.out.println("dct_lpf_psf() "+i+": "+filter[i]);
}
......@@ -630,7 +451,7 @@ public class ImageDtt {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
for (int i = 0; i < filter.length; i++){
dctdc_data[tileY][tileX][i] *= filter[i];
dct_data[tileY][tileX][i] *= filter[i];
}
}
}
......@@ -640,7 +461,7 @@ public class ImageDtt {
}
public double [][][][] dct_color_convert(
final double [][][][] dctdc_data,
final double [][][][] dct_data,
final double kr,
final double kb,
final double sigma_rb, // blur of channels 0,1 (r,b) in addition to 2 (g)
......@@ -649,10 +470,10 @@ public class ImageDtt {
final int threadsMax, // maximal number of threads to launch
final int globalDebugLevel)
{
final int tilesY=dctdc_data[0].length;
final int tilesX=dctdc_data[0][0].length;
final int tilesY=dct_data[0].length;
final int tilesX=dct_data[0][0].length;
final int nTiles=tilesX*tilesY;
final int dct_size = (int) Math.round(Math.sqrt(dctdc_data[0][0][0].length-1));
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 [][][][] yPrPb = new double [3][tilesY][tilesX][dct_len];
final double [][][] filters = new double [3][3][dct_len];
......@@ -680,9 +501,6 @@ public class ImageDtt {
if (sigmas[n] == 0.0) d = ((i == 0) && (j==0))? 1.0:0.0;
else d = Math.exp(-(i*i+j*j)/(2*sigmas[n]));
filters_proto_direct[n][i*dct_size+j] = d;
// if (i > 0) d*=2;
// if (j > 0) d*=2;
// s += d;
}
}
......@@ -690,7 +508,7 @@ public class ImageDtt {
s += norm_sym_weights[i]*filters_proto_direct[n][i];
}
System.out.println("dct_color_convert(): sigmas["+n+"]="+sigmas[n]+", sum="+s);
if (globalDebugLevel>0) System.out.println("dct_color_convert(): sigmas["+n+"]="+sigmas[n]+", sum="+s);
for (int i = 0; i < dct_len; i++){
filters_proto_direct[n][i] /=s;
}
......@@ -699,7 +517,7 @@ public class ImageDtt {
DttRad2 dtt = new DttRad2(dct_size);
for (int i = 0; i < filters_proto.length; i++){
filters_proto[i] = dtt.dttt_iiie(filters_proto_direct[i]);
System.out.println("filters_proto.length="+filters_proto.length+" filters_proto["+i+"].length="+filters_proto[i].length+" dct_len="+dct_len+" dct_size="+dct_size);
if (globalDebugLevel > 0) System.out.println("filters_proto.length="+filters_proto.length+" filters_proto["+i+"].length="+filters_proto[i].length+" dct_len="+dct_len+" dct_size="+dct_size);
for (int j=0; j < dct_len; j++) filters_proto[i][j] *= 2*dct_size;
}
......@@ -750,8 +568,7 @@ public class ImageDtt {
for (int k = 0; k <dct_len; k++){
yPrPb[i][tileY][tileX][k]=0.0;
for (int j = 0; j < filters[i].length; j++){
yPrPb[i][tileY][tileX][k] += filters[i][j][k] * dctdc_data[j][tileY][tileX][k];
// yPrPb[i][tileY][tileX][k] += filters[i][j][k] * dctdc_data[2][tileY][tileX][k]; // make it grey level (r=g=b)
yPrPb[i][tileY][tileX][k] += filters[i][j][k] * dct_data[j][tileY][tileX][k];
}
}
......@@ -769,9 +586,9 @@ public class ImageDtt {
// Restore DC
public double [] lapped_idctdc(
final double [][][] dctdc_data, // array [tilesY][tilesX][dct_size*dct_size+1] - last element is DC value
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]
final int dct_size,
final int window_type,
final int threadsMax, // maximal number of threads to launch
......@@ -779,8 +596,8 @@ public class ImageDtt {
{
// final int tilesX=dct_width/dct_size;
// final int tilesY=dct_data.length/(dct_width*dct_size);
final int tilesY=dctdc_data.length;
final int tilesX=dctdc_data[0].length;
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;
......@@ -805,7 +622,6 @@ public class ImageDtt {
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);
......@@ -823,12 +639,9 @@ 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];
System.arraycopy(dctdc_data[tileY][tileX], 0, tile_in, 0, tile_in.length);
// will get rid of the DC eventually
double dc = (dctdc_data[tileY][tileX].length > tile_in.length)?dctdc_data[tileY][tileX][tile_in.length]:0.0;
System.arraycopy(dct_data[tileY][tileX], 0, tile_in, 0, tile_in.length);
tile_dct=dtt.dttt_iv (tile_in, 0, dct_size);
for (int i = 0; i<tile_dct.length; i++) tile_dct[i] += dc;
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++) {
......@@ -844,6 +657,649 @@ 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, //
final EyesisCorrectionParameters.DCTParameters dctParameters, //
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
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] =lapped_dct_scale(
dpixels,
imgWidth,
dctParameters.dct_size,
(int) Math.round(dctParameters.dbg_src_size),
dctParameters.dbg_fold_scale,
dctParameters.dbg_fold_scale,
0, // dct_mode, // 0: dct/dct, 1: dct/dst, 2: dst/dct, 3: dst/dst
dctParameters.dct_window, // final int window_type,
chn,
dctParameters.tileX,
dctParameters.tileY,
dctParameters.dbg_mode,
threadsMax, // maximal number of threads to launch
debugLevel);
}
return dct_data;
}
public double [][][] lapped_dct_scale( // scale image to 8/9 size in each direction
final double [] dpixels,
final int width,
final int dct_size,
final int src_size, // source step (== dct_size - no scale, == 9 - shrink, ==7 - expand
final double scale_hor,
final double scale_vert,
final int dct_mode, // 0: dct/dct, 1: dct/dst, 2: dst/dct, 3: dst/dst
final int window_type,
final int color,
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 n2 = dct_size * 2;
final int tilesX = (width - n2) / src_size + 1;
final int tilesY = (height - n2) / src_size + 1;
final int nTiles=tilesX*tilesY;
final double [][][] dct_data = new double[tilesY][tilesX][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 i=0; i<dct_data[tileY][tileX].length;i++) dct_data[tileY][tileX][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);
// final double [] dciii = dtt0.dttt_iii (dc, dct_size);
// final double [] dciiie = dtt0.dttt_iiie (dc, dct_size);
if (globalDebugLevel > 0) {
System.out.println("lapped_dctdc(): width="+width+" height="+height);
}
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;
double [] tile_out; // = new double[dct_size * dct_size];
int tileY,tileX;
double [][][] fold_k = dtt.get_fold_2d(
// int n,
scale_hor,
scale_vert
);
// double [] tile_out_copy = null;
// 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;
//readDCTKernels() debugLevel = 1 kernels[0].size = 8 kernels[0].img_step = 16 kernels[0].asym_nonzero = 4 nColors = 3 numVert = 123 numHor = 164
// no aberration correction, just copy data
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, 0, fold_k); // DCCT
tile_out=dtt.dttt_iv (tile_folded, dct_mode, dct_size);
// if ((tileY == debug_tileY) && (tileX == debug_tileX) && (color == 2)) {
// tile_out_copy = tile_out.clone();
// }
System.arraycopy(tile_out, 0, dct_data[tileY][tileX], 0, tile_out.length);
}
}
};
}
startAndJoin(threads);
return dct_data;
}
public void dct_scale(
final double scale_hor, // < 1.0 - enlarge in dct domain (shrink in time/space)
final double scale_vert, // < 1.0 - enlarge in dct domain (shrink in time/space)
final boolean normalize, // preserve weighted dct values
final double [][][] dct_data,
final int debug_tileX,
final int debug_tileY,
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].length));
final int dct_len = dct_size*dct_size;
final double [] norm_sym_weights = new double [dct_size*dct_size];
for (int i = 0; i < dct_size; i++){
for (int j = 0; j < dct_size; j++){
double d = Math.cos(Math.PI*i/(2*dct_size))*Math.cos(Math.PI*j/(2*dct_size));
if (i > 0) d*= 2.0;
if (j > 0) d*= 2.0;
norm_sym_weights[i*dct_size+j] = d;
}
}
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;
double [] dct1 = new double [dct_size*dct_size];
double [] dct;
double [][] bidata = new double [2][2];
int dct_m1 = dct_size - 1;
int dct_m2 = dct_size - 2;
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
tileY = nTile/tilesX;
tileX = nTile - tileY * tilesX;
dct = dct_data[tileY][tileX];
double sum_orig=0;
if (normalize) {
for (int i = 0; i < dct_len; i++){
sum_orig += dct[i] *norm_sym_weights[i];
}
}
for (int i = 0; i < dct_size; i++){
double fi = i * scale_vert;
int i0 = (int) fi;
fi -= i0;
for (int j = 0; j < dct_size; j++){
double fj = j * scale_hor;
int j0 = (int) fj;
fj -= j0;
int indx = i0*dct_size+j0;
if ((i0 > dct_m1) || (j0 > dct_m1)){
bidata[0][0] = 0.0;
bidata[0][1] = 0.0;
bidata[1][0] = 0.0;
bidata[1][1] = 0.0;
} else {
bidata[0][0] = dct[indx];
if (i0 > dct_m2) {
bidata[1][0] = 0.0;
bidata[1][1] = 0.0;
if (j0 > dct_m2) {
bidata[0][1] = 0.0;
} else {
bidata[0][1] = dct[indx + 1];
}
} else {
bidata[1][0] = dct[indx+dct_size];
if (j0 > dct_m2) {
bidata[0][1] = 0.0;
bidata[1][1] = 0.0;
} else {
bidata[0][1] = dct[indx + 1];
bidata[1][1] = dct[indx + dct_size + 1];
}
}
}
// bilinear interpolation
dct1[i*dct_size+j] =
bidata[0][0] * (1.0-fi) * (1.0-fj) +
bidata[0][1] * (1.0-fi) * fj +
bidata[1][0] * fi * (1.0-fj) +
bidata[1][1] * fi * fj;
if ((globalDebugLevel > 0) && (tileY == debug_tileY) && (tileX == debug_tileX)) {
System.out.println(i+":"+j+" {"+bidata[0][0]+","+bidata[0][1]+","+bidata[1][0]+","+bidata[1][1]+"}, ["+fi+","+fj+"] "+bidata[1][1]);
}
}
}
if (normalize) {
double sum=0;
for (int i = 0; i < dct_len; i++){
sum += dct1[i] *norm_sym_weights[i];
}
if (sum >0.0) {
double k = sum_orig/sum;
for (int i = 0; i < dct_len; i++){
dct1[i] *= k;
}
}
}
// if ((tileY == debug_tileY) && (tileX == debug_tileX) && (color == 2)) {
if ((globalDebugLevel > 0) && (tileY == debug_tileY) && (tileX == debug_tileX)) {
double [][] scaled_tiles = {dct, dct1};
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
String [] titles = {"orig","scaled"};
sdfa_instance.showArrays(scaled_tiles, dct_size, dct_size, true, "scaled_tile", titles);
}
System.arraycopy(dct1, 0, dct, 0, dct_len); // replace original data
}
}
};
}
startAndJoin(threads);
}
......
......@@ -151,23 +151,11 @@ public class PixelMapping {
return (this.sensors != null) && (channel>=0) && (channel<this.sensors.length) && (this.sensors[channel]!=null);
}
/*
public int [] channelsForSubCamera(int subCamera){
if (this.sensors == null) return null;
int numChannels=0;
for (int i=0;i<this.sensors.length;i++) if ((this.sensors[i]!=null) &&(this.sensors[i].subcamera==subCamera)) numChannels++;
int [] result=new int [numChannels];
numChannels=0;
for (int i=0;i<this.sensors.length;i++) if ((this.sensors[i]!=null) &&(this.sensors[i].subcamera==subCamera)) result[numChannels++]=i;
return result;
}
*/
// Updating for nc393. subCamera here is 0..9 for Eyesis4pi393 - 0-based index of the file, so it combines physical camera (separate IP)
// as stored in "subcamera" field of the calibration file and "sensor_port". sensor_port may start from non-0, so we need to count all combinations
//removeUnusedSensorData xshould be off!
public int [] channelsForSubCamera(int subCamera){
System.out.println("channelsForSubCamera("+subCamera+"),this.sensors.length="+this.sensors.length);
// ArrayList<ArrayList<ArrayList<Integer>>> camera_IPs = new ArrayList<ArrayList<ArrayList<Integer>>>();
ArrayList<Point> cam_port = new ArrayList<Point>();
for (int i=0;i<this.sensors.length;i++) if (this.sensors[i]!=null) {
......@@ -175,6 +163,7 @@ public class PixelMapping {
if (!cam_port.contains(cp)){
cam_port.add(cp);
}
// System.out.println("this.sensors["+i+"]!=null, this.sensors[i].subcamera="+this.sensors[i].subcamera+", this.sensors[i].sensor_port="+this.sensors[i].sensor_port);
}
Point [] cam_port_arr = cam_port.toArray(new Point[0]);
Arrays.sort(cam_port_arr, new Comparator<Point>() {
......@@ -183,9 +172,7 @@ public class PixelMapping {
return (o1.x>o2.x)? 1:((o1.x < o2.x)?-1:(o1.y > o2.y)? 1:((o1.y < o2.y)?-1:0));
}
});
// for (int i=0; i<cam_port_arr.length;i++){
// System.out.println("----- physical camera #"+cam_port_arr[i].x+", sensor_port="+cam_port_arr[i].y);
// }
// debugging:
System.out.println("----- This filename subcamera "+subCamera+": physical camera "+cam_port_arr[subCamera].x+", sensor_port "+cam_port_arr[subCamera].y);
if (subCamera >= cam_port_arr.length) {
System.out.println("Error: Subcamera "+subCamera+" > that total namera of sensor ports in the system = "+cam_port_arr.length);
......
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