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

addin illustration generation

parent f68fa78e
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