Commit 6b59db60 authored by Andrey Filippov's avatar Andrey Filippov

Importing EO+LWIR calibration to 3d program

parent 6fa32fa8
......@@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.SwingUtilities;
import com.elphel.imagej.calibration.CalibrationFileManagement.MultipleExtensionsFileFilter;
import com.elphel.imagej.common.DoubleFHT;
import com.elphel.imagej.common.DoubleGaussianBlur;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
......@@ -109,15 +108,27 @@ public class PixelMapping {
}
}
public PixelMapping (String [] calibFiles, int debugLevel){
public PixelMapping (
String [] calibFiles,
int first_channel, // 0 - old way
int num_channels, // 0 - any
boolean update_channel, // false (replace file channel with effective channel (subtract first_channel)
int debugLevel){
this.debugLevel=debugLevel;
if (calibFiles==null) calibFiles=new String[0];
this.sensors=new SensorData[this.maxSensors];
this.sensors=new SensorData[(num_channels > 0)? num_channels: this.maxSensors];
for (int i=0;i<this.sensors.length;i++) this.sensors[i]=null;
int maxChannel=0;
for (int i=0;i<calibFiles.length;i++){
SensorData sensorData=new SensorData (calibFiles[i],this.debugLevel);
int channel=sensorData.getChannel();
int channel=sensorData.getChannel(); // from Properties
if ((channel < first_channel) || ((num_channels > 0) && (channel >= (first_channel + num_channels)))) {
continue; // wrong channels
}
channel -= first_channel;
if (update_channel) {
sensorData.setChannel(channel);
}
this.sensors[channel]=sensorData;
if (channel>maxChannel) maxChannel=channel;
}
......@@ -170,7 +181,7 @@ public class PixelMapping {
// } else if (this.debugLevel > -2) {
// System.out.print(".");
}
// ArrayList<ArrayList<ArrayList<Integer>>> camera_IPs = new ArrayList<ArrayList<ArrayList<Integer>>>();
ArrayList<Point> cam_port = new ArrayList<Point>();
for (int i=0;i<this.sensors.length;i++) if (this.sensors[i]!=null) {
......@@ -16221,6 +16232,7 @@ public class PixelMapping {
}
public SensorData (){} // just to get parameter names
public void setChannel(int chn){this.channel = chn;}
public int getChannel(){return this.channel;}
public int getSubChannel(){return this.subchannel;}
public int getSubCamera(){return this.subcamera;}
......
......@@ -98,17 +98,38 @@ public class EyesisCorrections {
// TODO: preserve some data when re-running with new source files
// FIXME: Make forgiving alien files
public void initSensorFiles(int debugLevel){
initSensorFiles(debugLevel, false);
initSensorFiles(debugLevel,
false,
false,
false);
}
public void initSensorFiles(int debugLevel, boolean missing_ok){
public void initSensorFiles(int debugLevel,
boolean missing_ok,
boolean all_sensors,
boolean no_vignetting
){
this.sharpKernelPaths=null;
this.smoothKernelPaths=null;
String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel);
this.pixelMapping=new PixelMapping(sensorPaths,debugLevel);
this.usedChannels= usedChannels(correctionsParameters.getSourcePaths(),missing_ok);
this.pixelMapping=new PixelMapping(
sensorPaths,
correctionsParameters.firstSubCameraConfig, // int first_channel, // 0 - old way
correctionsParameters.numSubCameras, // int num_channels, // 0 - any
true, // boolean update_channel, // false (replace file channel with effective channel (subtract first_channel)
debugLevel);
if (all_sensors) {
this.usedChannels = new boolean [this.pixelMapping.sensors.length];
for (int i = 0; i < this.usedChannels.length; i++) {
this.usedChannels[i] = true;
}
} else {
this.usedChannels= usedChannels(correctionsParameters.getSourcePaths(),missing_ok);
}
// TODO: Combine with additional channel map to be able to select single image (of all 3)
if (correctionsParameters.removeUnusedSensorData){
for (int nChn=0;nChn< this.usedChannels.length; nChn++) if (!this.usedChannels[nChn]) this.pixelMapping.removeChannel(nChn);
for (int nChn=0;nChn< this.usedChannels.length; nChn++) {
if (!this.usedChannels[nChn]) this.pixelMapping.removeChannel(nChn);
}
}
int numUsedChannels=0;
for (int nChn=0;nChn< this.usedChannels.length; nChn++) if (this.usedChannels[nChn]) numUsedChannels++;
......@@ -117,7 +138,9 @@ public class EyesisCorrections {
for (int nChn=0;nChn< this.usedChannels.length; nChn++) if (this.usedChannels[nChn]) sChannels+=" "+nChn;
System.out.println ("Number of used channels: "+numUsedChannels+" ("+sChannels+" )");
}
createChannelVignetting();
if (!no_vignetting) {
createChannelVignetting();
}
if ((this.debugLevel>101) && (correctionsParameters.sourcePaths!=null) && (correctionsParameters.sourcePaths.length>0)) {
testFF(correctionsParameters.sourcePaths[0]);
}
......@@ -126,12 +149,32 @@ public class EyesisCorrections {
}
}
public void initSensorFilesAux(int debugLevel){
// Never used !
public void initSensorFilesAux(int debugLevel, // what is different from initSensorFiles()? Never used !
boolean missing_ok,
boolean all_sensors,
boolean no_vignetting
){
// this.sharpKernelPaths=null;
// this.smoothKernelPaths=null;
String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel);
this.pixelMapping=new PixelMapping(sensorPaths,debugLevel);
this.usedChannels= usedChannels(correctionsParameters.getSourcePaths());
// this.pixelMapping=new PixelMapping(sensorPaths,debugLevel);
this.pixelMapping=new PixelMapping(
sensorPaths,
correctionsParameters.firstSubCameraConfig, // int first_channel, // 0 - old way
correctionsParameters.numSubCameras, // int num_channels, // 0 - any
true, // boolean update_channel, // false (replace file channel with effective channel (subtract first_channel)
debugLevel);
if (all_sensors) {
this.usedChannels = new boolean [this.pixelMapping.sensors.length];
for (int i = 0; i < this.usedChannels.length; i++) {
this.usedChannels[i] = true;
}
} else {
this.usedChannels= usedChannels(correctionsParameters.getSourcePaths(),missing_ok);
}
// TODO: Combine with additional channel map to be able to select single image (of all 3)
if (correctionsParameters.removeUnusedSensorData){
for (int nChn=0;nChn< this.usedChannels.length; nChn++) if (!this.usedChannels[nChn]) this.pixelMapping.removeChannel(nChn);
......@@ -229,7 +272,12 @@ public class EyesisCorrections {
// boolean processPlaneProjection= equirectangularParameters.generateCommonPlane &&
// equirectangularParameters.selectChannelsToProcess("Select channels for plane projection", this.pixelMapping.sensors.length);
this.pixelMapping=new PixelMapping(sensorPaths,debugLevel);
this.pixelMapping=new PixelMapping(
sensorPaths,
0, // int first_channel, // 0 - old way
0, // int num_channels, // 0 - any
false, // boolean update_channel, // false (replace file channel with effective channel (subtract first_channel)
debugLevel);
pixelMapping.generateAndSaveEquirectangularMaps(
correctionsParameters.equirectangularDirectory+
Prefs.getFileSeparator()+
......@@ -356,12 +404,16 @@ public class EyesisCorrections {
}
this.sharpKernelPaths=correctionsParameters.selectKernelChannelFiles(
0, // 0 - sharp, 1 - smooth
correctionsParameters.firstSubCameraConfig,
// correctionsParameters.numSubCameras,
numChannels, // number of channels
this.debugLevel);
if (this.sharpKernelPaths==null) return false;
if (nonlinParameters.useDiffNoiseGains) {
this.smoothKernelPaths=correctionsParameters.selectKernelChannelFiles(
1, // 0 - sharp, 1 - smooth
correctionsParameters.firstSubCameraConfig,
// correctionsParameters.numSubCameras,
numChannels, // number of channels
this.debugLevel);
if (this.smoothKernelPaths==null) return false;
......@@ -1024,7 +1076,9 @@ public class EyesisCorrections {
if (this.sharpKernelPaths==null){ // make sure the paths list is reset after changing parameters
this.sharpKernelPaths=correctionsParameters.selectKernelChannelFiles(
0, // 0 - sharp, 1 - smooth
this.usedChannels.length, // number of channels
correctionsParameters.firstSubCameraConfig,
correctionsParameters.numSubCameras,
// this.usedChannels.length, // number of channels
this.debugLevel);
}
if ((this.sharpKernelPaths==null) || (this.sharpKernelPaths[channel]==null)){
......@@ -1055,6 +1109,8 @@ public class EyesisCorrections {
if (this.smoothKernelPaths==null){ // make sure the paths list is reset after changing parameters
this.smoothKernelPaths=correctionsParameters.selectKernelChannelFiles(
1, // 0 - sharp, 1 - smooth
correctionsParameters.firstSubCameraConfig,
// correctionsParameters.numSubCameras,
this.usedChannels.length, // number of channels
this.debugLevel);
}
......@@ -1156,6 +1212,8 @@ public class EyesisCorrections {
if (this.smoothKernelPaths==null){ // make sure the paths list is reset after changing parameters
this.smoothKernelPaths=correctionsParameters.selectKernelChannelFiles(
1, // 0 - sharp, 1 - smooth
correctionsParameters.firstSubCameraConfig,
// correctionsParameters.numSubCameras,
this.usedChannels.length, // number of channels
this.debugLevel);
}
......
......@@ -281,6 +281,8 @@ public class EyesisDCT {
){
String [] sharpKernelPaths= correctionsParameters.selectKernelChannelFiles(
0, // 0 - sharp, 1 - smooth
correctionsParameters.firstSubCameraConfig,
// correctionsParameters.numSubCameras,
eyesisCorrections.usedChannels.length, // numChannels, // number of channels
eyesisCorrections.debugLevel);
if (sharpKernelPaths==null) return false;
......
......@@ -593,6 +593,7 @@ private Panel panel1,
addButton("Select second CLT image", panelClt1, color_configure);
addButton("CLT correlate", panelClt1, color_process);
addButton("Create CLT kernels", panelClt1, color_process);
addButton("Create AUX CLT kernels", panelClt1, color_process);
addButton("Read CLT kernels", panelClt1, color_process);
addButton("Reset CLT kernels", panelClt1, color_stop);
addButton("CLT process files", panelClt1, color_process);
......@@ -3902,7 +3903,11 @@ private Panel panel1,
return;
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL);
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL,
true, // true - ignore missing files
true, // boolean all_sensors,
true); //boolean no_vignetting
QUAD_CLT.createCLTKernels(
CLT_PARAMETERS,
......@@ -3910,7 +3915,44 @@ private Panel panel1,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
//==============================================================================
} else if (label.equals("Create AUX CLT kernels")) {
if (!CLT_PARAMETERS.showJDialog()) return;
if (EYESIS_CORRECTIONS_AUX == null) {
EYESIS_CORRECTIONS_AUX = new EyesisCorrections(SYNC_COMMAND.stopRequested,CORRECTION_PARAMETERS.getAux());
}
if ((QUAD_CLT_AUX == null) ||(QUAD_CLT_AUX.eyesisCorrections == null)){
QUAD_CLT_AUX = new QuadCLT (
QuadCLT.PREFIX_AUX,
PROPERTIES,
EYESIS_CORRECTIONS_AUX,
CORRECTION_PARAMETERS.getAux());
}
String configPath=getSaveCongigPath();
if (configPath.equals("ABORT")) return;
String cltPath=EYESIS_CORRECTIONS.correctionsParameters.selectCLTKernelDirectory( // create if it does not exist
true,
true);
if (cltPath==null) {
String msg="No CLT kernels (results) directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL,
true, // true - ignore missing files
true, // boolean all_sensors,
true); //boolean no_vignetting
QUAD_CLT_AUX.createCLTKernels(
CLT_PARAMETERS,
CONVOLVE_FFT_SIZE/2,
THREADS_MAX,
UPDATE_STATUS, // update status info
DEBUG_LEVEL);
//"Reset DCT kernels"
} else if (label.equals("Reset CLT kernels")) {
if (QUAD_CLT != null){
......@@ -5013,11 +5055,11 @@ private Panel panel1,
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Running initSensorFiles for the main camera ++++++++++++++");
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL+2, true); // missing_ok
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL+2, true, false, false); // missing_ok
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Running initSensorFiles for the auxiliary camera ++++++++++++++");
}
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL+2, true); // some files belong to oher cameras\
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL+2, true, false, false); // some files belong to oher cameras\
int numChannels= EYESIS_CORRECTIONS.getNumChannels();
......@@ -5147,11 +5189,11 @@ private Panel panel1,
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Running initSensorFiles for the main camera ++++++++++++++");
}
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL+2, true); // missing_ok
EYESIS_CORRECTIONS.initSensorFiles(DEBUG_LEVEL+2, true, false, false); // missing_ok
if (DEBUG_LEVEL > -2){
System.out.println("++++++++++++++ Running initSensorFiles for the auxiliary camera ++++++++++++++");
}
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL+2, true); // some files belong to oher cameras\
EYESIS_CORRECTIONS_AUX.initSensorFiles(DEBUG_LEVEL+2, true, false, false); // some files belong to other cameras\
int numChannels= EYESIS_CORRECTIONS.getNumChannels();
......
......@@ -867,7 +867,9 @@ public class QuadCLT {
String [] sharpKernelPaths= correctionsParameters.selectKernelChannelFiles(
0, // 0 - sharp, 1 - smooth
eyesisCorrections.usedChannels.length, // numChannels, // number of channels
correctionsParameters.firstSubCameraConfig,
correctionsParameters.numSubCameras,
// eyesisCorrections.usedChannels.length, // numChannels, // number of channels
eyesisCorrections.debugLevel);
if (sharpKernelPaths==null) return false;
for (int i=0;i<sharpKernelPaths.length;i++){
......@@ -884,8 +886,8 @@ public class QuadCLT {
for (int chn=0;chn<eyesisCorrections.usedChannels.length;chn++){
if (eyesisCorrections.usedChannels[chn] && (sharpKernelPaths[chn]!=null) && (clt_kernels[chn]==null)){
ImagePlus imp_kernel_sharp=new ImagePlus(sharpKernelPaths[chn]);
if (imp_kernel_sharp.getStackSize()<3) {
System.out.println("Need a 3-layer stack with kernels");
if ((imp_kernel_sharp.getStackSize()<3) && (imp_kernel_sharp.getStackSize() != 1)) {
System.out.println("Need a 3-layer stack with Bayer or single for mono kernels");
sharpKernelPaths[chn]=null;
continue;
}
......@@ -913,18 +915,20 @@ public class QuadCLT {
int tileWidth = 2 * dtt_size;
int width = tileWidth * kernelNumHor;
int height = flat_kernels[0].length/width;
String [] layerNames = {"red_clt_kernels","blue_clt_kernels","green_clt_kernels"};
if (flat_kernels.length ==1){
layerNames = new String[1];
layerNames[0] = "mono_clt_kernels";
}
ImageStack cltStack = sdfa_instance.makeStack(
flat_kernels,
width,
height,
layerNames);
String cltPath=correctionsParameters.cltKernelDirectory+
Prefs.getFileSeparator()+
correctionsParameters.cltKernelPrefix+
String.format("%02d",chn)+
String.format("%02d",chn + correctionsParameters.firstSubCameraConfig)+
correctionsParameters.cltSuffix;
String msg="Saving CLT convolution kernels to "+cltPath;
IJ.showStatus(msg);
......@@ -935,7 +939,8 @@ public class QuadCLT {
imp_clt.show();
}
FileSaver fs=new FileSaver(imp_clt);
fs.saveAsTiffStack(cltPath); // directory does not exist
// fs.saveAsTiffStack(cltPath); // directory does not exist
fs.saveAsTiff(cltPath); // directory does not exist
}
}
return true;
......@@ -951,6 +956,7 @@ public class QuadCLT {
){
int dtt_size = clt_parameters.transform_size;
String [] cltKernelPaths = correctionsParameters.selectCLTChannelFiles(
correctionsParameters.firstSubCameraConfig,
// 0, // 0 - sharp, 1 - smooth
eyesisCorrections.usedChannels.length, // numChannels, // number of channels
eyesisCorrections.debugLevel);
......@@ -974,8 +980,8 @@ public class QuadCLT {
for (int chn=0;chn<eyesisCorrections.usedChannels.length;chn++){
if (eyesisCorrections.usedChannels[chn] && (cltKernelPaths[chn]!=null)){
ImagePlus imp_kernel_clt=new ImagePlus(cltKernelPaths[chn]);
if (imp_kernel_clt.getStackSize()<3) {
System.out.println("Need a 3-layer stack with symmetrical DCT kernels");
if ((imp_kernel_clt.getStackSize()< 3) && (imp_kernel_clt.getStackSize()!= 1)) {
System.out.println("Need a 3-layer stack or Bayer and 1-layer for mono with CLT kernels");
cltKernelPaths[chn]=null;
continue;
}
......
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