aboutsummaryrefslogtreecommitdiff
path: root/src/itrans-threshold.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/itrans-threshold.c')
-rw-r--r--src/itrans-threshold.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/itrans-threshold.c b/src/itrans-threshold.c
new file mode 100644
index 0000000..3a1d788
--- /dev/null
+++ b/src/itrans-threshold.c
@@ -0,0 +1,106 @@
+/*
+ * itrans-threshold.c
+ *
+ * Threshold and adaptive threshold peak searches
+ *
+ * (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"
+
+unsigned int itrans_peaksearch_threshold(int16_t *image, ControlContext *ctx, double tilt_degrees, ImageDisplay *imagedisplay) {
+
+ int width, height;
+ int x, y;
+ unsigned int n_reflections = 0;
+
+ width = ctx->width; height = ctx->height;
+
+ /* Simple Thresholding */
+ for ( y=0; y<height; y++ ) {
+ for ( x=0; x<width; x++ ) {
+
+ if ( image[x + width*y] > 10 ) {
+ if ( ctx->fmode == FORMULATION_PIXELSIZE ) {
+ reflection_add_from_reciprocal(ctx, (signed)(x-ctx->x_centre)*ctx->pixel_size, (signed)(y-ctx->y_centre)*ctx->pixel_size,
+ tilt_degrees, image[x + width*y]);
+ } else {
+ reflection_add_from_dp(ctx, (signed)(x-ctx->x_centre), (signed)(y-ctx->y_centre), tilt_degrees, image[x + width*y]);
+ }
+ if ( ctx->first_image ) {
+ imagedisplay_mark_point(imagedisplay, x, y);
+ }
+ n_reflections++;
+ }
+
+ }
+ }
+
+ return n_reflections;
+
+}
+
+unsigned int itrans_peaksearch_adaptive_threshold(int16_t *image, ControlContext *ctx, double tilt_degrees, ImageDisplay *imagedisplay) {
+
+ int16_t max_val = 0;
+ int width, height;
+ unsigned int n_reflections = 0;
+
+ width = ctx->width; height = ctx->height;
+
+ /* 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++ ) {
+ for ( x=0; x<width; x++ ) {
+
+ if ( image[x + width*y] > max_val ) {
+ max_val = image[x + width*y];
+ max_x = x; max_y = y;
+ }
+
+ }
+ }
+
+ if ( max_val > 50 ) {
+ if ( ctx->fmode == FORMULATION_PIXELSIZE ) {
+ reflection_add_from_reciprocal(ctx, (signed)(max_x-ctx->x_centre)*ctx->pixel_size, (signed)(max_y-ctx->y_centre)*ctx->pixel_size,
+ tilt_degrees, max_val);
+ } else {
+ reflection_add_from_dp(ctx, (signed)(max_x-ctx->x_centre), (signed)(max_y-ctx->y_centre), tilt_degrees, max_val);
+ }
+ if ( ctx->first_image ) {
+ imagedisplay_mark_point(imagedisplay, max_x, max_y);
+ }
+ n_reflections++;
+
+ /* Remove it and its surroundings */
+ for ( y=((max_y-10>0)?max_y-10:0); y<((max_y+10)<height?max_y+10:height); y++ ) {
+ for ( x=((max_x-10>0)?max_x-10:0); x<((max_x+10)<width?max_x+10:width); x++ ) {
+ image[x + width*y] = 0;
+ }
+ }
+ }
+
+ } while ( max_val > 50 );
+
+ return n_reflections;
+
+}