Skip to content

Commit

Permalink
Merge pull request #2 from luxigo/master
Browse files Browse the repository at this point in the history
Allow running Eyesis_Correction and JP46_Reader_camera in headless mode
  • Loading branch information
AndreyFilippov committed Jan 4, 2016
2 parents 103e97e + 3ae3caf commit 01246a6
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 141 deletions.
6 changes: 6 additions & 0 deletions src/main/java/EyesisCorrectionParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static class CorrectionParameters{
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
Expand Down Expand Up @@ -201,6 +202,7 @@ public void getProperties(String prefix,Properties properties){
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"));
Expand Down Expand Up @@ -283,6 +285,8 @@ public boolean showDialog(String title) {
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;
Expand All @@ -294,6 +298,7 @@ public boolean showDialog(String title) {
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);
Expand Down Expand Up @@ -372,6 +377,7 @@ public boolean showDialog(String title) {
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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/EyesisCorrections.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public void createChannelVignetting(){
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");
Expand Down Expand Up @@ -701,7 +701,7 @@ public void saveTiffWithAlpha(
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,
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/EyesisTiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

//import org.apache.log4j.Logger;


import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
Expand All @@ -42,20 +43,31 @@
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,
Expand Down Expand Up @@ -175,7 +187,7 @@ public void saveTiffARGB(
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};
Expand Down Expand Up @@ -212,6 +224,7 @@ public void saveTiffARGB(
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);
Expand Down Expand Up @@ -257,7 +270,7 @@ public void saveTiffARGB32(
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

Expand Down
Loading

0 comments on commit 01246a6

Please sign in to comment.