Commit 01246a62 authored by Andrey Filippov's avatar Andrey Filippov

Merge pull request #2 from luxigo/master

Allow running Eyesis_Correction and JP46_Reader_camera in headless mode
parents 103e97e7 3ae3cafd
......@@ -61,6 +61,7 @@ public class EyesisCorrectionParameters {
public double outputRangeFP= 255.0; // 1.0 intensity will be saved as 255.0 (in float 32-bit mode)
public boolean imageJTags= false; // encode ImageJ info data to the TIFF output header
public String tiffCompression = "UNCOMPRESSED"; // tiff compression codec
public boolean jpeg = true; // convert to RGB and save JPEG (if save is true)
public boolean save = true;
public boolean save16 = false; // save 16-bit tiff also if the end result is 8 bit
......@@ -201,6 +202,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"equirectangularFormat")!=null) this.equirectangularFormat=Integer.parseInt(properties.getProperty(prefix+"equirectangularFormat"));
if (properties.getProperty(prefix+"outputRangeInt")!=null) this.outputRangeInt=Double.parseDouble(properties.getProperty(prefix+"outputRangeInt"));
if (properties.getProperty(prefix+"outputRangeFP")!=null) this.outputRangeFP=Double.parseDouble(properties.getProperty(prefix+"outputRangeFP"));
if (properties.getProperty(prefix+"tiffCompression")!=null) this.tiffCompression=properties.getProperty(prefix+"tiffCompression");
if (properties.getProperty(prefix+"imageJTags")!=null) this.imageJTags=Boolean.parseBoolean(properties.getProperty(prefix+"imageJTags"));
if (properties.getProperty(prefix+"jpeg")!=null) this.jpeg=Boolean.parseBoolean(properties.getProperty(prefix+"jpeg")); // convert to RGB and save jpeg (if save is true)
if (properties.getProperty(prefix+"save")!=null) this.save=Boolean.parseBoolean(properties.getProperty(prefix+"save"));
......@@ -283,6 +285,8 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Save chroma denoise mask (white - use hi-res, black - low-res)", this.saveChromaDenoiseMask);
gd.addCheckbox ("Rotate result image", this.rotate);
gd.addCheckbox ("Crop result image to the original size", this.crop);
String [] tiffCompressionChoices={"UNCOMPRESSED","LZW","JPEG", "JPEG_2000","ALT_JPEG2000"};
int tiffCompressionIndex=0;
String [] equirectangularFormatChoices={"RGBA 8-bit","RGBA 16-bit","RGBA 32-bit integer","RGBA 32-bit float","ImageJ stack"};
int [] equirectangularFormats={0,1,2,3,4};
int equirectangularFormatIndex=0;
......@@ -294,6 +298,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Map 1.0 intensity to this fraction of the full range 8/16/32-bit integer mode output", 100*this.outputRangeInt, 2,6,"%");
gd.addNumericField("Map 1.0 intensity to this value in 32-bit floating point output mode", this.outputRangeFP, 2,6,"");
gd.addCheckbox ("Encode ImageJ specific Info metadata to the output file TIFF header", this.imageJTags);
gd.addChoice("TIFF lossless compression codec",tiffCompressionChoices,tiffCompressionChoices[tiffCompressionIndex]);
gd.addCheckbox ("Convert to RGB48", this.toRGB);
gd.addCheckbox ("Convert to 8 bit RGB (and save JPEG if save is enabled)", this.jpeg);
......@@ -372,6 +377,7 @@ public class EyesisCorrectionParameters {
this.outputRangeInt=0.01*gd.getNextNumber();
this.outputRangeFP= gd.getNextNumber();
this.imageJTags= gd.getNextBoolean();
this.tiffCompression= tiffCompressionChoices[gd.getNextChoiceIndex()];
this.toRGB= gd.getNextBoolean();
this.jpeg= gd.getNextBoolean();
this.save= gd.getNextBoolean();
......
......@@ -473,7 +473,7 @@ public class EyesisCorrections {
this.defectsDiff[srcChannel]=this.pixelMapping.getDefectsDiff(srcChannel);
if (this.debugLevel>0){
if (this.defectsXY[srcChannel]==null){
System.out.println("No pixel defects info is availabele for channel "+srcChannel);
System.out.println("No pixel defects info is available for channel "+srcChannel);
} else {
System.out.println("Extracted "+this.defectsXY[srcChannel].length+" pixel outlayers for channel "+srcChannel+
" (x:y:difference");
......@@ -701,7 +701,7 @@ public class EyesisCorrections {
if (path!=null){
path+=Prefs.getFileSeparator()+imp.getTitle()+".tiff";
if (this.debugLevel>0) System.out.println("Saving equirectangular result to "+path);
(new EyesisTiff()).saveTiff(
(new EyesisTiff(correctionsParameters.tiffCompression)).saveTiff(
imp,
path,
correctionsParameters.equirectangularFormat,
......
......@@ -34,6 +34,7 @@ import java.util.Arrays;
//import org.apache.log4j.Logger;
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
......@@ -42,20 +43,31 @@ import loci.common.RandomAccessInputStream;
import loci.common.services.DependencyException;
import loci.common.services.ServiceException;
import loci.formats.FormatException;
import loci.formats.codec.CodecOptions;
import loci.formats.tiff.IFD;
import loci.formats.tiff.IFDList;
import loci.formats.tiff.TiffParser;
import loci.formats.tiff.TiffRational;
import loci.formats.tiff.TiffSaver;
import loci.formats.tiff.TiffCompression;
public class EyesisTiff {
// private static org.apache.log4j.Logger log= Logger.getLogger(EyesisTiff.class);
private String codec="UNCOMPRESSED";
public EyesisTiff(){
// Please initialize the log4j system properly
}
public EyesisTiff(String codec){
// Please initialize the log4j system properly
this.codec=codec;
}
public void saveTiff(
ImagePlus imp,
String path,
......@@ -175,7 +187,7 @@ public EyesisTiff(){
ifd.putIFDValue(IFD.SOFTWARE, "Elphel Eyesis");
ifd.putIFDValue(IFD.IMAGE_DESCRIPTION, description);
// copy some other data?
ifd.putIFDValue(IFD.COMPRESSION, 1); //TiffCompression.UNCOMPRESSED);
ifd.putIFDValue(IFD.COMPRESSION, TiffCompression.valueOf(codec).getCode());
ifd.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION,2); // RGB
ifd.putIFDValue(IFD.EXTRA_SAMPLES,2); // 0 = Unspecified data 1 = Associated alpha data (with pre-multiplied color) 2 = Unassociated alpha data
// int [] bpsArray={8,8,8,8};
......@@ -212,6 +224,7 @@ public EyesisTiff(){
TiffSaver tiffSaver = new TiffSaver(path);
tiffSaver.setWritingSequentially(true);
tiffSaver.setLittleEndian(false);
tiffSaver.setCodecOptions(TiffCompression.valueOf(codec).getCompressionCodecOptions(ifd));
tiffSaver.writeHeader();
// tiffSaver.writeIFD(ifd,0); //* SHould not write here, some fields are calculated during writeImage, that writes IFD too
// System.out.println("bytes.length="+bytes.length);
......@@ -257,7 +270,7 @@ public EyesisTiff(){
ifd.putIFDValue(IFD.SOFTWARE, "Elphel Eyesis");
ifd.putIFDValue(IFD.IMAGE_DESCRIPTION, description);
// copy some other data?
ifd.putIFDValue(IFD.COMPRESSION, 1); //TiffCompression.UNCOMPRESSED);
ifd.putIFDValue(IFD.COMPRESSION, TiffCompression.valueOf(codec).getCode());
ifd.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION,2); // RGB
ifd.putIFDValue(IFD.EXTRA_SAMPLES,2); // extra bytes (over 3) meaning Unassociated alpha data
......
This diff is collapsed.
......@@ -30,6 +30,7 @@ import ij.process.*;
import ij.gui.*;
import ij.plugin.frame.*;
import ij.text.*;
import ij.plugin.PlugIn;
import java.awt.*;
import java.awt.event.*;
......@@ -50,9 +51,8 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/* This plugin opens images in Elphel JP4/JP46 format (opens as JPEG, reads MakerNote and converts). */
public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
public class JP46_Reader_camera implements PlugIn, ActionListener {
/**
*
......@@ -61,6 +61,7 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
Panel panel1;
Panel confpanel;
Frame instance;
PlugInFrame plugInFrame;
String arg;
......@@ -75,44 +76,31 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
public boolean demux=true;
public String imageTitle="cameraImage";
private int ExifOffset=0x0c;
private Boolean headless=GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance();
public JP46_Reader_camera() {
super("JP46 Reader Camera");
if (IJ.versionLessThan("1.39t")) return;
if (instance!=null) {
instance.toFront();
return;
public void run(String arg) {
}
instance = this;
addKeyListener(IJ.getInstance());
panel1 = new Panel();
panel1.setLayout(new GridLayout(6, 1, 50, 5));
addButton("Open JP4/JP46...",panel1);
addButton("Open JP4/JP46 from camera",panel1);
addButton("Configure...",panel1);
addButton("Show image properties",panel1);
addButton("Decode image info to properties",panel1);
addButton("Split Bayer",panel1);
public JP46_Reader_camera(Boolean showGui) {
if (showGui) initGui();
}
public JP46_Reader_camera() {
initGui();
}
add(panel1);
private void initGui() {
if (headless) return;
pack();
GUI.center(this);
setVisible(true);
}
public JP46_Reader_camera(boolean showGUI) {
super("JP46 Reader Camera");
if (IJ.versionLessThan("1.39t")) return;
if (instance!=null) {
instance.toFront();
return;
}
instance = this;
addKeyListener(IJ.getInstance());
plugInFrame=new PlugInFrame("JP46 Reader Camera");
instance = (Frame)plugInFrame;
plugInFrame.addKeyListener(IJ.getInstance());
panel1 = new Panel();
......@@ -124,12 +112,14 @@ public class JP46_Reader_camera extends PlugInFrame implements ActionListener {
addButton("Show image properties",panel1);
addButton("Decode image info to properties",panel1);
addButton("Split Bayer",panel1);
add(panel1);
pack();
GUI.center(this);
setVisible(showGUI);
}
plugInFrame.add(panel1);
plugInFrame.pack();
GUI.center(plugInFrame);
plugInFrame.setVisible(true);
}
void addButton(String label, Panel panel) {
Button b = new Button(label);
b.addActionListener(this);
......@@ -1321,7 +1311,7 @@ Exception in thread "Thread-3564" java.lang.ArrayIndexOutOfBoundsException: 8970
*/
public static void main(String[] args) {
// set the plugins.dir property to make the plugin appear in the Plugins menu
Class<?> clazz = Aberration_Calibration.class;
Class<?> clazz = JP46_Reader_camera.class;
String url = clazz.getResource("/" + clazz.getName().replace('.', '/') + ".class").toString();
String pluginsDir = url.substring(5, url.length() - clazz.getName().length() - 6);
System.setProperty("plugins.dir", pluginsDir);
......
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