/* * indexamajig.c * * Find hits, index patterns, output hkl+intensity etc. * * (c) 2006-2009 Thomas White * * Part of CrystFEL - crystallography with a FEL * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "utils.h" #include "hdf5-file.h" #include "dirax.h" static void show_help(const char *s) { printf("Syntax: %s [options]\n\n", s); printf( "Process and index FEL diffraction images.\n" "\n" " -h, --help Display this help message.\n" "\n" " -i, --input= Specify file containing list of images to process.\n" " '-' means stdin, which is the default.\n" "\n"); } struct peak { int x; int y; int i; int invalid; }; static int image_fom(struct image *image) { int x, y; int integr, n; float fintegr, mean, sd, th; struct peak peaks[1024]; int i, n_peaks, n_nearby, n_valid; /* Measure mean */ integr = 0; n = 0; for ( x=0; x<1024; x++ ) { for ( y=600; y<1024; y++ ) { int val; if ( (x>400) && (x<600) ) continue; val = image->data[x+image->height*y]; if ( val < 0 ) continue; integr += val; n++; } } mean = (float)integr / n; /* As integer to keep maths fast */ /* Standard deviation */ integr = 0; for ( x=0; x<1024; x++ ) { for ( y=600; y<1024; y++ ) { float val; if ( (x>400) && (x<600) ) continue; val = (float)image->data[x+image->height*y]; if ( val < 0 ) continue; val -= mean; val = powf(val, 2.0); fintegr += val; } } sd = sqrtf(fintegr / n); /* Threshold */ th = mean + 5*sd; STATUS("mean=%f ,sd=%f, th=%f\n", mean, sd, th); /* Find pixels above threshold */ n_peaks = 0; for ( x=0; x<1024; x++ ) { for ( y=600; y<1024; y++ ) { int val; /* Chop out streaky region */ if ( (x>400) && (x<600) ) continue; val = image->data[x+image->height*y]; if ( val > th ) { peaks[n_peaks].x = x; peaks[n_peaks].y = y; peaks[n_peaks].i = val; peaks[n_peaks].invalid = 0; n_peaks++; } } } do { int max, max_i; int adjacent; n_nearby = 0; /* Find brightest peak */ max = 0; for ( i=0; i max ) { max = peaks[i].i; max_i = i; } } /* Must be at least one adjacent bright pixel */ adjacent = 0; for ( i=0; i 0 ) { printf("%s\n", line); index_pattern(&image); n_hits++; } n_images++; } while ( rval != NULL ); fclose(fh); STATUS("There were %i images.\n", n_images); STATUS("%i hits were found.\n", n_hits); return 0; }