DoubleFHTfht_instance=newDoubleFHT();// provide DoubleFHT instance to save on initializations (or null)
showDoubleFloatArraysSDFA_instance=null;// just for debugging?
deBayerScissorsdebayer_instance=newdeBayerScissors(debayerParameters.size,// size of the square array, centar is at size/2, size/2, only top half+line will be used
tile[chn],// will be filled, should have correct size before call
slidingWindow,// window (same size as the kernel)
imgWidth,// width of pixels array
tileX*step,// left corner X
tileY*step);// top corner Y
}
/* Scale green channel x0.5 as there are twice more pixels there as in red or blue. Or move it somewhere else and multiply to original range ? */
deBayerScissorsdebayer_instance=newdeBayerScissors(debayerParameters.size,// size of the square array, centar is at size/2, size/2, only top half+line will be used
both_masks=debayer_instance.aliasScissors(tile[greenChn],// fht array for green, will be masked in-place
if(tileX<2){
debayerParameters.debayerThreshold,// no high frequencies - use default uniform filter
inttrow=(tileY+((tileY&1)*tilesY))/2;
debayerParameters.debayerGamma,// power function applied to the amplitudes before generating spectral masks
if(updateStatus)IJ.showStatus("Reducing sampling aliases, row "+(trow+1)+" of "+tilesY);
debayerParameters.debayerBonus,// scale far pixels as (1.0+bonus*r/rmax)
// System.out.println("(1)Reducing sampling aliases, row "+(tileY+1)+" of "+tilesY+" ("+nTile+"/"+nTile0+") col="+(tileX+1));
debayerParameters.mainToAlias,// relative main/alias amplitudes to enable lixels (i.e. 0.5 means that if alias is >0.5*main, the pixel will be masked out)
if(globalDebugLevel>2)System.out.println("(1)Reducing sampling aliases, row "+(tileY+1)+" of "+tilesY+" : "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
debayerParameters.debayerMaskBlur,// for both masks sigma for gaussian blur of the binary masks (<0 -do not use "scissors")
}
debayerParameters.debayerUseScissors,// use "scissors", if false - just apply "diamond" ands "square" with DEBAYER_PARAMETERS.debayerRelativeWidthGreen and DEBAYER_PARAMETERS.debayerRelativeWidthRedblue
both_masks=debayer_instance.aliasScissors(tile[greenChn],// fht array for green, will be masked in-place
debayerParameters.debayerThreshold,// no high frequencies - use default uniform filter
debayerParameters.debayerGamma,// power function applied to the amplitudes before generating spectral masks
debayerParameters.debayerBonus,// scale far pixels as (1.0+bonus*r/rmax)
debayerParameters.mainToAlias,// relative main/alias amplitudes to enable pixels (i.e. 0.5 means that if alias is >0.5*main, the pixel will be masked out)
debayerParameters.debayerMaskBlur,// for both masks sigma for Gaussian blur of the binary masks (<0 -do not use "scissors")
debayerParameters.debayerUseScissors,// use "scissors", if false - just apply "diamond" ands "square" with DEBAYER_PARAMETERS.debayerRelativeWidthGreen and DEBAYER_PARAMETERS.debayerRelativeWidthRedblue
debayer_bonus,// scale far pixels as (1.0+bonus*r/rmax)
mainToAlias,// relative main/alias amplitudes to enable pixels (i.e. 0.5 means that if alias is >0.5*main, the pixel will be masked out)
this_debug);// relative main/alias amplitudes to enable lixels (i.e. 0.5 means that if alias is >0.5*main, the pixel will be masked out)
debayer_bonus,// scale far pixels as (1.0+bonus*r/rmax)
this_debug);// relative main/alias amplitudes to enable pixels (i.e. 0.5 means that if alias is >0.5*main, the pixel will be masked out)
/* add double mainToAlias){// relative main/alias amplitudes to enable pixels (i.e. 0.5 means that if alias is >0.5*main, the pixel will be masked out) */
/* add double mainToAlias){// relative main/alias amplitudes to enable pixels (i.e. 0.5 means that if alias is >0.5*main, the pixel will be masked out) */
privateint[][]polar2CartesianIndices;// for each polar angle/radius (angle*iRadiusPlus1+radius) - 4 interpolation corners (0:0, dx:0, 0:dy, dx:dy), the first (0:0) being the closest to the polar point
publicintiRadiusPlus1;// number of radius steps
privatedouble[][]polar2CartesianFractions;// a pair of dx, dy for interpolations (used with ) polar2CartesianIndices[][]]
publicintiAngle;
privateint[][]cartesian2PolarIndices;// each per-pixel array is a list of indices in polar array pointing to this cell (may be empty)
publicdoubleaStep;
privateint[]cartesian2PolarIndex;// Cartesian->polar array index (cell closest to the center). Is it possible that cartesian2PolarIndices does not include this one?
publicdoublerStep;
privateint[][]polarGreenMap=null;// each element is a variable length integer array with a list of the alias indices
publicintsize;
privateint[][]polarRedBlueMap=null;// each element is a variable length integer array with a list of the alias indices
publicintlength;
privateint[][]sameCartesian=null;// each element is a variable length integer array with a list of indices of the other polar cells that belong (point to) the same cartesian cell
// Make them private later, after debugging
privateint[]cartAmpList=null;// list of indices of the elements of the cartesian array (symmetrical around the center) so the distance is between ampRMinMax[0] and ampRMinMax[1]
privateint[][]polar2CartesianIndices;// for each polar angle/radius (angle*iRadiusPlus1+radius) - 4 interpolation corners (0:0, dx:0, 0:dy, dx:dy), the first (0:0) being the closest to the polar point
privatedouble[]ampRMinMax={0.0,0.0};
privatedouble[][]polar2CartesianFractions;// a pair of dx, dy for interpolations (used with ) polar2CartesianIndices[][]]
publicPolarSpectrums(){}// so "Compile and Run" will be happy
privateint[][]cartesian2PolarIndices;// each per-pixel array is a list of indices in polar array pointing to this cell (may be empty)
/* Convert cartesian to polar array, dimensions are set in the class constructor. Uses bi-linear interpolation */
privateint[]cartesian2PolarIndex;// Cartesian->polar array index (cell closest to the center). Is it possible that cartesian2PolarIndices does not include this one?
privateint[][]polarRedBlueMap=null;// each element is a variable length integer array with a list of the alias indices
inti;
privateint[][]sameCartesian=null;// each element is a variable length integer array with a list of indices of the other polar cells that belong (point to) the same cartesian cell
for(i=0;i<polPixels.length;i++){
privateint[]cartAmpList=null;// list of indices of the elements of the cartesian array (symmetrical around the center) so the distance is between ampRMinMax[0] and ampRMinMax[1]
/* Caculates maximal value of a center-symmetrical array of the amplitudes in a ring. Uses cached table of indices, recalculates if it changed */
if(symmHalf){
publicdoublemaxAmpInRing(double[]amps){returnmaxAmpInRing(amps,size*0.118,size*0.236);}// ~=1/3* (Math.sqrt(2)/4), 2/3* (Math.sqrt(2)/4) (center 1/3 ring between center and the closest alias for greens)
/* Caculates maximal value of a center-symmetrical array of the amplitudes in a ring. Uses cached table of indices, recalculates if it changed */
ampRMinMax[0]=rMin;
publicdoublemaxAmpInRing(double[]amps){returnmaxAmpInRing(amps,size*0.118,size*0.236);}// ~=1/3* (Math.sqrt(2)/4), 2/3* (Math.sqrt(2)/4) (center 1/3 ring between center and the closest alias for greens)
int[]rayLength=newint[iAngle+1];// index (radius)) of the current ray end for this angle
intl;
boolean[]rayOpen=newboolean[iAngle+1];// this ray can grow (not blocked)
doublemax;
for(i=0;i<iAngle;i++){
intnewVal;
rayLength[i]=0;
intstep=0;
rayOpen[i]=true;
intiMax=0;// index of the best ray
}
intindex=0;
intlastIndex;
booleangood=true;
intbase;
while(iMax>=0){
intl;
step++;
doublemax;
/* add polar point index */
intnewVal;
newVal=good?step:-step;
intstep=0;
// index=iMax*iRadiusPlus1+rayLength[iMax]; // rayLength[iMax] should point to a new cell (with intMap[]==0) may ommit - set in the end of the loop and before the loop?
// index=iMax*iRadiusPlus1+rayLength[iMax]; // rayLength[iMax] should point to a new cell (with intMap[]==0) may ommit - set in the end of the loop and before the loop?
/* Create per-polar pixel list of aliases for green Bayer. For each polar point it shows the polar coordinates of the same (and rotated by pi) point of aliases */
/* current implementation - us cartesian (original) pixels as all/nothing, maybe it makes sense to go directly polar-polar, but then it may leave gaps */
/* Create per-polar pixel list of aliases for green Bayer. For each polar point it shows the polar coordinates of the same (and rotated by pi) point of aliases */
{-1,-2},{-1,-1},{-1,0},{-1,1},
/* current implementation - us cartesian (original) pixels as all/nothing, maybe it makes sense to go directly polar-polar, but then it may leave gaps */