Commit 90e3e80a authored by Andrey Filippov's avatar Andrey Filippov

Refactoring

parent 5db80b77
......@@ -167,13 +167,22 @@ import ij.process.ImageProcessor;
String [] frame_titles, // frame titles or null
boolean show) {
int num_frames = pixels.length;
int num_slices = pixels[0].length;
int num_slices = 0; // pixels[0].length;
for (int i=0; i < num_frames; i++) {
if (pixels[i] != null) {
num_slices = pixels[i].length;
break;
}
}
if (num_slices == 0) {
return null;
}
double [][] dpixels = new double [num_frames*num_slices][];
for (int f = 0; f < num_frames; f++) {
for (int s = 0; s < num_slices; s ++) {
int indx = s + f * num_slices;
dpixels[indx] = pixels[f][s];
dpixels[indx] = (pixels[f] != null) ? pixels[f][s] : null;
}
}
String [] combo_titles;
......@@ -211,7 +220,7 @@ import ij.process.ImageProcessor;
dpixels, // double[][] pixels,
width, // int width,
height, // int height,
pixels[0].length, // int slices,
num_slices, // int slices,
title, // String title,
combo_titles, // String [] titles);
show); // boolean show
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.elphel.imagej.cuas;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import com.elphel.imagej.tileprocessor.ImageDtt;
......@@ -45,22 +46,65 @@ public class CuasMotionLMA {
public static final int RSLT_RMS = 7;
public static final int RSLT_RMS_A = 8;
public static final int RSLT_MAX2A = 9;
public static final int RSLT_ITERS =10;
public static final int RSLT_FAIL = 11;
public static final int RSLT_ITERS = 10;
public static final int RSLT_CENT_X = 11;
public static final int RSLT_CENT_Y = 12;
public static final int RSLT_CENT_MX= 13;
public static final int RSLT_CENT_F = 14;
public static final int RSLT_VX = 15;
public static final int RSLT_VY = 16;
public static final int RSLT_VSTR = 17;
public static final int RSLT_VFRAC = 18;
public static final int RSLT_BX = 19;
public static final int RSLT_BY = 20; // RSLT_BX+1;
public static final int RSLT_AX = 21; // RSLT_BX+2;
public static final int RSLT_AY = 22; // RSLT_BX+3;
public static final int RSLT_MISMATCH_BEFORE = 23;
public static final int RSLT_MISMATCH_AFTER = 24; // RSLT_MISMATCH_BEFORE+1;
public static final int RSLT_MISMATCH_DIRS= 25;
public static final int RSLT_MSCORE = 26;
public static final int RSLT_QA = 27;
public static final int RSLT_QRMS = 28;
public static final int RSLT_QRMS_A = 29;
public static final int RSLT_QMATCH = 30;
public static final int RSLT_QCENTER = 31;
public static final int RSLT_QSCORE = 32;
public static final int RSLT_WHEN = 33;
public static final int RSLT_FAIL = 34;
public static final int RSLT_LEN = RSLT_FAIL+1;
public static final String [] LMA_TITLES = {"X-OFFS","Y-OFFS", "AMPLITUDE","RADIUS","RAD_POS", "OVERSHOOT","OFFSET","RMSE","RMSE/A","MAX2A","ITERATIONS","FAILURE"};
public static final String [] LMA_TITLES =
{"X-OFFS","Y-OFFS", "AMPLITUDE", "RADIUS","RAD_POS", "OVERSHOOT","OFFSET","RMSE","RMSE/A","MAX2A","ITERATIONS",
"Centr-X","Centr-Y","Centr-max","Centr-frac",
"Vx", "Vy", "V-conf","V-frac", // from motion vectors
"X-before", "Y-before","X-after","Y-after", // from getHalfBeforeAfterPixXY()
"ERR-BEFORE", "ERR-AFTER", "BA-DIRS", // before dir + 16*after dir
"*MOTION-SCORE",
"*Q-AMPL","*Q-RMSE","*Q-RMSE/A","*Q-MATCH","*Q-CENTER","*Q-SCORE",
"WHEN", "FAILURE"};
public static final int FAIL_NONE = 0;
public static final int FAIL_A_LOW = 1; // amplitude is too low
public static final int FAIL_ACENT = 2; // ratio of maximal pixel to amplitude is too low
public static final int FAIL_RMSE = 3; // RMSE is too high
public static final int FAIL_RMSE_R = 4; // BOTH RMSE is not sufficient and RMSE/A is too high
public static final int FAIL_R0_HIGH = 5; // Full radius (including negative overshoot) is too high
public static final int FAIL_R1_LOW = 6; // Inner (positive) peak radius is too low
public static final int FAIL_K_LOW = 7; // Overshoot is too low (not used, it can be down to 0)
public static final int FAIL_K_HIGH = 8; // Overshoot is too high
public static final int FAIL_FAR = 9; // Peak is too far from the center
public static final int FAIL_HORIZON = 10; // Peak is below horizon
public static final int FAIL_CENT_STR = 1; // centroid amplitude is too low
public static final int FAIL_CENT_FRAC = 2; // Centroid fraction (energy in the peak fraction of all) is too low
public static final int FAIL_LMA = 3; // LMA fail to converge
public static final int FAIL_A_LOW = 4; // amplitude is too low
public static final int FAIL_ACENT = 5; // ratio of maximal pixel to amplitude is too low
public static final int FAIL_RMSE = 6; // RMSE is too high
public static final int FAIL_RMSE_R = 7; // BOTH RMSE is not sufficient and RMSE/A is too high
public static final int FAIL_R0_HIGH = 8; // Full radius (including negative overshoot) is too high
public static final int FAIL_R1_LOW = 9; // Inner (positive) peak radius is too low
public static final int FAIL_K_LOW = 10; // Overshoot is too low (not used, it can be down to 0)
public static final int FAIL_K_HIGH = 11; // Overshoot is too high
public static final int FAIL_FAR = 12; // Peak is too far from the center
public static final int FAIL_HORIZON = 13; // Peak is below horizon
public static final int FAIL_MISMATCH = 14; // Mismatch on both ends is too high
private int width;
private double [][] window;
......@@ -194,8 +238,20 @@ public class CuasMotionLMA {
return initial_rms[0];
}
public double [] getResult() {
public static double [] getEmpty() {
double rslt[] = new double [RSLT_LEN];
Arrays.fill(rslt, Double.NaN);
return rslt;
}
public double [] getResult() {
double rslt[] = getEmpty();
setResult(rslt);
return rslt;
}
public void setResult(double [] rslt) {
rslt[RSLT_X] = getCenter()[0];
rslt[RSLT_Y] = getCenter()[1];
rslt[RSLT_A] = getA();
......@@ -207,7 +263,16 @@ public class CuasMotionLMA {
rslt[RSLT_RMS_A] = getRMS()/getA();
rslt[RSLT_MAX2A] = max_val/getA(); // ratio of maximal value to LMA amplitude
rslt[RSLT_ITERS] = getIters();
return rslt;
return;
}
public static void copyMotion(
double [] dst,
double [] src) {
dst[RSLT_VX] = src[RSLT_VX];
dst[RSLT_VY] = src[RSLT_VY];
dst[RSLT_VSTR] = src[RSLT_VSTR];
dst[RSLT_VFRAC] = src[RSLT_VFRAC];
}
public double [] getCenter(){
......
......@@ -4723,20 +4723,22 @@ public class GpuQuad{ // quad camera description
* and temporal distance from the middle frame. Accumulation uses the feature developed for the
* thermal camera motion blur correction that allows accumulation in the transform domain. It only
* works with the negative scales, so the result will be a negative image in the TD.
* @param vector_field sparse array of motion vectors (may be longer, only Vx and Vy used). Null elements
* @param targets_array sparse array of motion vectors (may be longer, only Vx and Vy used). Null elements
* are allowed, they will be skipped, resultin in null TpTask elements.
* @param offset_scale multiply all vectors by this value when calculating pixel offsets
* @param magnitude_scale Scale data for accumulation (here positive, will be negated). If 0 - will use scale=1.0 (no accumulation)
* @param index_vx - index of vx in the targets_array[tile] array
* @param image_width image width in tiles (80 for 640-wide images).
* @return condensed array of TpTask
*/
public static TpTask [] setRectilinearMovingTasks(
final double [][] vector_field,
final double [][] targets_array,
final double offset_scale,
final double magnitude_scale,
final int index_vx,
final int tilesX) {
final float fmagnitude_scale = (magnitude_scale==0)? 1.0f : ((float) -magnitude_scale);
final int tiles = vector_field.length;
final int tiles = targets_array.length;
final TpTask [] tp_tasks_full = new TpTask [tiles];
final Thread[] threads = ImageDtt.newThreadArray();
final AtomicInteger ai = new AtomicInteger(00);
......@@ -4747,11 +4749,11 @@ public class GpuQuad{ // quad camera description
threads[ithread] = new Thread() {
@Override
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if (vector_field[nTile] != null){
for (int nTile = ai.getAndIncrement(); nTile < tiles; nTile = ai.getAndIncrement()) if (targets_array[nTile] != null){
int tileY = nTile / tilesX;
int tileX = nTile % tilesX;;
double dx = vector_field[nTile][0]*offset_scale;
double dy = vector_field[nTile][1]*offset_scale;
double dx = targets_array[nTile][index_vx + 0]*offset_scale;
double dy = targets_array[nTile][index_vx + 1]*offset_scale;
double [] cxy0 = { // uniform coordinates for the center scene
(tileX + 0.5) * GPUTileProcessor.DTT_SIZE,
(tileY + 0.5) * GPUTileProcessor.DTT_SIZE};
......
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