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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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(ImageRecord imagerecord, ControlContext *ctx) {
int x, y;
unsigned int n_reflections;
int width, height;
uint16_t *image;
double tilt_degrees;
tilt_degrees = imagerecord.tilt;
image = imagerecord.image;
width = imagerecord.width;
height = imagerecord.height;
n_reflections = 0;
for ( x=1; x<width-1; x++ ) {
for ( y=1; y<height-1; y++ ) {
double dx1, dx2, dy1, dy2;
double dxs, dys;
double grad;
/* Get gradients */
dx1 = image[x+width*y] - image[(x+1)+width*y];
dx2 = image[(x-1)+width*y] - image[x+width*y];
dy1 = image[x+width*y] - image[(x+1)+width*(y+1)];
dy2 = image[x+width*(y-1)] - image[x+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+width*mask_y];
did_something = 0;
for ( sy=biggest(mask_y-PEAK_WINDOW_SIZE/2, 0); sy<smallest(mask_y+PEAK_WINDOW_SIZE/2, height); sy++ ) {
for ( sx=biggest(mask_x-PEAK_WINDOW_SIZE/2, 0); sx<smallest(mask_x+PEAK_WINDOW_SIZE/2, width); sx++ ) {
if ( image[sx+width*sy] > max ) {
max = image[sx+width*sy];
mask_x = sx;
mask_y = sy;
did_something = 1;
}
}
}
}
if ( !did_something ) {
if ( imagerecord.fmode == FORMULATION_PIXELSIZE ) {
reflection_add_from_reciprocal(ctx, (signed)(mask_x-imagerecord.x_centre)*imagerecord.pixel_size,
(signed)(mask_y-imagerecord.y_centre)*imagerecord.pixel_size,
tilt_degrees, image[mask_x + width*mask_y]);
} else {
reflection_add_from_dp(ctx, (signed)(mask_x-imagerecord.x_centre)/imagerecord.resolution, (signed)(mask_y-imagerecord.y_centre)/imagerecord.resolution,
tilt_degrees, image[mask_x + width*mask_y]);
}
n_reflections++;
}
}
}
}
return n_reflections;
}
|