Commit 3f9c52b0 authored by Andrey Filippov's avatar Andrey Filippov

merged with lwir

parents 13959a97 047fdb5e
...@@ -55,6 +55,8 @@ import org.w3c.dom.NodeList; ...@@ -55,6 +55,8 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.elphel.imagej.readers.ImagejJp4Tiff;
import ij.IJ; import ij.IJ;
import ij.ImageJ; import ij.ImageJ;
import ij.ImagePlus; import ij.ImagePlus;
...@@ -69,6 +71,7 @@ import ij.plugin.frame.PlugInFrame; ...@@ -69,6 +71,7 @@ import ij.plugin.frame.PlugInFrame;
import ij.process.ImageConverter; import ij.process.ImageConverter;
import ij.process.ImageProcessor; import ij.process.ImageProcessor;
import ij.text.TextWindow; import ij.text.TextWindow;
import loci.formats.FormatException;
...@@ -87,6 +90,8 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener { ...@@ -87,6 +90,8 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
static File dir; static File dir;
ImagejJp4Tiff imagejJp4Tiff = new ImagejJp4Tiff();
public String camera_url = "http://192.168.0.236:8081/"; public String camera_url = "http://192.168.0.236:8081/";
public String camera_img = "bimg"; public String camera_img = "bimg";
public String camera_img_new = "towp/wait/bimg"; // will always wait for the next image (repetitive acquisitions get new images) public String camera_img_new = "towp/wait/bimg"; // will always wait for the next image (repetitive acquisitions get new images)
...@@ -109,8 +114,9 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener { ...@@ -109,8 +114,9 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
panel1 = new Panel(); panel1 = new Panel();
panel1.setLayout(new GridLayout(6, 1, 50, 5)); panel1.setLayout(new GridLayout(8, 1, 50, 5));
addButton("Open JP4/Tiff...",panel1);
addButton("Open JP4/JP46...",panel1); addButton("Open JP4/JP46...",panel1);
addButton("Open JP4/JP46 from camera",panel1); addButton("Open JP4/JP46 from camera",panel1);
addButton("Configure...",panel1); addButton("Configure...",panel1);
...@@ -137,8 +143,8 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener { ...@@ -137,8 +143,8 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
panel1 = new Panel(); panel1 = new Panel();
panel1.setLayout(new GridLayout(6, 1, 50, 5)); panel1.setLayout(new GridLayout(8, 1, 50, 5));
addButton("Open JP4/Tiff...",panel1);
addButton("Open JP4/JP46...",panel1); addButton("Open JP4/JP46...",panel1);
addButton("Open JP4/JP46 from camera",panel1); addButton("Open JP4/JP46 from camera",panel1);
addButton("Configure...",panel1); addButton("Configure...",panel1);
...@@ -169,7 +175,11 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener { ...@@ -169,7 +175,11 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
if (label==null) return; if (label==null) return;
/* button */ /* button */
if (label.equals("Open JP4/JP46...")) { if (label.equals("Open JP4/Tiff...")) {
read_jp4Tiff(arg,true);
}else if (label.equals("Open JP4/Tiff (no scale)...")) {
read_jp4Tiff(arg,false);
}else if (label.equals("Open JP4/JP46...")) {
read_jp46(arg,true); read_jp46(arg,true);
}else if (label.equals("Open JP4/JP46 (no scale)...")) { }else if (label.equals("Open JP4/JP46 (no scale)...")) {
read_jp46(arg,false); read_jp46(arg,false);
...@@ -227,7 +237,54 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener { ...@@ -227,7 +237,54 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
imp_stack.getProcessor().resetMinAndMax(); imp_stack.getProcessor().resetMinAndMax();
imp_stack.show(); imp_stack.show();
} }
public void read_jp4Tiff(String arg, // not used?
boolean scale) {
String LOG_LEVEL = ABSOLUTELY_SILENT? "OFF" : (IS_SILENT?"ERROR":"INFO");
boolean LOG_LEVEL_SET = loci.common.DebugTools.enableLogging(LOG_LEVEL);
if (!LOG_LEVEL_SET) { // only first time true
loci.common.DebugTools.setRootLevel(LOG_LEVEL);
}
JFileChooser fc=null;
//try {fc = new JFileChooser();}
fc = new JFileChooser();
//catch (Throwable e) {IJ.error("This plugin requires Java 2 or Swing."); return;}
fc.setMultiSelectionEnabled(true);
if (dir==null) {
String sdir = OpenDialog.getDefaultDirectory();
if (sdir!=null)
dir = new File(sdir);
}
if (dir!=null)
fc.setCurrentDirectory(dir);
int returnVal = fc.showOpenDialog(IJ.getInstance());
if (returnVal!=JFileChooser.APPROVE_OPTION)
return;
File[] files = fc.getSelectedFiles();
if (files.length==0) { // getSelectedFiles does not work on some JVMs
files = new File[1];
files[0] = fc.getSelectedFile();
}
String path = fc.getCurrentDirectory().getPath()+Prefs.getFileSeparator();
dir = fc.getCurrentDirectory();
for (int i=0; i<files.length; i++) {
try {
ImagePlus imp = imagejJp4Tiff.readTiffJp4(path + files[i].getName(), scale);
// imp.updateAndDraw();
imp.show();
} catch (IOException | FormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // throws IOException, FormatException { // std - include non-elphel properties with prefix std
// open(path, files[i].getName(), arg, scale);
}
}
public void read_jp46(String arg, boolean scale) { public void read_jp46(String arg, boolean scale) {
JFileChooser fc=null; JFileChooser fc=null;
//try {fc = new JFileChooser();} //try {fc = new JFileChooser();}
...@@ -274,6 +331,7 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener { ...@@ -274,6 +331,7 @@ public class JP46_Reader_camera0 extends PlugInFrame implements ActionListener {
confpanel = new Panel(); confpanel = new Panel();
gd.addPanel(confpanel); gd.addPanel(confpanel);
addButton("Open JP4/Tiff (no scale)...", confpanel);
addButton("Open JP4/JP46 (no scale)...", confpanel); addButton("Open JP4/JP46 (no scale)...", confpanel);
addButton("Open JP4/JP46 from camera (no scale)", confpanel); addButton("Open JP4/JP46 from camera (no scale)", confpanel);
...@@ -1413,9 +1471,13 @@ Exception in thread "Thread-3564" java.lang.ArrayIndexOutOfBoundsException: 8970 ...@@ -1413,9 +1471,13 @@ Exception in thread "Thread-3564" java.lang.ArrayIndexOutOfBoundsException: 8970
NodeList allNodes=doc.getDocumentElement().getElementsByTagName("*"); NodeList allNodes=doc.getDocumentElement().getElementsByTagName("*");
for (int i=0;i<allNodes.getLength();i++) { for (int i=0;i<allNodes.getLength();i++) {
String name= allNodes.item(i).getNodeName(); String name= allNodes.item(i).getNodeName();
String value=allNodes.item(i).getFirstChild().getNodeValue(); String value="";
imp.setProperty(name, value); try {
value=allNodes.item(i).getFirstChild().getNodeValue();
} catch(Exception e) {
}
imp.setProperty(name, value);
} }
return true; return true;
......
...@@ -6,7 +6,7 @@ package com.elphel.imagej.calibration; ...@@ -6,7 +6,7 @@ package com.elphel.imagej.calibration;
** Copyright (C) 2011-2014 Elphel, Inc. ** Copyright (C) 2011-2014 Elphel, Inc.
** **
** -----------------------------------------------------------------------------** ** -----------------------------------------------------------------------------**
** **
** DistortionProcessConfiguration.java is free software: you can redistribute it and/or modify ** DistortionProcessConfiguration.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by ** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or ** the Free Software Foundation, either version 3 of the License, or
...@@ -23,16 +23,17 @@ package com.elphel.imagej.calibration; ...@@ -23,16 +23,17 @@ package com.elphel.imagej.calibration;
** **
*/ */
import ij.IJ;
import ij.Prefs;
import ij.gui.GenericDialog;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.util.Properties; import java.util.Properties;
import com.elphel.imagej.common.WindowTools; import com.elphel.imagej.common.WindowTools;
import ij.IJ;
import ij.Prefs;
import ij.gui.GenericDialog;
public class DistortionProcessConfiguration{ public class DistortionProcessConfiguration{
public String sourceDirectory=""; public String sourceDirectory="";
public String gridDirectory= ""; public String gridDirectory= "";
...@@ -50,7 +51,7 @@ import com.elphel.imagej.common.WindowTools; ...@@ -50,7 +51,7 @@ import com.elphel.imagej.common.WindowTools;
public String selectSourceDirectory(boolean smart, String defaultPath, boolean newAllowed) { public String selectSourceDirectory(boolean smart, String defaultPath, boolean newAllowed) {
String dir= CalibrationFileManagement.selectDirectory( String dir= CalibrationFileManagement.selectDirectory(
smart, smart,
newAllowed, // save newAllowed, // save
"Source (acquired from the camera) image directory", // title "Source (acquired from the camera) image directory", // title
"Select source directory", // button "Select source directory", // button
null, // filter null, // filter
...@@ -61,7 +62,7 @@ import com.elphel.imagej.common.WindowTools; ...@@ -61,7 +62,7 @@ import com.elphel.imagej.common.WindowTools;
public String selectGridFileDirectory(boolean smart, String defaultPath, boolean newAllowed) { public String selectGridFileDirectory(boolean smart, String defaultPath, boolean newAllowed) {
String dir= CalibrationFileManagement.selectDirectory( String dir= CalibrationFileManagement.selectDirectory(
smart, smart,
newAllowed, // save newAllowed, // save
"Grid files directory (grid patterns extracted from the images)", // title "Grid files directory (grid patterns extracted from the images)", // title
"Select grid files directory", // button "Select grid files directory", // button
null, // filter null, // filter
...@@ -69,7 +70,7 @@ import com.elphel.imagej.common.WindowTools; ...@@ -69,7 +70,7 @@ import com.elphel.imagej.common.WindowTools;
if (dir!=null) this.gridDirectory=dir; if (dir!=null) this.gridDirectory=dir;
return dir; return dir;
} }
public void setProperties(String prefix,Properties properties){ public void setProperties(String prefix,Properties properties){
properties.setProperty(prefix+"sourceDirectory", this.sourceDirectory); properties.setProperty(prefix+"sourceDirectory", this.sourceDirectory);
properties.setProperty(prefix+"gridDirectory", this.gridDirectory); properties.setProperty(prefix+"gridDirectory", this.gridDirectory);
...@@ -123,9 +124,9 @@ import com.elphel.imagej.common.WindowTools; ...@@ -123,9 +124,9 @@ import com.elphel.imagej.common.WindowTools;
gd.addCheckbox ("Show grid files as images", this.showGridImages); gd.addCheckbox ("Show grid files as images", this.showGridImages);
gd.addCheckbox ("Save grid files", this.saveGridImages); gd.addCheckbox ("Save grid files", this.saveGridImages);
gd.addCheckbox ("Overwrite existing result files", this.overwriteResultFiles); gd.addCheckbox ("Overwrite existing result files", this.overwriteResultFiles);
gd.addNumericField("Debug level", this.debugLevel,0); gd.addNumericField("Debug level", this.debugLevel,0);
WindowTools.addScrollBars(gd); WindowTools.addScrollBars(gd);
gd.showDialog(); gd.showDialog();
...@@ -144,7 +145,7 @@ import com.elphel.imagej.common.WindowTools; ...@@ -144,7 +145,7 @@ import com.elphel.imagej.common.WindowTools;
this.debugLevel= (int) gd.getNextNumber(); this.debugLevel= (int) gd.getNextNumber();
System.out.println("1.newSourceDirectory = "+newSourceDirectory); System.out.println("1.newSourceDirectory = "+newSourceDirectory);
System.out.println("1.newGridDirectory = "+ newGridDirectory); System.out.println("1.newGridDirectory = "+ newGridDirectory);
if ((newSourceDirectory.length()==0) || (newSourceDirectory.indexOf('?')>=0)) if ((newSourceDirectory.length()==0) || (newSourceDirectory.indexOf('?')>=0))
newSourceDirectory= selectSourceDirectory(false, this.sourceDirectory, true); newSourceDirectory= selectSourceDirectory(false, this.sourceDirectory, true);
else else
newSourceDirectory= selectSourceDirectory(true, newSourceDirectory, true); // if matches, no dialog newSourceDirectory= selectSourceDirectory(true, newSourceDirectory, true); // if matches, no dialog
...@@ -174,7 +175,7 @@ import com.elphel.imagej.common.WindowTools; ...@@ -174,7 +175,7 @@ import com.elphel.imagej.common.WindowTools;
if (this.sourceDirectory.length()==0){ if (this.sourceDirectory.length()==0){
defaultPaths[0]=""; defaultPaths[0]="";
} }
CalibrationFileManagement.MultipleExtensionsFileFilter sourceFilter = CalibrationFileManagement.MultipleExtensionsFileFilter sourceFilter =
new CalibrationFileManagement.MultipleExtensionsFileFilter("",extensions,"Source files"); new CalibrationFileManagement.MultipleExtensionsFileFilter("",extensions,"Source files");
String [] sourceFiles=null; String [] sourceFiles=null;
...@@ -206,5 +207,26 @@ import com.elphel.imagej.common.WindowTools; ...@@ -206,5 +207,26 @@ import com.elphel.imagej.common.WindowTools;
} }
return sourceFiles; return sourceFiles;
} }
public String[] selectSourceSets() {
File dir= new File (this.sourceDirectory);
if (this.debugLevel>1) System.out.println("selectSourceSets, dir="+this.sourceDirectory);
if (!dir.exists()) {
String error="Source directory "+this.sourceDirectory+" does not exist.";
IJ.showMessage("No files selected");
if (this.debugLevel>1) System.out.println("selectSourceFiles() ERROR:"+error);
return null;
}
File [] sourceFileSets = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File current, String name) {
return new File(current, name).isDirectory();
}
});
String [] sourceSets = new String[sourceFileSets.length];
for (int i=0;i<sourceSets.length;i++) sourceSets[i]=sourceFileSets[i].getPath();
return sourceSets;
}
} }
...@@ -665,9 +665,12 @@ horizontal axis: ...@@ -665,9 +665,12 @@ horizontal axis:
boolean noMessageBoxes=true; boolean noMessageBoxes=true;
int numAbsolutePoints = matchSimulatedPattern.calculateDistortions( int numAbsolutePoints = matchSimulatedPattern.calculateDistortions(
null, // LwirReaderParameters lwirReaderParameters, // null is OK
// allow more of grid around pointers? // allow more of grid around pointers?
distortionParameters, // distortionParameters, //
this.patternDetectParameters, this.patternDetectParameters,
// this.patternDetectParameters.minGridPeriod/2,
// this.patternDetectParameters.maxGridPeriod/2,
simulParameters, simulParameters,
equalizeGreens, imp_eq, equalizeGreens, imp_eq,
this.laserPointers, // null, //LASER_POINTERS, // this.laserPointers, // null, //LASER_POINTERS, //
...@@ -838,23 +841,26 @@ horizontal axis: ...@@ -838,23 +841,26 @@ horizontal axis:
// matchSimulatedPatterns[numSensor].getChannel(images[numSensor])+" "); // matchSimulatedPatterns[numSensor].getChannel(images[numSensor])+" ");
int numAbsolutePoints = this.matchSimulatedPatterns[numSensor].calculateDistortions( int numAbsolutePoints = this.matchSimulatedPatterns[numSensor].calculateDistortions(
// allow more of grid around pointers? null, // LwirReaderParameters lwirReaderParameters, // null is OK
distortionParameters, // // allow more of grid around pointers?
this.patternDetectParameters, distortionParameters, //
simulParameters, this.patternDetectParameters,
equalizeGreens, imp_eq, // this.patternDetectParameters.minGridPeriod/2,
this.laserPointers, // null, //LASER_POINTERS, // // this.patternDetectParameters.maxGridPeriod/2,
// LaserPointer laserPointer, // simulParameters,
// LaserPointer object or null equalizeGreens, imp_eq,
true, // don't care -removeOutOfGridPointers this.laserPointers, // null, //LASER_POINTERS, //
null, // double [][][] hintGrid, // predicted grid array (or null) // LaserPointer laserPointer, //
0, // double hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only // LaserPointer object or null
true, // don't care -removeOutOfGridPointers
threadsMax, null, // double [][][] hintGrid, // predicted grid array (or null)
updateStatus, 0, // double hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
debug_level,
distortionParameters.loop_debug_level, // debug level threadsMax,
noMessageBoxes); updateStatus,
debug_level,
distortionParameters.loop_debug_level, // debug level
noMessageBoxes);
if (numAbsolutePoints <= 0) { // no pointers in this image if (numAbsolutePoints <= 0) { // no pointers in this image
String msg = "*** No laser pointers matched for " + images[numSensor].getTitle() + " - they are needed for absolute grid positioning"; String msg = "*** No laser pointers matched for " + images[numSensor].getTitle() + " - they are needed for absolute grid positioning";
if (debug_level > 0) System.out.println("Warning: " + msg); if (debug_level > 0) System.out.println("Warning: " + msg);
......
...@@ -112,6 +112,30 @@ import ij.process.ImageProcessor; ...@@ -112,6 +112,30 @@ import ij.process.ImageProcessor;
return; return;
} else showArrays(pixels, width, height, titles); } else showArrays(pixels, width, height, titles);
} }
public void showComplex(double[][][] cpixels, String title) {
int height = cpixels.length;
int width = cpixels[0].length;
double [][]pixels = new double [height*width][];
int indx = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
pixels[indx++] = cpixels[y][x];
}
}
showComplex(pixels, width, title);
}
public void showComplex(double[][] cpixels, int width, String title) {
int height = cpixels.length/width;
double [][]pixels = new double [2][cpixels.length];
for (int i = 0; i< cpixels.length; i++) {
pixels[0][i]= cpixels[i][0];
pixels[1][i]= cpixels[i][1];
}
String [] titles = {"Re", "Im"};
showArrays(pixels, width, height, true, title, titles);
}
public void showArrays(float[][] pixels, int width, int height, boolean asStack, String title, String [] titles) { public void showArrays(float[][] pixels, int width, int height, boolean asStack, String title, String [] titles) {
int i,j; int i,j;
......
...@@ -1358,7 +1358,11 @@ Exception in thread "Thread-3564" java.lang.ArrayIndexOutOfBoundsException: 8970 ...@@ -1358,7 +1358,11 @@ Exception in thread "Thread-3564" java.lang.ArrayIndexOutOfBoundsException: 8970
itr=set.iterator(); itr=set.iterator();
while(itr.hasNext()) { while(itr.hasNext()) {
str = (String) itr.next(); str = (String) itr.next();
imp_dst.setProperty(str,prop.getProperty(str)); try {
imp_dst.setProperty(str,prop.getProperty(str));
} catch (Exception e) {
imp_dst.setProperty(str,"");
}
} }
} }
} }
...@@ -1407,7 +1411,12 @@ Exception in thread "Thread-3564" java.lang.ArrayIndexOutOfBoundsException: 8970 ...@@ -1407,7 +1411,12 @@ Exception in thread "Thread-3564" java.lang.ArrayIndexOutOfBoundsException: 8970
NodeList allNodes=doc.getDocumentElement().getElementsByTagName("*"); NodeList allNodes=doc.getDocumentElement().getElementsByTagName("*");
for (int i=0;i<allNodes.getLength();i++) { for (int i=0;i<allNodes.getLength();i++) {
String name= allNodes.item(i).getNodeName(); String name= allNodes.item(i).getNodeName();
String value=allNodes.item(i).getFirstChild().getNodeValue(); String value="";
try {
value=allNodes.item(i).getFirstChild().getNodeValue();
} catch(Exception e) {
}
imp.setProperty(name, value); imp.setProperty(name, value);
} }
......
...@@ -640,7 +640,7 @@ the type of pixel data in this file getPixelType() ...@@ -640,7 +640,7 @@ the type of pixel data in this file getPixelType()
} }
// copied from JP46_Reader_camera.java // copied from JP46_Reader_camera.java
public ImagePlus encodeProperiesToInfo(ImagePlus imp){ public static ImagePlus encodeProperiesToInfo(ImagePlus imp){
String info="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties>"; String info="<?xml version=\"1.0\" encoding=\"UTF-8\"?><properties>";
Set<Object> jp4_set; Set<Object> jp4_set;
Properties jp4_prop; Properties jp4_prop;
...@@ -661,7 +661,7 @@ the type of pixel data in this file getPixelType() ...@@ -661,7 +661,7 @@ the type of pixel data in this file getPixelType()
return imp; return imp;
} }
public boolean decodeProperiesFromInfo(ImagePlus imp){ public static boolean decodeProperiesFromInfo(ImagePlus imp){
if (imp.getProperty("Info")==null) return false; if (imp.getProperty("Info")==null) return false;
String xml= (String) imp.getProperty("Info"); String xml= (String) imp.getProperty("Info");
...@@ -684,11 +684,15 @@ the type of pixel data in this file getPixelType() ...@@ -684,11 +684,15 @@ the type of pixel data in this file getPixelType()
NodeList allNodes=doc.getDocumentElement().getElementsByTagName("*"); NodeList allNodes=doc.getDocumentElement().getElementsByTagName("*");
for (int i=0;i<allNodes.getLength();i++) { for (int i=0;i<allNodes.getLength();i++) {
String name= allNodes.item(i).getNodeName(); String name= allNodes.item(i).getNodeName();
String value=allNodes.item(i).getFirstChild().getNodeValue(); // System.out.print(name+" -> ");
imp.setProperty(name, value); String value = "";
try {
value=allNodes.item(i).getFirstChild().getNodeValue();
} catch (Exception e) {
}
// System.out.println(value);
imp.setProperty(name, value);
} }
return true; 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