Commit 737075f8 authored by Andrey Filippov's avatar Andrey Filippov

added source image padding to match WOI in properties, making kernel

generation with large-cell calibration pattern
......@@ -5949,6 +5949,16 @@ if (MORE_BUTTONS) {
IJ.showMessage("LENS_DISTORTION.fittingStrategy is not set");
return;
}
DistortionCalibrationData dcd = LENS_DISTORTIONS.getDistortionCalibrationData();
if (dcd == null) {
dcd = DISTORTION_CALIBRATION_DATA;
}
if (dcd == null) {
System.out.println("dcd is null");
return;
}
GenericDialog gd=new GenericDialog ("Parameters of the filter by predicted grid");
gd.addNumericField("Mismatch tolerance of match between the predicted and acquired grid", 0.5, 1,4,"fraction of grid half-period");
gd.addCheckbox ("Calibrate by translation (false - orientation only)", true);
......@@ -5957,6 +5967,8 @@ if (MORE_BUTTONS) {
gd.addCheckbox ("Process images with estimated orientation and no matched laser pointers", false);
gd.addCheckbox ("Use image sets data if available (false - use camera data)", true);
gd.addNumericField("Process only one specified image (<0 - all)", -1, 0);
gd.addNumericField("Start image set", 0, 0);
gd.addNumericField("End image set", dcd.getNumSets()-1, 0);
gd.showDialog();
if (gd.wasCanceled()) return;
......@@ -5967,6 +5979,8 @@ if (MORE_BUTTONS) {
boolean processBlind= gd.getNextBoolean();
boolean useSetsData= gd.getNextBoolean();
int imageNumber= (int) gd.getNextNumber();
int start_set= (int) gd.getNextNumber();
int end_set= (int) gd.getNextNumber();
if (imageNumber>=0) processAll=true; // no additional filtering
int numMatched=LENS_DISTORTIONS.applyHintedGrids(
......@@ -5977,6 +5991,8 @@ if (MORE_BUTTONS) {
ignoreLaserPointers,
processBlind,
imageNumber,
start_set,
end_set,
useSetsData,
THREADS_MAX, //int threadsMax,
UPDATE_STATUS, // boolean updateStatus,
......@@ -925,6 +925,8 @@ import ij.text.TextWindow;
getImagePlusProperty(imp_grid,"WOI_TOP",0),
getImagePlusProperty(imp_grid,"WOI_WIDTH", eyesisCameraParameters.getSensorWidth(nc)),
getImagePlusProperty(imp_grid,"WOI_HEIGHT", eyesisCameraParameters.getSensorHeight(nc)));
// boolean woi_compensated = getImagePlusProperty(imp_grid,"WOI_COMPENSATED",false);
boolean woi_compensated = (this.gIP[numFile].woi.x == 0) && (this.gIP[numFile].woi.y == 0);
this.gIP[numFile].gridImage = imp_grid; // Save all images?
this.gIP[numFile].laserPixelCoordinates = MatchSimulatedPattern.getPointersXYUV(imp_grid, laserPointers);
......@@ -958,9 +960,23 @@ import ij.text.TextWindow;
throw new IllegalArgumentException (msg);
}
float [][] pixels=new float[stack.getSize()][]; // now - 8 (x,y,u,v,contrast, vignR,vignG,vignB
for (int i=0;i<pixels.length;i++) pixels[i]= (float[]) stack.getPixels(i+1); // pixel X : negative - no grid here
if (!woi_compensated) {
System.out.print(" woi_compensation-a "+numFile+" ");
for (int i = 0; i < pixels[0].length; i++) {
pixels[0][i] += this.gIP[numFile].woi.x;
pixels[1][i] += this.gIP[numFile].woi.y;
}
this.gIP[numFile].woi.width += this.gIP[numFile].woi.x;
this.gIP[numFile].woi.x = 0;
this.gIP[numFile].woi.height += this.gIP[numFile].woi.y;
this.gIP[numFile].woi.y = 0;
woi_compensated = true;
}
set_pixels[nc] = pixels;
set_widths[nc] = imp_grid.getWidth();
for (int i=0;i<pixels.length;i++) pixels[i]= (float[]) stack.getPixels(i+1); // pixel X : negative - no grid here
int numBadNodes = 0;
if (this.eyesisCameraParameters.badNodeThreshold>0.0){
boolean thisDebug =false;
......@@ -1208,8 +1224,25 @@ import ij.text.TextWindow;
IJ.showMessage("Error",msg);
throw new IllegalArgumentException (msg);
}
// boolean woi_compensated_master= getImagePlusProperty(imp_master_grid,"WOI_COMPENSATED",false);
boolean woi_compensated_master = (getImagePlusProperty(imp_master_grid,"WOI_TOP",0) == 0) &&
(getImagePlusProperty(imp_master_grid,"WOI_LEFT",0) == 0);
float [][] pixels_master =new float[stack_master.getSize()][]; // now - 8 (x,y,u,v,contrast, vignR,vignG,vignB
for (int i=0;i<pixels_master.length;i++) pixels_master[i]= (float[]) stack_master.getPixels(i+1); // pixel X : negative - no grid here
if (!woi_compensated_master) {
for (int i = 0; i < pixels_master[0].length; i++) {
pixels_master[0][i] += this.gIP[imgMaster].woi.x;
pixels_master[1][i] += this.gIP[imgMaster].woi.y;
}
this.gIP[imgMaster].woi.width += this.gIP[imgMaster].woi.x;
this.gIP[imgMaster].woi.x = 0;
this.gIP[imgMaster].woi.height += this.gIP[imgMaster].woi.y;
this.gIP[imgMaster].woi.y = 0;
woi_compensated_master = true;
}
int width_master = imp_master_grid.getWidth();
// If master is LWIR - reset it's shift to zero
if (lwir_mark >=0) {
......@@ -1251,8 +1284,24 @@ import ij.text.TextWindow;
IJ.showMessage("Error",msg);
throw new IllegalArgumentException (msg);
}
// boolean woi_compensated = getImagePlusProperty(imp_grid,"WOI_COMPENSATED",false);
boolean woi_compensated = (this.gIP[imgNum].woi.x == 0) && (this.gIP[imgNum].woi.y == 0);
float [][] pixels =new float[stack.getSize()][]; // now - 8 (x,y,u,v,contrast, vignR,vignG,vignB
for (int i=0;i<pixels.length;i++) pixels[i]= (float[]) stack.getPixels(i+1); // pixel X : negative - no grid here
if (!woi_compensated) {
System.out.print(" woi_compensation-b "+imgNum+" ");
for (int i = 0; i < pixels[0].length; i++) {
pixels[0][i] += this.gIP[imgNum].woi.x;
pixels[1][i] += this.gIP[imgNum].woi.y;
}
this.gIP[imgNum].woi.width += this.gIP[imgNum].woi.x;
this.gIP[imgNum].woi.x = 0;
this.gIP[imgNum].woi.height += this.gIP[imgNum].woi.y;
this.gIP[imgNum].woi.y = 0;
woi_compensated = true;
}
int width_lwir = imp_grid.getWidth();
double [] sensor_wh = {
this.gIP[imgNum].woi.width + this.gIP[imgNum].woi.x,
......@@ -1404,6 +1453,7 @@ import ij.text.TextWindow;
int [] uv_shift_rot,
PatternParameters patternParameters) {
ImagePlus imp_grid = null;
boolean woi_compensated = true;
if (this.gIP[img_num].gridImage!=null){ // use in-memory grid images instead of the files
int numGridImg=img_num;
if (numGridImg>=this.gIP.length) numGridImg=this.gIP.length-1;
......@@ -1416,6 +1466,9 @@ import ij.text.TextWindow;
throw new IllegalArgumentException (msg);
}
(new JP46_Reader_camera()).decodeProperiesFromInfo(imp_grid);
woi_compensated = (getImagePlusProperty(imp_grid,"WOI_TOP",0) == 0) &&
(getImagePlusProperty(imp_grid,"WOI_LEFT",0) == 0);
// woi_compensated = getImagePlusProperty(imp_grid,"WOI_COMPENSATED",false);
} else {
System.out.println("Grid is not in memory, file path is not specified");
return null;
......@@ -1427,8 +1480,23 @@ import ij.text.TextWindow;
throw new IllegalArgumentException (msg);
}
float [][] pixels=new float[stack.getSize()][]; // now - 8 (x,y,u,v,contrast, vignR,vignG,vignB
for (int i=0;i<pixels.length;i++) pixels[i]= (float[]) stack.getPixels(i+1); // pixel X : negative - no grid here
int [] combinedUVShiftRot=MatchSimulatedPattern.combineUVShiftRot(
if (!woi_compensated) { // in memory - always compensated
System.out.print(" woi_compensation-c "+img_num+" ");
for (int i = 0; i < pixels[0].length; i++) {
pixels[0][i] += this.gIP[img_num].woi.x;
pixels[1][i] += this.gIP[img_num].woi.y;
}
this.gIP[img_num].woi.width += this.gIP[img_num].woi.x;
this.gIP[img_num].woi.x = 0;
this.gIP[img_num].woi.height += this.gIP[img_num].woi.y;
this.gIP[img_num].woi.y = 0;
woi_compensated = true;
}
int [] combinedUVShiftRot=MatchSimulatedPattern.combineUVShiftRot(
this.gIP[img_num].getUVShiftRot(),
uv_shift_rot);
this.gIP[img_num].setUVShiftRot(combinedUVShiftRot); // uv_shift_rot);
......@@ -2020,7 +2088,7 @@ import ij.text.TextWindow;
}
sb.append("\n");
}
new TextWindow("Image calibration state (pointers/hinted state)", header, sb.toString(), 900,1400);
new TextWindow("Image calibration state (pointers/hinted state)", header, sb.toString(), 1400, 900);
}
......@@ -3286,6 +3354,7 @@ import ij.text.TextWindow;
int numOfGridNodes=0;
int numOfGridNodes_extra=0;
for (int fileNumber=0;fileNumber<numImages;fileNumber++){
boolean woi_compensated = true;
if (this.gIP[fileNumber].gridImage!=null){ // use in-memory grid images instead of the files
int numGridImg=fileNumber;
if (numGridImg>=this.gIP.length) numGridImg=this.gIP.length-1;
......@@ -3293,6 +3362,7 @@ import ij.text.TextWindow;
this.gIP[numGridImg].gridImage.getTitle());
if (this.debugLevel>1) System.out.print((fileNumber+1)+": "+this.gIP[numGridImg].gridImage.getTitle());
imp_grid=this.gIP[numGridImg].gridImage;
// in memory grid pixels are always compensated
} 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);
......@@ -3304,6 +3374,10 @@ import ij.text.TextWindow;
}
// TODO: here - need to decode properties
jp4_reader.decodeProperiesFromInfo(imp_grid);
// woi_compensated = getImagePlusProperty(imp_grid,"WOI_COMPENSATED",false);
woi_compensated = (getImagePlusProperty(imp_grid,"WOI_TOP",0) == 0) &&
(getImagePlusProperty(imp_grid,"WOI_LEFT",0) == 0);
if (keep_images) {
this.gIP[fileNumber].gridImage = imp_grid;
}
......@@ -3337,7 +3411,19 @@ import ij.text.TextWindow;
}
float [][] pixels=new float[stack.getSize()][]; // now - 8 (x,y,u,v,contrast, vignR,vignG,vignB
for (int i=0;i<pixels.length;i++) pixels[i]= (float[]) stack.getPixels(i+1); // pixel X : negative - no grid here
if (!woi_compensated) {
System.out.print(" woi_compensation-d "+fileNumber+" ");
for (int i = 0; i < pixels[0].length; i++) {
pixels[0][i] += this.gIP[fileNumber].woi.x;
pixels[1][i] += this.gIP[fileNumber].woi.y;
}
this.gIP[fileNumber].woi.width += this.gIP[fileNumber].woi.x;
this.gIP[fileNumber].woi.x = 0;
this.gIP[fileNumber].woi.height += this.gIP[fileNumber].woi.y;
this.gIP[fileNumber].woi.y = 0;
woi_compensated = true;
}
if (this.eyesisCameraParameters.badNodeThreshold>0.0){
boolean thisDebug =false;
......@@ -3815,7 +3901,7 @@ import ij.text.TextWindow;
}
return n;
}
// check if the channel is the first in group
// check if the channel is the first in group that represents settings
public boolean firstInGroup(int chn) {
if (chn >= 24) return (chn == 24);
if ((chn == getEo0()) || (chn == getLwir0())) return true;
......@@ -3828,6 +3914,14 @@ import ij.text.TextWindow;
else return (num[0] == 1);
}
// can be a clone of the previous channel (same value)
public int sourceToCopy(int chn) {
if ((chn == getEo0()) || (chn == getLwir0())) return -1; // no prototype to copy
return chn -1; // copy from previous
}
public String getSubName(int chn, boolean full) {
int groups = getSubGroups();
if (groups == 1) return full?"Single subcamera":"sub"; // single camera
......
......@@ -270,6 +270,9 @@ public class Distortions {
@Override
public void run() {
for (int imgNum=imageNumberAtomic.getAndIncrement(); imgNum<numImg;imgNum=imageNumberAtomic.getAndIncrement()){
// if (imgNum == 443) {
// System.out.println("calculateGridImageMasks(), imgNum="+imgNum);
// }
distortionCalibrationData[imgNum].calculateMask(
minContrast,
shrinkBlurSigma,
......@@ -2705,6 +2708,43 @@ For each point in the image
int mspDebugLevel,
int global_debug_level, // DEBUG_LEVEL
int debug_level // debug level used inside loops
){
return applyHintedGrids(
laserPointer, // LaserPointer object that specifies actual laser pointers on the target
removeOutOfGridPointers,
hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
processAll, // if true - process all images, false - only disabled
ignoreLaserPointers, // ignore laser pointers, rely on hints only
processBlind, // try to match without known orientation and no laser pointers
imageNumber, // <0 - all, >=0 only this image
0, // int start_set,
this.fittingStrategy.distortionCalibrationData.getNumSets()-1, // int end_set,
useSetData,
threadsMax,
updateStatus,
mspDebugLevel,
global_debug_level, // DEBUG_LEVEL
debug_level // debug level used inside loops
);
}
public int applyHintedGrids(
LaserPointer laserPointer, // LaserPointer object that specifies actual laser pointers on the target
boolean removeOutOfGridPointers,
double hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
boolean processAll, // if true - process all images, false - only disabled
boolean ignoreLaserPointers, // ignore laser pointers, rely on hints only
boolean processBlind, // try to match without known orientation and no laser pointers
int imageNumber, // <0 - all, >=0 only this image
int start_set,
int end_set,
boolean useSetData,
int threadsMax,
boolean updateStatus,
int mspDebugLevel,
int global_debug_level, // DEBUG_LEVEL
int debug_level // debug level used inside loops
){
int debugThreshold0=0;
int debugThreshold=2;
......@@ -2728,22 +2768,26 @@ For each point in the image
double [] xy0={0.0,0.0} ; //(old) debug only
int numSuccess=0;
DistortionCalibrationData dcd=fittingStrategy.distortionCalibrationData;
for (int numGridImage=0;numGridImage<dcd.gIP.length;numGridImage++)
if (((imageNumber<0) || (imageNumber==numGridImage)) &&(processAll ||
for (int numGridImage=0;numGridImage<dcd.gIP.length;numGridImage++) {
int set_number = dcd.gIP[numGridImage].getSetNumber();
if ((set_number >= start_set) &&
(set_number <= end_set) &&
(((imageNumber<0) ||
((imageNumber==numGridImage)) &&(processAll) ||
(!dcd.gIP[numGridImage].enabled &&
((hintGridTolerance>0.0)||((dcd.gIP[numGridImage].matchedPointers>0)) && !ignoreLaserPointers)))){ // skip no-pointers if only orientation is hinted
((hintGridTolerance>0.0) || ((dcd.gIP[numGridImage].matchedPointers>0)) && !ignoreLaserPointers))))){ // skip no-pointers if only orientation is hinted
if (((dcd.gIP[numGridImage].matchedPointers==0) || ignoreLaserPointers)&&
(dcd.gIS[dcd.get_gIS_index(numGridImage)].orientationEstimated)) {
if ( !processBlind) {
if (this.debugLevel>0) {
System.out.println("\n**** Orientation is not known exactly for image # "+numGridImage+" - "+dcd.gIP[numGridImage].path+
", and there are no laser pointer references (processBlind==false) - skipping");
", and there are no laser pointer references (processBlind==false) - skipping");
}
continue;
} else {
if (this.debugLevel>0) {
System.out.println("\n**** Orientation is not known exactly for image # "+numGridImage+" - "+dcd.gIP[numGridImage].path+
", and there are no laser pointer references, but processBlind is enabled, proceeding");
", and there are no laser pointer references, but processBlind is enabled, proceeding");
}
}
}
......@@ -2772,17 +2816,17 @@ For each point in the image
}
double [][][] pixelsXYSet={
dcd.gIP[numGridImage].pixelsXY,
dcd.gIP[numGridImage].pixelsXY_extra};
dcd.gIP[numGridImage].pixelsXY,
dcd.gIP[numGridImage].pixelsXY_extra};
int [][][] pixelsUVSet={
dcd.gIP[numGridImage].pixelsUV,
dcd.gIP[numGridImage].pixelsUV_extra};
// shifts pixelsUV to have minimal u,v of 0 (stores shift in this.minUV), sets PATTERN_GRID
// shifts pixelsUV to have minimal u,v of 0 (stores shift in this.minUV), sets PATTERN_GRID
matchSimulatedPattern.restorePatternGridFromGridList(
pixelsXYSet, //double [][] pixelsXY,
pixelsUVSet, // int [][] pixelsUV,
dcd.gIP[numGridImage].intensityRange
); // width and height will be calculated from maximal of pixelsXY
); // width and height will be calculated from maximal of pixelsXY
boolean OK=matchSimulatedPattern.createUV_INDEX( /// **** fails here
null, //imp, // or null - just to determine WOI (when getWOI matches image size)
xy0, // add to patterGrid xy, null OK
......@@ -2811,7 +2855,7 @@ For each point in the image
goniometerTiltAxial[2], // inter-axis angle
setNumber, // -1 or specific image set
true // filter border
);
);
if (global_debug_level>0){
System.out.println("\n**** applyHintedGrids(): processing grid image # "+numGridImage+", path="+dcd.gIP[numGridImage].path);
}
......@@ -2825,21 +2869,21 @@ For each point in the image
int rslt= matchSimulatedPattern.combineGridCalibration(
laserPointer, // LaserPointer object or null
ignoreLaserPointers?null:dcd.gIP[numGridImage].laserPixelCoordinates, //pointersXY,
removeOutOfGridPointers, //
hintGrid, // predicted grid array (or null)
hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
global_debug_level, // DEBUG_LEVEL
noMessageBoxes );
removeOutOfGridPointers, //
hintGrid, // predicted grid array (or null)
hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
global_debug_level, // DEBUG_LEVEL
noMessageBoxes );
if (global_debug_level>0){
System.out.println("applyHintedGrids(): rslt="+rslt);
}
if (rslt<0) { // failed hinting
dcd.gIP[numGridImage].hintedMatch =0;
} else {
// re-create pixelsXY, pixelsXY_extra, pixelsUV, pixelsUV_extra
int size=0;
int size_extra=0;
/* System.out.println("numGridImage="+numGridImage+" matchSimulatedPattern.getHeight()="+matchSimulatedPattern.getHeight()+
// re-create pixelsXY, pixelsXY_extra, pixelsUV, pixelsUV_extra
int size=0;
int size_extra=0;
/* System.out.println("numGridImage="+numGridImage+" matchSimulatedPattern.getHeight()="+matchSimulatedPattern.getHeight()+
" matchSimulatedPattern.getWidth()="+matchSimulatedPattern.getWidth()+
" matchSimulatedPattern.targetUV is "+((matchSimulatedPattern.targetUV==null)?"null":"not null")+
" matchSimulatedPattern.pixelsUV is "+((matchSimulatedPattern.pixelsUV==null)?"null":"not null")
......@@ -2848,87 +2892,87 @@ For each point in the image
" matchSimulatedPattern.targetUV[0] is "+((matchSimulatedPattern.targetUV[0]==null)?"null":"not null")+
" matchSimulatedPattern.pixelsUV[0] is "+((matchSimulatedPattern.pixelsUV[0]==null)?"null":"not null")
);*/
for (int v=0;v<matchSimulatedPattern.getHeight();v++) for (int u=0;u<matchSimulatedPattern.getWidth();u++) {
/* System.out.println("v="+v+", u="+u);
for (int v=0;v<matchSimulatedPattern.getHeight();v++) for (int u=0;u<matchSimulatedPattern.getWidth();u++) {
/* System.out.println("v="+v+", u="+u);
System.out.println(" matchSimulatedPattern.targetUV[v][u] is "+((matchSimulatedPattern.targetUV[v][u]==null)?"null":"not null"));
System.out.println(" matchSimulatedPattern.pixelsUV[v][u] is "+((matchSimulatedPattern.pixelsUV[v][u]==null)?"null":"not null"));*/
if ((matchSimulatedPattern.targetUV[v][u]!=null) && (matchSimulatedPattern.pXYUV [v][u]!=null)){
if ((matchSimulatedPattern.targetUV[v][u]!=null) && (matchSimulatedPattern.pXYUV [v][u]!=null) &&
(matchSimulatedPattern.pXYUV[v][u][0]>=0.0) || (matchSimulatedPattern.pXYUV[v][u][1]>=0.0)) { // disregard negative sensor pixels
// System.out.println(" matchSimulatedPattern.targetUV[v][u] is "+((matchSimulatedPattern.targetUV[v][u]==null)?"null":"not null"));
// System.out.println(" matchSimulatedPattern.targetUV[v][u][0]= "+matchSimulatedPattern.targetUV[v][u][0]);
// System.out.println(" matchSimulatedPattern.targetUV[v][u][1]= "+matchSimulatedPattern.targetUV[v][u][1]); //********
// System.out.println(" patternParameters is "+((patternParameters==null)?"null":"not null"));
// int tu=matchSimulatedPattern.targetUV[v][u][0];
// int tv=matchSimulatedPattern.targetUV[v][u][1];
//
if (patternParameters.getXYZM(matchSimulatedPattern.targetUV[v][u][0],matchSimulatedPattern.targetUV[v][u][1],false,station)!=null) {
size++;
} else {
size_extra++;
}
}
}
}
// Move to DCD?
dcd.gIP[numGridImage].resetMask();
dcd.gIP[numGridImage].pixelsXY=new double [size][6];
dcd.gIP[numGridImage].pixelsUV=new int [size][2];
dcd.gIP[numGridImage].pixelsXY_extra=new double [size_extra][6];
dcd.gIP[numGridImage].pixelsUV_extra=new int [size_extra][2];
int index=0;
int index_extra=0;
for (int v=0;v<matchSimulatedPattern.getHeight();v++) for (int u=0;u<matchSimulatedPattern.getWidth();u++) {
/* System.out.println("+ v="+v+", u="+u);
if ((matchSimulatedPattern.targetUV[v][u]!=null) && (matchSimulatedPattern.pXYUV [v][u]!=null)){
if ((matchSimulatedPattern.targetUV[v][u]!=null) && (matchSimulatedPattern.pXYUV [v][u]!=null) &&
(matchSimulatedPattern.pXYUV[v][u][0]>=0.0) || (matchSimulatedPattern.pXYUV[v][u][1]>=0.0)) { // disregard negative sensor pixels
// System.out.println(" matchSimulatedPattern.targetUV[v][u] is "+((matchSimulatedPattern.targetUV[v][u]==null)?"null":"not null"));
// System.out.println(" matchSimulatedPattern.targetUV[v][u][0]= "+matchSimulatedPattern.targetUV[v][u][0]);
// System.out.println(" matchSimulatedPattern.targetUV[v][u][1]= "+matchSimulatedPattern.targetUV[v][u][1]); //********
// System.out.println(" patternParameters is "+((patternParameters==null)?"null":"not null"));
// int tu=matchSimulatedPattern.targetUV[v][u][0];
// int tv=matchSimulatedPattern.targetUV[v][u][1];
//
if (patternParameters.getXYZM(matchSimulatedPattern.targetUV[v][u][0],matchSimulatedPattern.targetUV[v][u][1],false,station)!=null) {
size++;
} else {
size_extra++;
}
}
}
}
// Move to DCD?
dcd.gIP[numGridImage].resetMask();
dcd.gIP[numGridImage].pixelsXY=new double [size][6];
dcd.gIP[numGridImage].pixelsUV=new int [size][2];
dcd.gIP[numGridImage].pixelsXY_extra=new double [size_extra][6];
dcd.gIP[numGridImage].pixelsUV_extra=new int [size_extra][2];
int index=0;
int index_extra=0;
for (int v=0;v<matchSimulatedPattern.getHeight();v++) for (int u=0;u<matchSimulatedPattern.getWidth();u++) {
/* System.out.println("+ v="+v+", u="+u);
System.out.println(" + matchSimulatedPattern.targetUV[v][u] is "+((matchSimulatedPattern.targetUV[v][u]==null)?"null":"not null"));
System.out.println(" + matchSimulatedPattern.pixelsUV[v][u] is "+((matchSimulatedPattern.pixelsUV[v][u]==null)?"null":"not null"));*/
if ((matchSimulatedPattern.targetUV[v][u]!=null) &&(matchSimulatedPattern.pXYUV[v][u]!=null) ) {
// System.out.println("++ v="+v+", u="+u+" index="+index+" ("+size+"), index_extra="+index_extra+" ("+size_extra+")");
if ((matchSimulatedPattern.targetUV[v][u]!=null) &&(matchSimulatedPattern.pXYUV[v][u]!=null) &&
(matchSimulatedPattern.pXYUV[v][u][0]>=0.0) || (matchSimulatedPattern.pXYUV[v][u][1]>=0.0)) { // disregard negative sensor pixels
if (
(v>=matchSimulatedPattern.gridContrastBrightness[0].length) ||
(u>=matchSimulatedPattern.gridContrastBrightness[0][0].length)){
System.out.println(
" matchSimulatedPattern.gridContrastBrightness[0].length="+matchSimulatedPattern.gridContrastBrightness[0].length+
" matchSimulatedPattern.gridContrastBrightness[0][0].length="+matchSimulatedPattern.gridContrastBrightness[0][0].length+
" v="+v+" u="+u);
}
}
// setting dcd.gIP[numGridImage].pixelsUV[index] with rotated/shifted
if (patternParameters.getXYZM(matchSimulatedPattern.targetUV[v][u][0],matchSimulatedPattern.targetUV[v][u][1],false,station)!=null) {
dcd.gIP[numGridImage].pixelsXY[index][0]=matchSimulatedPattern.pXYUV[v][u][0];
dcd.gIP[numGridImage].pixelsXY[index][1]=matchSimulatedPattern.pXYUV[v][u][1];
dcd.gIP[numGridImage].pixelsUV[index][0]=matchSimulatedPattern.targetUV[v][u][0];
dcd.gIP[numGridImage].pixelsUV[index][1]=matchSimulatedPattern.targetUV[v][u][1];
dcd.gIP[numGridImage].pixelsXY[index][2]=matchSimulatedPattern.gridContrastBrightness[0][v][u]; // grid contrast
dcd.gIP[numGridImage].pixelsXY[index][3]=matchSimulatedPattern.gridContrastBrightness[1][v][u]/dcd.gIP[numGridImage].intensityRange[0]; // red
dcd.gIP[numGridImage].pixelsXY[index][4]=matchSimulatedPattern.gridContrastBrightness[2][v][u]/dcd.gIP[numGridImage].intensityRange[1]; // green
dcd.gIP[numGridImage].pixelsXY[index][5]=matchSimulatedPattern.gridContrastBrightness[3][v][u]/dcd.gIP[numGridImage].intensityRange[2]; // blue
index++;
} else {
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][0]=matchSimulatedPattern.pXYUV[v][u][0];
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][1]=matchSimulatedPattern.pXYUV[v][u][1];
dcd.gIP[numGridImage].pixelsUV_extra[index_extra][0]=matchSimulatedPattern.targetUV[v][u][0];
dcd.gIP[numGridImage].pixelsUV_extra[index_extra][1]=matchSimulatedPattern.targetUV[v][u][1];
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][2]=matchSimulatedPattern.gridContrastBrightness[0][v][u]; // grid contrast
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][3]=matchSimulatedPattern.gridContrastBrightness[1][v][u]/dcd.gIP[numGridImage].intensityRange[0]; // red
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][4]=matchSimulatedPattern.gridContrastBrightness[2][v][u]/dcd.gIP[numGridImage].intensityRange[1]; // green
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][5]=matchSimulatedPattern.gridContrastBrightness[3][v][u]/dcd.gIP[numGridImage].intensityRange[2]; // blue
index_extra++;
}
}
}
dcd.gIP[numGridImage].hintedMatch =(hintGridTolerance>0.0)?2:1; // orientation or both orientation and translation
if ((matchSimulatedPattern.targetUV[v][u]!=null) &&(matchSimulatedPattern.pXYUV[v][u]!=null) ) {
// System.out.println("++ v="+v+", u="+u+" index="+index+" ("+size+"), index_extra="+index_extra+" ("+size_extra+")");
if ((matchSimulatedPattern.targetUV[v][u]!=null) &&(matchSimulatedPattern.pXYUV[v][u]!=null) &&
(matchSimulatedPattern.pXYUV[v][u][0]>=0.0) || (matchSimulatedPattern.pXYUV[v][u][1]>=0.0)) { // disregard negative sensor pixels
if (
(v>=matchSimulatedPattern.gridContrastBrightness[0].length) ||
(u>=matchSimulatedPattern.gridContrastBrightness[0][0].length)){
System.out.println(
" matchSimulatedPattern.gridContrastBrightness[0].length="+matchSimulatedPattern.gridContrastBrightness[0].length+
" matchSimulatedPattern.gridContrastBrightness[0][0].length="+matchSimulatedPattern.gridContrastBrightness[0][0].length+
" v="+v+" u="+u);
}
}
// setting dcd.gIP[numGridImage].pixelsUV[index] with rotated/shifted
if (patternParameters.getXYZM(matchSimulatedPattern.targetUV[v][u][0],matchSimulatedPattern.targetUV[v][u][1],false,station)!=null) {
dcd.gIP[numGridImage].pixelsXY[index][0]=matchSimulatedPattern.pXYUV[v][u][0];
dcd.gIP[numGridImage].pixelsXY[index][1]=matchSimulatedPattern.pXYUV[v][u][1];
dcd.gIP[numGridImage].pixelsUV[index][0]=matchSimulatedPattern.targetUV[v][u][0];
dcd.gIP[numGridImage].pixelsUV[index][1]=matchSimulatedPattern.targetUV[v][u][1];
dcd.gIP[numGridImage].pixelsXY[index][2]=matchSimulatedPattern.gridContrastBrightness[0][v][u]; // grid contrast
dcd.gIP[numGridImage].pixelsXY[index][3]=matchSimulatedPattern.gridContrastBrightness[1][v][u]/dcd.gIP[numGridImage].intensityRange[0]; // red
dcd.gIP[numGridImage].pixelsXY[index][4]=matchSimulatedPattern.gridContrastBrightness[2][v][u]/dcd.gIP[numGridImage].intensityRange[1]; // green
dcd.gIP[numGridImage].pixelsXY[index][5]=matchSimulatedPattern.gridContrastBrightness[3][v][u]/dcd.gIP[numGridImage].intensityRange[2]; // blue
index++;
} else {
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][0]=matchSimulatedPattern.pXYUV[v][u][0];
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][1]=matchSimulatedPattern.pXYUV[v][u][1];
dcd.gIP[numGridImage].pixelsUV_extra[index_extra][0]=matchSimulatedPattern.targetUV[v][u][0];
dcd.gIP[numGridImage].pixelsUV_extra[index_extra][1]=matchSimulatedPattern.targetUV[v][u][1];
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][2]=matchSimulatedPattern.gridContrastBrightness[0][v][u]; // grid contrast
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][3]=matchSimulatedPattern.gridContrastBrightness[1][v][u]/dcd.gIP[numGridImage].intensityRange[0]; // red
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][4]=matchSimulatedPattern.gridContrastBrightness[2][v][u]/dcd.gIP[numGridImage].intensityRange[1]; // green
dcd.gIP[numGridImage].pixelsXY_extra[index_extra][5]=matchSimulatedPattern.gridContrastBrightness[3][v][u]/dcd.gIP[numGridImage].intensityRange[2]; // blue
index_extra++;
}
}
}
dcd.gIP[numGridImage].hintedMatch =(hintGridTolerance>0.0)?2:1; // orientation or both orientation and translation
dcd.gIP[numGridImage].matchedPointers=rslt; // update number of matched pointers
if ((dcd.gIP[numGridImage].hintedMatch>1) || (dcd.gIP[numGridImage].matchedPointers>0)) numSuccess++;
// Update rotation/shift
//matchSimulatedPattern
int [] fileUVShiftRot=dcd.gIP[numGridImage].getUVShiftRot();
int [] extraUVShiftRot=matchSimulatedPattern.getUVShiftRot(true); // last shift/rotation during matching pattern, correct for zero shift
// int [] extraDbg=matchSimulatedPattern.getUVShiftRot(false);
// int [] extraDbg=matchSimulatedPattern.getUVShiftRot(false);
int [] combinedUVShiftRot=MatchSimulatedPattern.combineUVShiftRot(fileUVShiftRot,extraUVShiftRot);
dcd.gIP[numGridImage].setUVShiftRot(combinedUVShiftRot);
System.out.println("applyHintedGrids(): dcd.gIP["+numGridImage+"].hintedMatch="+dcd.gIP[numGridImage].hintedMatch+
......@@ -2938,10 +2982,11 @@ For each point in the image
System.out.println("applyHintedGrids(): fileUVShiftRot= "+fileUVShiftRot[0]+"/"+fileUVShiftRot[1]+":"+fileUVShiftRot[2]);
System.out.println(" "+nonzero+"extraUVShiftRot= "+extraUVShiftRot[0]+"/"+extraUVShiftRot[1]+":"+extraUVShiftRot[2]);
System.out.println(" combinedUVShiftRot="+combinedUVShiftRot[0]+"/"+combinedUVShiftRot[1]+":"+combinedUVShiftRot[2]);
// System.out.println(" extraDbg="+extraDbg[0]+"/"+extraDbg[1]+":"+extraDbg[2]);
// System.out.println(" extraDbg="+extraDbg[0]+"/"+extraDbg[1]+":"+extraDbg[2]);
}
}
}
}
return numSuccess;
}
public void showSourceImage(int numGridImage){
......
......@@ -1135,11 +1135,14 @@ public class EyesisAberrations {
for (int imgNum=0;imgNum<sourcePaths.length;imgNum++){
if (!selectedImages[imgNum]) sourcePaths[imgNum]=null;
else {
String filename=this.aberrationParameters.sourcePrefix+IJ.d2s(distortionCalibrationData.gIP[imgNum].timestamp,6).replace('.','_')+
String.format("-%02d"+this.aberrationParameters.sourceSuffix, distortionCalibrationData.gIP[imgNum].channel); // sensor number
sourcePaths[imgNum]=this.aberrationParameters.sourceDirectory+Prefs.getFileSeparator()+filename;
/// String filename=this.aberrationParameters.sourcePrefix+IJ.d2s(distortionCalibrationData.gIP[imgNum].timestamp,6).replace('.','_')+
/// String.format("-%02d"+this.aberrationParameters.sourceSuffix, distortionCalibrationData.gIP[imgNum].channel); // sensor number
/// sourcePaths[imgNum]=this.aberrationParameters.sourceDirectory+Prefs.getFileSeparator()+filename;
sourcePaths[imgNum]=distortionCalibrationData.gIP[imgNum].source_path;
File srcFile=new File(sourcePaths[imgNum]);
if (!srcFile.exists()){
String filename = sourcePaths[imgNum].substring(sourcePaths[imgNum].lastIndexOf(Prefs.getFileSeparator()));
if (skipMissing) {
if (debugLevel>0) System.out.println("Skipping missing file: "+sourcePaths[imgNum]);
sourcePaths[imgNum]=null;
......@@ -1242,6 +1245,14 @@ public class EyesisAberrations {
if (debugLevel>0) System.out.println("Processing file #"+(imgNum+1)+ " ( of "+files.length+") :"+files[imgNum][0]);
ImagePlus imp=new ImagePlus(files[imgNum][0]); // read source file
JP4_INSTANCE.decodeProperiesFromInfo(imp);
// pad image to full sensor size
int numGridImage=fileIndices[imgNum];
int chn = distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].getChannel();
int [] sensor_width_height = distortions.fittingStrategy.distortionCalibrationData.eyesisCameraParameters.getSensorWidthHeight(chn);
imp = ShowDoubleFloatArrays.padBayerToFullSize(
imp, // ImagePlus imp_src,
sensor_width_height, // eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
// TODO: Add vignetting correction ?
MatchSimulatedPattern matchSimulatedPattern= new MatchSimulatedPattern(distortionParameters.FFTSize);
boolean [] correlationSizesUsed=null;
......@@ -1256,20 +1267,20 @@ public class EyesisAberrations {
double hintTolerance=0.0;
if (partialToReprojected){ // replace px, py with projected values form the grid
// this.distortions is set to the global LENS_DISTORTIONS
int numGridImage=fileIndices[imgNum];
/// int numGridImage=fileIndices[imgNum];
projectedGrid=distortions.estimateGridOnSensor( // return grid array [v][u][0- x, 1 - y, 2 - u, 3 - v]
distortions.fittingStrategy.distortionCalibrationData.getImageStation(numGridImage), // station number,
distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].channel, // subCamera,
distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].getChannel(), // subCamera,
Double.NaN, // goniometerHorizontal, - not used
Double.NaN, // goniometerAxial, - not used
Double.NaN, // inter-axis angle, - not used ?
distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].getSetNumber(), //imageSet,
true); //filterBorder)
false); // true); //filterBorder) // TODO: MAKE IT configurable parameter!
hintTolerance=5.0; // TODO:set from configurable parameter
if (applySensorCorrection){
boolean applied=distortions.correctGridOnSensor(
projectedGrid,
distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].channel);
distortions.fittingStrategy.distortionCalibrationData.gIP[numGridImage].getChannel());
if (debugLevel>0) {
if (applied) System.out.println("Applied sensor correction to the projected grid");
else System.out.println("No sensor correction available to apply to the projected grid");
......@@ -1285,7 +1296,7 @@ public class EyesisAberrations {
// patternDetectParameters.maxGridPeriod/2,
simulParameters,
colorComponents.equalizeGreens,
imp,
imp, // has WOI_TOP and possibly - WOI_COMPENSATED
null, // LaserPointer laserPointer, // LaserPointer object or null
true, // don't care -removeOutOfGridPointers
projectedGrid, // null, // double [][][] hintGrid, // predicted grid array (or null)
......@@ -1301,7 +1312,9 @@ public class EyesisAberrations {
}
// now replace extracted grid X,Y with projected (need to add sensor correction)
if (projectedGrid!=null){
int numReplaced= matchSimulatedPattern.replaceGridXYWithProjected(projectedGrid,(debugLevel>1)?imp.getTitle():null);
int numReplaced= matchSimulatedPattern.replaceGridXYWithProjected(
projectedGrid,
((debugLevel>1)?imp.getTitle():null));
if (debugLevel>0) System.out.println("Replaced extracted XY with projected ones for "+numReplaced+" nodes");
}
correlationSizesUsed=matchSimulatedPattern.getCorrelationSizesUsed();
......@@ -1314,7 +1327,7 @@ public class EyesisAberrations {
threadsMax,
updateStatus,
debugLevel,
loopDebugLevel); // debug level
loopDebugLevel+1); // debug level
createPSFMap(
matchSimulatedPattern,
......@@ -2312,6 +2325,7 @@ public class EyesisAberrations {
final int mapWidth=imp_sel.getWidth();
final AtomicInteger tilesFinishedAtomic = new AtomicInteger(1); // first finished will be 1
final int debugNumColors=6;
final int dbgTile0 = -1; // 245; //
for (int ithread = 0; ithread < threads.length; ithread++) {
// Concurrently run in as many threads as CPUs
threads[ithread] = new Thread() {
......@@ -2346,6 +2360,9 @@ public class EyesisAberrations {
nTY=tilesToProcessXY[nTile][1];
y0=tilesToProcessXY[nTile][3];
x0=tilesToProcessXY[nTile][2];
if (nTile == dbgTile0) {
System.out.println("#!# "+x0+":"+y0+" Processing tile["+nTY+"]["+nTX+"] ("+(nTile+1)+" of "+patternCells+") : "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
}
if (updateStatus) IJ.showStatus("Processing tile["+nTY+"]["+nTX+"] ("+(nTile+1)+" of "+patternCells+")");
if (masterDebugLevel>1) System.out.println("#!# "+x0+":"+y0+" Processing tile["+nTY+"]["+nTX+"] ("+(nTile+1)+" of "+patternCells+") : "+IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
if (overexposed!=null){
......@@ -2383,7 +2400,7 @@ public class EyesisAberrations {
fht_instance, // provide DoubleFHT instance to save on initializations (or null)
debug_level,// ((x0<512)&& (y0<512))?3:debug_level DEBUG during "focusing"
masterDebugLevel, // get rid of it? // ** NEW
globalDebugLevel,// ** NEW
globalDebugLevel + ((nTile == dbgTile0)? 3:0),// ** NEW
debugLateralShifts?debugLateral[nTY][nTX]:null
);
if (kernels!=null) {
......@@ -2678,7 +2695,7 @@ public class EyesisAberrations {
double [] localBarray;
if ((simArray==null) || (psfParameters.approximateGrid)){ // just for testing
if ((simArray==null) || (psfParameters.approximateGrid)){ // just for testing(never here?)
/* Calculate pattern parameters, including distortion */
if (matchSimulatedPattern.PATTERN_GRID==null) {
double[][] distortedPattern= matchSimulatedPattern.findPatternDistorted(input_bayer, // pixel array to process (no windowing!)
......@@ -2775,7 +2792,7 @@ public class EyesisAberrations {
simul_pixels= normalizeAndWindow (simul_pixels, fullHamming);
} else {
Rectangle PSFCellSim=new Rectangle (x0*subpixel/2,y0*subpixel/2,size*subpixel/2,size*subpixel/2);
Rectangle PSFCellSim=new Rectangle (x0*subpixel/2,y0*subpixel/2,size*subpixel/2,size*subpixel/2); // getting here
simul_pixels=new double[6][];
// simulationPattern.debugLevel=globalDebugLevel;
......@@ -2837,7 +2854,7 @@ public class EyesisAberrations {
}
for (i=0;i<4;i++) if (!colorComponents.colorsToCorrect[i]) input_bayer[i]=null; // leave composite greens even if disabled
if (debugThis) {
SDFA_INSTANCE.showArrays(input_bayer, fft_size*subpixel, fft_size*subpixel, title);
// SDFA_INSTANCE.showArrays(input_bayer, fft_size*subpixel, fft_size*subpixel, title);
}
if (globalDebugLevel>2) System.out.println ( " input_bayer.length="+input_bayer.length+" simul_pixels.length="+simul_pixels.length+" fft_size*subpixel="+fft_size*subpixel);
for (i=0;(i<input_bayer.length) && (i<simul_pixels.length);i++) if ((colorComponents.colorsToCorrect[i]) && (input_bayer[i]!=null)){
......@@ -2846,7 +2863,7 @@ public class EyesisAberrations {
if (debugThis) SDFA_INSTANCE.showArrays(input_bayer, true, title+"-input");
if (debugThis) SDFA_INSTANCE.showArrays(simul_pixels, true, title+"-SIM");
if (globalDebugLevel>2)globalDebugLevel=0; //************************************************************
//if (globalDebugLevel>2)globalDebugLevel=0; //************************************************************
double [][] inverted=new double[colorComponents.colorsToCorrect.length][];
double wvAverage=Math.sqrt(0.5*(wVectors[0][0]*wVectors[0][0]+wVectors[0][1]*wVectors[0][1]+
wVectors[1][0]*wVectors[1][0]+wVectors[1][1]*wVectors[1][1]));
......@@ -3127,6 +3144,11 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
double [] denominatorPixels= forward_OTF? modelPixels.clone(): measuredPixels.clone();
double [] nominatorPixels= forward_OTF? measuredPixels.clone(): modelPixels.clone();
if ((debug>2) ||((globalDebugLevel>2) && (title!=""))) { /* Increase debug level later */ // was 3
double [][] meas_sim = {measuredPixels, modelPixels};
// String [] dbg_titles = {"measured","simulated"};
SDFA_INSTANCE.showArrays(meas_sim, true, title+"-MEAS_SIM");
}
if (fht_instance==null) fht_instance=new DoubleFHT(); // move upstream to reduce number of initializations
int i;
fht_instance.swapQuadrants(denominatorPixels);
......@@ -3231,7 +3253,7 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
/* ======================================================================== */
/* Trying to remove aliasing artifacts when the decimated (pixel resolution) image is deconvolved with full resolution (sub-pixel resolution)
model pattern. This effect is also easily visible if the decimated model is deconvolved with the same one art full resolution.
model pattern. This effect is also easily visible if the decimated model is deconvolved with the same one at full resolution.
Solution is to clone the power spectrum of the full resolution model with the shifts to match oversampling (15 clones for the 4x oversampling),
And add them together (adding also zero frequerncy point - it might be absent on the model) but not include the original (true one) and
use the result to create a rejectiobn mask - if the energy was high, (multiplicative) mask should be zero at those points. */
......
......@@ -1718,12 +1718,12 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
Arrays.fill(numMatchedPointersEnabledPerStation[n], 0);
}
int [] numHintedMatch= new int [matchedPointersIndex.length];
int [] numHintedMatchSelected=new int [matchedPointersIndex.length];
int [] numHintedMatchEnabled= new int [matchedPointersIndex.length];
int [][] numHintedMatchPerStation= new int [matchedPointersIndex.length][];
int [][] numHintedMatchSelectedPerStation=new int [matchedPointersIndex.length][];
int [][] numHintedMatchEnabledPerStation= new int [matchedPointersIndex.length][];
int [] numHintedMatch= new int [hintedMatchIndex.length];
int [] numHintedMatchSelected=new int [hintedMatchIndex.length];
int [] numHintedMatchEnabled= new int [hintedMatchIndex.length];
int [][] numHintedMatchPerStation= new int [hintedMatchIndex.length][];
int [][] numHintedMatchSelectedPerStation=new int [hintedMatchIndex.length][];
int [][] numHintedMatchEnabledPerStation= new int [hintedMatchIndex.length][];
for (int n=0;n<numHintedMatch.length;n++){
numHintedMatch[n]=0;
numHintedMatchSelected[n]=0;
......@@ -1771,9 +1771,12 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
}
numMatchedPointersEnabledPerStation[mpi][imageStations[i]]++;
numMatchedPointersEnabled[mpi]++;
numHintedMatchEnabledPerStation[hmi][imageStations[i]]++;
numHintedMatchEnabled[hmi]++;
if (hmi>=numHintedMatchEnabledPerStation.length) {
System.out.println("*** Bug: hmi>=numHintedMatchEnabledPerStation.length");
} else {
numHintedMatchEnabledPerStation[hmi][imageStations[i]]++;
numHintedMatchEnabled[hmi]++;
}
}
......@@ -2013,6 +2016,7 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
IJ.showMessage("Error",msg);
return;
}
int numSubCams=this.distortionCalibrationData.getNumSubCameras();
int [] choice_offsets = new int [this.parameterEnable.length];
//
String header="Strategy #\tType";
......@@ -2061,12 +2065,14 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
int subMaxNum = -1;
if (this.distortionCalibrationData.isSubcameraParameter(parIndex)) { // only for subcamera parameters
if (zeroAndOther) {
subMaxNum = this.distortionCalibrationData.firstInGroup(subCam)?-1:0; //this.distortionCalibrationData.getSubGroup(subCam);
// subMaxNum = this.distortionCalibrationData.firstInGroup(subCam)?-1:0; //this.distortionCalibrationData.getSubGroup(subCam);
subMaxNum = (this.distortionCalibrationData.sourceToCopy(subCam) < 0)?-1:0; //this.distortionCalibrationData.getSubGroup(subCam);
} else {
subMaxNum = subCam-1; // 0 will be -1 - this may be wrong to align to higher index
}
}
/*=========*/
String [] commonChoices = (isTilt?this.definedModesTiltEq:(noWeak?this.definedModesNoWeak:this.definedModes));
......@@ -2080,24 +2086,33 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
thisChoice = this.definedModesAll[this.parameterMode[numSeries][ipar]];
} else { // only can happen if (!isTilt) && (noWeak)
choice_offsets[ipar] = commonChoices.length;
theseChoices = new String [commonChoices.length + subMaxNum + 1];
// theseChoices = new String [commonChoices.length + subMaxNum + 1];
theseChoices = new String [commonChoices.length];
for (int ch = 0; ch < commonChoices.length; ch++) theseChoices[ch] = commonChoices[ch];
/*
if (zeroAndOther) {
if (subMaxNum >=0) { // can only be 0
theseChoices[commonChoices.length] = "same as "+this.distortionCalibrationData.masterSub(subCam);
// theseChoices[commonChoices.length] = "same as "+this.distortionCalibrationData.masterSub(subCam);
// TODO: Make human-readable channel name?
theseChoices[commonChoices.length] = "same as "+this.distortionCalibrationData.sourceToCopy(subCam);
}
} else {
for (int ch = 0; ch <= subMaxNum; ch++) {
theseChoices[ch + commonChoices.length] = "same as "+ch;
}
}
*/
// choice index for "same as ..." starts with this.definedModesAll.length, but in the listbox index is lower
int indx = this.parameterMode[numSeries][ipar];
if (indx >= this.definedModesAll.length) {
indx -= (this.definedModesAll.length - choice_offsets[ipar]);
}
thisChoice = theseChoices[indx];
if (indx < theseChoices.length) {
thisChoice = theseChoices[indx];
} else {
thisChoice = "same as "+ (indx - theseChoices.length);
}
// System.out.println("selectStrategyStep(): this.parameterMode["+numSeries+"]["+ipar+"]=" + this.parameterMode[numSeries][ipar]+" indx = "+indx);
}
if (thisChoice.equals("fixed")) thisChoice = "-";
......@@ -2278,7 +2293,8 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
int subMaxNum = -1;
if (this.distortionCalibrationData.isSubcameraParameter(parIndex)) { // only for subcamera parameters
if (zeroAndOther) {
subMaxNum = this.distortionCalibrationData.firstInGroup(subCam)?-1:0; //this.distortionCalibrationData.getSubGroup(subCam);
// subMaxNum = this.distortionCalibrationData.firstInGroup(subCam)?-1:0; //this.distortionCalibrationData.getSubGroup(subCam);
subMaxNum = (this.distortionCalibrationData.sourceToCopy(subCam) < 0)?-1:0; //this.distortionCalibrationData.getSubGroup(subCam);
} else {
subMaxNum = subCam-1; // 0 will be -1 - this may be wrong to align to higher index
}
......@@ -2297,7 +2313,9 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
for (int ch = 0; ch < commonChoices.length; ch++) theseChoices[ch] = commonChoices[ch];
if (zeroAndOther) {
if (subMaxNum >=0) {
theseChoices[commonChoices.length] = "same as "+this.distortionCalibrationData.masterSub(subCam);
// theseChoices[commonChoices.length] = "same as "+this.distortionCalibrationData.masterSub(subCam);
// TODO: Make human-readable channel name?
theseChoices[commonChoices.length] = "same as "+this.distortionCalibrationData.sourceToCopy(subCam);
}
} else {
for (int ch = 0; ch <= subMaxNum; ch++) {
......@@ -2309,6 +2327,12 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
if (indx >= this.definedModesAll.length) {
indx -= (this.definedModesAll.length - choice_offsets[i]);
}
// currently only out of limits can occur with a single choice, so
if (indx >= theseChoices.length) {
indx = theseChoices.length - 1;
}
thisChoice = theseChoices[indx];
System.out.println("selectStrategyStep(): this.parameterMode["+numSeries+"]["+i+"]=" + this.parameterMode[numSeries][i]+" indx = "+indx);
}
......@@ -2474,6 +2498,10 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
// make adjustment for "same as (other lower numbered subcamera)"
if ((choice_offsets[i] > 0) && (this.parameterMode[numSeries][i] >= choice_offsets[i])){
if (zeroAndOther) { // add reference channel
int ref_chn = this.distortionCalibrationData.sourceToCopy(this.parameterList[i][0]);
this.parameterMode[numSeries][i] += ref_chn;
}
System.out.print("selectStrategyStep(): choice_offsets["+i+"]="+choice_offsets[i]+ " this.parameterMode["+numSeries+"]["+i+"]=" + this.parameterMode[numSeries][i]);
this.parameterMode[numSeries][i] += (this.definedModesAll.length - choice_offsets[i]);
System.out.println(", corrected=" + this.parameterMode[numSeries][i]);
......@@ -2485,12 +2513,14 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
selectGroups(numSeries,i);
}
}
if (zeroAndOther){
if (zeroAndOther ){
for (int i =0; i<this.parameterEnable.length;i++) {
// if ((this.parameterList[i][0]>1) && (this.parameterList[i][0]!=24)){ // "other" subchannels - copy from subchannel1
if (!this.distortionCalibrationData.firstInGroup(this.parameterList[i][0])){ // "other" subchannels - copy from subchannel1
/// if (this.distortionCalibrationData.sourceToCopy(this.parameterList[i][0]) >= 0){ // "other" subchannels - copy from subchannel1
// int refChannel=(this.parameterList[i][0]<24)?1:24;
int refChannel= this.distortionCalibrationData.masterSub(this.parameterList[i][0]);
/// int refChannel= this.distortionCalibrationData.sourceToCopy(this.parameterList[i][0]);
int iSub1=getParameterNumber(refChannel, this.parameterList[i][1]);
if (this.parameterEnable[iSub1]){
......
......@@ -6136,7 +6136,7 @@ public class MatchSimulatedPattern {
MatchSimulatedPattern.PatternDetectParameters patternDetectParameters,
SimulationPattern.SimulParameters simulParameters,
boolean equalizeGreens,
ImagePlus imp, // image to process
ImagePlus imp, // image to process // has WOI_TOP and possibly - WOI_COMPENSATED
LaserPointer laserPointer, // LaserPointer object or null
boolean removeOutOfGridPointers, //
double [][][] hintGrid, // predicted grid array (or null)
......
......@@ -626,7 +626,7 @@ Cv=(Cy*x-Cx*y)+(-Cy*Dx+Cx*Dy)
float [][] simArray=new float [2][];
simArray[0]=(new SimulationPattern(simulParameters)).combineWithCanvas(0.0, k*width, k*height, scaledWoi,simArray0[0]);
simArray[1]=(new SimulationPattern(simulParameters)).combineWithCanvas(0.0, k*width, k*height, scaledWoi,simArray0[1]);
if (globalDebugLevel>1) SDFA_INSTANCE.showArrays(simArray,width*k,height*k,true, "full-simulation");
if (globalDebugLevel>0) SDFA_INSTANCE.showArrays(simArray,width*k,height*k,true, "full-simulation");
return simArray;
}
......
......@@ -1325,6 +1325,11 @@ import ij.gui.GenericDialog;
public int getSensorWidth(int subCam) { return this.eyesisSubCameras[0][subCam].getSensorWidth();} // for the future? different sensors
public int getSensorHeight(int subCam) { return this.eyesisSubCameras[0][subCam].getSensorHeight();}// for the future? different sensors
public int [] getSensorWidthHeight(int subCam) {
int [] wh = {getSensorWidth( subCam), getSensorHeight( subCam)};
return wh;
}
public int getDecimateMasks(int subCam) { return this.eyesisSubCameras[0][subCam].getDecimateMasks();}// for the future? different sensors
public void setSensorWidth(int subCam, int v) {
......
package com.elphel.imagej.common;
import java.awt.Rectangle;
import java.util.Map;
import java.util.Properties;
import ij.IJ;
import ij.ImagePlus;
......@@ -654,5 +656,86 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg
}
/**
* Pad acquired Bayer image to the full sensor width/height. Used when optical center pixel coordinates do not match for channels
* and WOI is adjusted during image capture to avoid ERS mismatch between horizontal pairs
* @param imp_src source image with WOI specified as properties (sizes and offsets should be even)
* @param wh {sesnor_width, sensor_height} in pixels
* @param replicate fill gaps by replicating existing pixels
* @return full size image
*/
public static ImagePlus padBayerToFullSize(
ImagePlus imp_src,
int [] wh, // null OK - will use {woi_left+width, woi_top+height}
boolean replicate) {
int woi_top = Integer.parseInt((String) imp_src.getProperty("WOI_TOP")); // enforce even
int woi_left = Integer.parseInt((String) imp_src.getProperty("WOI_LEFT"));
int woi_width = imp_src.getWidth(); // Integer.parseInt((String) imp_src.getProperty("WOI_WIDTH"));
int woi_height = imp_src.getHeight(); // Integer.parseInt((String) imp_src.getProperty("WOI_HEIGHT"));
Properties properties = imp_src.getProperties();
if (wh == null) {
wh = new int [2];
wh[0] = woi_left + woi_width;
wh[1] = woi_top + woi_height;
}
if ((woi_top == 0) && (woi_left == 0) && (woi_width == wh[0]) && (woi_height == wh[1])){
return imp_src; // good as is
}
float [] full_pixels = new float [wh[0]*wh[1]];
float [] pixels=(float []) imp_src.getProcessor().getPixels();
int dst_col = woi_left;
int copy_width = woi_width;
if ((dst_col + copy_width) > wh[0]) {
copy_width = wh[0] - dst_col;
}
for (int src_row = 0; src_row < woi_height; src_row++) {
int dst_row = src_row + woi_top;
if (dst_row < wh[1]) {
System.arraycopy( pixels, src_row * woi_width, full_pixels, dst_row * wh[0] + dst_col, copy_width);
}
}
if (replicate) {
// replicate top
for (int dst_row = 0; dst_row < woi_top; dst_row++) {
int src_row = woi_top + (dst_row & 1);
System.arraycopy( full_pixels, src_row * wh[0] + dst_col, full_pixels, dst_row * wh[0] + dst_col, copy_width);
}
// replicate bottom
for (int dst_row = woi_top + woi_height; dst_row < wh[1]; dst_row++) {
int src_row = woi_top + woi_height - 2 + (dst_row & 1);
System.arraycopy( full_pixels, src_row * wh[0] + dst_col, full_pixels, dst_row * wh[0] + dst_col, copy_width);
}
// right and left are not likely, as there is no need to use them - horizontal mismatch does not influence ERS
for (int col = 0; col < woi_left; col++) {
for (int row = 0; row < wh[1]; row++) {
full_pixels[row*wh[0] + col] = full_pixels[row*wh[0] + woi_left + (col & 1)];
}
}
for (int col = woi_left + woi_width; col < wh[0]; col++) {
for (int row = 0; row < wh[1]; row++) {
full_pixels[row*wh[0] + col] = full_pixels[row*wh[0] + woi_left + woi_width - 2 +(col & 1)];
}
}
}
ImageProcessor ip = new FloatProcessor(wh[0],wh[1]);
ip.setPixels(full_pixels);
ip.resetMinAndMax(); // is it needed here?
ImagePlus imp = new ImagePlus(imp_src.getTitle(),ip); // OK to have the same name?
for (Map.Entry<?, ?> entry: properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
imp.setProperty(key, value);
}
imp.setProperty("WOI_WIDTH", wh[0]+"");
imp.setProperty("WOI_HEIGHTH", wh[1]+"");
imp.setProperty("WOI_TOP", "0");
imp.setProperty("WOI_LEFT", "0");
return imp;
}
}
......@@ -619,6 +619,7 @@ private Panel panel1,
addButton("CLT reset 3D", panelClt2, color_stop);
addButton("MAIN extrinsics", panelClt2, color_process);
addButton("CLT Poly corr", panelClt2, color_process);
addButton("DRY RUN", panelClt2, color_configure);
addButton("CLT 3D", panelClt2, color_process);
addButton("CLT planes", panelClt2, color_conf_process);
addButton("CLT ASSIGN", panelClt2, color_process);
......@@ -4407,14 +4408,16 @@ private Panel panel1,
/// ============================================
} else if (label.equals("CLT 3D") || label.equals("MAIN extrinsics") || label.equals("CLT Poly corr")) {
} else if (label.equals("CLT 3D") || label.equals("MAIN extrinsics") || label.equals("CLT Poly corr") || label.equals("DRY RUN")) {
boolean adjust_extrinsics = label.equals("MAIN extrinsics") || label.equals("CLT Poly corr");
boolean adjust_poly = label.equals("CLT Poly corr");
boolean dry_run = label.equals("DRY RUN");// init kernel/geometry only
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
clt3d(adjust_extrinsics, adjust_poly);
clt3d(adjust_extrinsics, adjust_poly, dry_run);
return;
} else if (label.equals("AUX extrinsics") || label.equals("AUX Poly corr")) {
boolean adjust_extrinsics = label.equals("AUX extrinsics") || label.equals("AUX Poly corr");
......@@ -5562,7 +5565,8 @@ private Panel panel1,
public boolean clt3d(
boolean adjust_extrinsics,
boolean adjust_poly
boolean adjust_poly,
boolean dry_run // init kernel/geometry only
) {
if (QUAD_CLT == null){
QUAD_CLT = new QuadCLT (
......@@ -5607,7 +5611,9 @@ private Panel panel1,
return false;
}
}
if (dry_run) {
return true;
}
QUAD_CLT.processCLTQuads3d(
adjust_extrinsics, // boolean adjust_extrinsics,
adjust_poly, // boolean adjust_poly,
......@@ -5639,7 +5645,9 @@ private Panel panel1,
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null) || (QUAD_CLT.tp.clt_3d_passes.size() == 0)) {
boolean OK = clt3d(
false, // boolean adjust_extrinsics,
false); // boolean adjust_poly);
false, // boolean adjust_poly);
false); // boolean dry_run // init kernel/geometry only
if (! OK) {
String msg = "DSI data is not available and \"CLT 3D\" failed";
IJ.showMessage("Error",msg);
......@@ -5680,7 +5688,8 @@ private Panel panel1,
if ((QUAD_CLT == null) || (QUAD_CLT.tp == null) || (QUAD_CLT.tp.clt_3d_passes == null) || (QUAD_CLT.tp.clt_3d_passes.size() == 0)) {
boolean OK = clt3d(
false, // boolean adjust_extrinsics,
false); // boolean adjust_poly);
false, // boolean adjust_poly);
false); // boolean dry_run // init kernel/geometry only
if (! OK) {
String msg = "DSI data is not available and \"CLT 3D\" failed";
IJ.showMessage("Error",msg);
......
......@@ -1810,12 +1810,32 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
System.out.println("heading =\t"+ heading+"\tdegrees");
System.out.println("numSensors =\t"+ numSensors);
System.out.println("'=== Individual input parameters ===");
System.out.print ("forward = ");for (int i = 0; i < numSensors;i++) System.out.print("\t"+forward[i]); System.out.println("\tmm");
System.out.print ("right = "); for (int i = 0; i < numSensors;i++) System.out.print("\t"+right[i]); System.out.println("\tmm");
System.out.print ("height = "); for (int i = 0; i < numSensors;i++) System.out.print("\t"+height[i]); System.out.println("\tmm");
System.out.print ("roll = "); for (int i = 0; i < numSensors;i++) System.out.print("\t"+roll[i]); System.out.println("\tdegrees");
System.out.print ("px0 = "); for (int i = 0; i < numSensors;i++) System.out.print("\t"+pXY0[i][0]); System.out.println("\tpix");
System.out.print ("py0 = "); for (int i = 0; i < numSensors;i++) System.out.print("\t"+pXY0[i][1]); System.out.println("\tpix");
System.out.print ("forward = ");
if (forward != null) {
for (int i = 0; i < numSensors;i++) System.out.print("\t"+forward[i]); System.out.println("\tmm");
} else System.out.println("\tnull");
System.out.print ("right = ");
if (right != null) {
for (int i = 0; i < numSensors;i++) System.out.print("\t"+right[i]); System.out.println("\tmm");
} else System.out.println("\tnull");
System.out.print ("height = ");
if (height != null) {
for (int i = 0; i < numSensors;i++) System.out.print("\t"+height[i]); System.out.println("\tmm");
} else System.out.println("\tnull");
System.out.print ("roll = ");
if (roll != null) {
for (int i = 0; i < numSensors;i++) System.out.print("\t"+roll[i]); System.out.println("\tdegrees");
} else System.out.println("\tnull");
System.out.print ("px0 = ");
if (pXY0 != null) {
for (int i = 0; i < numSensors;i++) System.out.print("\t"+pXY0[i][0]); System.out.println("\tpix");
} else System.out.println("\tnull");
System.out.print ("py0 = ");
if (pXY0 != null) {
for (int i = 0; i < numSensors;i++) System.out.print("\t"+pXY0[i][1]); System.out.println("\tpix");
} else System.out.println("\tnull");
System.out.println("'=== Common calculated parameters ===");
System.out.println("common_right =\t"+common_right + "\tmm");
......@@ -1827,19 +1847,35 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
if (showAll){
System.out.println("'=== Intermediate data: coordinates corrected for common elevation and heading ===");
System.out.print ("X_he ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_he[i][0]); System.out.println("\tmm");
System.out.print ("Y_he ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_he[i][1]); System.out.println("\tmm");
System.out.print ("Z_he ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_he[i][2]); System.out.println("\tmm");
if (XYZ_he != null) {
System.out.print ("X_he ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_he[i][0]); System.out.println("\tmm");
System.out.print ("Y_he ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_he[i][1]); System.out.println("\tmm");
System.out.print ("Z_he ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_he[i][2]); System.out.println("\tmm");
} else {
System.out.println("X_he, Y_he and Z_he are null");
}
System.out.println("'=== Intermediate data: coordinates corrected for common elevation, heading and roll ===");
System.out.print ("X_her ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_her[i][0]); System.out.println("\tmm");
System.out.print ("Y_her ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_her[i][1]); System.out.println("\tmm");
System.out.print ("Z_her ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_her[i][2]); System.out.println("\tmm");
if (XYZ_her != null) {
System.out.print ("X_her ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_her[i][0]); System.out.println("\tmm");
System.out.print ("Y_her ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_her[i][1]); System.out.println("\tmm");
System.out.print ("Z_her ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+XYZ_her[i][2]); System.out.println("\tmm");
} else {
System.out.println("X_her, Y_her and Z_her are null");
}
}
System.out.println("'=== Individual calculated parameters ===");
System.out.print ("residual_roll = "); for (int i = 0; i < numSensors;i++) System.out.print("\t"+(roll[i]-common_roll));System.out.println("\tdegrees");
System.out.print ("residual_roll = ");
if (roll != null) {
for (int i = 0; i < numSensors;i++) System.out.print("\t"+(roll[i]-common_roll));System.out.println("\tdegrees");
} else System.out.println("\tnull");
if (rXY != null) {
System.out.print ("X_rel ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+rXY[i][0]); System.out.println("\trelative to disparityRadius");
System.out.print ("Y_rel ="); for (int i = 0; i < numSensors;i++) System.out.print("\t"+rXY[i][1]); System.out.println("\trelative to disparityRadius");
} else {
System.out.println("X_rel and Y_rel are null");
}
}
// return distance from disparity (in pixel units) for the current camera geometry
......
......@@ -35,7 +35,6 @@ import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -59,7 +58,6 @@ import ij.WindowManager;
//import ij.gui.Overlay;
import ij.io.FileSaver;
import ij.process.ColorProcessor;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;
......@@ -875,12 +873,12 @@ public class QuadCLT {
for (int i=0;i<sharpKernelPaths.length;i++){
System.out.println(i+":"+sharpKernelPaths[i]);
}
if (clt_kernels == null){
clt_kernels = new double[eyesisCorrections.usedChannels.length][][][][][];
for (int chn=0;chn<eyesisCorrections.usedChannels.length;chn++){
clt_kernels[chn] = null;
}
}
if (clt_kernels == null){
clt_kernels = new double[eyesisCorrections.usedChannels.length][][][][][];
for (int chn=0;chn<eyesisCorrections.usedChannels.length;chn++){
clt_kernels[chn] = null;
}
}
ShowDoubleFloatArrays sdfa_instance = new ShowDoubleFloatArrays();
for (int chn=0;chn<eyesisCorrections.usedChannels.length;chn++){
......@@ -2714,7 +2712,7 @@ public class QuadCLT {
eyesisCorrections.JP4_INSTANCE.decodeProperiesFromInfo(imp_srcs[srcChannel]); // decode existent properties from info
if (debugLevel>0) System.out.println("Processing "+sourceFiles[nFile]);
}
imp_srcs[srcChannel] = padBayerToFullSize(
imp_srcs[srcChannel] = ShowDoubleFloatArrays.padBayerToFullSize(
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
......@@ -3279,81 +3277,6 @@ public class QuadCLT {
return nf;
}
/**
* Pad acquired Bayer image to the full sensor width/height. Used when optical center pixel coordinates do not match for channels
* and WOI is adjusted during image capture to avoid ERS mismatch between horizontal pairs
* @param imp_src source image with WOI specified as properties (sizes and offsets should be even)
* @param wh {sesnor_width, sensor_height} in pixels
* @param replicate fill gaps by replicating existing pixels
* @return full size image
*/
ImagePlus padBayerToFullSize(
ImagePlus imp_src,
int [] wh,
boolean replicate) {
int woi_top = Integer.parseInt((String) imp_src.getProperty("WOI_TOP")); // enforce even
int woi_left = Integer.parseInt((String) imp_src.getProperty("WOI_LEFT"));
int woi_width = imp_src.getWidth(); // Integer.parseInt((String) imp_src.getProperty("WOI_WIDTH"));
int woi_height = imp_src.getHeight(); // Integer.parseInt((String) imp_src.getProperty("WOI_HEIGHT"));
Properties properties = imp_src.getProperties();
if ((woi_top == 0) && (woi_left == 0) && (woi_width == wh[0]) && (woi_height == wh[1])){
return imp_src; // good as is
}
float [] full_pixels = new float [wh[0]*wh[1]];
float [] pixels=(float []) imp_src.getProcessor().getPixels();
int dst_col = woi_left;
int copy_width = woi_width;
if ((dst_col + copy_width) > wh[0]) {
copy_width = wh[0] - dst_col;
}
for (int src_row = 0; src_row < woi_height; src_row++) {
int dst_row = src_row + woi_top;
if (dst_row < wh[1]) {
System.arraycopy( pixels, src_row * woi_width, full_pixels, dst_row * wh[0] + dst_col, copy_width);
}
}
if (replicate) {
// replicate top
for (int dst_row = 0; dst_row < woi_top; dst_row++) {
int src_row = woi_top + (dst_row & 1);
System.arraycopy( full_pixels, src_row * wh[0] + dst_col, full_pixels, dst_row * wh[0] + dst_col, copy_width);
}
// replicate bottom
for (int dst_row = woi_top + woi_height; dst_row < wh[1]; dst_row++) {
int src_row = woi_top + woi_height - 2 + (dst_row & 1);
System.arraycopy( full_pixels, src_row * wh[0] + dst_col, full_pixels, dst_row * wh[0] + dst_col, copy_width);
}
// right and left are not likely, as there is no need to use them - horizontal mismatch does not influence ERS
for (int col = 0; col < woi_left; col++) {
for (int row = 0; row < wh[1]; row++) {
full_pixels[row*wh[0] + col] = full_pixels[row*wh[0] + woi_left + (col & 1)];
}
}
for (int col = woi_left + woi_width; col < wh[0]; col++) {
for (int row = 0; row < wh[1]; row++) {
full_pixels[row*wh[0] + col] = full_pixels[row*wh[0] + woi_left + woi_width - 2 +(col & 1)];
}
}
}
ImageProcessor ip = new FloatProcessor(wh[0],wh[1]);
ip.setPixels(full_pixels);
ip.resetMinAndMax(); // is it needed here?
ImagePlus imp = new ImagePlus(imp_src.getTitle(),ip); // OK to have the same name?
for (Map.Entry<?, ?> entry: properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
imp.setProperty(key, value);
}
imp.setProperty("WOI_WIDTH", wh[0]+"");
imp.setProperty("WOI_HEIGHTH", wh[1]+"");
imp.setProperty("WOI_TOP", "0");
imp.setProperty("WOI_LEFT", "0");
return imp;
}
/**
* Conditions images for a single image set
......@@ -3417,7 +3340,7 @@ public class QuadCLT {
// imp_srcs[srcChannel].show(); // REMOVE ME!
this.geometryCorrection.woi_tops[srcChannel] = Integer.parseInt((String) imp_srcs[srcChannel].getProperty("WOI_TOP"));
imp_srcs[srcChannel] = padBayerToFullSize(
imp_srcs[srcChannel] = ShowDoubleFloatArrays.padBayerToFullSize(
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
......@@ -5006,7 +4929,7 @@ public class QuadCLT {
eyesisCorrections.JP4_INSTANCE.decodeProperiesFromInfo(imp_srcs[srcChannel]); // decode existent properties from info
if (debugLevel>0) System.out.println("Processing "+sourceFiles[nFile]);
}
imp_srcs[srcChannel] = padBayerToFullSize(
imp_srcs[srcChannel] = ShowDoubleFloatArrays.padBayerToFullSize(
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
......@@ -8907,7 +8830,7 @@ public class QuadCLT {
eyesisCorrections.JP4_INSTANCE.decodeProperiesFromInfo(imp_srcs[srcChannel]); // decode existent properties from info
if (debugLevel>0) System.out.println("Processing "+sourceFiles[nFile]);
}
imp_srcs[srcChannel] = padBayerToFullSize(
imp_srcs[srcChannel] = ShowDoubleFloatArrays.padBayerToFullSize(
imp_srcs[srcChannel], // ImagePlus imp_src,
eyesisCorrections.pixelMapping.sensors[srcChannel].getSensorWH(),
true); // boolean replicate);
......
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