diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-03-31 12:50:00 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-03-31 12:50:00 +0000 |
commit | 3bc91ef5e88444cbd9366f0b1516a91af6313e8d (patch) | |
tree | 4cd3fa16fe8cc241cd37c46d2c69d556c9b5825d /src/itrans-zaefferer.c | |
parent | 8810e9ff13e9fb0db420dbdc529ef2f9dfe89d7c (diff) |
Tidy up itrans framework: move each peak detection algorithm to its own file
Fit svn::ignore properties (again?)
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@16 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/itrans-zaefferer.c')
-rw-r--r-- | src/itrans-zaefferer.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/itrans-zaefferer.c b/src/itrans-zaefferer.c new file mode 100644 index 0000000..b51c5cc --- /dev/null +++ b/src/itrans-zaefferer.c @@ -0,0 +1,103 @@ +/* + * itrans-zaefferer.c + * + * Zaefferer peak search + * + * (c) 2007 Thomas White <taw27@cam.ac.uk> + * + * dtr - Diffraction Tomography Reconstruction + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdint.h> + +#include "control.h" +#include "imagedisplay.h" +#include "reflections.h" +#include "utils.h" + +#define PEAK_WINDOW_SIZE 20 + +unsigned int itrans_peaksearch_zaefferer(int16_t *image, ControlContext *ctx, double tilt_degrees, ImageDisplay *imagedisplay) { + + int x, y; + unsigned int n_reflections; + + n_reflections = 0; + for ( x=1; x<ctx->width-1; x++ ) { + for ( y=1; y<ctx->height-1; y++ ) { + + double dx1, dx2, dy1, dy2; + double dxs, dys; + double grad; + + if ( ctx->max_d ) { + if ( (x-ctx->x_centre)*(x-ctx->x_centre) + (y-ctx->y_centre)*(y-ctx->y_centre) > ctx->max_d*ctx->max_d ) { + continue; + } + } + + /* Get gradients */ + dx1 = image[x+ctx->width*y] - image[(x+1)+ctx->width*y]; + dx2 = image[(x-1)+ctx->width*y] - image[x+ctx->width*y]; + dy1 = image[x+ctx->width*y] - image[(x+1)+ctx->width*(y+1)]; + dy2 = image[x+ctx->width*(y-1)] - image[x+ctx->width*y]; + + /* Average gradient measurements from both sides */ + dxs = ((dx1*dx1) + (dx2*dx2)) / 2; + dys = ((dy1*dy1) + (dy2*dy2)) / 2; + + /* Calculate overall gradient */ + grad = dxs + dys; + + if ( grad > 400 ) { + + unsigned int mask_x, mask_y; + unsigned int sx, sy; + double max; + unsigned int did_something = 1; + + mask_x = x; + mask_y = y; + + while ( (did_something) && (distance(mask_x, mask_y, x, y)<50) ) { + max = image[mask_x+ctx->width*mask_y]; + did_something = 0; + for ( sy=biggest(mask_y-PEAK_WINDOW_SIZE/2, 0); sy<smallest(mask_y+PEAK_WINDOW_SIZE/2, ctx->height); sy++ ) { + for ( sx=biggest(mask_x-PEAK_WINDOW_SIZE/2, 0); sx<smallest(mask_x+PEAK_WINDOW_SIZE/2, ctx->width); sx++ ) { + if ( image[sx+ctx->width*sy] > max ) { + max = image[sx+ctx->width*sy]; + mask_x = sx; + mask_y = sy; + did_something = 1; + } + } + } + } + + if ( !did_something ) { + if ( ctx->fmode == FORMULATION_PIXELSIZE ) { + reflection_add_from_reciprocal(ctx, (signed)(mask_x-ctx->width/2)*ctx->pixel_size, + (signed)(mask_y-ctx->height/2)*ctx->pixel_size, + tilt_degrees, image[mask_x + ctx->width*mask_y]); + } else { + reflection_add_from_dp(ctx, (signed)(mask_x-ctx->width/2), (signed)(mask_y-ctx->height/2), + tilt_degrees, image[mask_x + ctx->width*mask_y]); + } + if ( ctx->first_image ) { + imagedisplay_mark_point(imagedisplay, mask_x, mask_y); + } + n_reflections++; + } + + } + } + } + + return n_reflections; + +} |