aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-29 16:51:12 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-29 16:51:12 +0000
commit293dceaf57048dc725ebd9e71021e28d2e721e09 (patch)
tree53f9a7182f9d86bd326102deeb7d9d9d1f01e92c
parent28fe29530075a28f6ac7a2f86628a00c7cb69af9 (diff)
Fix muppetries
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@87 bf6ca9ba-c028-0410-8290-897cf20841d1
-rw-r--r--src/itrans-threshold.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/itrans-threshold.c b/src/itrans-threshold.c
index 69acd24..71c39a1 100644
--- a/src/itrans-threshold.c
+++ b/src/itrans-threshold.c
@@ -14,6 +14,7 @@
#endif
#include <stdint.h>
+#include <assert.h>
#include "control.h"
#include "imagedisplay.h"
@@ -37,10 +38,14 @@ unsigned int itrans_peaksearch_threshold(ImageRecord imagerecord, ControlContext
if ( image[x + width*y] > max ) max = image[x + width*y];
}
}
-
+
for ( y=0; y<height; y++ ) {
for ( x=0; x<width; x++ ) {
if ( image[x + width*y] > max/3 ) {
+ assert(x<width);
+ assert(y<height);
+ assert(x>=0);
+ assert(y>=0);
if ( imagerecord.fmode == FORMULATION_PIXELSIZE ) {
reflection_add_from_reciprocal(ctx,
(signed)(x-imagerecord.x_centre)*imagerecord.pixel_size,
@@ -66,19 +71,28 @@ unsigned int itrans_peaksearch_adaptive_threshold(ImageRecord imagerecord, Contr
uint16_t max_val = 0;
int width, height;
unsigned int n_reflections = 0;
- uint16_t *image = imagerecord.image;
+ uint16_t *image;
double tilt_degrees = imagerecord.tilt;
+ uint16_t max;
+ int x, y;
+ image = imagerecord.image;
width = imagerecord.width;
height = imagerecord.height;
+ max = 0;
+ for ( y=0; y<height; y++ ) {
+ for ( x=0; x<width; x++ ) {
+ if ( image[x + width*y] > max ) max = image[x + width*y];
+ }
+ }
+
/* Adaptive Thresholding */
do {
int max_x = 0;
int max_y = 0;;
- int x, y;
-
+
/* Locate the highest point */
max_val = 0;
for ( y=0; y<height; y++ ) {
@@ -92,16 +106,20 @@ unsigned int itrans_peaksearch_adaptive_threshold(ImageRecord imagerecord, Contr
}
}
- if ( max_val > 50 ) {
+ if ( max_val > max/10 ) {
+ assert(max_x<width);
+ assert(max_y<height);
+ assert(max_x>=0);
+ assert(max_y>=0);
if ( imagerecord.fmode == FORMULATION_PIXELSIZE ) {
reflection_add_from_reciprocal(ctx,
- (signed)(x-imagerecord.x_centre)*imagerecord.pixel_size,
- (signed)(y-imagerecord.y_centre)*imagerecord.pixel_size,
- tilt_degrees, image[x + width*y]);
+ (signed)(max_x-imagerecord.x_centre)*imagerecord.pixel_size,
+ (signed)(max_y-imagerecord.y_centre)*imagerecord.pixel_size,
+ tilt_degrees, image[max_x + width*max_y]);
} else {
- reflection_add_from_dp(ctx, (signed)(x-imagerecord.x_centre)/imagerecord.resolution,
- (signed)(y-imagerecord.y_centre)/imagerecord.resolution,
- tilt_degrees, image[x + width*y]);
+ reflection_add_from_dp(ctx, (signed)(max_x-imagerecord.x_centre)/imagerecord.resolution,
+ (signed)(max_y-imagerecord.y_centre)/imagerecord.resolution,
+ tilt_degrees, image[max_x + width*max_y]);
}
n_reflections++;