aboutsummaryrefslogtreecommitdiff
path: root/src/itrans.c
blob: 1332bb8c385b60dec0ccbe04fe59c409fe5896ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * itrans.c
 *
 * Parameterise features in an image for reconstruction
 *
 * (c) 2007 Thomas White <taw27@cam.ac.uk>
 *	    Gordon Ball <gfb21@cam.ac.uk>
 *
 *  dtr - Diffraction Tomography Reconstruction
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdint.h>
#include <gsl/gsl_matrix.h>

#include "control.h"
#include "imagedisplay.h"
#include "reflections.h"
#include "itrans-threshold.h"
#include "itrans-zaefferer.h"
#include "itrans-lsq.h"
#include "peakdetect.h"

static unsigned int itrans_peaksearch_iterative(int16_t *image, ControlContext *ctx, double tilt_degrees, ImageDisplay *imagedisplay) {

	unsigned int n_reflections;	
	gsl_matrix *m;
	gsl_matrix *p;
	int i;
	double px,py;

	m = createImageMatrix(ctx, image);
	p = iterate(m, &n_reflections);
	for ( i=0; i<n_reflections; i++ ) {
	
		px = gsl_matrix_get(p,0,i);
		py = gsl_matrix_get(p,1,i);
		if ( ctx->fmode == FORMULATION_PIXELSIZE ) {
			reflection_add_from_reciprocal(ctx, (px-ctx->x_centre)*ctx->pixel_size, (py-ctx->y_centre)*ctx->pixel_size,
								tilt_degrees, 1.0);
		} else {
			reflection_add_from_dp(ctx, (px-ctx->x_centre), (py-ctx->y_centre), tilt_degrees, 1.0);
		}
		if (ctx->first_image) imagedisplay_mark_point(imagedisplay, (unsigned int)px, (unsigned int)py);
		
	}
	gsl_matrix_free(m);
	gsl_matrix_free(p);
	
	return n_reflections;
	
}

void itrans_process_image(int16_t *image, ControlContext *ctx, double tilt_degrees) {
	
	unsigned int n_reflections;
	ImageDisplay *imagedisplay = NULL;
	
	if ( ctx->first_image ) {
		imagedisplay = imagedisplay_open(image, ctx->width, ctx->height, "Image Display");
		imagedisplay_add_tilt_axis(imagedisplay, ctx, ctx->omega);
	}
	
	switch ( ctx->psmode ) {
		case PEAKSEARCH_THRESHOLD : n_reflections = itrans_peaksearch_threshold(image, ctx, tilt_degrees, imagedisplay); break;
		case PEAKSEARCH_ADAPTIVE_THRESHOLD : n_reflections = itrans_peaksearch_adaptive_threshold(image, ctx, tilt_degrees, imagedisplay); break;
		case PEAKSEARCH_LSQ : n_reflections = itrans_peaksearch_lsq(image, ctx, tilt_degrees, imagedisplay); break;
		case PEAKSEARCH_ZAEFFERER : n_reflections = itrans_peaksearch_zaefferer(image, ctx, tilt_degrees, imagedisplay); break;
		case PEAKSEARCH_ITERATIVE : n_reflections = itrans_peaksearch_iterative(image, ctx, tilt_degrees, imagedisplay); break;
		default: n_reflections = 0;
	}
	
	ctx->first_image = 0;
	printf(" ..... %i peaks found\n", n_reflections);
	
}