Skip to content

Commit f6f06a1

Browse files
committed
NAN initialize results.
1 parent 4fa6067 commit f6f06a1

File tree

8 files changed

+1030
-1144
lines changed

8 files changed

+1030
-1144
lines changed

tests/Distortion Correlation Impact.ipynb renamed to example/Distortion Correlation Impact.ipynb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "d236b7d9-0991-4e00-b27d-f60671cbaefc",
6+
"metadata": {},
7+
"source": [
8+
"# Distortion Impact\n",
9+
"\n",
10+
"Recreate the analysis from \n",
11+
"\n",
12+
"Cecilia Mauceri, Yang Cheng, Yumi Iwashita and Adnan Ansar. \"A Validation Pipeline for Lunar Digital Elevation Models,\" AIAA 2025-2072. AIAA SCITECH 2025 Forum. January 2025. [link](https://arc.aiaa.org/doi/abs/10.2514/6.2025-2072)\n",
13+
"\n",
14+
"This script artificially distorts DEMs to create map distortion with known parameters and then demonstrates how the correlator can detect this distortion.\n",
15+
"\n",
16+
"## Setup"
17+
]
18+
},
319
{
420
"cell_type": "code",
521
"execution_count": 1,
@@ -45,6 +61,14 @@
4561
"plt.rcParams['figure.figsize'] = [10, 3]"
4662
]
4763
},
64+
{
65+
"cell_type": "markdown",
66+
"id": "09cbfc1c-cb87-4d87-8eed-95db43566dff",
67+
"metadata": {},
68+
"source": [
69+
"## Render DEM for visual comparison"
70+
]
71+
},
4872
{
4973
"cell_type": "code",
5074
"execution_count": 3,
@@ -231,7 +255,7 @@
231255
"source": [
232256
"## Self-compare\n",
233257
"\n",
234-
"Landmark compared to itself should have near zero deltas"
258+
"Landmark compared to itself without distortion should have near zero deltas"
235259
]
236260
},
237261
{

example/EarthDemo.ipynb

Lines changed: 420 additions & 415 deletions
Large diffs are not rendered by default.

example/MoonDemo.ipynb

Lines changed: 378 additions & 542 deletions
Large diffs are not rendered by default.

example/Rendering.ipynb

Lines changed: 112 additions & 110 deletions
Large diffs are not rendered by default.

example/image_comparison_demo.ipynb

Lines changed: 66 additions & 60 deletions
Large diffs are not rendered by default.

src/landmark_tools/feature_tracking/correlation_results.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* limitations under the License.
2222
*/
2323

24+
#include <math.h> // for NAN
2425
#include <stdlib.h> // for malloc, free
2526
#include <stdbool.h> // for bool, false
2627
#include "landmark_tools/feature_tracking/correlation_results.h"
@@ -39,12 +40,12 @@ bool allocate_correlation_results(CorrelationResults* corr_struct, size_t num_pi
3940
return false;
4041
}
4142

42-
// Initialize all values to 0
43+
// Initialize all values to NAN
4344
for (size_t i = 0; i < num_pixels; ++i) {
44-
corr_struct->delta_x[i] = 0.0f;
45-
corr_struct->delta_y[i] = 0.0f;
46-
corr_struct->delta_z[i] = 0.0f;
47-
corr_struct->correlation[i] = 0.0f;
45+
corr_struct->delta_x[i] = NAN;
46+
corr_struct->delta_y[i] = NAN;
47+
corr_struct->delta_z[i] = NAN;
48+
corr_struct->correlation[i] = NAN;
4849
}
4950

5051
return true;
@@ -67,4 +68,4 @@ void destroy_correlation_results(CorrelationResults* corr_struct) {
6768
free(corr_struct->correlation);
6869
corr_struct->correlation = NULL;
6970
}
70-
}
71+
}

src/landmark_tools/feature_tracking/feature_match.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,18 @@ bool process_matched_feature(
324324

325325
// Update maps with weighted contributions
326326
int32_t index = m * num_cols + n;
327-
results->delta_x[index] += (float)(delta_map[0] * weight);
328-
results->delta_y[index] += (float)(delta_map[1] * weight);
329-
results->delta_z[index] += (float)(delta_map[2] * weight);
330-
results->correlation[index] += (float)(covariance * weight);
331327

328+
if(isnan(results->delta_x[index])){
329+
results->delta_x[index] = (float)(delta_map[0] * weight);
330+
results->delta_y[index] = (float)(delta_map[1] * weight);
331+
results->delta_z[index] = (float)(delta_map[2] * weight);
332+
results->correlation[index] = (float)(covariance * weight);
333+
}else{
334+
results->delta_x[index] += (float)(delta_map[0] * weight);
335+
results->delta_y[index] += (float)(delta_map[1] * weight);
336+
results->delta_z[index] += (float)(delta_map[2] * weight);
337+
results->correlation[index] += (float)(covariance * weight);
338+
}
332339
// Update weights
333340
if (isnan(weights[index])) {
334341
weights[index] = weight;
@@ -414,6 +421,7 @@ bool MatchFeaturesWithLocalDistortion(
414421
}
415422

416423
double covariances[num_points];
424+
memset(covariances, 0, sizeof(double)*num_points);
417425
int32_t num_matched_features = MatchFeaturesWithNaNHandling(
418426
parameters,
419427
child_landmark->srm,

src/landmark_tools/opencv_tools/feature_matching_2d.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,20 @@ bool process_matched_feature_2d(
102102

103103
// Update correlation results with weighted contributions
104104
int32_t index = m * num_cols + n;
105-
results->delta_x[index] += (float)(p_delta_map[0] * weight);
106-
results->delta_y[index] += (float)(p_delta_map[1] * weight);
107-
results->delta_z[index] += (float)(p_delta_map[2] * weight);
108-
results->correlation[index] += (float)(correlation * weight);
109-
105+
110106
// Update weight matrix for later normalization
111107
if (isnan(weights[index])) {
112108
weights[index] = weight; // First contribution to this point
109+
results->delta_x[index] = (float)(p_delta_map[0] * weight);
110+
results->delta_y[index] = (float)(p_delta_map[1] * weight);
111+
results->delta_z[index] = (float)(p_delta_map[2] * weight);
112+
results->correlation[index] = (float)(correlation * weight);
113113
} else {
114114
weights[index] += weight; // Accumulate weights for multiple features
115+
results->delta_x[index] += (float)(p_delta_map[0] * weight);
116+
results->delta_y[index] += (float)(p_delta_map[1] * weight);
117+
results->delta_z[index] += (float)(p_delta_map[2] * weight);
118+
results->correlation[index] += (float)(correlation * weight);
115119
}
116120
}
117121
}
@@ -372,4 +376,4 @@ bool MatchFeatures_local_distortion_2d(
372376
free(weights);
373377

374378
return true;
375-
}
379+
}

0 commit comments

Comments
 (0)