Commit 782eb01a authored by Andrey Filippov's avatar Andrey Filippov

pending commits while working on LWIR16 calibration

parent 016b8b7c
......@@ -1041,6 +1041,8 @@ if (MORE_BUTTONS) {
addButton("Goniometer Move", panelLWIR,color_debug);
addButton("LWIR Goniometer", panelLWIR,color_conf_process);
addButton("LWIR grids", panelLWIR,color_process);
addButton("LWIR15 GEOM", panelLWIR,color_configure);
addButton("Import Subsystem", panelLWIR,color_configure);
addButton("Select LWIR grids", panelLWIR,color_configure);
addButton("Grid offset", panelLWIR,color_process);
......@@ -5822,7 +5824,7 @@ if (MORE_BUTTONS) {
double patternHeight=PATTERN_PARAMETERS.patternHeight;
double targetAngleHorizontal=360*Math.atan(patternWidth/2/distanceToTarget)/Math.PI;
double targetAngleVertical= 360*Math.atan(patternHeight/2/distanceToTarget)/Math.PI;
if (DEBUG_LEVEL>0) System.out.println(
if (DEBUG_LEVEL>-1) System.out.println(
"Using:\n"+
"Distance from target: "+IJ.d2s(distanceToTarget,1)+" mm\n"+
" Taget width: "+IJ.d2s(patternWidth,1)+" mm\n"+
......@@ -9387,6 +9389,7 @@ if (MORE_BUTTONS) {
/* ======================================================================== */
if (label.equals("LWIR_ACQUIRE")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
/*
ImagePlus [][] imps;
if (LWIR_PARAMETERS.isLwir16()) {
if (LWIR16_READER == null) {
......@@ -9403,6 +9406,49 @@ if (MORE_BUTTONS) {
LWIR_READER.acquire(DISTORTION_PROCESS_CONFIGURATION.sourceDirectory); // directory to save
// ImagePlus [] imps = LWIR_READER.acquire("attic/lwir_test_images"); // directory to save
}
*/
if ((GONIOMETER==null) || (LWIR_PARAMETERS.isLwir16()?(GONIOMETER.lwir16Reader == null):(GONIOMETER.lwirReader == null))) {
if (LWIR_PARAMETERS.isLwir16()) {
if (LWIR16_READER == null) {
LWIR16_READER = new Lwir16Reader(LWIR_PARAMETERS);
}
GONIOMETER= new Goniometer(
LWIR16_READER,
DISTORTION, //MatchSimulatedPattern.DistortionParameters distortion,
PATTERN_DETECT, //MatchSimulatedPattern.PatternDetectParameters patternDetectParameters,
EYESIS_CAMERA_PARAMETERS, //EyesisCameraParameters eyesisCameraParameters,
LASER_POINTERS, // MatchSimulatedPattern.LaserPointer laserPointers
SIMUL, //SimulationPattern.SimulParameters simulParametersDefault,
GONIOMETER_PARAMETERS, //LensAdjustment.FocusMeasurementParameters focusMeasurementParameters,
DISTORTION_PROCESS_CONFIGURATION);
LWIR16_READER.setMotorsPosition(GONIOMETER_PARAMETERS.goniometerMotors.getCurrentPositions()); // getTargetPositions()); // Used target, not current to prevent minor variations
} else {
if (LWIR_READER == null) {
LWIR_READER = new LwirReader(LWIR_PARAMETERS);
}
GONIOMETER= new Goniometer(
LWIR_READER,
DISTORTION, //MatchSimulatedPattern.DistortionParameters distortion,
PATTERN_DETECT, //MatchSimulatedPattern.PatternDetectParameters patternDetectParameters,
EYESIS_CAMERA_PARAMETERS, //EyesisCameraParameters eyesisCameraParameters,
LASER_POINTERS, // MatchSimulatedPattern.LaserPointer laserPointers
SIMUL, //SimulationPattern.SimulParameters simulParametersDefault,
GONIOMETER_PARAMETERS, //LensAdjustment.FocusMeasurementParameters focusMeasurementParameters,
DISTORTION_PROCESS_CONFIGURATION);
LWIR_READER.setMotorsPosition(GONIOMETER_PARAMETERS.goniometerMotors.getCurrentPositions()); // getTargetPositions()); // Used target, not current to prevent minor variations
}
if (DEBUG_LEVEL>1){
System.out.println("Initialized Goniometer class for "+LWIR_PARAMETERS.getCameraName());
}
} else if (DEBUG_LEVEL>1){
System.out.println("GONIOMETER was initialized for "+LWIR_PARAMETERS.getCameraName());
}
if (LWIR_PARAMETERS.isLwir16()) {
LWIR16_READER.acquire(DISTORTION_PROCESS_CONFIGURATION.sourceDirectory); // directory to save
} else {
LWIR_READER.acquire(DISTORTION_PROCESS_CONFIGURATION.sourceDirectory); // directory to save
}
return;
}
......@@ -9451,7 +9497,7 @@ if (MORE_BUTTONS) {
double patternHeight=PATTERN_PARAMETERS.patternHeight;
double targetAngleHorizontal=360*Math.atan(patternWidth/2/distanceToTarget)/Math.PI;
double targetAngleVertical= 360*Math.atan(patternHeight/2/distanceToTarget)/Math.PI;
if (DEBUG_LEVEL>0) System.out.println(
if (DEBUG_LEVEL>-1) System.out.println(
"Using:\n"+
"Distance from target: "+IJ.d2s(distanceToTarget,1)+" mm\n"+
" Taget width: "+IJ.d2s(patternWidth,1)+" mm\n"+
......@@ -9475,6 +9521,12 @@ if (MORE_BUTTONS) {
calculateLwirGrids();
return;
}
/* ======================================================================== */
if (label.equals("LWIR15 GEOM")) {
EYESIS_CAMERA_PARAMETERS.setLwir16Geometry();
return;
}
/* ======================================================================== */
if (label.equals("Import Subsystem")) {
importSystem(null, "EYESIS_CAMERA_PARAMETERS.");
......@@ -9978,7 +10030,8 @@ if (MORE_BUTTONS) {
//DistortionProcessConfiguration
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
LENS_DISTORTIONS=new Distortions(LENS_DISTORTION_PARAMETERS,PATTERN_PARAMETERS,REFINE_PARAMETERS,this.SYNC_COMMAND.stopRequested);
int min_files = 8; // use folders that have all 8 files
// Maybe wrong ! Use folders that have at least all EO channels?
int min_files = lwirReaderParameters.getNumChannels();// 8; // use folders that have all 8 files
int lwir_chn0 = lwirReaderParameters.getLwirChn0();
int eo_chn0 = lwirReaderParameters.getEoChn0();
int numStations = 3;
......@@ -10011,7 +10064,7 @@ if (MORE_BUTTONS) {
for (int numStation=0;numStation<numStations;numStation++){
DirectoryChoser dc = new DirectoryChoser(
gridFilter,
min_files,
min_files, // not actually used
0,
null);
dc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
......@@ -10215,8 +10268,8 @@ if (MORE_BUTTONS) {
matchSimulatedPattern.invalidateFlatFieldForGrid(); //Reset Flat Field calibration - different image.
matchSimulatedPattern.invalidateFocusMask();
boolean is_lwir = LWIR_PARAMETERS.is_LWIR(imp_sel);
int numAbsolutePoints=matchSimulatedPattern.calculateDistortions(
boolean is_lwir = LWIR_PARAMETERS.is_LWIR(imp_sel); // Not used!
int numAbsolutePoints=matchSimulatedPattern.calculateDistortions( // matchSimulatedPattern.PATTERN_GRID already set
LWIR_PARAMETERS, // LwirReaderParameters lwirReaderParameters,
DISTORTION, //
PATTERN_DETECT,
......@@ -11543,7 +11596,7 @@ if (MORE_BUTTONS) {
} else {
System.out.println("No pattern grid file (ground gtruth) is provided");
}
if ((configPaths[3] !=null) && (configPaths[3] != "")){ // load sensor
if ((configPaths[3] !=null) && !configPaths[3].equals("")){ // load sensor
if (distortions.fittingStrategy==null) return false; // Why?
if (DEBUG_LEVEL>0) System.out.println("Autoloading sensor calibration files "+configPaths[3]);
distortions.setDistortionFromImageStack(
......@@ -45,6 +45,7 @@ import com.elphel.imagej.common.PolynomialApproximation;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.common.WindowTools;
import com.elphel.imagej.jp4.JP46_Reader_camera;
import com.elphel.imagej.lwir.LwirReaderParameters;
import Jama.Matrix;
import ij.IJ;
......@@ -894,6 +895,24 @@ import ij.text.TextWindow;
}
// from data organized as image sets
public static int getChannelFromPath(String path) {
// int indexSuffix=path.length()-suffix.length();
int indexSuffix = path.lastIndexOf(".");
int indexLastDash=indexSuffix-1;
while ((indexLastDash>0) &&
(indexLastDash>(indexSuffix-3)) &&
(path.charAt(indexLastDash)!='_') &&
(path.charAt(indexLastDash)!='-')) indexLastDash--;
return Integer.parseInt(path.substring(indexLastDash+1,indexSuffix));
}
private boolean invertColor(int chn) {
//TODO: Add looking at the image property to find out if inversion is already contained in the grid files
return eyesisCameraParameters.isLWIR(chn);
}
public void setupDirDistortionCalibrationData (
String [][] stationFilenames, // per-station List of image set directories
String [] source_dirs, // directories of the source files per station
......@@ -927,9 +946,17 @@ import ij.text.TextWindow;
// this.dir = dir;
int dot_index = dir.lastIndexOf("_");
String digits = "0123456789";
int ts_start = dot_index -1;
// allow "_<comment> after timestanp
int end_pos =dir.length();
while ((dot_index > 0) && (
(digits.indexOf(dir.charAt(dot_index -1)) < 0) ||
(digits.indexOf(dir.charAt(dot_index +1)) < 0))) { // not a digit before and after last "_"
end_pos = dot_index;
dot_index = dir.lastIndexOf("_", dot_index-1);
}
int ts_start = dot_index -1;
while ((ts_start >=0) && (digits.indexOf(dir.charAt(ts_start)) >= 0)) ts_start--;
this.ts = Double.parseDouble(dir.substring(ts_start + 1).replace('_','.'));
this.ts = Double.parseDouble(dir.substring(ts_start + 1, end_pos).replace('_','.'));
String [] files = (new File(dir)).list(gridFilter); // are these full files?
paths = new String[num_chn];
for (String path:files) {
......@@ -1022,8 +1049,9 @@ import ij.text.TextWindow;
String [] paths = dt.getPaths();
String [] spaths = dt.getSourcePaths();
int with_pointers = -1;
for (int nc = 0; nc < paths.length; nc++) {
String p = paths[nc];
for (int indx = 0; indx < paths.length; indx++) {
String p = paths[indx];
int nc = getChannelFromPath(p);
boolean first_in_set = true;
if (p != null) {
this.gIP[numFile] = new GridImageParameters(numFile);
......@@ -1031,11 +1059,13 @@ import ij.text.TextWindow;
this.gIP[numFile].source_path = spaths[nc];
this.gIP[numFile].setStationNumber(dt.getStation());
this.gIP[numFile].timestamp = dt.getTs();
this.gIP[numFile].channel = nc;
this.gIP[numFile].setNumber = nis;
this.gIP[numFile].channel = nc; // **************** what if not all files present?- fixed this.gIP[numFile].setNumber = nis;
this.gIP[numFile].gridImageSet = this.gIS[nis];
this.gIP[numFile].setNumber= nis;
this.gIS[nis].imageSet[nc]=this.gIP[numFile];
boolean is_small = getImagePlusProperty(imp_grid,"WOI_WIDTH",0) <= MAX_LWIR_WIDTH;
// boolean is_small = getImagePlusProperty(imp_grid,"WOI_WIDTH",0) <= MAX_LWIR_WIDTH;
boolean is_lwir = eyesisCameraParameters.isLWIR(nc);
//numFile
if (first_in_set || read_grids) {
if (read_grids) {
......@@ -1068,7 +1098,8 @@ import ij.text.TextWindow;
System.out.print("<"+(this.gIP[numFile].matchedPointers));
// Not using LWIR pointers here!
// if (!ignore_LWIR_pointers || (getImagePlusProperty(imp_grid,"WOI_TOP",0) > MAX_LWIR_WIDTH)) {
if (!ignore_LWIR_pointers || !is_small) {
// if (!ignore_LWIR_pointers || !is_small) { // here invert_color = true;
if (!ignore_LWIR_pointers || !eyesisCameraParameters.isLWIR(nc)) { // here invert_color = true;
with_pointers = numFile;
System.out.print("|"+numFile);
}
......@@ -1113,7 +1144,8 @@ import ij.text.TextWindow;
int [] numBadNodes = new int [2];
double badNodeThreshold = is_small? this.eyesisCameraParameters.badNodeThresholdLWIR : this.eyesisCameraParameters.badNodeThreshold;
// double badNodeThreshold = is_small? this.eyesisCameraParameters.badNodeThresholdLWIR : this.eyesisCameraParameters.badNodeThreshold;
double badNodeThreshold = is_lwir? this.eyesisCameraParameters.badNodeThresholdLWIR : this.eyesisCameraParameters.badNodeThreshold;
if (badNodeThreshold > 0.0){
boolean thisDebug =false;
// thisDebug|= (fileNumber== 720); // chn 25
......@@ -1134,7 +1166,7 @@ import ij.text.TextWindow;
if (disableNoFlatfield && !this.gIP[numFile].flatFieldAvailable) this.gIP[numFile].enabled=false; // just to use old mixed data
int [][] shiftRotMatrix= MatchSimulatedPattern.getRemapMatrix(this.gIP[numFile].getUVShiftRot());
int [] sizeSizeExtra=setGridsWithRemap(
int [] sizeSizeExtra=setGridsWithRemap( // apply current remap to the grid file data
numFile,
shiftRotMatrix, // int [][] reMap,
pixels,
......@@ -1173,13 +1205,15 @@ import ij.text.TextWindow;
}
}
if (with_pointers < 0) { // no matching pointers, will try to match selected channel with the pattern
int main_channel = 4; // one of the EO channels to match with the pattern
// int main_channel = 4; // one of the EO channels to match with the pattern
int main_channel = eyesisCameraParameters.getFirstHighRes(); // one of the EO channels to match with the pattern
// boolean [] sensor_mask = null; // later may be used to limit scope to EO-only
int extra_search = 2;
// int base_channel = this.gIP[with_pointers].channel;
if (this.gIS[nis].imageSet[main_channel] != null) {
int imgNum = this.gIS[nis].imageSet[main_channel].imgNumber;
boolean invert_color = (main_channel & 4) == 0; // first 4 - LWIR
// boolean invert_color = (main_channel & 4) == 0; // first 4 - LWIR
boolean invert_color = invertColor(main_channel); // eyesisCameraParameters.isLWIR(main_channel);
if (this.updateStatus) IJ.showStatus("Matching with the pattern, grid file "+(imgNum+1)+" (of "+(numFiles)+"): "+this.gIP[imgNum].path);
if (this.debugLevel>-1) System.out.print(imgNum+">("+this.gIP[imgNum].getStationNumber()+
......@@ -1199,7 +1233,7 @@ import ij.text.TextWindow;
sensor_wh, // test set pixels width/height pair to reduce weight near the margins (or null)
false // true // boolean bdebug
);
System.out.print(" {"+uv_shift_rot[0]+":"+uv_shift_rot[1]+"]");
System.out.print(" {"+uv_shift_rot[0]+":"+uv_shift_rot[1]+"], invert_color="+invert_color);
this.gIS[nis].imageSet[main_channel].setUVShiftRot(uv_shift_rot);
......@@ -1226,7 +1260,9 @@ import ij.text.TextWindow;
int extra_search = 1;
int base_channel = this.gIP[with_pointers].channel;
for (int nc = 0; nc < this.gIS[nis].imageSet.length; nc++) if ((sensor_mask == null) || sensor_mask[nc]) {
boolean invert_color = ((base_channel ^ nc) & 4) != 0;
// boolean invert_color = ((base_channel ^ nc) & 4) != 0;
boolean invert_color = invertColor(base_channel) ^ invertColor(nc); // eyesisCameraParameters.isLWIR(main_channel);
if ((this.gIS[nis].imageSet[nc].matchedPointers <= 0) && (nc != base_channel)) { // Later add non-laser conditions
int imgNum = this.gIS[nis].imageSet[nc].imgNumber; // with_pointers - base_channel + nc;
if (this.updateStatus) IJ.showStatus("Re-reading grid file "+(imgNum+1)+" (of "+(numFiles)+"): "+this.gIP[imgNum].path);
......@@ -1522,30 +1558,6 @@ import ij.text.TextWindow;
}
// suggest set grid offset by comparing with known (by mark) set.
// Wrong Grid UV should cause parallel shift - same Z, different XY
/*
public int [] suggestOffset (
int num_img,
boolean non_estimated,
boolean even,
PatternParameters patternParameters) {
int num_set = this.gIP[num_img].getSetNumber();
double [] ref_xyz = getXYZFromMarked(num_set, non_estimated);
if (ref_xyz == null) {
System.out.println("Error: Could not find reference goniometer XYZ for set "+num_set);
return null;
}
double [] diff_xyz = this.gIS[num_set].GXYZ.clone();
for (int i = 0; i < diff_xyz.length; i++) diff_xyz[i]-=ref_xyz[i];
return suggestOffset (
num_img,
diff_xyz, // z is not used, may ne just[2]
even,
patternParameters,
null);
}
*/
public int [] suggestOffset (
int num_img,
double [] diff_xyz, // This XYZ minus reference XYZ z is not used, may be just[2]
......@@ -1781,6 +1793,12 @@ import ij.text.TextWindow;
sb.append("Lens Distortion Model\t");
for (int i=0;i<numSubCameras;i++) sb.append("\t"+lensDistortionModels[i]);
sb.append("\n");
sb.append("LWIR/EO\t");
for (int i=0;i<numSubCameras;i++) {
sb.append("\t"+LwirReaderParameters.sensorName(eyesisCameraParameters.isLWIR(i)));
}
sb.append("\n");
sb.append("Sensor width\t");
for (int i=0;i<numSubCameras;i++) sb.append("\t"+eyesisCameraParameters.getSensorWidth(i));
......@@ -1796,8 +1814,14 @@ import ij.text.TextWindow;
for (int i=0;i<numSubCameras;i++) cameraPars[i]=eyesisCameraParameters.getParametersVector(stationNumber,i);
// parameters same order as in this
for (int n=0;n<cameraPars[0].length;n++) if (isSubcameraParameter(n) && isIntrinsicParameter(n)){
int digits = 3;
if (getParameterName(n).startsWith("subcamP")) {
digits = 2;
} else if (getParameterName(n).startsWith("subcamDistortion")) {
digits = 4;
}
sb.append(getParameterName(n)+"\t"+getParameterUnits(n));
for (int i=0;i<numSubCameras;i++) sb.append("\t"+IJ.d2s(cameraPars[i][n],3));
for (int i=0;i<numSubCameras;i++) sb.append("\t"+IJ.d2s(cameraPars[i][n],digits));
sb.append("\n");
}
sb.append("---"); for (int i=-1;i<numSubCameras;i++) sb.append("\t"); sb.append("\n");
......@@ -1863,6 +1887,12 @@ import ij.text.TextWindow;
// for (int i=0;i<numSubCameras;i++) sb.append("\t"+lensDistortionModels[i]);
// sb.append("\n");
sb.append("LWIR/EO\t");
for (int i=0;i<numSubCameras;i++) {
sb.append("\t"+LwirReaderParameters.sensorName(eyesisCameraParameters.isLWIR(i)));
}
sb.append("\n");
sb.append("Sensor width\t");
for (int i=0;i<numSubCameras;i++) sb.append("\t"+eyesisCameraParameters.getSensorWidth(i));
sb.append("\n");
......@@ -1941,7 +1971,9 @@ import ij.text.TextWindow;
// sb.append("---"); for (int i=-1;i<numSubCameras;i++) sb.append("\t"); sb.append("\n");
int flindex =getParameterIndexByName("subcamFocalLength");
sb.append(getParameterName(flindex)+"\t"+getParameterUnits(flindex));
for (int i=0;i<numSubCameras;i++) sb.append("\t"+IJ.d2s(cameraPars[i][flindex],3));
for (int i=0;i<numSubCameras;i++) {
sb.append("\t"+IJ.d2s(cameraPars[i][flindex],3));
}
sb.append("\n");
sb.append("Camera roll"+"\t"+"degrees"+"\t"+IJ.d2s(commonRot,3));
......@@ -2394,7 +2426,8 @@ import ij.text.TextWindow;
this.gIP[i].hintedMatch=0; // is it needed?
this.gIP[i].enabled=false; // failed against minimal grid period (too far) - probably double reflection in the windows
}
if (this.gIP[i].hintedMatch==0) {
// if (this.gIP[i].hintedMatch==0) {
if ((this.gIP[i].hintedMatch==0) && (this.gIP[i].matchedPointers < minPointers)) { // added
this.gIP[i].enabled=false; // failed against predicted grid
} else {
if (
......@@ -2572,7 +2605,7 @@ import ij.text.TextWindow;
}
if (bestRating>0){
EyesisSubCameraParameters esp = this.eyesisCameraParameters.eyesisSubCameras[stationNumber][bestChannel];
System.out.println("Image number: "+this.gIS[i].imageSet[bestChannel].getImageNumber());
System.out.println("setInitialOrientation(): Image number: "+this.gIS[i].imageSet[bestChannel].getImageNumber());
double [] uv_center = getGridUVfromXY(
esp.px0, // final double px,
esp.py0, // final double py,
......@@ -2587,11 +2620,11 @@ import ij.text.TextWindow;
if (this.debugLevel>0) {
System.out.println("Center UV = "+uv_center[0]+","+uv_center[1]);
}
// Now will try bilinear interpolate first, then extrapolate
double [] patt_xyz = patternParameters.getXYZ(
uv_center, // double [] uv,
false, // boolean verbose,
this.gIS[i].getStationNumber()); // int station); // u=0,v=0 - center!
if (patt_xyz == null) {
if (this.debugLevel>0) {
System.out.println("Center UV = NULL");
......@@ -3886,7 +3919,8 @@ import ij.text.TextWindow;
this.gIP[fileNumber].gridImage = imp_grid;
}
}
boolean is_small = getImagePlusProperty(imp_grid,"WOI_WIDTH",0) <= MAX_LWIR_WIDTH;
// boolean is_small = getImagePlusProperty(imp_grid,"WOI_WIDTH",0) <= MAX_LWIR_WIDTH;
boolean is_lwir = eyesisCameraParameters.isLWIR(this.gIP[fileNumber].channel);
this.gIP[fileNumber].woi = new Rectangle(
getImagePlusProperty(imp_grid,"WOI_LEFT",0),
getImagePlusProperty(imp_grid,"WOI_TOP",0),
......@@ -3929,7 +3963,8 @@ import ij.text.TextWindow;
woi_compensated = true;
}
double badNodeThreshold = is_small? this.eyesisCameraParameters.badNodeThresholdLWIR : this.eyesisCameraParameters.badNodeThreshold;
// double badNodeThreshold = is_small? this.eyesisCameraParameters.badNodeThresholdLWIR : this.eyesisCameraParameters.badNodeThreshold;
double badNodeThreshold = is_lwir? this.eyesisCameraParameters.badNodeThresholdLWIR : this.eyesisCameraParameters.badNodeThreshold;
// TODO: maybe adjust threshold to grid period, not the sensor type?
if (badNodeThreshold>0.0){
......@@ -3994,7 +4029,7 @@ import ij.text.TextWindow;
}
}
}
if (this.debugLevel>0) {
if (this.debugLevel>-1) {
System.out.println("readAllGrids(), numImages="+numImages+", total number of grid nodes="+numOfGridNodes+", unused nodes "+numOfGridNodes_extra);
}
// probably - do not need to verify that this.gIS is null - should do that anyway. UPDATE: no, now reading config file creates gIS
......@@ -4371,6 +4406,7 @@ import ij.text.TextWindow;
return 0;
}
// TODO: Cleanup below to use isLWIR form EyesisCameraParameters
// get "effective" grid period scaled for low-res (as LWIR) sensors
public double getEffectivePeriod(int numImg) {
......
......@@ -25,6 +25,7 @@ package com.elphel.imagej.calibration;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Properties;
import com.elphel.imagej.common.WindowTools;
......@@ -223,8 +224,10 @@ import ij.gui.GenericDialog;
return new File(current, name).isDirectory();
}
});
// TODO:Sort set list
String [] sourceSets = new String[sourceFileSets.length];
for (int i=0;i<sourceSets.length;i++) sourceSets[i]=sourceFileSets[i].getPath();
Arrays.sort(sourceSets);
return sourceSets;
}
......
......@@ -520,6 +520,10 @@ public class Distortions {
/* double [] XYZM=patternParameters.getXYZM( // will throw if outside or masked out
fittingStrategy.distortionCalibrationData.gIP[imgNum].pixelsUV[pointNumber][0],
fittingStrategy.distortionCalibrationData.gIP[imgNum].pixelsUV[pointNumber][1]);*/
if ((targetXYZ[index]==null) || (XYZMP==null)) {
System.out.println("Null problem in imgNum="+imgNum+", point "+pointNumber);
continue;
}
this.targetXYZ[index][0]=XYZMP[0];
this.targetXYZ[index][1]=XYZMP[1];
this.targetXYZ[index][2]=XYZMP[2];
......@@ -3293,6 +3297,7 @@ For each point in the image
int global_debug_level, // DEBUG_LEVEL
int debug_level // debug level used inside loops
){
int debugThreshold0=0;
int debugThreshold=2;
MatchSimulatedPattern matchSimulatedPattern = new MatchSimulatedPattern(64); // new instance, all reset, FFTSize=64 will not be used
......@@ -3316,6 +3321,10 @@ For each point in the image
int numSuccess=0;
DistortionCalibrationData dcd=fittingStrategy.distortionCalibrationData;
for (int numGridImage=0;numGridImage<dcd.gIP.length;numGridImage++) {
if (numGridImage >= 1680) {
System.out.println("Processing debug image "+numGridImage);
System.out.println("Processing debug image "+numGridImage);
}
int set_number = dcd.gIP[numGridImage].getSetNumber();
if ((set_number >= start_set) &&
(set_number <= end_set) &&
......@@ -3338,6 +3347,17 @@ For each point in the image
}
}
}
if ((dcd.gIP[numGridImage].matchedPointers > 0) && !ignoreLaserPointers) { // just re-enable with the same shifts (will fail if pointers were just added, but it failed anyway)
if (!dcd.gIP[numGridImage].enabled) {
if (this.debugLevel>0) {
System.out.println("Re-enabling grid #"+numGridImage+" that has pointer(s) with the previously set UVShiftRot =={0,0,0}");
}
dcd.gIP[numGridImage].enabled = true;
dcd.gIP[numGridImage].newEnabled = true;
}
continue;
}
if (this.debugLevel>debugThreshold0) {
System.out.println("\n---- applyHintedGrids() image #"+numGridImage+" (imageNumber="+imageNumber+") "+
" dcd.gIP["+numGridImage+"].pixelsXY.length="+dcd.gIP[numGridImage].pixelsXY.length+
......@@ -3385,7 +3405,6 @@ For each point in the image
System.out.println("++++++ BUG: in applyHintedGrids() failed in createUV_INDEX()");
continue;
}
double [] goniometerTiltAxial=dcd.getImagesetTiltAxial(numGridImage);
if ((goniometerTiltAxial==null) || Double.isNaN(goniometerTiltAxial[0]) || Double.isNaN(goniometerTiltAxial[1])){
if (this.debugLevel>0) {
......@@ -3551,7 +3570,7 @@ For each point in the image
public int [][] getImageMarkers(int numGridImage){
String source_path=fittingStrategy.distortionCalibrationData.gIP[numGridImage].source_path;
if (source_path != null) {
final ImagePlus imp = new ImagePlus(source_path);
ImagePlus imp = new ImagePlus(source_path);
imp.show();
/*
Thread msg_box_thread = new Thread() {
......@@ -3580,6 +3599,25 @@ For each point in the image
System.out.println("This image does not have point marks - please mark it in "+source_path);
IJ.showMessage("This image does not have point marks - please mark it in "+source_path);
return null;
/*
boolean mark_and_continue = IJ.showMessageWithCancel("Mark and Continue", "This image does not have point marks - please mark it in "+source_path);
if (mark_and_continue) {
imp = new ImagePlus(source_path);
System.out.println("got it again!");
pointRoi = null;
if (imp.getRoi() instanceof PointRoi) {
pointRoi = (PointRoi) imp.getRoi();
} else {
System.out.println("This image does not have point marks - please mark it in "+source_path);
IJ.showMessage("This image does not have point marks - please mark it in "+source_path);
return null;
}
} else {
return null;
}
*/
}
Point [] points = pointRoi.getContainedPoints();
int [][] ipoints = new int [points.length][2];
......
......@@ -2016,6 +2016,9 @@ public class MatchSimulatedPattern {
ix = (interpolateXY[maxIndex][0] + j) % size;
for (int i = 0; i < 2; i++) {
iy = interpolateXY[maxIndex][1] + i; // next: OOB 2147483647
if (iy >= fft_complex.length) {
iy = fft_complex.length - 1; // was Index 17 out of bounds for length 17
}
interpolateAmplitudes[maxIndex][i][j] = Math.sqrt(fft_complex[iy][ix][0] * fft_complex[iy][ix][0]
+ fft_complex[iy][ix][1] * fft_complex[iy][ix][1]);
interpolatePhases[maxIndex][i][j] = Math.atan2(
......@@ -7688,7 +7691,7 @@ public class MatchSimulatedPattern {
int shiftSelect = (((shifts[0][0] - coeff[0][2]) * (shifts[0][0] - coeff[0][2]) + (shifts[0][1] - coeff[1][2])
* (shifts[0][1] - coeff[1][2])) > ((shifts[1][0] - coeff[0][2]) * (shifts[1][0] - coeff[0][2])
+ (shifts[1][1] - coeff[1][2]) * (shifts[1][1] - coeff[1][2]))) ? 1 : 0;
if (this.debugLevel > 1) {
if (this.debugLevel > 0) {
double d1 = Math.sqrt((shifts[0][0] - coeff[0][2]) * (shifts[0][0] - coeff[0][2])
+ (shifts[0][1] - coeff[1][2]) * (shifts[0][1] - coeff[1][2]));
double d2 = Math.sqrt((shifts[1][0] - coeff[0][2]) * (shifts[1][0] - coeff[0][2])
......@@ -8068,7 +8071,8 @@ public class MatchSimulatedPattern {
numCells++;
}
if (numCells > 0) {
setPatternGridArray(maxU - minU + 1, maxV - minV + 1);
// setPatternGridArray(maxU - minU + 1, maxV - minV + 1); // FIXME: Does nothing
this.PATTERN_GRID = setPatternGridArray(maxU - minU + 1, maxV - minV + 1); // FIXME: Does nothing
double[] xy = new double[2];
int[] uv = new int[2];
for (int i = 0; i < pixels[0].length; i++)
......
......@@ -2,6 +2,7 @@ package com.elphel.imagej.calibration;
import java.awt.Rectangle;
import java.util.Properties;
import com.elphel.imagej.common.PolynomialApproximation;
import com.elphel.imagej.jp4.JP46_Reader_camera;
/*
......@@ -743,6 +744,7 @@ import ij.io.Opener;
public double[] getXYZM(int u, int v, boolean verbose, int station){ // u=0,v=0 - center!
int u1=u+this.U0;
int v1=v+this.V0;
double r2 = 0.25;
if ((v1<0) || (u1<0) || (v1 >= this.gridGeometry.length) || (u1 >= this.gridGeometry[0].length) ||
(this.gridGeometry[v1][u1][3]==0)) {
if ((this.debugLevel>1) && verbose && ((v1<0) || (u1<0) || (v1 >= this.gridGeometry.length) || (u1 >= this.gridGeometry[0].length))){
......@@ -755,13 +757,68 @@ import ij.io.Opener;
return null;
}
if (this.stationZCorr==null) return this.gridGeometry[v1][u1];
double [] result=this.gridGeometry[v1][u1].clone();
double [] result = this.gridGeometry[v1][u1].clone();
// use lower station if grid file does not have current
int useStation=(this.stationZCorr[v1][u1].length>station)?station:(this.stationZCorr[v1][u1].length-1);
result[2]+=this.stationZCorr[v1][u1][useStation];
return result;
// return this.gridGeometry[v1][u1];
}
/**
* Use this for just initial orientation
* @param u
* @param v
* @param verbose
* @return {x,y,z}
*/
public double[] extrapolateXYZ(
double u,
double v,
boolean verbose){ // u=0,v=0 - center! No correction for stationZCorr - anyway it is not accurate outside
double u1 = u + this.U0;
double v1 = v + this.V0;
double r2 = 0.0001;
double [] result = null;
PolynomialApproximation pa = new PolynomialApproximation();
double [][][] data = new double[gridGeometry.length * gridGeometry[0].length][3][];
int di = 0;
for (int vg = 0; vg < gridGeometry.length; vg++) {
double dv2 = v1 - vg;
dv2 = dv2*dv2 + r2;;
for (int ug = 0; ug < gridGeometry[0].length; ug++) {
data[di][0] = new double[2];
data[di][0][0] = ug;
data[di][0][1] = vg;
data[di][1] = new double[3];
data[di][2] = new double[1];
if ((gridGeometry[vg][ug] != null) && (gridGeometry[vg][ug][3] > 0.0)){
data[di][1][0] = gridGeometry[vg][ug][0]; // x
data[di][1][1] = gridGeometry[vg][ug][1]; // y
data[di][1][2] = gridGeometry[vg][ug][2]; // z
double du = u1 - ug;
data[di][2][0] = gridGeometry[vg][ug][3] / (du*du + dv2);
}
di++;
}
}
double [][] coeff = pa.quadraticApproximation(
data,
true, // forceLinear, // use linear approximation
null); // damping,
if (coeff== null) return null;
result = new double[3]; // out of grid, so all but x,y,z are 0.0;
for (int i = 0; i < 3; i++) {
result[i] = coeff[i][0]*u1 + coeff[i][1]*v1 + coeff[i][2];
}
/*
if (this.stationZCorr==null) return result; // this.gridGeometry[v1][u1];
// use lower station if grid file does not have current
int useStation=(this.stationZCorr[v1][u1].length>station)?station:(this.stationZCorr[v1][u1].length-1);
result[2]+=this.stationZCorr[v1][u1][useStation];
*/
return result;
}
public double[] getXYZ(
double [] uv,
boolean verbose,
......@@ -776,8 +833,11 @@ import ij.io.Opener;
corn[2] = getXYZM(iu, iv + 1, verbose, station);
corn[3] = getXYZM(iu + 1, iv + 1, verbose, station);
if ((corn[0] == null) || (corn[1] == null) || (corn[2] == null) || (corn[3] == null)) {
System.out.println("Optical axis outside of the grid: TODO: modify getXYZM() to handle!");
return null;
if (verbose) {
System.out.println("Optical axis outside of the grid: TODO: modify getXYZM() to handle!");
}
return extrapolateXYZ (uv[0], uv[1], verbose);
// return null;
}
double [] rslt_xyz = new double[3];
rslt_xyz[0] = (1-fu) * (1-fv) * corn[0][0] + fu * (1-fv) * corn[1][0] + (1-fu) * fv * corn[2][0] + fu * fv * corn[3][0];
......@@ -915,7 +975,7 @@ import ij.io.Opener;
};
return result;
}
public double[] getXYZMPE(
public double[] getXYZMPE( // update this and other to interpolate
int u,
int v,
int station,
......
......@@ -14,6 +14,7 @@ import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.common.WindowTools;