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
parent 9d5dd318
......@@ -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 {