aboutsummaryrefslogtreecommitdiff
path: root/src/mapping.c
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-19 23:13:58 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-19 23:13:58 +0000
commitb31565d11bcb28ca33b4a51cb363549c46444cd8 (patch)
tree59c573a21eaae8c8e82f5491d7167ff0c854ae95 /src/mapping.c
parentde770d8c43a57b1941e2f6942f75deb8c99475aa (diff)
Preparation for handing precessed data
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@65 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/mapping.c')
-rw-r--r--src/mapping.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/mapping.c b/src/mapping.c
new file mode 100644
index 0000000..adf3205
--- /dev/null
+++ b/src/mapping.c
@@ -0,0 +1,84 @@
+/*
+ * mapping.c
+ *
+ * 3D Mapping
+ *
+ * (c) 2007 Thomas White <taw27@cam.ac.uk>
+ *
+ * dtr - Diffraction Tomography Reconstruction
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "reflections.h"
+#include "control.h"
+#include "imagedisplay.h"
+#include "itrans.h"
+
+ReflectionContext *mapping_create(ControlContext *ctx) {
+
+ ReflectionContext *rctx;
+ ImageDisplay *sum_id;
+ int16_t max_val;
+ int max_x, max_y;
+ int twidth, theight;
+ int x, y, i;
+ int16_t *image_total;
+
+ /* Create reflection context */
+ rctx = reflection_init();
+
+ /* Find centre of image stack
+ * Determine maximum size of image to accommodate, and allocate memory */
+ twidth = 0; theight = 0;
+ for ( i=0; i<ctx->n_images; i++ ) {
+ if ( ctx->images[i].width > twidth ) twidth = ctx->images[i].width;
+ if ( ctx->images[i].height > theight ) theight = ctx->images[i].height;
+ }
+ image_total = malloc(twidth * theight * sizeof(int16_t));
+ memset(image_total, 0, twidth * theight * sizeof(int16_t));
+
+ /* Add the image stack together */
+ for ( i=0; i<ctx->n_images; i++ ) {
+ int xoffs, yoffs;
+ xoffs = (twidth - ctx->images[i].width)/2;
+ yoffs = (theight - ctx->images[i].height)/2;
+ for ( y=0; y<theight; y++ ) {
+ for ( x=0; x<twidth; x++ ) {
+ image_total[x + twidth*y] += ctx->images[i].image[x + twidth*y]/ctx->n_images;
+ }
+ }
+ }
+
+ /* Locate the highest point */
+ max_val = 0; max_x = 0; max_y = 0;
+ for ( y=0; y<theight; y++ ) {
+ for ( x=0; x<twidth; x++ ) {
+ if ( image_total[x + twidth*y] > max_val ) {
+ max_val = image_total[x + twidth*y];
+ max_x = x; max_y = y;
+ }
+ }
+ }
+ ctx->x_centre = max_x;
+ ctx->y_centre = max_y;
+
+ /* Display */
+ sum_id = imagedisplay_open(image_total, twidth, theight, "Sum of All Images");
+ imagedisplay_mark_point(sum_id, ctx->x_centre, ctx->y_centre);
+ imagedisplay_add_tilt_axis(sum_id, ctx, ctx->omega);
+
+ /* Pass all images through itrans
+ * (let itrans add the reflections to rctx for now) */
+ ctx->reflectionctx = rctx;
+ for ( i=0; i<ctx->n_images; i++ ) {
+ itrans_process_image(ctx->images[i].image, ctx, ctx->images[i].tilt);
+ }
+
+ return rctx;
+
+}
+