/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ /* program: sddsimageprofiles.c * purpose: analyze images stored as horizontal lines (one per column), * based on ideas of B-X Yang. * M. Borland, 2000 $Log: sddsimageprofiles.c,v $ Revision 1.10 2009/10/23 16:25:18 soliday It was leaving the last row off when doing -profileType=y Revision 1.9 2005/11/07 21:48:10 soliday Updated to remove Linux compiler warnings. Revision 1.8 2005/11/04 22:46:14 soliday Updated code to be compiled by a 64 bit processor. Revision 1.7 2005/10/18 14:09:44 jiaox Fixed a background option bug that caused the program crashed. Revision 1.6 2003/09/18 21:44:24 soliday Added the peak method. Revision 1.5 2003/09/02 19:16:04 soliday Cleaned up code for Linux. Revision 1.4 2003/06/19 22:53:34 soliday Fixed a bug if the numbers in the column names started with 0 instead of 1. Revision 1.3 2002/08/14 17:12:47 soliday Added Open License Revision 1.2 2001/01/10 19:35:39 soliday Standardized usage message. Revision 1.1 2000/10/23 16:03:21 soliday First version. */ #include "mdb.h" #include "SDDS.h" #include "scan.h" #define SET_PIPE 0 #define SET_PROFILETYPE 1 #define SET_COLPREFIX 2 #define SET_METHOD 3 #define SET_AVECTOR 4 #define SET_BVECTOR 5 #define SET_OFFSET 6 #define SET_BACKGROUND 7 #define N_OPTIONS 8 char *option[N_OPTIONS] = { "pipe", "profileType", "columnPrefix", "method", "aVector", "bVector", "offset", "background" }; char *USAGE = "sddsimageprofiles [] []\n\ [-pipe=[input][,output]]\n\ [-columnPrefix=]\n\ [-profileType={x|y}]\n\ [-method={centerLine|integrated|averaged|peak}]\n\ [-background=]\n\ [-aVector=,]\n\ [-bVector=,]\n\ [-offset=,]\n\n\ Program by Robert Soliday. ("__DATE__")\n\n\ \ -method If this option is not specified it is a real profile.\n\ If centerLine is specified it will find the row with the\n\ greatest integrated profile and display that line only.\n\ If integrated is specified it will sum all the profiles\n\ together. If averaged is specified it will divide the sum\n\ of all the profiles by the number of profiles. If peak is\n\ specified it will find the peak point and display the profile\n\ for that row.\n"; typedef struct { short *shortData; int32_t *longData; float *floatData; double *doubleData; } IMAGE_DATA; int xImageProfile(IMAGE_DATA *data, int32_t *type, long rows, SDDS_DATASET *SDDS_dataset, long method, long x1, long x2, long y1, long y2, long *colIndex, long *colIndex2); int yImageProfile(IMAGE_DATA *data, int32_t *type, long rows, SDDS_DATASET *SDDS_dataset, long method, long x1, long x2, long y1, long y2, long *colIndex, long *colIndex2); long xPeakLine(IMAGE_DATA *data, int32_t *type, long *colIndex, long x1, long x2, long y1, long y2); long yPeakLine(IMAGE_DATA *data, int32_t *type, long *colIndex, long x1, long x2, long y1, long y2); long xCenterLine(IMAGE_DATA *data, int32_t *type, long *colIndex, long x1, long x2, long y1, long y2); long yCenterLine(IMAGE_DATA *data, int32_t *type, long *colIndex, long x1, long x2, long y1, long y2); long GetData(SDDS_DATASET *SDDS_orig, char *input, IMAGE_DATA **data, int32_t **type, long **colIndex, long **colIndex2, char *colPrefix, long *validColumns); int main(int argc, char **argv) { SDDS_DATASET SDDS_dataset, SDDS_orig, SDDS_bg; long i_arg; SCANNED_ARG *s_arg; IMAGE_DATA *data, *bg_data; char *input=NULL, *output=NULL, *colPrefix=NULL, *background=NULL; long profileType=1, noWarnings=0, tmpfile_used=0, method=0; unsigned long pipeFlags=0; long rows, bg_rows, i, j, validColumns=0, bg_validColumns=0; int32_t *type, *bg_type; long axstart=0; long bystart=0; long *colIndex, *colIndex2, *bg_colIndex, *bg_colIndex2; long ax=0, ay=0, bx=0, by=0; long ax2=0, ay2=0, bx2=0, by2=0; long x1, x2, y1, y2; long offset_used=0; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&s_arg, argc, argv); if (argc<3) bomb(NULL, USAGE); for (i_arg=1; i_arg rows) x1 = rows+1; if (x2 > rows) x2 = rows+1; if (y1 < colIndex2[0]) y1 = colIndex2[0]; if (y2 < colIndex2[0]) y2 = colIndex2[0]; if (y1 > colIndex2[validColumns-1]) y1 = colIndex2[validColumns-1]+1; if (y2 > colIndex2[validColumns-1]) y2 = colIndex2[validColumns-1]+1; y1 += 1 - colIndex2[0]; y2 += 1 - colIndex2[0]; /* fprintf(stdout, "%ld %ld\n%ld %ld\n%ld %ld\n%ld %ld\n", x1, y1, x2, y1, x2, y2, x1, y2); */ if (profileType == 1) { xImageProfile(data, type, rows, &SDDS_dataset, method, x1-1, x2-1, y1-1, y2-1, colIndex, colIndex2); } else { yImageProfile(data, type, rows, &SDDS_dataset, method, x1-1, x2-1, y1-1, y2-1, colIndex, colIndex2); } bx2 += bx; by2 += by; } ax2 += ax; ay2 += ay; bx2=0; by2=bystart; } /* Close the output file */ if (SDDS_Terminate(&SDDS_dataset) != 1) { SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); exit(1); } return(0); } int xImageProfile(IMAGE_DATA *data, int32_t *type, long rows, SDDS_DATASET *SDDS_dataset, long method, long x1, long x2, long y1, long y2, long *colIndex, long *colIndex2) { int i, j, k=0; double val=0; long center; int32_t *index; double *values; char value[30]; index = malloc(sizeof(int32_t)*rows); values = malloc(sizeof(double)*rows); if (method == 0) { /* Highest point */ for (i=x1; i maxValue) { index = i; maxValue = val; } } } return(index); } long yCenterLine(IMAGE_DATA *data, int32_t *type, long *colIndex, long x1, long x2, long y1, long y2) { int i, j, start=1; double val, maxValue=0; long index=0; for (i=y1; i maxValue) { index = i; maxValue = val; } } } return(index); } long GetData(SDDS_DATASET *SDDS_orig, char *input, IMAGE_DATA **data, int32_t **type, long **colIndex, long **colIndex2, char *colPrefix, long *validColumns) { long rows, i, j, temp, temp2; int32_t orig_column_names; char **orig_column_name; /* Open image file */ if (!SDDS_InitializeInput(SDDS_orig, input)) { SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); exit(1); } /* Read column names */ if (!(orig_column_name = SDDS_GetColumnNames(SDDS_orig, &orig_column_names))) { SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); exit(1); } /* Allocate memory for image file data */ *data = malloc(sizeof(IMAGE_DATA)*orig_column_names); *type = malloc(sizeof(int32_t)*orig_column_names); /* Read page */ if (SDDS_ReadPage(SDDS_orig) != 1) { SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); exit(1); } /* Get number of rows */ rows = SDDS_RowCount(SDDS_orig); *colIndex = malloc(sizeof(long)*orig_column_names); *colIndex2 = malloc(sizeof(long)*orig_column_names); /* Read all numerical data from file */ for (i=0; i