Commit 7c9b8ed9 authored by Andrey Filippov's avatar Andrey Filippov

addin illustration generation

parent f68fa78e
......@@ -112,7 +112,7 @@ public class Aberration_Calibration extends PlugInFrame implements ActionListene
private Panel panelGoniometer;
private Panel panelPixelMapping, panelStereo,panelStereo1;
private Panel panelLWIR;
// private Panel panelLWIR16;
private Panel panelIllustrations;
private ShowDoubleFloatArrays SDFA_INSTANCE; // just for debugging?
JP46_Reader_camera JP4_INSTANCE;
......@@ -597,6 +597,7 @@ public static MatchSimulatedPattern.DistortionParameters DISTORTION =new MatchSi
1 // public int debugLevel=1;
);
public static CalibrationIllustration CALIBRATION_ILLUSTRATION = null;
public static RefineParameters REFINE_PARAMETERS = new RefineParameters();
public static DistortionCalibrationData DISTORTION_CALIBRATION_DATA=null;
// public static FittingStrategy FITTING_STRATEGY=null;
......@@ -666,7 +667,7 @@ public static MatchSimulatedPattern.DistortionParameters DISTORTION =new MatchSi
public static Goniometer GONIOMETER=null;
public static LwirReaderParameters LWIR_PARAMETERS = new LwirReaderParameters();
public static CalibrationIllustrationParameters CALIBRATION_ILLUSTRATION_PARAMETERS = new CalibrationIllustrationParameters(LWIR_PARAMETERS);
// new CalibrationHardwareInterface.LaserPointers();
public class SyncCommand{
public boolean isRunning= false;
......@@ -687,7 +688,7 @@ public static MatchSimulatedPattern.DistortionParameters DISTORTION =new MatchSi
addKeyListener(IJ.getInstance());
// setLayout(new GridLayout(ADVANCED_MODE?8:5, 1));
// setLayout(new GridLayout(ADVANCED_MODE?9:6, 1));
setLayout(new GridLayout(ADVANCED_MODE?21:21, 1));
setLayout(new GridLayout(ADVANCED_MODE?22:22, 1));
Color color_configure= new Color(200, 200,160);
Color color_process= new Color(180, 180, 240);
Color color_conf_process= new Color(180, 240, 240);
......@@ -1064,6 +1065,13 @@ if (MORE_BUTTONS) {
addButton("Manual hint", panelLWIR,color_configure);
add(panelLWIR);
panelIllustrations= new Panel();
panelIllustrations.setLayout(new GridLayout(1, 0, 5, 5)); // rows, columns, vgap, hgap
addButton("Illustrations Configure", panelIllustrations,color_configure);
addButton("Illustrations", panelIllustrations,color_bundle);
add(panelIllustrations);
pack();
GUI.center(this);
setVisible(true);
......@@ -9372,6 +9380,77 @@ if (MORE_BUTTONS) {
selectLwirGrids(LWIR_PARAMETERS);
return;
}
/* ======================================================================== */
if (label.equals("Illustrations Configure")) {
CALIBRATION_ILLUSTRATION_PARAMETERS.showJDialog();
return;
}
/* ======================================================================== */
if (label.equals("Illustrations")) {
if (LENS_DISTORTIONS==null) {
IJ.showMessage("LENS_DISTORTION is not set"); // to use all grids imported
return;
}
EYESIS_ABERRATIONS.setDistortions(LENS_DISTORTIONS);
if (EYESIS_ABERRATIONS.aberrationParameters.illustrationsDirectory.length()>0){
File dFile=new File(EYESIS_ABERRATIONS.aberrationParameters.illustrationsDirectory);
if (!dFile.isDirectory() && !dFile.mkdirs()) {
String msg="Failed to create directory "+EYESIS_ABERRATIONS.aberrationParameters.illustrationsDirectory;
IJ.showMessage("Warning",msg);
System.out.println("Warning: "+msg);
EYESIS_ABERRATIONS.aberrationParameters.illustrationsDirectory=""; // start over with selecting directory
}
}
String configPath=EYESIS_ABERRATIONS.aberrationParameters.selectIllustrationsDirectory(
true,
EYESIS_ABERRATIONS.aberrationParameters.illustrationsDirectory,
true);
if (configPath==null){
String msg="No illustrations directory selected, command aborted";
System.out.println("Warning: "+msg);
IJ.showMessage("Warning",msg);
return;
}
configPath+=Prefs.getFileSeparator()+"config-illustrations";
try {
saveTimestampedProperties(
configPath, // full path or null
null, // use as default directory if path==null
true,
PROPERTIES);
} catch (Exception e){
String msg="Failed to save configuration to "+configPath+", command aborted";
System.out.println("Error: "+msg);
IJ.showMessage("Error",msg);
return;
}
if (CALIBRATION_ILLUSTRATION == null) {
CALIBRATION_ILLUSTRATION = new CalibrationIllustration(
CALIBRATION_ILLUSTRATION_PARAMETERS, // CalibrationIllustrationParameters illustrationParameters,
EYESIS_ABERRATIONS, // EyesisAberrations eyesisAberrations,
LENS_DISTORTIONS, // Distortions distortions,
SYNC_COMMAND.stopRequested, // AtomicInteger stopRequested,
MASTER_DEBUG_LEVEL); // int debug_level);
/*
CALIBRATION_ILLUSTRATION = new CalibrationIllustration(
LWIR_PARAMETERS, // LwirReaderParameters lwirReaderParameters,
LENS_DISTORTION_PARAMETERS, // LensDistortionParameters lensDistortionParameters,
PATTERN_PARAMETERS, // PatternParameters patternParameters,
REFINE_PARAMETERS, // RefineParameters refineParameters,
DISTORTION_PROCESS_CONFIGURATION, // DistortionProcessConfiguration distortionProcessConfiguration,
EYESIS_CAMERA_PARAMETERS, // EyesisCameraParameters eyesisCameraParameters,
SYNC_COMMAND.stopRequested, // AtomicInteger stopRequested,
MASTER_DEBUG_LEVEL); // int debug_level);
*/
}
// CALIBRATION_ILLUSTRATION.selectUsefulGrids();
CALIBRATION_ILLUSTRATION.convertSourceFiles();
return;
}
/* ======================================================================== */
if (label.equals("Manual hint")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
......@@ -10214,7 +10293,6 @@ if (MORE_BUTTONS) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
LENS_DISTORTIONS=new Distortions(LENS_DISTORTION_PARAMETERS,PATTERN_PARAMETERS,REFINE_PARAMETERS,this.SYNC_COMMAND.stopRequested);
// 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 [] type_map = lwirReaderParameters.getTypeMap(); // 0 - eo, 1 -0 lwir
int lwir_chn0 = lwirReaderParameters.getLwirChn0();
......@@ -10242,8 +10320,6 @@ if (MORE_BUTTONS) {
allornone_eo = gd.getNextBoolean();
allornone_lwir = gd.getNextBoolean();
// String [] grid_extensions={".tif",".tiff"};
// String [] src_extensions={".tif",".tiff"};
String [] grid_extensions={".tiff"};
String [] src_extensions={".tiff"};
MultipleExtensionsFileFilter gridFilter =
......@@ -10251,11 +10327,8 @@ if (MORE_BUTTONS) {
MultipleExtensionsFileFilter sourceFilter =
new MultipleExtensionsFileFilter("",src_extensions,"Source calibration images");
// CalibrationFileManagement.DirectoryContentsFilter gridDirFilter =
// new CalibrationFileManagement.DirectoryContentsFilter (gridFilter, min_files, 0, null);
String [][] gridFileDirs= new String [numStations][];
// int [][] gridUseTypes = new int [numStations][]; // +1 - use eo channels,+2 - use lwir channels (in pointed set)
boolean [][][] gridUseChn = new boolean [numStations][][]; // channels to use in each scene
String [] sourceStationDirs = new String [numStations]; // directories of the source files per station
......@@ -11002,7 +11075,11 @@ if (MORE_BUTTONS) {
ABERRATIONS_PARAMETERS.autoRestore=false;
// String confPath=loadProperties(null,PROCESS_PARAMETERS.kernelsDirectory, PROCESS_PARAMETERS.useXML, PROPERTIES);
String confPath = readPropertiesPath(null, PROCESS_PARAMETERS.kernelsDirectory,PROCESS_PARAMETERS.useXML);
PROPERTIES = readProperties( confPath, true, PROPERTIES);
Properties properties = readProperties( confPath, true, PROPERTIES);
if (properties == null) {
return;
}
PROPERTIES = properties; // readProperties( confPath, true, PROPERTIES);
getAllProperties(PROPERTIES);
if (DEBUG_LEVEL>0) System.out.println("Configuration parameters are restored from " + confPath);
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
......@@ -16016,6 +16093,9 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
} else {
properties = new Properties();
}
if (path == null) {
return null;
}
InputStream is;
try {
is = new FileInputStream(path);
......@@ -16151,6 +16231,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
boolean select_FOCUSING_FIELD=!select;
boolean select_POWER_CONTROL=!select;
boolean select_LWIR=!select;
boolean select_ILLUSTRATIONS=!select;
if (select) {
GenericDialog gd = new GenericDialog("Select parameters to save");
gd.addMessage("===== Individual parameters ======");
......@@ -16193,6 +16274,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
gd.addCheckbox("FOCUSING_FIELD",select_FOCUSING_FIELD);
gd.addCheckbox("POWER_CONTROL",select_POWER_CONTROL);
gd.addCheckbox("LWIR",select_LWIR);
gd.addCheckbox("Illustrations",select_ILLUSTRATIONS);
WindowTools.addScrollBars(gd);
gd.showDialog();
......@@ -16236,6 +16318,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
select_FOCUSING_FIELD=gd.getNextBoolean();
select_POWER_CONTROL=gd.getNextBoolean();
select_LWIR=gd.getNextBoolean();
select_ILLUSTRATIONS=gd.getNextBoolean();
}
if (select_MASTER_DEBUG_LEVEL) properties.setProperty("MASTER_DEBUG_LEVEL", MASTER_DEBUG_LEVEL+"");
......@@ -16277,6 +16360,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
if ((select_FOCUSING_FIELD) && (FOCUSING_FIELD!=null)) FOCUSING_FIELD.setProperties("FOCUSING_FIELD.", properties);
if (select_POWER_CONTROL) POWER_CONTROL.setProperties("POWER_CONTROL.", properties);
if (select_LWIR) LWIR_PARAMETERS.setProperties("LWIR.", properties);
if (select_ILLUSTRATIONS) CALIBRATION_ILLUSTRATION_PARAMETERS.setProperties("ILLUSTRATIONS.", properties);
if (select) properties.remove("selected");
}
......@@ -16321,6 +16405,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
if (FOCUSING_FIELD!=null) FOCUSING_FIELD.getProperties("FOCUSING_FIELD.", properties,false); // false -> overwrite distortions center
POWER_CONTROL.getProperties("POWER_CONTROL.", properties);
LWIR_PARAMETERS.getProperties("LWIR.", properties);
CALIBRATION_ILLUSTRATION_PARAMETERS.getProperties("ILLUSTRATIONS.", properties);
}
private String selectSourceDirectory(String defaultPath) {
package com.elphel.imagej.calibration;
import java.awt.Color;
import java.awt.Rectangle;
import java.io.File;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import com.elphel.imagej.calibration.DistortionCalibrationData.GridImageParameters;
import com.elphel.imagej.cameras.ThermalColor;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.correction.EyesisCorrections;
import com.elphel.imagej.lwir.LwirReaderParameters;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.Prefs;
import ij.gui.Line;
import ij.process.ImageProcessor;
public class CalibrationIllustration {
EyesisAberrations eyesisAberrations;
Distortions distortions;
CalibrationIllustrationParameters illustrationParameters;
LwirReaderParameters lwirReaderParameters;
AtomicInteger stopRequested;
int debug_level;
int numStations;
int numSubCameras;
String [][] gridFileDirs; // = new String [numStations][];
boolean [][][] gridUseChn; // = new boolean [numStations][][]; // channels to use in each scene
String [] sourceStationDirs; // = new String [numStations]; // directories of the source files per station
String [] grid_extensions={".tiff"};
String [] src_extensions={".tiff"};
public CalibrationIllustration (
CalibrationIllustrationParameters illustrationParameters,
EyesisAberrations eyesisAberrations,
Distortions distortions,
AtomicInteger stopRequested,
int debug_level) {
this.illustrationParameters = illustrationParameters;
this.eyesisAberrations = eyesisAberrations;
this.distortions = distortions;
this.stopRequested = stopRequested;
this.debug_level = debug_level;
}
public void plotGrid(
int numImg,
ImagePlus imp,
Color color_grid,
Color color_grid_extra // at least one end points to extra (unreliable) nodes (may be null)
) {
int line_width = 1; //https://imagej.nih.gov/ij/developer/api/ij/ij/gui/Line.html#drawPixels(ij.process.ImageProcessor)
DistortionCalibrationData dcd = distortions.fittingStrategy.distortionCalibrationData;
GridImageParameters gip = dcd.gIP[numImg];
int [][] pUV = gip.pixelsUV;
int [][] pUV_extra = gip.pixelsUV_extra;
double [][] pXY = gip.pixelsXY;
double [][] pXY_extra = gip.pixelsXY_extra;
int minU=pUV[0][0],maxU=minU,minV=pUV[0][1],maxV=minV;
for (int i = 0; i < pUV.length; i++) {
if (pUV[i][0] < minU) minU = pUV[i][0];
else if (pUV[i][0] > maxU) maxU = pUV[i][0];
if (pUV[i][1] < minV) minV = pUV[i][1];
else if (pUV[i][1] > maxV) maxV = pUV[i][1];
}
if (color_grid_extra != null) {
for (int i = 0; i < pUV_extra.length; i++) {
if (pUV_extra[i][0] < minU) minU = pUV_extra[i][0];
else if (pUV_extra[i][0] > maxU) maxU = pUV_extra[i][0];
if (pUV_extra[i][1] < minV) minV = pUV_extra[i][1];
else if (pUV_extra[i][1] > maxV) maxV = pUV_extra[i][1];
}
}
Rectangle dimsUV= new Rectangle(minU-1, minV-1, maxU-minU+2, maxV-minV+2);
int [] grid = new int [dimsUV.height * dimsUV.width];
Arrays.fill(grid, -1);
int main_len = pUV.length;
for (int i = 0; i < main_len; i++) {
int indx = (pUV[i][0]-dimsUV.x) + (pUV[i][1]-dimsUV.y)* dimsUV.width;
grid[indx] = i;
}
if (color_grid_extra != null) {
for (int i = 0; i < pUV_extra.length; i++) {
int indx = (pUV_extra[i][0]-dimsUV.x) + (pUV_extra[i][1]-dimsUV.y)* dimsUV.width;
grid[indx] = i + main_len;
}
}
ImageProcessor ip = imp.getProcessor();
ip.setLineWidth(line_width);
// int upper = dimsUV.width * (dimsUV.height-1);
int upper = dimsUV.width * dimsUV.height;
for (int indx = dimsUV.width + 1; indx < upper; indx++) if (grid[indx] >= 0){
// try to the right and down
int g0 = grid[indx];
for (int dir = 0; dir <2; dir++) { // 90 - right, 1 - down
int indx1 = indx + ((dir > 0) ? dimsUV.width : 1);
if (indx1 < grid.length) {
int g1 = grid[indx1];
if (g1 >= 0) {
if ((g0 < main_len) && (g1 < main_len)) {
ip.setColor(color_grid);
} else {
ip.setColor(color_grid_extra); // should not get here with color_grid_extra==null
}
double [] pXY0 = (g0 < main_len) ? pXY[g0] : pXY_extra[g0 - main_len];
double [] pXY1 = (g1 < main_len) ? pXY[g1] : pXY_extra[g1 - main_len];
Line line = new Line(pXY0[0], pXY0[1], pXY1[0],pXY1[1]);
line.drawPixels(ip);
}
}
}
}
}
public boolean convertSourceFiles() {
double threshold_contrast = 10.0;
int threshold_number = 10; // grid should have this number of nodes with above-threshold contrast
int CONTRAST_INDEX = 2;
//this.eyesisCameraParameters.numStations
boolean [] selectedChannels = eyesisAberrations.aberrationParameters.getChannelSelection(distortions);
DistortionCalibrationData dcd = distortions.fittingStrategy.distortionCalibrationData;
int numStations = dcd.eyesisCameraParameters.getNumStations();
boolean [] station_sel = new boolean[numStations];
// Arrays.fill(station_sel, true);
station_sel[0]= true; // only 06-L
MultipleExtensionsFileFilter sourceFilter =
new MultipleExtensionsFileFilter("",src_extensions,"Source calibration images");
int lwir0 = illustrationParameters.getLwirReaderParameters().getLwirChn0();
int eo0 = illustrationParameters.getLwirReaderParameters().getEoChn0();
for (int nChn = 0; nChn < selectedChannels.length; nChn++) if (selectedChannels[nChn]) {
// iterate through all image set (some grids may be missing)
for (int nSet = 0; nSet < dcd.gIS.length; nSet++) {
if (station_sel[dcd.gIS[nSet].getStationNumber()]) { // some stations only
// construct source file name
String srcPath = null;
int numImg = -1;
if (dcd.gIS[nSet].imageSet[nChn] != null) {
srcPath = dcd.gIS[nSet].imageSet[nChn].source_path;
numImg = dcd.gIS[nSet].imageSet[nChn].getImageNumber();
} else {
// find other non-null
for (int i = 0; i < dcd.gIS[nSet].imageSet.length; i++) {
if (dcd.gIS[nSet].imageSet[i] != null) {
String other_path = dcd.gIS[nSet].imageSet[i].source_path;
String set_path = other_path.substring(0,other_path.lastIndexOf(Prefs.getFileSeparator()));
File set_dir = new File(set_path);
String [] sfiles = set_dir.list(sourceFilter);
for (String spath:sfiles) {
int chn = DistortionCalibrationData.pathToChannel(spath);
if (chn == nChn) {
srcPath = (new File(set_dir,spath)).getPath();
break;
}
}
break;
}
}
}
// open 32-bit image
if (srcPath == null) {
System.out.println ("Source image for set "+nSet+", channel "+nChn+" does not exist");
continue;
}
ImagePlus imp = new ImagePlus(srcPath);
// convert to 8-bit color?
int width = imp.getWidth();
int height = imp.getHeight();
float [] pixels = (float[]) imp.getProcessor().getPixels();
String title = imp.getTitle();
if (title.lastIndexOf(".") > 0) {
title = title.substring(0, title.lastIndexOf("."));
}
String title_annot = title+"-annot";
if (numImg >=0) { // check if it is a bad image
int num_above = 0;
GridImageParameters gip = dcd.gIP[numImg];
double [][] pXY = gip.pixelsXY;
for (int i = 0; i < pXY.length; i++ ) {
if (pXY[i][CONTRAST_INDEX] > threshold_contrast) num_above++;
}
if (num_above < threshold_number) {
title_annot = title+"-annot"+"-BAD";
}
}
double [][] pseudo_pixels = new double [4] [pixels.length];
ThermalColor tc = new ThermalColor(
illustrationParameters.getPalette(), // public int lwir_palette = 0; // 0 - white - hot, 1 - black - hot, 2+ - colored
illustrationParameters.getLwirRange(nChn- lwir0)[0],
illustrationParameters.getLwirRange(nChn- lwir0)[1],
255.0);
for (int i = 0; i < pixels.length; i++) {
double [] rgb = tc.getRGB((double) pixels[i]);
pseudo_pixels[0][i] = rgb[0]; // red
pseudo_pixels[1][i] = rgb[1]; // green
pseudo_pixels[2][i] = rgb[2]; // blue
pseudo_pixels[3][i] = 1.0; // alpha
}
String [] rgb_titles = {"red","green","blue","alpha"};
ImageStack stack = (new ShowDoubleFloatArrays()).makeStack(
pseudo_pixels, // iclt_data,
width, // (tilesX + 0) * clt_parameters.transform_size,
height, // (tilesY + 0) * clt_parameters.transform_size,
rgb_titles, // or use null to get chn-nn slice names
true); // replace NaN with 0.0
ImagePlus imp_annot = EyesisCorrections.convertRGBAFloatToRGBA32(
stack, // ImageStack stackFloat, //r,g,b,a
// name+"ARGB"+suffix, // String title,
title_annot, // String title,
0.0, // double r_min,
255.0, // double r_max,
0.0, // double g_min,
255.0, // double g_max,
0.0, // double b_min,
255.0, // double b_max,
0.0, // double alpha_min,
1.0); // double alpha_max)
if (numImg >=0) {
plotGrid(numImg,
imp_annot,
new Color(250, 0, 0), // color_grid,
new Color(200, 200,0) // null // //at least one end points to extra (unreliable) nodes
);
}
// imp_pseudo.getProcessor().resetMinAndMax();
// imp_pseudo.show();
String illustrations_dir = eyesisAberrations.aberrationParameters.illustrationsDirectory;
String chn_ill_dir = illustrations_dir+Prefs.getFileSeparator()+ illustrationParameters.channel_dir_prefix+String.format("%02d", nChn);
// create directory if it does not exist
File destDir= new File (chn_ill_dir);
if (!destDir.exists()){
if (!destDir.mkdirs()) {
IJ.showMessage("Error","Failed to create results directory "+chn_ill_dir);
continue;
}
}
EyesisCorrections.saveAndShow(
imp_annot,
chn_ill_dir,
illustrationParameters.save_png,
false, // show
illustrationParameters.JPEG_quality, // <0 - keep current, 0 - force Tiff, >0 use for JPEG
0); // debug_level);
}
}
}
return true;
}
/*
public CalibrationIllustration (
LwirReaderParameters lwirReaderParameters,
LensDistortionParameters lensDistortionParameters,
PatternParameters patternParameters,
RefineParameters refineParameters,
DistortionProcessConfiguration distortionProcessConfiguration,
EyesisCameraParameters eyesisCameraParameters,
AtomicInteger stopRequested,
int debug_level) {
this.lwirReaderParameters = lwirReaderParameters;
this.lensDistortionParameters = lensDistortionParameters;
this.patternParameters = patternParameters;
this.refineParameters = refineParameters;
this.distortionProcessConfiguration = distortionProcessConfiguration;
this.eyesisCameraParameters = eyesisCameraParameters;
this.stopRequested = stopRequested;
this.debug_level = debug_level;
}
*/
}
package com.elphel.imagej.calibration;
import java.util.Properties;
import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.lwir.LwirReaderParameters;
public class CalibrationIllustrationParameters {
double dflt_lwir_lo = 22500.0;
double dflt_lwir_hi = 23500.0;
LwirReaderParameters lwirReaderParameters;
double [][] lwir_ranges; // = new double [lwirReaderParameters.getLwirChannels(false).length][2];
int palette = 0; // 0 - white - hot, 1 - black - hot, 2+ - colored
String src_chn_prefix="src_chn-";
boolean save_png = true;
int JPEG_quality = 90;
String channel_dir_prefix = "chn_";
public CalibrationIllustrationParameters (LwirReaderParameters lwirReaderParameters) {
this.lwirReaderParameters = lwirReaderParameters;
}
public void setProperties(String prefix,Properties properties){
// properties.setProperty(prefix+"camera_name", this.camera_name+"");
set_parameters();
for (int i = 0; i < lwir_ranges.length; i++) {
properties.setProperty(prefix+"lwir_range_lo_"+i, this.lwir_ranges[i][0]+"");
properties.setProperty(prefix+"lwir_range_hi_"+i, this.lwir_ranges[i][1]+"");
}
properties.setProperty(prefix+"palette", this.palette+"");
properties.setProperty(prefix+"save_png", this.save_png+"");
properties.setProperty(prefix+"JPEG_quality", this.JPEG_quality+"");
properties.setProperty(prefix+"channel_dir_prefix", this.channel_dir_prefix);
}
public void getProperties(String prefix,Properties properties){
set_parameters();
for (int i = 0; i < lwir_ranges.length; i++) {
if (properties.getProperty(prefix+"lwir_range_lo_"+i)!=null) {
this.lwir_ranges[i][0] = Double.parseDouble(properties.getProperty(prefix+"lwir_range_lo_"+i));
}
if (properties.getProperty(prefix+"lwir_range_hi_"+i)!=null) {
this.lwir_ranges[i][1] = Double.parseDouble(properties.getProperty(prefix+"lwir_range_hi_"+i));
}
}
if (properties.getProperty(prefix+"palette")!=null) this.palette = Integer.parseInt(properties.getProperty(prefix+"palette"));
if (properties.getProperty(prefix+"save_png")!=null) this.save_png = Boolean.parseBoolean(properties.getProperty(prefix+"save_png"));
if (properties.getProperty(prefix+"JPEG_quality")!=null) this.JPEG_quality = Integer.parseInt(properties.getProperty(prefix+"JPEG_quality"));
if (properties.getProperty(prefix+"channel_dir_prefix")!=null) this.channel_dir_prefix = (String) properties.getProperty(prefix+"channel_dir_prefix");
}
public void dialogQuestions(GenericJTabbedDialog gd) {
for (int i = 0; i < lwir_ranges.length; i++) {
gd.addNumericField("LWIR chn:"+i+" low range", this.lwir_ranges[i][0], 0,8,"","LWIR sensor range low level ");
gd.addNumericField("LWIR chn:"+i+" high range", this.lwir_ranges[i][1], 0,8,"","LWIR sensor range high level ");
}
gd.addNumericField("Thermal color palette", this.palette, 0,3,"","0 - white-hot, 1 - black-hot, 2+ - colored");
gd.addCheckbox("Save as PNG instead of JPEG", save_png);
gd.addNumericField("JPEG quality", this.JPEG_quality, 0,3,"","Jpeg quality, 0 - use Tiff");
gd.addStringField ("Channel directory prefix",this.channel_dir_prefix, 15,"prefix to a directory name to save channel annotated files");
}
public void dialogAnswers(GenericJTabbedDialog gd) {
for (int i = 0; i < lwir_ranges.length; i++) {
this.lwir_ranges[i][0] = gd.getNextNumber();
this.lwir_ranges[i][1] = gd.getNextNumber();
}
this.palette = (int) gd.getNextNumber();
this.save_png = gd.getNextBoolean();
this.JPEG_quality = (int) gd.getNextNumber();
this.channel_dir_prefix = gd.getNextString();
}
public boolean showJDialog() {
set_parameters();
GenericJTabbedDialog gd = new GenericJTabbedDialog("Set illustration parameters",800,900);
dialogQuestions(gd);
gd.showDialog();
if (gd.wasCanceled()) return false;
dialogAnswers(gd);
return true;
}
public void set_parameters () {
// this.lwirReaderParameters = lwirReaderParameters;
if ((lwir_ranges == null) || (lwir_ranges.length != lwirReaderParameters.getLwirChannels(false).length)){
lwir_ranges = new double [lwirReaderParameters.getLwirChannels(false).length][2];
for (int i = 0; i < lwir_ranges.length; i++) {
this.lwir_ranges[i][0] = dflt_lwir_lo;
this.lwir_ranges[i][1] = dflt_lwir_hi;
}
}
}
public int getPalette() {
return this.palette;
}
public double [] getLwirRange(int lwir_index) {
return lwir_ranges[lwir_index];
}
public LwirReaderParameters getLwirReaderParameters() {
return lwirReaderParameters;
}
}
......@@ -1039,16 +1039,6 @@ import ij.text.TextWindow;
System.out.println("sfiles == null");
}
for (String spath:sfiles) {
/*
int last_dash = spath.lastIndexOf('-');
int last = spath.lastIndexOf('_');
if (last_dash >last) last = last_dash;
int last_dot = spath.lastIndexOf('.');
if (last_dot < 0) {
last_dot = spath.length();
}
int chn = Integer.parseInt(spath.substring(last+1, last_dot));
*/
int chn = pathToChannel(spath);
spaths[chn] = (new File(set_dir,spath)).getPath();
}
......
......@@ -4784,6 +4784,7 @@ public class EyesisAberrations {
public static class AberrationParameters{
public String sourceDirectory="";
public String partialKernelDirectory="";
public String illustrationsDirectory="";
public String psfKernelDirectory="";
public String aberrationsKernelDirectory="";
public String calibrationDirectory="";
......@@ -4821,6 +4822,7 @@ public class EyesisAberrations {
public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"sourceDirectory",this.sourceDirectory);
properties.setProperty(prefix+"partialKernelDirectory",this.partialKernelDirectory);
properties.setProperty(prefix+"illustrationsDirectory",this.illustrationsDirectory);
properties.setProperty(prefix+"psfKernelDirectory",this.psfKernelDirectory);
properties.setProperty(prefix+"aberrationsKernelDirectory",this.aberrationsKernelDirectory);
properties.setProperty(prefix+"calibrationDirectory",this.calibrationDirectory);
......@@ -4866,6 +4868,7 @@ public class EyesisAberrations {
public void getProperties(String prefix,Properties properties){
if (properties.getProperty(prefix+"sourceDirectory")!=null) this.sourceDirectory=properties.getProperty(prefix+"sourceDirectory");
if (properties.getProperty(prefix+"partialKernelDirectory")!=null) this.partialKernelDirectory=properties.getProperty(prefix+"partialKernelDirectory");
if (properties.getProperty(prefix+"illustrationsDirectory")!=null) this.illustrationsDirectory=properties.getProperty(prefix+"illustrationsDirectory");
if (properties.getProperty(prefix+"psfKernelDirectory")!=null) this.psfKernelDirectory=properties.getProperty(prefix+"psfKernelDirectory");
if (properties.getProperty(prefix+"aberrationsKernelDirectory")!=null) this.aberrationsKernelDirectory=properties.getProperty(prefix+"aberrationsKernelDirectory");
if (properties.getProperty(prefix+"calibrationDirectory")!=null) this.calibrationDirectory=properties.getProperty(prefix+"calibrationDirectory");
......@@ -5018,6 +5021,8 @@ public class EyesisAberrations {
gd.addCheckbox("Select source directory", false);
gd.addStringField("Partial kernels directory", this.partialKernelDirectory, 60);
gd.addCheckbox("Select partial kernels directory", false);
gd.addStringField("Illustrations directory", this.illustrationsDirectory, 60);
gd.addCheckbox("Select illustrations directory", false);
gd.addStringField("Combined kernels directory", this.psfKernelDirectory, 60);
gd.addCheckbox("Select combined kernsls directory", false);
gd.addStringField("Aberrations kernels directory", this.aberrationsKernelDirectory, 60);
......@@ -5071,6 +5076,8 @@ public class EyesisAberrations {
if (gd.getNextBoolean()) selectSourceDirectory(false, this.sourceDirectory, false);
this.partialKernelDirectory=gd.getNextString();
if (gd.getNextBoolean()) selectPartialKernelDirectory(false, this.partialKernelDirectory, false);
this.illustrationsDirectory=gd.getNextString();
if (gd.getNextBoolean()) selectIllustrationsDirectory(false, this.illustrationsDirectory, false);
this.psfKernelDirectory=gd.getNextString();
if (gd.getNextBoolean()) selectPSFKernelDirectory(false, this.psfKernelDirectory, false);
this.aberrationsKernelDirectory=gd.getNextString();
......@@ -5133,6 +5140,19 @@ public class EyesisAberrations {
if (dir!=null) this.partialKernelDirectory=dir;
return dir;
}
public String selectIllustrationsDirectory(boolean smart, String defaultPath, boolean newAllowed) {
String dir= CalibrationFileManagement.selectDirectory(
smart,
newAllowed, // save
"Illustrations directory", // title
"Select illustrations directory", // button
null, // filter
defaultPath); //this.sourceDirectory);
if (dir!=null) this.illustrationsDirectory=dir;
return dir;
}
public String selectPSFKernelDirectory(boolean smart, String defaultPath, boolean newAllowed) {
String dir= CalibrationFileManagement.selectDirectory(
smart,
......
......@@ -2696,7 +2696,7 @@ public class EyesisCorrections {
}
public void saveAndShow(
public static void saveAndShow(
ImagePlus imp,
String path,
boolean png,
......@@ -2716,12 +2716,12 @@ public class EyesisCorrections {
}
}
if (hasAlphaHighByte && (jpegQuality <= 0)){
if (hasAlphaHighByte && ((jpegQuality <= 0) || png)){
if (png){
if (debugLevel > 0) System.out.println("Saving RGBA result to "+path+".png");
(new EyesisTiff()).savePNG_ARGB32(
imp,
path+".png"
path +".png"
);
} else {
......@@ -2729,7 +2729,7 @@ public class EyesisCorrections {
try {
(new EyesisTiff()).saveTiffARGB32(
imp,
path+".tiff",
path, // +".tiff",
false, // correctionsParameters.imageJTags,
debugLevel);
} catch (IOException e) {
......
......@@ -102,6 +102,26 @@ public class LwirReaderParameters {
public LwirReaderParameters() {
}
public int [] getLwirChannels(boolean absolote) {
int [] absolute_chn = new int [lwir_channels.length];
for (int i = 0; i < absolute_chn.length; i++) {
absolute_chn[i] = lwir_channels[i] + (absolote? getLwirChn0() : 0);
}
return absolute_chn;
}
public int [] getAbsoluteEoChannels(boolean absolote) {
int [] absolute_chn = new int [eo_channels.length];
for (int i = 0; i < absolute_chn.length; i++) {
absolute_chn[i] = eo_channels[i] + + (absolote? getEoChn0():0);
}
return absolute_chn;
}
// protected int [] lwir_channels = {0, 1, 2 ,3};
// protected int [] eo_channels = {0, 1, 2 ,3};
public LwirReaderParameters(String name) {
if (NAME_TALON.equals(name)) camera_name = NAME_TALON;
else if (NAME_LWIR16.equals(name)) camera_name = NAME_LWIR16;
......@@ -133,11 +153,11 @@ public class LwirReaderParameters {
public int getNumFrames() {
return num_frames;
}
public int getLwirChn0 () {
public int getLwirChn0() {
return lwir_chn0;
}
public int getEoChn0 () {
public int getEoChn0() {
return isLwir16() ? 16:4;// eo_chn0;
}
......
......@@ -2191,7 +2191,7 @@ public class QuadCLT extends QuadCLTCPU {
true, // smart,
true); //newAllowed, // save
for (int sub_img = 0; sub_img < imps_RGB.length; sub_img++){
eyesisCorrections.saveAndShow(
EyesisCorrections.saveAndShow(
imps_RGB[sub_img],
x3d_path,
correctionsParameters.png && !clt_parameters.black_back,
......@@ -2720,7 +2720,7 @@ public class QuadCLT extends QuadCLTCPU {
true, // smart,
true); //newAllowed, // save
for (int sub_img = 0; sub_img < imps_RGB.length; sub_img++){
quadCLT_main.eyesisCorrections.saveAndShow(
EyesisCorrections.saveAndShow(
imps_RGB[sub_img],
x3d_path,
quadCLT_main.correctionsParameters.png && !clt_parameters.black_back,
......
......@@ -5159,7 +5159,7 @@ public class QuadCLTCPU {
true, // smart,
true); //newAllowed, // save
for (int sub_img = 0; sub_img < 4; sub_img++){
eyesisCorrections.saveAndShow(
EyesisCorrections.saveAndShow(
imps_RGB[sub_img],
x3d_path,
correctionsParameters.png && !clt_parameters.black_back,
......@@ -12185,7 +12185,7 @@ public class QuadCLTCPU {
}
ImagePlus ip_thumb = new ImagePlus(name,ip);
eyesisCorrections.saveAndShow(
EyesisCorrections.saveAndShow(
ip_thumb,
dir,
false,
......
......@@ -50,6 +50,7 @@ import com.elphel.imagej.cameras.EyesisCorrectionParameters;
import com.elphel.imagej.common.GenericJTabbedDialog;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.correction.CorrectionColorProc;
import com.elphel.imagej.correction.EyesisCorrections;
import com.elphel.imagej.gpu.GPUTileProcessor;
import com.elphel.imagej.jp4.JP46_Reader_camera;
......@@ -1030,7 +1031,7 @@ public class TwoQuadCLT {
true, // smart,
true); //newAllowed, // save
for (int sub_img = 0; sub_img < imps_RGB.length; sub_img++){
quadCLT_main.eyesisCorrections.saveAndShow(
EyesisCorrections.saveAndShow(
imps_RGB[sub_img],
x3d_path,
quadCLT_main.correctionsParameters.png && !clt_parameters.black_back,
......@@ -1916,7 +1917,7 @@ public class TwoQuadCLT {
true, // smart,
true); //newAllowed, // save
for (int sub_img = 0; sub_img < imps_RGB.length; sub_img++){
quadCLT_main.eyesisCorrections.saveAndShow(
EyesisCorrections.saveAndShow(
imps_RGB[sub_img],
x3d_path,
quadCLT_main.correctionsParameters.png && !clt_parameters.black_back,
......
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