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";
// 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]
......@@ -1782,6 +1794,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");
......@@ -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)) {
if (verbose) {
System.out.println("Optical axis outside of the grid: TODO: modify getXYZM() to handle!");
return null;
}
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;
import Jama.Matrix;
import ij.IJ;
/*
**
** EyesisCameraParameters.java
......@@ -1306,6 +1307,86 @@ import ij.gui.GenericDialog;
EyesisSubCameraParameters subCam=this.eyesisSubCameras[stationNumber][subCamNumber];
return subCam.enableNoLaser;
}
/**
* Get number of the first high-res camera
* @return
*/
public int getFirstHighRes() {
int sensor_max_width = 0;
int first_high_res = 0;
for (int ncam = 0; ncam < eyesisSubCameras[0].length; ncam ++) {
if (eyesisSubCameras[0][ncam].sensorWidth > sensor_max_width) {
sensor_max_width = eyesisSubCameras[0][ncam].sensorWidth;
first_high_res = ncam;
}
}
return first_high_res;
}
public boolean isLWIR(int ncam) {
return eyesisSubCameras[0][ncam].isLWIR();
}
/**
* Setting default camera geometry parameters for LWIR16 prototype system
* @return false if number of cameras is not 20
*/
public boolean setLwir16Geometry() {
if (this.eyesisSubCameras[0].length != 20) {
IJ.showMessage("Requires number of subcameras to be set to 20 before running this command");
return false;
}
double CENTER_FORWARD = 110.1; // mm from middle 1/4-20 "high" mount
double CENTER_UP = 72.35; // mm from middle 1/4-20 "high" mount
double EO_FORWARD = 47.89; // mm outer lens element center (maybe later replace with entr. pupil location?
double EO_HORVERT = 113.3; // mm 1/sqrt(radius)
double LWIR_RADIUS = 110.0; // mm radius of LWIR ring
double LWIR_FORWARD = 46.83; // mm outer lens element center (maybe later replace with entr. pupil location?
double CENTER_ABOVE_HORIZONTAL = 175; // mm camera mount (middle 1/4-20 "high" mount) above goniomneter horizontal axis
int [][] eo_ru = {{-1,1},{1,1},{-1,-1},{1,-1}};
for (int ncam = 0; ncam < eyesisSubCameras[0].length; ncam ++) {
boolean isLWIR = ncam < 16;
for (int nstation = 0; nstation < eyesisSubCameras.length; nstation++) {
eyesisSubCameras[nstation][ncam].cartesian= true;
eyesisSubCameras[nstation][ncam].cartesian= true;
eyesisSubCameras[nstation][ncam].subcamera= ncam / 4;
eyesisSubCameras[nstation][ncam].sensor_port= ncam % 4;
eyesisSubCameras[nstation][ncam].sensor_port= 0; // or ncam?
eyesisSubCameras[nstation][ncam].sensorWidth= isLWIR ? 640 : 2592;
eyesisSubCameras[nstation][ncam].sensorHeight= isLWIR ? 512 : 1936;
eyesisSubCameras[nstation][ncam].focalLength= isLWIR ? 14.0 : 4.5;
eyesisSubCameras[nstation][ncam].pixelSize= isLWIR ? 12.0 : 2.2;
eyesisSubCameras[nstation][ncam].distortionRadius= isLWIR ? 3.24 : 2.8512; // mm - half width of the sensor
eyesisSubCameras[nstation][ncam].px0= isLWIR ? 320.0 : 1296.0;
eyesisSubCameras[nstation][ncam].py0= isLWIR ? 256.0 : 968.0;
if (isLWIR) {
eyesisSubCameras[nstation][ncam].forward = CENTER_FORWARD+LWIR_FORWARD;
eyesisSubCameras[nstation][ncam].height = CENTER_UP + LWIR_RADIUS * Math.cos(Math.PI/8 * ncam);
eyesisSubCameras[nstation][ncam].right = LWIR_RADIUS * Math.sin(Math.PI/8 * ncam);
} else {
int ieo = ncam-16;
eyesisSubCameras[nstation][ncam].forward = CENTER_FORWARD+EO_FORWARD;
eyesisSubCameras[nstation][ncam].height = CENTER_UP + EO_HORVERT * eo_ru[ieo][1];
eyesisSubCameras[nstation][ncam].right = EO_HORVERT * eo_ru[ieo][0];
}
eyesisSubCameras[nstation][ncam].phi = 0.0;
eyesisSubCameras[nstation][ncam].theta = 0.0;
eyesisSubCameras[nstation][ncam].psi = 0.0;
eyesisSubCameras[nstation][ncam].updateCartesian();
eyesisSubCameras[nstation][ncam].lwir = isLWIR;
}
}
for (int nstation = 0; nstation < centerAboveHorizontal.length; nstation++) {
centerAboveHorizontal[nstation] = CENTER_ABOVE_HORIZONTAL;
}
IJ.showMessage("Camera geometry is set to LWIR16 design (16 LWIR + 4 EO)");
return true;
}
/**
*
* @param eyesisCameraParameters current parameters of the Eyesis camera, subcameras and goniometer
......@@ -1604,7 +1685,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][1]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
......@@ -1638,7 +1720,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][2]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1671,7 +1754,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
} else if (numSubCameras==1) {
this.cartesian = false;
......@@ -1706,7 +1790,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
} else if (numSubCameras == 21) {
// ================
......@@ -1744,7 +1829,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][1]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1777,7 +1863,9 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][2]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1810,7 +1898,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][3]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1843,7 +1932,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][4]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1876,7 +1966,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][5]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1909,7 +2000,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][6]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1942,7 +2034,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][7]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -1975,7 +2068,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][8]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2008,7 +2102,9 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][9]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2041,7 +2137,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][10]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2074,7 +2171,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][11]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2107,7 +2205,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][12]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2140,7 +2239,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][13]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2173,7 +2273,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][14]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2206,7 +2307,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][15]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2239,7 +2341,9 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][16]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2272,7 +2376,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][17]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2305,7 +2410,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][18]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2338,7 +2444,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][19]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2371,7 +2478,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
this.eyesisSubCameras[numStation][20]=new EyesisSubCameraParameters( //TODO: modify for lens adjustment defaults?
this.defaultSensorWidth,
......@@ -2404,7 +2512,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
//
// end of PHG21 parameters
......@@ -2442,7 +2551,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
for (int i=8;i<16;i++) if (i<numSubCameras) this.eyesisSubCameras[numStation][i]=new EyesisSubCameraParameters( // middle 8 cameras
this.defaultSensorWidth,
......@@ -2475,7 +2585,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
for (int i=16;i<24;i++) if (i<numSubCameras) this.eyesisSubCameras[numStation][i]=new EyesisSubCameraParameters( // bottom eight cameras
this.defaultSensorWidth,
......@@ -2508,7 +2619,8 @@ import ij.gui.GenericDialog;
1.0, //channelWeightDefault
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
if (24<numSubCameras) this.eyesisSubCameras[numStation][24]=new EyesisSubCameraParameters(
this.defaultSensorWidth,
......@@ -2541,7 +2653,8 @@ import ij.gui.GenericDialog;
8.0, //channelWeightDefault (was 4)
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
if (25<numSubCameras) this.eyesisSubCameras[numStation][25]=new EyesisSubCameraParameters(
this.defaultSensorWidth,
......@@ -2574,8 +2687,8 @@ import ij.gui.GenericDialog;
8.0, //channelWeightDefault (was 4)
0, // public int subcamera
0, // public int sensor_port
0); // public int subchannel
0, // public int subchannel
false); // lwir
}
}
public void recenterVertically(boolean [] subcams, boolean [] stations){
......
......@@ -68,7 +68,7 @@ import java.util.Properties;
public int subcamera = 0;
public int sensor_port = 0;
public int subchannel = 0;
public boolean lwir = false; // invert color for LWIR sensors
/*
Modifying to accommodate for eccentricity of different terms (2 parameters per term) and elliptical shape (another 2 terms). When all are
......@@ -115,7 +115,8 @@ import java.util.Properties;
double channelWeightDefault,
int subcamera,
int sensor_port,
int subchannel
int subchannel,
boolean lwir // LWIR camera with inverted color
){
this.decimateMasks = decimateMasks;
this.sensorWidth= sensorWidth;
......@@ -158,7 +159,7 @@ import java.util.Properties;
this.subcamera = subcamera;
this.sensor_port = sensor_port;
this.subchannel = subchannel;
this.lwir = lwir;
updateCartesian(); // set alternative
}
// defects are not cloned!
......@@ -197,7 +198,8 @@ import java.util.Properties;
this.channelWeightDefault,
this.subcamera,
this.sensor_port,
this.subchannel
this.subchannel,
this.lwir
);
}
public void setDefaultNonRadial(){
......@@ -247,8 +249,7 @@ import java.util.Properties;
properties.setProperty(prefix+"subcamera", this.subcamera+"");
properties.setProperty(prefix+"sensor_port", this.sensor_port+"");
properties.setProperty(prefix+"subchannel", this.subchannel+"");
properties.setProperty(prefix+"lwir", this.lwir+"");
}
public void getProperties(String prefix,Properties properties){
getProperties(prefix,properties, -1);
......@@ -333,7 +334,8 @@ import java.util.Properties;
this.sensor_port=Integer.parseInt(properties.getProperty(prefix+"sensor_port"));
if (properties.getProperty(prefix+"subchannel")!=null)
this.subchannel=Integer.parseInt(properties.getProperty(prefix+"subchannel"));
if (properties.getProperty(prefix+"lwir")!=null)
this.lwir=Boolean.parseBoolean(properties.getProperty(prefix+"lwir"));
}
public void setChannelWeightCurrent(
double weight){
......@@ -363,9 +365,14 @@ import java.util.Properties;
this.cartesian = cartesian;
}
public boolean isLWIR() {
return this.lwir;
}
public double getPixelSize() {
return this.pixelSize;
}
public double getDistortionRadius() {
return this.distortionRadius;
}
......
......@@ -88,7 +88,6 @@ public class Lwir16Reader {
public static final String SCRIPT_CAPTURE= "capture_range.php"; // capture synchronized images
public static final String SCRIPT_RESET= "reset_frames.php"; // Reset frame numbers
public static final String SCRIPT_WAIT= "wait_frame.php"; // wait for absolute frame (positive) or skip frames (nefative)
// will remove later
public static final String IMAGE_URL_FIRST="/towp/wait/img/save"; // next image name, same image number/time
public static final String SKIP_FRAME_URL= "/towp/wait/meta"; // Wait for the next frame, return meta data
......@@ -288,38 +287,6 @@ public class Lwir16Reader {
}
startAndJoin(threads);
/*
for (int chn = 0; chn < num_channels; chn++) {
int width = sets[0][chn].getWidth();
int height = sets[0][chn].getHeight();
String title = sets[0][chn].getTitle()+"_average"+num_frames;
float [] pixels_avg = (float []) sets[0][chn].getProcessor().getPixels(); //null pointer
for (int n = 1; n < num_frames; n++) {
float [] pixels = (float []) sets[n][chn].getProcessor().getPixels();
for (int i = 0; i < pixels_avg.length; i++) {
pixels_avg[i] += pixels[i];
}
}
double scale = 1.0/num_frames;
for (int i = 0; i < pixels_avg.length; i++) {
pixels_avg[i] *= scale;
}
ImageProcessor ip=new FloatProcessor(width,height);
ip.setPixels(pixels_avg);
ip.resetMinAndMax();
imps_avg[chn]= new ImagePlus(title, ip);
Properties properties0 = sets[0][chn].getProperties();
for (String key:properties0.stringPropertyNames()) {
imps_avg[chn].setProperty(key, properties0.getProperty(key));
}
imps_avg[chn].setProperty("average", ""+num_frames);
if (motorsPosition!=null) for (int m=0;m<motorsPosition.length;m++ ) {
imps_avg[chn].setProperty("MOTOR"+(m+1), ""+motorsPosition[m]);
}
ImagejJp4Tiff.encodeProperiesToInfo(imps_avg[chn]);
// TODO: Overwrite some properties?
}
*/
return imps_avg;
}
......@@ -744,6 +711,7 @@ public class Lwir16Reader {
}
}
public double getFutureTimestamnp (String ip, double delay) { // delay in seconds from master
if (lwirReaderParameters.getDebugLevel() > 0) {
System.out.println("Increasing delay by 3.0s when there is some printing");
......@@ -797,22 +765,28 @@ public class Lwir16Reader {
* @param lrp
* @param delay
* @param duration -1 - start only, 0 - stop only, >0 - start+stop (LWIR cameras)
* @param duration_eo -1 - start only, 0 - stop only, >0 - start+stop (EO cameras)
* @param duration_eo -1 - start only, 0 - stop only, >0 - start+stop (EO cameras). If stop only - will wait for both masters
* @return <0 - error, >0 last frame of the master camera/port in sequence
*/
public int captureRange(LwirReaderParameters lrp, double delay, int duration, int duration_eo) {
boolean sync2eo = true;
int lwir_master_index = 0;
int eo_master_index = 4;
String [] all_ips = lrp.getAllIPs();
int num_lwir = lrp.getLwirIPs().length;
int [] port_masks= getPortMasks(lrp);
double target_ts = getFutureTimestamnp (lrp.getLwirIP(lwir_master_index), delay);
String master_ip = all_ips[sync2eo? eo_master_index : lwir_master_index];
double target_ts = getFutureTimestamnp (master_ip, delay);
if (Double.isNaN(target_ts)) {
return -1;
}
String [] all_ips = lrp.getAllIPs();
String [] urls = new String [all_ips.length];
for (int i = 0; i < urls.length; i++) {
int dur = (i>= num_lwir)?duration_eo:duration;
urls[i]=String.format("http://%s/%s?sensor_port=0&ts=%f&m=%d&d=%d", all_ips[i], SCRIPT_CAPTURE, target_ts, port_masks[i], dur);
if ((dur == 0) && ((i==lwir_master_index) || (i==eo_master_index))){
urls[i] += "&wait";
}
}
boolean OK = true;
Document [] docs = collectXmlResponses(urls);
......@@ -849,12 +823,19 @@ public class Lwir16Reader {
}
int master_frame = Integer.parseInt(((Node)
(((Node) docs[lwir_master_index].getDocumentElement().getElementsByTagName("frame").item(0)).getChildNodes().item(0))).getNodeValue());
if (lrp.getDebugLevel() > 0) System.out.println(String.format("master_frame=%d(0x%x)", master_frame,master_frame));
if ((lrp.getDebugLevel() > 0) && ((duration==0) || (duration_eo==0)) ) {
System.out.println(String.format("master_frame=%d(0x%x)", master_frame,master_frame));
for (int i = 0; i < urls.length; i++) {
System.out.println(i+": "+urls[i]);
}
}
// System.out.println("mater_frame = "+master_frame+", target_ts="+target_ts);
return master_frame;
}
public boolean startStopCompressor(LwirReaderParameters lrp, boolean start, double delay) {
if (lrp.getDebugLevel() > 0) System.out.println("startStopCompressor() start="+start);
// if (lrp.getDebugLevel() > 0) System.out.println("startStopCompressor() start="+start);
if (lrp.getDebugLevel() > -1) System.out.println("startStopCompressor() start="+start);
int duration = start? -1: 0;
int end_frame = captureRange(lrp, delay, duration, duration);
if (end_frame < 0) return false;
......@@ -1003,12 +984,13 @@ public class Lwir16Reader {
}
resetFrameBuffers(lrp); // actually only needed after stopping, here just in case
// start capturing frames into each camera buffer
int end_frame = captureRange(lrp, lrp.getAcquireDelay(), lrp.getAvgNumberLwir(),lrp.getAvgNumberEO());
// int end_frame =
captureRange(lrp, lrp.getAcquireDelay(), lrp.getAvgNumberLwir(),lrp.getAvgNumberEO());
// public static final String IMAGE_URL_NEXT= "/torp/next/wait/img/save"; // same image name, same image number/time
// public static final String IMAGE_URL_NEXT= "/torp/wait/img/next/save"; // same image name, same image number/time
int [] port_masks= getPortMasks(lrp);
String [] all_IPs = lrp.getAllIPs();
// int [] port_masks= getPortMasks(lrp);
// String [] all_IPs = lrp.getAllIPs();
final int num_lwir = lrp.getLwirIPs().length;
final int avg_lwir = lrp.getAvgNumberLwir();
final int avg_eo = lrp.getAvgNumberEO();
......@@ -1076,7 +1058,9 @@ public class Lwir16Reader {
public void run() {
for (int chn = indxAtomic.getAndIncrement(); chn < num_channels; chn = indxAtomic.getAndIncrement()) {
if (imgs[chn] != null) {
int num_frames = (chn < (num_lwir*IMGSRV_PORTS.length))? avg_lwir : avg_eo;
boolean is_lwir = chn < (num_lwir*IMGSRV_PORTS.length);
// int num_frames = (chn < (num_lwir*IMGSRV_PORTS.length))? avg_lwir : avg_eo;
int num_frames = is_lwir? avg_lwir : avg_eo;
if (num_frames > 0) {
float [] pixels_avg = (float []) imgs[chn].getProcessor().getPixels();
double scale = 1.0/num_frames;
......@@ -1090,6 +1074,9 @@ public class Lwir16Reader {
if (motorsPosition!=null) for (int m=0;m<motorsPosition.length;m++ ) {
imgs[chn].setProperty("MOTOR"+(m+1), ""+motorsPosition[m]);
}
imgs[chn].setProperty(
LwirReaderParameters.SENSOR_TYPE,
LwirReaderParameters.SENSOR_TYPES[is_lwir?1:0]);
ImagejJp4Tiff.encodeProperiesToInfo(imgs[chn]);
}
}
......@@ -1098,6 +1085,29 @@ public class Lwir16Reader {
};
}
startAndJoin(threads);
if (dirpath != null) {
File f_dir = new File(dirpath);
// get series path from the first channel file title
String first_name = imgs[0].getTitle();
String set_name = first_name.substring(0, first_name.lastIndexOf('_'));
String set_path = dirpath+Prefs.getFileSeparator()+set_name;
File set_dir = new File(set_path);
set_dir.mkdirs(); // including parent
LOGGER.warn("Saving image set to: "+set_dir.getAbsolutePath());
for (ImagePlus imp:imgs) {
String fname = imp.getTitle();
// fname = fname.substring(0, fname.lastIndexOf('_')) + ".tiff"; // remove _average
// fname = fname.substring(0, fname.lastIndexOf('.')) + ".tiff"; // remove _average
fname = fname + ".tiff"; // remove _average
FileSaver fs=new FileSaver(imp);
String path=set_path+Prefs.getFileSeparator()+fname;
IJ.showStatus("Saving "+path);
LOGGER.info("LWIR_ACQUIRE: 'Saving "+path );
fs.saveAsTiff(path);
}
}
if (lrp.isShowImages()) {
for (ImagePlus imp: imgs) {
imp.show();
......@@ -1159,8 +1169,10 @@ public class Lwir16Reader {
img_numbers[i] = -1;
}
img_names[i] = (String) imps[i].getProperty("CONTENT_FILENAME");
if (lrp.getDebugLevel() > 0) {
LOGGER.warn("Seconds for "+i+" - "+img_seconds[i]+", number"+img_numbers[i]+", name "+img_names[i]);
}
}
// Make a sparse array for all lwir+eo channels with nulls for channels that are not measured.
ImagePlus [] imps_all = new ImagePlus [all_IPs.length * IMGSRV_PORTS.length];
int indx = 0;
......@@ -1307,7 +1319,7 @@ public class Lwir16Reader {
}
}
}
skipMasterFrames(two_IPs, 4); // make sure all previous parameters are applied
skipMasterFrames(two_IPs, 4); // make sure all previous parameters are applied // waits for both LWIR and EO
// second reset after cameras running synchronously
OK &= resetAllFrames(lrp);
skipMasterFrames(two_IPs, 1);
......
......@@ -31,6 +31,7 @@ import java.io.FilenameFilter;
import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.readers.EyesisTiff;
import ij.ImagePlus;
import ij.Prefs;
......@@ -41,6 +42,8 @@ public class LwirReaderParameters {
public final static String [] CAMERA_NAMES= {NAME_TALON,NAME_LWIR16};
public final static int [] BOSON_FFC_FRAMES= {2,4,8,16};
public final static int [] FFC_GROUPS= {1,2,4};
public static final String [] SENSOR_TYPES = {"EO","LWIR"};
public static final String SENSOR_TYPE = "SENSOR_TYPE";
private boolean parameters_updated = false;
protected String camera_name = "Talon"; // "LWIR16";
......@@ -94,7 +97,7 @@ public class LwirReaderParameters {
protected boolean show_images = false;
protected int lwir_chn0 = 0; // not configurable
protected int eo_chn0 = 4; // not configurable
// protected int eo_chn0 = 4; // not configurable
public LwirReaderParameters() {
......@@ -104,6 +107,15 @@ public class LwirReaderParameters {
else if (NAME_LWIR16.equals(name)) camera_name = NAME_LWIR16;
}
public static boolean is_LWIR(String type) {
return ((type != null) && type.equals(SENSOR_TYPES[1]));
}
public static boolean is_EO(String type) {
return ((type != null) && type.equals(SENSOR_TYPES[1]));
}
public static String sensorName(boolean lwir) {
return SENSOR_TYPES[lwir?1:0];
}
// --- interface methods
public int getAvgNumberLwir() {
......@@ -126,7 +138,11 @@ public class LwirReaderParameters {
}
public int getEoChn0 () {
return eo_chn0;
return isLwir16() ? 16:4;// eo_chn0;
}
public int getNumChannels() {
return 20;
}
public boolean is_LWIR(int width) {
......@@ -134,6 +150,14 @@ public class LwirReaderParameters {
}
public boolean is_LWIR(ImagePlus imp){
// See if image has LwirReaderParameters.SENSOR_TYPE property, then use is_LWIR(String property_value),
// if not - use old width property
if (imp.getProperty("WOI_WIDTH")==null) {
EyesisTiff.decodeProperiesFromInfo(imp);
}
if (imp.getProperty(SENSOR_TYPE)!=null) {
return is_LWIR((String) imp.getProperty(SENSOR_TYPE));
}
return is_LWIR(imp.getWidth());
}
......
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