Commit 24a92f5c authored by Andrey Filippov's avatar Andrey Filippov

Testing DATI

parent b3e9f364
...@@ -27,6 +27,7 @@ import com.elphel.imagej.common.ShowDoubleFloatArrays; ...@@ -27,6 +27,7 @@ import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.gpu.TpTask; import com.elphel.imagej.gpu.TpTask;
import com.elphel.imagej.ims.Imx5; import com.elphel.imagej.ims.Imx5;
import com.elphel.imagej.readers.ElphelTiffReader; import com.elphel.imagej.readers.ElphelTiffReader;
import com.elphel.imagej.readers.ImagejJp4Tiff;
import com.elphel.imagej.tileprocessor.ImageDtt; import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.IntersceneMatchParameters; import com.elphel.imagej.tileprocessor.IntersceneMatchParameters;
import com.elphel.imagej.tileprocessor.QuadCLT; import com.elphel.imagej.tileprocessor.QuadCLT;
...@@ -41,6 +42,7 @@ import ij.plugin.filter.GaussianBlur; ...@@ -41,6 +42,7 @@ import ij.plugin.filter.GaussianBlur;
import ij.process.FloatProcessor; import ij.process.FloatProcessor;
import ij.process.ImageConverter; import ij.process.ImageConverter;
import ij.process.ImageProcessor; import ij.process.ImageProcessor;
import loci.formats.FormatException;
public class OrthoMap implements Comparable <OrthoMap>, Serializable{ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -55,6 +57,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -55,6 +57,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
public transient String name; // timestamp public transient String name; // timestamp
public transient double ts; public transient double ts;
public transient String path; // full path to the model directory (including /vXX?) public transient String path; // full path to the model directory (including /vXX?)
public transient String scenes_path; // full path to the model directory (including /vXX?)
public double [] lla; // lat/long/alt public double [] lla; // lat/long/alt
public LocalDateTime dt; public LocalDateTime dt;
// affine convert (input) rectified coordinates (meters) relative to vert_meters to source image // affine convert (input) rectified coordinates (meters) relative to vert_meters to source image
...@@ -69,6 +72,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -69,6 +72,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
public int orig_zoom_level; public int orig_zoom_level;
public boolean orig_zoom_valid; public boolean orig_zoom_valid;
public double need_extra_zoom; public double need_extra_zoom;
public double averageRawPixel = Double.NaN; // measure of scene temperature
public transient double averageImagePixel = Double.NaN; // average image pixel value (to combine with raw)
transient HashMap <Integer, FloatImageData> images; transient HashMap <Integer, FloatImageData> images;
HashMap <Double, PairwiseOrthoMatch> pairwise_matches; HashMap <Double, PairwiseOrthoMatch> pairwise_matches;
...@@ -76,6 +81,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -76,6 +81,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
private void writeObject(ObjectOutputStream oos) throws IOException { private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject(); oos.defaultWriteObject();
oos.writeObject(path); oos.writeObject(path);
oos.writeObject(scenes_path);
// lla is not transient // lla is not transient
// dt is not transient // dt is not transient
// affine is not transient // affine is not transient
...@@ -97,6 +103,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -97,6 +103,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
path = (String) ois.readObject(); path = (String) ois.readObject();
name = getNameFromPath(path); name = getNameFromPath(path);
ts= Double.parseDouble(name.replace("_", ".")); ts= Double.parseDouble(name.replace("_", "."));
scenes_path= (String) ois.readObject();
// lla is not transient // lla is not transient
// dt is not transient // dt is not transient
// affine is not transient // affine is not transient
...@@ -107,6 +114,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -107,6 +114,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
// orig_image was not saved // orig_image was not saved
// alt_image was not saved // alt_image was not saved
images = new HashMap <Integer, FloatImageData>(); // field images was not saved images = new HashMap <Integer, FloatImageData>(); // field images was not saved
averageImagePixel = Double.NaN; // average image pixel value (to combine with raw)
// pairwise_matches is not transient // pairwise_matches is not transient
// pairwise_matches = new HashMap<Double, PairwiseOrthoMatch>(); // pairwise_matches = new HashMap<Double, PairwiseOrthoMatch>();
} }
...@@ -129,11 +138,14 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -129,11 +138,14 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
public int getHeight() { public int getHeight() {
return orig_height; return orig_height;
} }
public int getOriginalZoomLevel() {
return orig_zoom_level;
}
// Generate ALT image path from the GEO // Generate ALT image path from the GEO
public static String getAltPath(String path) { public static String getAltPath(String path) {
int p1 = path.lastIndexOf("."); int p1 = path.lastIndexOf(".");
return path.substring(0,p1)+ALT_SUFFIX+".tiff"; return path.substring(0,p1)+ALT_SUFFIX+".tiff";
} }
public static String getNameFromPath(String path) { public static String getNameFromPath(String path) {
int p1 = path.lastIndexOf(Prefs.getFileSeparator()); int p1 = path.lastIndexOf(Prefs.getFileSeparator());
...@@ -143,8 +155,65 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -143,8 +155,65 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
return path.substring(p1+1, p2); return path.substring(p1+1, p2);
} }
public OrthoMap (String path) { /**
* Gets average pixel value of all sensors of the reference scene
* @return
*/
public double getTemperature() {
if (Double.isNaN(averageRawPixel)) {
final String TIFF_EXT=".tiff";
final File [] raw_files = (new File(scenes_path)).listFiles();
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger ati = new AtomicInteger(0);
final double [] avg_arr = new double [threads.length];
final double [] npix_arr = new double [threads.length];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int thread_num = ati.getAndIncrement();
ImagejJp4Tiff imagejJp4Tiff = new ImagejJp4Tiff();
for (int iFile = ai.getAndIncrement(); iFile < raw_files.length; iFile = ai.getAndIncrement()) {
if (raw_files[iFile].getName().endsWith(TIFF_EXT)) {
ImagePlus imp = null;
String spath = raw_files[iFile].toString();
try {
imp= imagejJp4Tiff.readTiffJp4(spath);
} catch (IOException e) {
System.out.println("getImagesMultithreaded IOException " + spath);
} catch (FormatException e) {
System.out.println("getImagesMultithreaded FormatException " + spath);
}
if (imp != null) {
npix_arr[thread_num] = imp.getWidth()*imp.getHeight();
float [] fpixels = (float[]) imp.getProcessor().getPixels();
for (int i = 0; i < fpixels.length; i++) {
avg_arr[thread_num] += fpixels[i];
}
avg_arr[thread_num] /= npix_arr[thread_num];
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
double avg=0, num=0;
for (int i = 0; i < avg_arr.length; i++) {
avg+=avg_arr[i]*npix_arr[i];
num+=npix_arr[i];
}
averageRawPixel = avg/num;
}
return averageRawPixel;
}
public OrthoMap (
String path,
String scenes_path) {
this.path = path; this.path = path;
this.scenes_path = scenes_path;
name = getNameFromPath(path); name = getNameFromPath(path);
ts= Double.parseDouble(name.replace("_", ".")); ts= Double.parseDouble(name.replace("_", "."));
Properties imp_prop = null; Properties imp_prop = null;
...@@ -171,6 +240,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -171,6 +240,8 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
need_extra_zoom = FloatImageData.needZoomIn(orig_pix_meters); need_extra_zoom = FloatImageData.needZoomIn(orig_pix_meters);
images = new HashMap <Integer, FloatImageData>(); images = new HashMap <Integer, FloatImageData>();
pairwise_matches = new HashMap<Double, PairwiseOrthoMatch>(); pairwise_matches = new HashMap<Double, PairwiseOrthoMatch>();
averageRawPixel = Double.NaN; // measure of scene temperature
averageImagePixel = Double.NaN; // average image pixel value (to combine with raw)
} }
...@@ -221,6 +292,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -221,6 +292,7 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
if (orig_image == null) { if (orig_image == null) {
readImageData(); readImageData();
} }
getAveragePixel();
return orig_image; return orig_image;
} }
public FloatImageData getAltData() { public FloatImageData getAltData() {
...@@ -246,9 +318,47 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -246,9 +318,47 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
if (orig_zoom_valid) { if (orig_zoom_valid) {
images.put(orig_zoom_level, orig_image); images.put(orig_zoom_level, orig_image);
} }
averageImagePixel = Double.NaN;
return true; return true;
} }
public double getAveragePixel() {
if (Double.isNaN(averageImagePixel)) {
if (orig_image == null) {
readImageData();
}
final float [] pixels = orig_image.data;
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(0);
final AtomicInteger ati = new AtomicInteger(0);
final double [] avg_arr = new double [threads.length];
final double [] npix_arr = new double [threads.length];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
int thread_num = ati.getAndIncrement();
for (int ipix = ai.getAndIncrement(); ipix < pixels.length; ipix = ai.getAndIncrement()) {
float p = pixels[ipix];
if (!Float.isNaN(p)) {
avg_arr[thread_num] += p;
npix_arr[thread_num] +=1;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
double avg=0, num=0;
for (int i = 0; i < avg_arr.length; i++) {
avg+=avg_arr[i]; // *npix_arr[i];
num+=npix_arr[i];
}
averageImagePixel = avg/num;
}
return averageImagePixel;
}
private boolean readAltData() { // assuming the same scale as main image private boolean readAltData() { // assuming the same scale as main image
ImagePlus imp = new ImagePlus(getAltPath(path)); ImagePlus imp = new ImagePlus(getAltPath(path));
int width = imp.getWidth(); int width = imp.getWidth();
......
...@@ -1101,6 +1101,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1101,6 +1101,7 @@ public class ImageDtt extends ImageDttCPU {
public void interRectilinearCorrTD( public void interRectilinearCorrTD(
final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others final ImageDttParameters imgdtt_params, // Now just extra correlation parameters, later will include, most others
final boolean batch_mode,
final int erase_clt, final int erase_clt,
final float [] fpixels, final float [] fpixels,
final int [] wh, // null (use sensor dimensions) or pair {width, height} in pixels final int [] wh, // null (use sensor dimensions) or pair {width, height} in pixels
...@@ -1136,27 +1137,27 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1136,27 +1137,27 @@ public class ImageDtt extends ImageDttCPU {
}; };
gpuQuad.setLpfRbg( // constants memory - same for all cameras gpuQuad.setLpfRbg( // constants memory - same for all cameras
lpf_rgb, lpf_rgb,
globalDebugLevel > 2); !batch_mode && (globalDebugLevel > 2));
final float [] lpf_flat = floatGetCltLpfFd(gpu_sigma_corr); final float [] lpf_flat = floatGetCltLpfFd(gpu_sigma_corr);
gpuQuad.setLpfCorr(// constants memory - same for all cameras gpuQuad.setLpfCorr(// constants memory - same for all cameras
"lpf_corr", // String const_name, // "lpf_corr" "lpf_corr", // String const_name, // "lpf_corr"
lpf_flat, lpf_flat,
globalDebugLevel > 2); !batch_mode && (globalDebugLevel > 2));
final float [] lpf_rb_flat = floatGetCltLpfFd(gpu_sigma_rb_corr); final float [] lpf_rb_flat = floatGetCltLpfFd(gpu_sigma_rb_corr);
gpuQuad.setLpfCorr(// constants memory - same for all cameras gpuQuad.setLpfCorr(// constants memory - same for all cameras
"lpf_rb_corr", // String const_name, // "lpf_corr" "lpf_rb_corr", // String const_name, // "lpf_corr"
lpf_rb_flat, lpf_rb_flat,
globalDebugLevel > 2); !batch_mode && (globalDebugLevel > 2));
final float [] log_flat = floatGetCltHpfFd(gpu_sigma_log_corr); final float [] log_flat = floatGetCltHpfFd(gpu_sigma_log_corr);
gpuQuad.setLpfCorr(// constants memory - same for all cameras gpuQuad.setLpfCorr(// constants memory - same for all cameras
"LoG_corr", // String const_name, // "lpf_corr" "LoG_corr", // String const_name, // "lpf_corr"
log_flat, log_flat,
globalDebugLevel > 2); !batch_mode && (globalDebugLevel > 2));
if (globalDebugLevel > 2) { if (!batch_mode && (globalDebugLevel > 2)) {
gpuQuad.printConstMem("lpf_data", true); gpuQuad.printConstMem("lpf_data", true);
gpuQuad.printConstMem("lpf_corr", true); gpuQuad.printConstMem("lpf_corr", true);
gpuQuad.printConstMem("lpf_rb_corr", true); gpuQuad.printConstMem("lpf_rb_corr", true);
...@@ -1176,7 +1177,7 @@ public class ImageDtt extends ImageDttCPU { ...@@ -1176,7 +1177,7 @@ public class ImageDtt extends ImageDttCPU {
use_reference_buffer, use_reference_buffer,
wh, wh,
erase_clt); // put results into a "reference" buffer erase_clt); // put results into a "reference" buffer
if (globalDebugLevel > 2) { if (!batch_mode && (globalDebugLevel > 2)) {
ComboMatch.renderFromTD ( ComboMatch.renderFromTD (
false, // boolean use_reference, false, // boolean use_reference,
"img"); //String suffix "img"); //String suffix
......
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