Commit 6894dccd authored by Andrey Filippov's avatar Andrey Filippov

Trying to get GPS data

parent db9a0992
......@@ -217,21 +217,20 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version><!--$NO-MVN-MAN-VER$-->
<version>1.3.2</version><!--$NO-MVN-MAN-VER$-->
<executions>
<execution>
<phase>package</phase>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- <mainClass>Aberration_Calibration</mainClass> -->
<!-- <mainClass>Aberration_Calibration</mainClass> -->
<mainClass>Eyesis_Correction</mainClass>
</configuration>
</plugin>
......@@ -253,11 +252,35 @@
<format>Build {0,date,yyyy-MM-dd} {0,time,HH:MM:SS} on host {1}</format>
<items>
<item>timestamp</item>
<!-- <item>foxel-MRHM7AP</item> -->
</items>
</configuration>
</plugin>
</plugin>
<!-- Trying sources/javadocs -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>
<goal>sources</goal>
<goal>resolve</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
</configuration>
</execution>
</executions>
</plugin>
<!-- End of Trying sources/javadocs -->
</plugins>
</pluginManagement>
</build>
......
......@@ -2741,7 +2741,7 @@ public class EyesisCorrections {
} else {
if (debugLevel > 0) System.out.println("Saving RGBA result to "+path+".tiff");
try {
(new EyesisTiff()).saveTiffARGB32(
EyesisTiff.saveTiffARGB32(
imp,
path+".tiff", //path, // +".tiff",
false, // correctionsParameters.imageJTags,
......@@ -2777,7 +2777,7 @@ public class EyesisCorrections {
if ((imp.getStackSize() == 4) && imp.getStack().getSliceLabel(4).equals("alpha")){
try {
(new EyesisTiff()).saveTiff(
EyesisTiff.saveTiff(
imp,
path+".tiff",
mode, //
......
......@@ -43,6 +43,7 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -70,9 +71,22 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.plugins.tiff.ExifGPSTagSet;
import javax.imageio.plugins.tiff.TIFFDirectory;
import javax.imageio.plugins.tiff.TIFFTagSet;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import org.w3c.dom.Node;
import com.elphel.imagej.calibration.CalibrationFileManagement;
import com.elphel.imagej.calibration.CalibrationIllustration;
import com.elphel.imagej.calibration.CalibrationIllustrationParameters;
......@@ -95,6 +109,8 @@ import com.elphel.imagej.ims.EventLogger;
import com.elphel.imagej.ims.Imx5;
import com.elphel.imagej.jp4.JP46_Reader_camera;
import com.elphel.imagej.lwir.LwirReader;
import com.elphel.imagej.readers.ChangeImageResolution;
import com.elphel.imagej.readers.DumpImageMetadata;
import com.elphel.imagej.readers.EyesisTiff;
import com.elphel.imagej.tensorflow.TensorflowInferModel;
import com.elphel.imagej.tileprocessor.Clt1d;
......@@ -578,6 +594,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
if (ADVANCED_MODE) {
addButton("Tiff Writer", panel7);
addButton("Tiff Properties", panel7);
addButton("Add TIFF resolution", panel7);
}
plugInFrame.add(panel7);
......@@ -1662,7 +1679,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
/* ======================================================================== */
} else if (label.equals("Tiff Writer")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
EyesisTiff eyesisTiff = new EyesisTiff();
// EyesisTiff eyesisTiff = new EyesisTiff();
ImagePlus imp_sel = WindowManager.getCurrentImage();
if (imp_sel == null) {
IJ.showMessage("Error", "No images selected");
......@@ -1676,7 +1693,7 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
}
try {
try {
eyesisTiff.saveTiff(imp_sel, path, CORRECTION_PARAMETERS.equirectangularFormat,
EyesisTiff.saveTiff(imp_sel, path, CORRECTION_PARAMETERS.equirectangularFormat,
(CORRECTION_PARAMETERS.equirectangularFormat == 3) ? CORRECTION_PARAMETERS.outputRangeFP
: CORRECTION_PARAMETERS.outputRangeInt,
CORRECTION_PARAMETERS.imageJTags, DEBUG_LEVEL);
......@@ -1696,13 +1713,109 @@ public class Eyesis_Correction implements PlugIn, ActionListener {
/* ======================================================================== */
} else if (label.equals("Tiff Properties")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
EyesisTiff eyesisTiff = new EyesisTiff();
ImagePlus imp_sel = WindowManager.getCurrentImage();
if (imp_sel == null) {
IJ.showMessage("Error", "No images selected");
return;
}
eyesisTiff.propertiesTiff(imp_sel);
String orig_path = imp_sel.getOriginalFileInfo().getFilePath();
try {
DumpImageMetadata.processFile(new File(orig_path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// EyesisTiff.propertiesTiff(imp_sel);
return;
/* ======================================================================== */
} else if (label.equals("Add TIFF resolution")) {
DEBUG_LEVEL = MASTER_DEBUG_LEVEL;
ImagePlus imp_sel = WindowManager.getCurrentImage();
if (imp_sel == null) {
IJ.showMessage("Error", "No images selected");
return;
}
String orig_path = imp_sel.getOriginalFileInfo().getFilePath();
// Testing change image resolution
File inputFile = new File(orig_path);
IIOMetadata inMetadata = null;
try {
inMetadata = DumpImageMetadata.getFileMetadata(inputFile);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return;
}
double resolutionDPI = 600;
File outputFile = new File(orig_path+"_"+((int)resolutionDPI)+"-01.tiff");
BufferedImage image = null;
try {
image = ChangeImageResolution.readImage(inputFile); // wrong imageType 0 (should be 2)
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
IIOMetadataNode newMetadata = ChangeImageResolution.createResolutionMetadata(resolutionDPI);
// IIOMetadataNode addMetadata = ChangeImageResolution.createResolutionMetadata0(resolutionDPI);
// inMetaData.appendChild()
try {
inMetadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, newMetadata);
} catch (IIOInvalidTreeException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return;
}
Node metadata_as_tree = inMetadata.getAsTree("javax_imageio_tiff_image_1.0");
BufferedImage bufferedImageAlpha = new BufferedImage(
image.getWidth(),
image.getHeight(),
BufferedImage.TYPE_INT_ARGB
);
ImageWriter tiffWriter = ImageIO.getImageWritersByFormatName("tiff").next();
ImageWriteParam tiffWriteParam = tiffWriter.getDefaultWriteParam();
tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);
ImageTypeSpecifier imageType = ImageTypeSpecifier.createFromRenderedImage(bufferedImageAlpha);
IIOMetadata imageMetadata = tiffWriter.getDefaultImageMetadata(imageType, tiffWriteParam);
TIFFDirectory directory = null;
try {
directory = TIFFDirectory.createFromMetadata(imageMetadata);
} catch (IIOInvalidTreeException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
/// TIFFTagSet tag_set = ExifGPSTagSet.getInstance();
/// directory.addTagSet(tag_set); // ExifGPSTagSet.getInstance());
//// imageMetadata = directory.getAsMetadata();
System.out.println("\n=== metadata_as_tree ===:");
DumpImageMetadata.displayMetadataNode(metadata_as_tree, 1);
System.out.println("\n=== imageMetadata as javax_imageio_tiff_image_1.0 ===:");
DumpImageMetadata.displayMetadataNode(imageMetadata.getAsTree("javax_imageio_tiff_image_1.0"), 1);
try {
// imageMetadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, metadata_as_tree);
imageMetadata.mergeTree("javax_imageio_tiff_image_1.0", metadata_as_tree);
} catch (IIOInvalidTreeException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return;
}
System.out.println("\n=== imageMetadata merged as javax_imageio_tiff_image_1.0 ===:");
DumpImageMetadata.displayMetadataNode(imageMetadata.getAsTree("javax_imageio_tiff_image_1.0"), 1);
// works with inMetadata. Will it with imageMetadata?
try {
ChangeImageResolution.writeImage(outputFile, image, imageMetadata); // inMetadata); // newMetadata);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
/* ======================================================================== */
} else if (label.equals("Configure PP")) {
......
package com.elphel.imagej.ims;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Properties;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
public abstract class Did_ins <T extends Did_ins <T>>{
final static LocalDateTime DT_01_06_1980 = LocalDateTime.of(1980,1,6,0,0);
final static int WEEK_SECONDS = 7 * 24 * 3600;
/** GPS number of weeks since January 6th, 1980 */
public int week; // uint32_t
......@@ -49,6 +52,20 @@ public abstract class Did_ins <T extends Did_ins <T>>{
return new int [] { week, (int)Math.round(timeOfWeek * 1000.0)};
}
public static LocalDateTime getLocalDateTime(int week, double tow) {
/** GPS number of weeks since January 6th, 1980 */
/** GPS time of week (since Sunday morning) in seconds */
int seconds = (int) Math.floor(tow);
int nanos = (int) Math.floor((tow-seconds)*1E9);
return DT_01_06_1980.plusWeeks(week).
plusSeconds(seconds).plusNanos(nanos);
}
public LocalDateTime getLocalDateTime() {
return getLocalDateTime(week, timeOfWeek);
}
public boolean isDidSane() {
if ((week < MIN_WEEK) || (week > MAX_WEEK)) {
System.out.println("isDidSane(): bad week = "+week+
......
package com.elphel.imagej.readers;
//https://www.silverbaytech.com/2014/06/04/iiometadata-tutorial-part-3-writing-metadata/
/*
* Copyright (c) 2014 Kevin Hunter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//package com.silverbaytech.blog.imageIoMetadata;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
public class ChangeImageResolution
{
private static String getFileExtension(File file)
{
String fileName = file.getName();
int lastDot = fileName.lastIndexOf('.');
return fileName.substring(lastDot + 1);
}
public static BufferedImage readImage(File file) throws IOException
{
ImageInputStream stream = null;
BufferedImage image = null;
try
{
stream = ImageIO.createImageInputStream(file);
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
if (readers.hasNext())
{
ImageReader reader = readers.next();
reader.setInput(stream);
image = reader.read(0);
}
}
finally
{
if (stream != null)
{
stream.close();
}
}
return image;
}
//https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/imageio/metadata/doc-files/standard_metadata.html
public static IIOMetadataNode createResolutionMetadata(double resolutionDPI)
{
String pixelSize = Double.toString(25.4 / resolutionDPI);
IIOMetadataNode horizontal = new IIOMetadataNode("HorizontalPixelSize");
horizontal.setAttribute("value", pixelSize);
IIOMetadataNode vertical = new IIOMetadataNode("VerticalPixelSize");
vertical.setAttribute("value", pixelSize);
IIOMetadataNode dimension = new IIOMetadataNode("Dimension");
dimension.appendChild(horizontal);
dimension.appendChild(vertical);
IIOMetadataNode root = new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName);
root.appendChild(dimension);
return root;
}
public static IIOMetadataNode createResolutionMetadata0(double resolutionDPI)
{
String pixelSize = Double.toString(25.4 / resolutionDPI);
IIOMetadataNode horizontal = new IIOMetadataNode("HorizontalPixelSize");
horizontal.setAttribute("value", pixelSize);
IIOMetadataNode vertical = new IIOMetadataNode("VerticalPixelSize");
vertical.setAttribute("value", pixelSize);
IIOMetadataNode dimension = new IIOMetadataNode("Dimension");
dimension.appendChild(horizontal);
dimension.appendChild(vertical);
return dimension;
// IIOMetadataNode root = new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName);
// root.appendChild(dimension);
// return root;
}
public static void writeImage(File outputFile, BufferedImage image, IIOMetadataNode newMetadata) throws IOException
{
String extension = getFileExtension(outputFile);
ImageTypeSpecifier imageType = ImageTypeSpecifier.createFromBufferedImageType(image.getType());
ImageOutputStream stream = null;
try
{
Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix(extension);
while(writers.hasNext())
{
ImageWriter writer = writers.next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
IIOMetadata imageMetadata = writer.getDefaultImageMetadata(imageType, writeParam);
if (!imageMetadata.isStandardMetadataFormatSupported())
{
continue;
}
if (imageMetadata.isReadOnly())
{
continue;
}
imageMetadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, newMetadata);
IIOImage imageWithMetadata = new IIOImage(image, null, imageMetadata);
stream = ImageIO.createImageOutputStream(outputFile);
writer.setOutput(stream);
writer.write(null, imageWithMetadata, writeParam);
}
}
finally
{
if (stream != null)
{
stream.close();
}
}
}
public static void writeImage(File outputFile, BufferedImage image, IIOMetadata newMetadata) throws IOException
{
String extension = getFileExtension(outputFile);
ImageTypeSpecifier imageType = ImageTypeSpecifier.createFromBufferedImageType(image.getType());
ImageOutputStream stream = null;
try
{
Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix(extension);
while(writers.hasNext())
{
ImageWriter writer = writers.next();
ImageWriteParam writeParam = writer.getDefaultWriteParam();
/*
IIOMetadata imageMetadata = writer.getDefaultImageMetadata(imageType, writeParam);
if (!imageMetadata.isStandardMetadataFormatSupported())
{
continue;
}
if (imageMetadata.isReadOnly())
{
continue;
}
imageMetadata.mergeTree(IIOMetadataFormatImpl.standardMetadataFormatName, newMetadata);
*/
IIOImage imageWithMetadata = new IIOImage(image, null, newMetadata);
stream = ImageIO.createImageOutputStream(outputFile);
writer.setOutput(stream);
writer.write(null, imageWithMetadata, writeParam);
}
}
finally
{
if (stream != null)
{
stream.close();
}
}
}
public static void main(String[] args)
{
if (args.length != 3)
{
System.out
.println("Usage: ChangeImageResolution inputFile newResolutionDPI outputFile");
return;
}
try
{
File inputFile = new File(args[0]);
double resolutionDPI = Double.parseDouble(args[1]);
File outputFile = new File(args[2]);
BufferedImage image = readImage(inputFile);
IIOMetadataNode newMetadata = createResolutionMetadata(resolutionDPI);
writeImage(outputFile, image, newMetadata);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
/*
https://www.silverbaytech.com/2014/05/29/iiometadata-tutorial-part-2-retrieving-image-metadata/
*/
package com.elphel.imagej.readers;
/*
* Copyright (c) 2014 Kevin Hunter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//package com.silverbaytech.blog.imageIoMetadata;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.ImageInputStream;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
/**
* Dump the ImageIO metadata associated with one or more images.
*
* @author Kevin Hunter
*
*/
public class DumpImageMetadata
{
private static String getFileExtension(File file)
{
String fileName = file.getName();
int lastDot = fileName.lastIndexOf('.');
return fileName.substring(lastDot + 1);
}
private static void indent(int level)
{
for (int i = 0; i < level; i++)
{
System.out.print(" ");
}
}
private static void displayAttributes(NamedNodeMap attributes)
{
if (attributes != null)
{
int count = attributes.getLength();
for (int i = 0; i < count; i++)
{
Node attribute = attributes.item(i);
System.out.print(" ");
System.out.print(attribute.getNodeName());
System.out.print("='");
System.out.print(attribute.getNodeValue());
System.out.print("'");
}
}
}
public static void displayMetadataNode(Node node, int level)
{
indent(level);
System.out.print("<");
System.out.print(node.getNodeName());
NamedNodeMap attributes = node.getAttributes();
displayAttributes(attributes);
Node child = node.getFirstChild();
if (child == null)
{
String value = node.getNodeValue();
if (value == null || value.length() == 0)
{
System.out.println("/>");
}
else
{
System.out.print(">");
System.out.print(value);
System.out.print("<");
System.out.print(node.getNodeName());
System.out.println(">");
}
return;
}
System.out.println(">");
while (child != null)
{
displayMetadataNode(child, level + 1);
child = child.getNextSibling();
}
indent(level);
System.out.print("</");
System.out.print(node.getNodeName());
System.out.println(">");
}
private static void dumpMetadata(IIOMetadata metadata)
{
String[] names = metadata.getMetadataFormatNames();
int length = names.length;
for (int i = 0; i < length; i++)
{
indent(2);
System.out.println("Format name: " + names[i]);
displayMetadataNode(metadata.getAsTree(names[i]), 3);
}
}
private static void processFileWithReader(File file, ImageReader reader) throws IOException
{
ImageInputStream stream = null;
try
{
stream = ImageIO.createImageInputStream(file);
reader.setInput(stream, true);
IIOMetadata metadata = reader.getImageMetadata(0);
indent(1);
System.out.println("Image metadata");
dumpMetadata(metadata);
IIOMetadata smetadata = reader.getStreamMetadata();
if (smetadata != null)
{
indent(1);
System.out.println("Stream metadata");
dumpMetadata(smetadata);
}
}
finally
{
if (stream != null)
{
stream.close();
}
}
}
public static void processFile(File file) throws IOException
{
System.out.println("\nProcessing " + file.getName() + ":\n");
String extension = getFileExtension(file);
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(extension);
while (readers.hasNext())
{
ImageReader reader = readers.next();
System.out.println("Reader: " + reader.getClass().getName());
processFileWithReader(file, reader);
}
}
public static IIOMetadata getFileMetadata(File file) throws IOException {
String extension = getFileExtension(file);
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(extension);
IIOMetadata metadata = null;
if (readers.hasNext()) {
ImageReader reader = readers.next();
System.out.println("Reader: " + reader.getClass().getName());
// processFileWithReader(file, reader);
ImageInputStream stream = null;
try
{
stream = ImageIO.createImageInputStream(file);
reader.setInput(stream, true);
metadata = reader.getImageMetadata(0);
}
finally
{
if (stream != null)
{
stream.close();
}
}
}
return metadata;
}
public static void processDirectory(File directory) throws IOException
{
System.out.println("Processing all files in " + directory.getAbsolutePath());
File[] contents = directory.listFiles();
for (File file : contents)
{
if (file.isFile())
{
processFile(file);
}
}
}
public static void main(String[] args)
{
try
{
for (int i = 0; i < args.length; i++)
{
File fileOrDirectory = new File(args[i]);
if (fileOrDirectory.isFile())
{
processFile(fileOrDirectory);
}
else
{
processDirectory(fileOrDirectory);
}
}
System.out.println("\nDone");
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
\ No newline at end of file
......@@ -59,9 +59,6 @@ import loci.formats.FormatTools;
import loci.formats.in.MetadataLevel;
import loci.formats.in.TiffReader;
import loci.formats.meta.MetadataStore;
import loci.formats.tiff.IFD;
import loci.formats.tiff.IFDList;
import loci.formats.tiff.TiffRational;
import ome.xml.model.primitives.Timestamp;
/*
......
This diff is collapsed.
......@@ -57,6 +57,9 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.elphel.imagej.correction.Eyesis_Correction;
import com.elphel.imagej.tileprocessor.QuadCLTCPU;
//import org.apache.log4j.Logger;
import ij.IJ;
......@@ -305,13 +308,42 @@ the type of pixel data in this file getPixelType()
) throws IOException, FormatException, ServiceException, DependencyException{
if (imp.getType()==ImagePlus.COLOR_RGB) { // 4*8 bit - type = 0
if (debugLevel>1) System.out.println("Saving 8-bit TIFF with alpha-channel: "+path); // is it possible to just add alpha to high bytes?
saveTiffARGB32(imp, path, imageJTags, debugLevel);
ElphelTiffWriter.saveTiffARGB32(imp, path, imageJTags, debugLevel);
// saveTiffARGB32(imp, path, imageJTags, debugLevel);
return;
} else if (imp.getStackSize()==4) {
if (debugLevel>1) System.out.println("Saving 32-bit float TIFF with alpha-channel: "+path);
saveTiffARGB(imp, path, mode, scale, imageJTags,debugLevel);
return;
} else if (imp.getType()==ImagePlus.GRAY32) {
int lwir_palette = 0;
double [] minmax = null;
String title = imp.getTitle();
float [] fpixels = (float[]) imp.getProcessor().getPixels();
double [] dpixels = new double [fpixels.length];
for (int i = 0; i < fpixels.length; i++) {
dpixels[i] = fpixels[i];
}
ImagePlus imp_rgb = QuadCLTCPU.linearStackToColorLWIR(
Eyesis_Correction.CLT_PARAMETERS, // clt_parameters, // CLTParameters clt_parameters,
lwir_palette, // int lwir_palette, // <0 - do not convert
minmax, // minmax, // double [] minmax,
title, // String name,
"-rgba", // String suffix, // such as disparity=...
true, // boolean toRGB,
new double[][] {dpixels}, // faded_textures[nslice], // double [][] texture_data,
imp.getWidth(), // int width, // int tilesX,
imp.getHeight(), // int height, // int tilesY,
debugLevel); // int debugLevel )
// File test_dump = new File("/home/elphel/Documents/DoD/Ukraine/photos/test/1694531940_120446-02-gps.tiff");
// DumpImageMetadata.processFile(test_dump);
if (debugLevel>1) System.out.println("Saving 8-bit RGBA TIFF with alpha-channel: "+path); // is it possible to just add alpha to high bytes?
ElphelTiffWriter.saveTiffARGB32(imp_rgb, path, imageJTags, debugLevel);
// saveTiffARGB32(imp_rgb, path, imageJTags, debugLevel);
return;
}
IJ.showMessage("Not yet implemented for this image type");
}
......@@ -523,8 +555,8 @@ the type of pixel data in this file getPixelType()
// copy some other data?
ifd.putIFDValue(IFD.COMPRESSION, 1); //TiffCompression.UNCOMPRESSED);
ifd.putIFDValue(IFD.PHOTOMETRIC_INTERPRETATION,2); // RGB
// ifd.putIFDValue(IFD.EXTRA_SAMPLES,2); // extra bytes (over 3) meaning Unassociated alpha data
ifd.putIFDValue(IFD.EXTRA_SAMPLES,1); // extra bytes (over 3) meaning Unassociated alpha data
ifd.putIFDValue(IFD.EXTRA_SAMPLES,2); // extra 2 bytes (over 3) meaning Unassociated alpha data
// ifd.putIFDValue(IFD.EXTRA_SAMPLES,1); // extra 1 byte (over 3) meaning Associated alpha data
ifd.putIFDValue(IFD.SAMPLE_FORMAT,1); //
// int [] bpsArray={8,8,8,8};
// ifd.putIFDValue(IFD.BITS_PER_SAMPLE, bpsArray); // will be done automatically
......@@ -571,7 +603,6 @@ the type of pixel data in this file getPixelType()
public static void propertiesTiff(ImagePlus imp){
FileInfo fi = imp.getOriginalFileInfo();
if ((fi==null) ||(fi.directory==null) || (fi.fileFormat!=FileInfo.TIFF)) {
......@@ -628,7 +659,15 @@ the type of pixel data in this file getPixelType()
sb.append("}");
byte [] bstring=new byte [Array.getLength(value)];
for (int i=0;i<bstring.length;i++) bstring[i]= (byte) Integer.parseInt(Array.get(value, i).toString());
for (int i=0;i<bstring.length;i++) {
try {
bstring[i]= (byte) Integer.parseInt(Array.get(value, i).toString());
} catch (java.lang.NumberFormatException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
bstring[i]=(byte) 0x3f;
}
}
// String astring=new String((byte []) value);
String astring="";
try {
......
......@@ -9161,80 +9161,90 @@ public class QuadCLTCPU {
// convert to ImageStack of 3 slices
// String [] sliceNames = is_mono? new String[]{"mono"}: new String[]{"red", "blue", "green"};
int main_color_index = is_mono? 0 : 2;
double [][] rbg_in = is_mono?
new double [][] {texture_data[0]} :
new double[][] {texture_data[0],texture_data[1],texture_data[2]};
double [] alpha_pixels = null; // (0..1.0)
if (texture_data.length > rbg_in.length) {
alpha_pixels = texture_data[rbg_in.length];
}
if (!toRGB) { // Double [][] uses
ImagePlus imp;
if (alpha_pixels != null) {
String [] titles = {"Y","alpha"};
ImageStack stack = ShowDoubleFloatArrays.makeStack(
new double[][] {rbg_in[0],alpha_pixels}, // iclt_data,
width, // (tilesX + 0) * clt_parameters.transform_size,
height, // (tilesY + 0) * clt_parameters.transform_size,
titles, // or use null to get chn-nn slice names
true); // replace NaN with 0.0
imp = new ImagePlus(name+suffix, stack);
imp.getProcessor().resetMinAndMax();
} else {
ImageProcessor ip= new FloatProcessor(width,height);
ip.setPixels(rbg_in[0]);
ip.resetMinAndMax();
imp = new ImagePlus(name+suffix, ip);
}
return imp;
}
String [] rgb_titles = {"red","green","blue"};
String [] rgba_titles = {"red","green","blue","alpha"};
String [] titles = (alpha_pixels == null) ? rgb_titles : rgba_titles;
int num_slices = (alpha_pixels == null) ? 3 : 4;
double mn = minmax[0]; // colorProcParameters.lwir_low;
double mx = minmax[1]; // colorProcParameters.lwir_high;
ThermalColor tc = new ThermalColor(
lwir_palette, // colorProcParameters.lwir_palette,
mn,
mx,
255.0);
double [][] rgba = new double [num_slices][];
for (int i = 0; i < 3; i++) rgba[i] = new double [texture_data[main_color_index].length];
for (int i = 0; i < rbg_in[main_color_index].length; i++) {
if (i==160000) {
System.out.println ("i="+i);
}
double [] rgb = tc.getRGB(texture_data[main_color_index][i]);
rgba[0][i] = rgb[0]; // red
rgba[1][i] = rgb[1]; // green
rgba[2][i] = rgb[2]; // blue
}
if (alpha_pixels != null) {
rgba[3] = alpha_pixels; // 0..1
}
ImageStack stack = ShowDoubleFloatArrays.makeStack(
rgba, // iclt_data,
width, // (tilesX + 0) * clt_parameters.transform_size,
height, // (tilesY + 0) * clt_parameters.transform_size,
titles, // or use null to get chn-nn slice names
true); // replace NaN with 0.0
ImagePlus imp_rgba = EyesisCorrections.convertRGBAFloatToRGBA32(
stack, // ImageStack stackFloat, //r,g,b,a
// name+"ARGB"+suffix, // String title,
name+suffix, // 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)
return imp_rgba;
double [][] rbg_in = is_mono? new double [][] {texture_data[0]} : new double[][] {texture_data[0],texture_data[1],texture_data[2]};
double [] alpha_pixels = null; // (0..1.0)
if (texture_data.length > rbg_in.length) {
alpha_pixels = texture_data[rbg_in.length];
} else {
alpha_pixels = new double[texture_data[0].length];
for (int i = 0; i < alpha_pixels.length; i++) {
alpha_pixels[i] = Double.isNaN(rbg_in[0][i]) ? 0.0 : 1.0;
}
}
if (!toRGB) { // Double [][] uses
ImagePlus imp;
if (alpha_pixels != null) {
String [] titles = {"Y","alpha"};
ImageStack stack = ShowDoubleFloatArrays.makeStack(
new double[][] {rbg_in[0],alpha_pixels}, // iclt_data,
width, // (tilesX + 0) * clt_parameters.transform_size,
height, // (tilesY + 0) * clt_parameters.transform_size,
titles, // or use null to get chn-nn slice names
true); // replace NaN with 0.0
imp = new ImagePlus(name+suffix, stack);
imp.getProcessor().resetMinAndMax();
} else {
ImageProcessor ip= new FloatProcessor(width,height);
ip.setPixels(rbg_in[0]);
ip.resetMinAndMax();
imp = new ImagePlus(name+suffix, ip);
}
return imp;
}
String [] rgb_titles = {"red","green","blue"};
String [] rgba_titles = {"red","green","blue","alpha"};
String [] titles = (alpha_pixels == null) ? rgb_titles : rgba_titles;
int num_slices = (alpha_pixels == null) ? 3 : 4;
if (minmax == null) {
minmax = new double [] {Double.NaN, Double.NaN};
for (int i = 0; i < rbg_in[0].length; i++) if (!Double.isNaN(rbg_in[0][i])){
if (!(rbg_in[0][i] >= minmax[0])) minmax[0] = rbg_in[0][i];
if (!(rbg_in[0][i] <= minmax[1])) minmax[1] = rbg_in[0][i];
}
}
double mn = minmax[0]; // colorProcParameters.lwir_low;
double mx = minmax[1]; // colorProcParameters.lwir_high;
ThermalColor tc = new ThermalColor(
lwir_palette, // colorProcParameters.lwir_palette,
mn,
mx,
255.0);
double [][] rgba = new double [num_slices][];
for (int i = 0; i < 3; i++) rgba[i] = new double [texture_data[main_color_index].length];
for (int i = 0; i < rbg_in[main_color_index].length; i++) {
if (i==160000) {
System.out.println ("i="+i);
}
double [] rgb = tc.getRGB(texture_data[main_color_index][i]);
rgba[0][i] = rgb[0]; // red
rgba[1][i] = rgb[1]; // green
rgba[2][i] = rgb[2]; // blue
}
if (alpha_pixels != null) {
rgba[3] = alpha_pixels; // 0..1
}
ImageStack stack = ShowDoubleFloatArrays.makeStack(
rgba, // iclt_data,
width, // (tilesX + 0) * clt_parameters.transform_size,
height, // (tilesY + 0) * clt_parameters.transform_size,
titles, // or use null to get chn-nn slice names
true); // replace NaN with 0.0
ImagePlus imp_rgba = EyesisCorrections.convertRGBAFloatToRGBA32(
stack, // ImageStack stackFloat, //r,g,b,a
// name+"ARGB"+suffix, // String title,
name+suffix, // 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)
return imp_rgba;
}
......@@ -16328,7 +16338,8 @@ public class QuadCLTCPU {
width, // int width, // int tilesX,
height, // int height, // int tilesY,
debugLevel); // int debugLevel )
String preview_path = model_dir + Prefs.getFileSeparator() + title+".jpeg";
int jpeg_q = correctionsParameters.JPEG_quality;
String preview_path = model_dir + Prefs.getFileSeparator() + title+((jpeg_q==0)? ".tiff":".jpeg");
if (new File(preview_path).exists() && !correctionsParameters.thumb_overwrite) {
System.out.println("file "+preview_path+" exists, skipping preview generation");
return false;
......@@ -16341,7 +16352,7 @@ public class QuadCLTCPU {
model_dir,
false,
false,
correctionsParameters.JPEG_quality, // jpegQuality); // jpegQuality){// <0 - keep current, 0 - force Tiff, >0 use for JPEG
jpeg_q, // jpegQuality); // jpegQuality){// <0 - keep current, 0 - force Tiff, >0 use for JPEG
(debugLevel > -2) ? debugLevel : 1); // int debugLevel (print what it saves)
return true;
}
......
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