aboutsummaryrefslogtreecommitdiff
path: root/src/templates.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-08-20 17:11:11 +0200
committerThomas White <taw@physics.org>2012-02-22 15:26:56 +0100
commit93e57e1aa3088a21c750ddef9fd4d6ae219097db (patch)
tree02c45314c93b18db68ad725f43f6522333a916da /src/templates.c
parent2e563d59a7f3f93b4fe1b1170dc6b47043c7170c (diff)
Use a faster integration when matching templates
Diffstat (limited to 'src/templates.c')
-rw-r--r--src/templates.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/templates.c b/src/templates.c
index 943ddbd0..dbdfe21b 100644
--- a/src/templates.c
+++ b/src/templates.c
@@ -25,6 +25,9 @@
#include <assert.h>
+#define INTEGRATION_SQUARE_SIDE (10)
+
+
/* Private data for template indexing */
struct _indexingprivate_template
{
@@ -179,6 +182,27 @@ IndexingPrivate *generate_templates(UnitCell *cell, const char *filename,
}
+static int fast_integrate_peak(struct image *image, int xp, int yp)
+{
+ int x, y;
+ double total = 0;
+ int r = INTEGRATION_SQUARE_SIDE;
+
+ for ( x=xp-r; x<=xp+r; x++ ) {
+ for ( y=yp-r; y<=yp+r; y++ ) {
+
+ if ( (x>=image->width) || (x<0) ) continue;
+ if ( (y>=image->height) || (y<0) ) continue;
+
+ total += image->data[x+image->width*y];
+
+ }
+ }
+
+ return total;
+}
+
+
static double integrate_all_rot(struct image *image, struct reflhit *hits,
int n, double rot)
{
@@ -187,16 +211,12 @@ static double integrate_all_rot(struct image *image, struct reflhit *hits,
for ( i=0; i<n; i++ ) {
- float x, y, intensity;
float xp, yp;
xp = cos(rot)*hits[i].x + sin(rot)*hits[i].y;
yp = -sin(rot)*hits[i].x + cos(rot)*hits[i].y;
- if ( integrate_peak(image, xp, yp, &x, &y,
- &intensity, 0, 0) ) continue;
-
- itot += intensity;
+ itot += fast_integrate_peak(image, xp, yp);
}
return itot;