Commit f468c5ba authored by Andrey Filippov's avatar Andrey Filippov

fixed incorrect combining of the affine transformation and the

LMA-calculated correction.
parent c48eb737
...@@ -1053,7 +1053,7 @@ public class ComboMatch { ...@@ -1053,7 +1053,7 @@ public class ComboMatch {
double maximal_rms = 0.25; // double maximal_rms = 0.25; //
int min_overlap = 3000; // do not try to match if there is too small overlap (scaled pixels) int min_overlap = 3000; // do not try to match if there is too small overlap (scaled pixels)
int num_iter_lma = 5; int num_iter_lma = 5;
GenericJTabbedDialog gd = new GenericJTabbedDialog("Setup SpiralMatch",1200,900); GenericJTabbedDialog gd = new GenericJTabbedDialog("Setup SpiralMatch",1200,300);
if (pairwiseOrthoMatch != null) { if (pairwiseOrthoMatch != null) {
gd.addCheckbox ("Use existing image pair", use_exixting_pair, "Use existing affine settings for this pair, do not use spiral search."); gd.addCheckbox ("Use existing image pair", use_exixting_pair, "Use existing affine settings for this pair, do not use spiral search.");
} }
......
...@@ -3016,15 +3016,13 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{ ...@@ -3016,15 +3016,13 @@ public class OrthoMap implements Comparable <OrthoMap>, Serializable{
Matrix B1 = m_ref.getMatrix(0,1,2,2); Matrix B1 = m_ref.getMatrix(0,1,2,2);
Matrix B2 =m_other.getMatrix(0,1,2,2); Matrix B2 =m_other.getMatrix(0,1,2,2);
Matrix A = A2.times(A1); Matrix A = A2.times(A1);
Matrix B = A2.times(B1).plus(B2); Matrix B = A2.times(B2).plus(B1);
double [][] affine = { double [][] affine = {
{A.get(0,0),A.get(0,1),B.get(0,0)}, {A.get(0,0),A.get(0,1),B.get(0,0)},
{A.get(1,0),A.get(1,1),B.get(1,0)}}; {A.get(1,0),A.get(1,1),B.get(1,0)}};
return affine; return affine;
} }
/** /**
* Get planar approximation of the ground * Get planar approximation of the ground
* *
......
...@@ -1132,6 +1132,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1132,6 +1132,7 @@ public class OrthoMapsCollection implements Serializable{
boolean show_vf, boolean show_vf,
double [][] ground_planes, // null or double[2] - will return ground planes: double [][] ground_planes, // null or double[2] - will return ground planes:
int debugLevel){ int debugLevel){
boolean show_lma_dbg = !batch_mode && (debugLevel > 1);
if (woi == null) { if (woi == null) {
woi = new Rectangle(); woi = new Rectangle();
} }
...@@ -1491,7 +1492,8 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1491,7 +1492,8 @@ public class OrthoMapsCollection implements Serializable{
boolean last_run = false; boolean last_run = false;
int min_good_tiles = min_tiles_overlap/2; int min_good_tiles = min_tiles_overlap/2;
// show_lma_dbg
String dbg_lma_prefix = show_lma_dbg? ("LMA_"+gpu_pair[0]+"-"+gpu_pair[1]+"_ntry"+ntry+"_"):null;
int num_good_tiles = orthoPairLMA.prepareLMA( int num_good_tiles = orthoPairLMA.prepareLMA(
// will always calculate relative affine, starting with unity // will always calculate relative affine, starting with unity
...@@ -1532,6 +1534,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -1532,6 +1534,7 @@ public class OrthoMapsCollection implements Serializable{
rms_diff, // double rms_diff, // 0.001 rms_diff, // double rms_diff, // 0.001
num_iter, // int num_iter, // 20 num_iter, // int num_iter, // 20
last_run, // boolean last_run, last_run, // boolean last_run,
dbg_lma_prefix, // String dbg_prefix,
debugLevel); // int debug_level) debugLevel); // int debug_level)
if (debugLevel > -3) { if (debugLevel > -3) {
System.out.println("LMA result = "+lma_rslt); System.out.println("LMA result = "+lma_rslt);
...@@ -3714,7 +3717,7 @@ public class OrthoMapsCollection implements Serializable{ ...@@ -3714,7 +3717,7 @@ public class OrthoMapsCollection implements Serializable{
lines[indx]=String.format( lines[indx]=String.format(
"%3d %17s %26s %6.2f",indx, name, sdt, agl); "%3d %17s %26s %6.2f",indx, name, sdt, agl);
} }
GenericJTabbedDialog gd = new GenericJTabbedDialog("Select the "+fs[num_scene]+" image from the list ",1200,1000); GenericJTabbedDialog gd = new GenericJTabbedDialog("Select the "+fs[num_scene]+" image from the list ",1200,100);
gd.addChoice(fs[num_scene]+" image:", gd.addChoice(fs[num_scene]+" image:",
lines, lines,
lines[default_choice], lines[default_choice],
......
...@@ -29,6 +29,7 @@ package com.elphel.imagej.orthomosaic; ...@@ -29,6 +29,7 @@ package com.elphel.imagej.orthomosaic;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import com.elphel.imagej.common.ShowDoubleFloatArrays;
import com.elphel.imagej.gpu.GPUTileProcessor; import com.elphel.imagej.gpu.GPUTileProcessor;
import com.elphel.imagej.tileprocessor.ImageDtt; import com.elphel.imagej.tileprocessor.ImageDtt;
import com.elphel.imagej.tileprocessor.QuadCLT; import com.elphel.imagej.tileprocessor.QuadCLT;
...@@ -62,6 +63,38 @@ public class OrthoPairLMA { ...@@ -62,6 +63,38 @@ public class OrthoPairLMA {
public double getCenterRadius() { public double getCenterRadius() {
return center_radius; return center_radius;
} }
public void debugStateImage(String title) {
String [] titles = {"Yhor", "Yvert", "fXhor", "fXvert", "Dhor", "Dvert","DWhor", "DWvert", "Whor", "Wvert"};
double [][] dbg_img = new double[titles.length][N];
double [] fx = getFxDerivs(
parameters_vector, // double [] vector,
null, // final double [][] jt, // should be null or initialized with [vector.length][]
0); // debug_level); // final int debug_level)
for (int i = 0; i < N; i++) {
dbg_img[0][i] = y_vector[2*i + 0];
dbg_img[1][i] = y_vector[2*i + 1];
dbg_img[2][i] = fx[2*i + 0];
dbg_img[3][i] = fx[2*i + 1];
dbg_img[4][i] = y_vector[2*i + 0]-fx[2*i + 0];
dbg_img[5][i] = y_vector[2*i + 1]-fx[2*i + 1];
if (last_ymfx != null) {
dbg_img[6][i] = last_ymfx[2*i + 0];
dbg_img[7][i] = last_ymfx[2*i + 1];
}
dbg_img[8][i] = weights[2*i + 0];
dbg_img[9][i] = weights[2*i + 1];
}
ShowDoubleFloatArrays.showArrays(
dbg_img,
woi.width,
woi.height,
true,
title,
titles);
}
public int prepareLMA( public int prepareLMA(
// will always calculate relative affine, starting with unity // will always calculate relative affine, starting with unity
int width, // tilesX int width, // tilesX
...@@ -397,16 +430,24 @@ public class OrthoPairLMA { ...@@ -397,16 +430,24 @@ public class OrthoPairLMA {
double rms_diff, // 0.001 double rms_diff, // 0.001
int num_iter, // 20 int num_iter, // 20
boolean last_run, boolean last_run,
String dbg_prefix,
int debug_level) int debug_level)
{ {
boolean [] rslt = {false,false}; boolean [] rslt = {false,false};
this.last_rms = null; // remove? this.last_rms = null; // remove?
int iter = 0; int iter = 0;
if (dbg_prefix != null) {
debugStateImage(dbg_prefix+"-initial");
}
for (iter = 0; iter < num_iter; iter++) { for (iter = 0; iter < num_iter; iter++) {
rslt = lmaStep( rslt = lmaStep(
lambda, lambda,
rms_diff, rms_diff,
debug_level); debug_level);
if (dbg_prefix != null) {
debugStateImage(dbg_prefix+"-step_"+iter);
}
if (rslt == null) { if (rslt == null) {
return -1; // false; // need to check return -1; // false; // need to check
} }
...@@ -676,7 +717,7 @@ public class OrthoPairLMA { ...@@ -676,7 +717,7 @@ public class OrthoPairLMA {
public void run() { public void run() {
for (int iTile = ai.getAndIncrement(); iTile < N; iTile = ai.getAndIncrement()) if (tile_centers[iTile] !=null) { for (int iTile = ai.getAndIncrement(); iTile < N; iTile = ai.getAndIncrement()) if (tile_centers[iTile] !=null) {
double x = tile_centers[iTile][0] - origin[0]; double x = tile_centers[iTile][0] - origin[0];
double y = tile_centers[iTile][1] - origin[0]; double y = tile_centers[iTile][1] - origin[1];
double vx = (vector[0] - 1.0) * x + vector[1] * y + vector[4]; double vx = (vector[0] - 1.0) * x + vector[1] * y + vector[4];
double vy = vector[2] * x + (vector[3] - 1.0) * y + vector[5]; double vy = vector[2] * x + (vector[3] - 1.0) * y + vector[5];
fx[2 * iTile + 0] = vx; fx[2 * iTile + 0] = vx;
......
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