Doxygen Source Code Documentation
3dExtrema.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Data Structures | |
struct | extrema |
Defines | |
#define | PROGRAM_NAME "3dExtrema" |
#define | PROGRAM_AUTHOR "B. Douglas Ward" |
#define | PROGRAM_INITIAL "12 April 2001" |
#define | PROGRAM_LATEST "15 August 2001" |
#define | EX_MAX_LL 5000 |
#define | EX_MAX_NV 26 |
#define | EX_DIMENSION 3 |
#define | EX_GT 1 |
#define | EX_GE 2 |
#define | EX_LT 3 |
#define | EX_LE 4 |
#define | MTEST(ptr) |
#define | DOPEN(ds, name) |
#define | SUB_POINTER(ds, vv, ind, ptr) |
Typedefs | |
typedef extrema | extrema |
Functions | |
void | EX_error (char *message) |
extrema * | initialize_extrema () |
void | print_extrema (int index, extrema *extrema_ptr) |
void | print_all_extrema (int ivolume, int islice, extrema *extrema_ptr) |
float | extrema_distance (extrema *aextrema, extrema *bextrema) |
void | find_nearest_extrema (extrema *new_extrema, extrema *head_extrema) |
extrema * | add_extrema (extrema *new_extrema, extrema *head_extrema) |
extrema * | new_extrema (float *centroid, float intensity, extrema *head_extrema) |
void | delete_extrema (extrema *extrema_ptr) |
extrema * | remove_extrema (extrema *aextrema, extrema *head_extrema) |
extrema * | average_extrema (extrema *aextrema, extrema *bextrema) |
extrema * | weight_extrema (extrema *aextrema, extrema *bextrema) |
extrema * | merge_extrema (extrema *aextrema, extrema *bextrema, extrema *head_extrema) |
extrema * | sort_extrema (extrema *head_extrema) |
extrema * | agglomerate_extrema (extrema *head_extrema, float sep_dist) |
float * | to_3dmm (int ixyz) |
extrema * | find_extrema (float *fvol, int num_nv, int nfirst, int nlast) |
int | from_3dmm (float *location) |
void | save_extrema (extrema *extrema_ptr, byte iextrema, byte *bar) |
void | save_all_extrema (extrema *extrema_ptr, byte *bar) |
void | EX_Syntax (void) |
int | EX_read_opts (int argc, char *argv[]) |
void * | initialize_program (int argc, char *argv[], int *nopt) |
void | process_all_datasets (int argc, char *argv[], int nopt) |
void | write_bucket () |
void | output_results () |
int | main (int argc, char *argv[]) |
Variables | |
THD_coorder | EX_cord |
int | EX_nx |
int | EX_ny |
int | EX_nz |
int | EX_nxy |
int | EX_nxyz |
int | EX_quiet = 0 |
int | EX_relation = 1 |
int | EX_maxima = 1 |
int | EX_strict = 1 |
int | EX_interior = 1 |
int | EX_slice = 1 |
int | EX_sort = 1 |
int | EX_merge = 1 |
float | EX_sep_dist = 0.0 |
float | EX_mask_thr = 1.0 |
float | EX_data_thr = 0.0 |
int | EX_nbricks = 0 |
extrema * | EX_head_extrema [EX_MAX_LL] |
int | EX_num_ll = 0 |
int | EX_offset [EX_MAX_NV] |
char * | EX_mask_filename = NULL |
char * | EX_output_prefix = NULL |
char * | EX_session = "./" |
byte * | EX_mask = NULL |
char * | commandline = NULL |
THD_3dim_dataset * | EX_dset = NULL |
Define Documentation
|
Value: do{ int pv ; (ds) = THD_open_dataset((name)) ; \ if( !ISVALID_3DIM_DATASET((ds)) ){ \ fprintf(stderr,"*** Can't open dataset: %s\n",(name)) ; exit(1) ; } \ THD_load_datablock( (ds)->dblk ) ; \ pv = DSET_PRINCIPAL_VALUE((ds)) ; \ if( DSET_ARRAY((ds),pv) == NULL ){ \ fprintf(stderr,"*** Can't access data: %s\n",(name)) ; exit(1); } \ if( DSET_BRICK_TYPE((ds),pv) == MRI_complex ){ \ fprintf(stderr,"*** Can't use complex data: %s\n",(name)) ; exit(1); } \ break ; } while (0) Definition at line 116 of file 3dExtrema.c. |
|
Definition at line 62 of file 3dExtrema.c. Referenced by average_extrema(), extrema_distance(), print_extrema(), to_3dmm(), and weight_extrema(). |
|
Definition at line 65 of file 3dExtrema.c. Referenced by EX_read_opts(), and find_extrema(). |
|
Definition at line 64 of file 3dExtrema.c. Referenced by EX_read_opts(), and find_extrema(). |
|
Definition at line 67 of file 3dExtrema.c. Referenced by EX_read_opts(), and find_extrema(). |
|
Definition at line 66 of file 3dExtrema.c. Referenced by EX_read_opts(), and find_extrema(). |
|
Definition at line 60 of file 3dExtrema.c. Referenced by process_all_datasets(). |
|
Definition at line 61 of file 3dExtrema.c. |
|
Value: if((ptr)==NULL) \ ( printf ("Cannot allocate memory \n"), exit(1) ) Definition at line 107 of file 3dExtrema.c. |
|
Definition at line 26 of file 3dExtrema.c. Referenced by main(). |
|
Definition at line 27 of file 3dExtrema.c. Referenced by main(). |
|
Definition at line 28 of file 3dExtrema.c. Referenced by main(). |
|
Definition at line 25 of file 3dExtrema.c. Referenced by EX_error(), initialize_program(), and main(). |
|
Value: do{ switch( DSET_BRICK_TYPE((ds),(vv)) ){ \ default: fprintf(stderr,"\n*** Illegal datum! ***\n");exit(1); \ case MRI_short:{ short * fim = (short *) DSET_ARRAY((ds),(vv)) ; \ (ptr) = (void *)( fim + (ind) ) ; \ } break ; \ case MRI_byte:{ byte * fim = (byte *) DSET_ARRAY((ds),(vv)) ; \ (ptr) = (void *)( fim + (ind) ) ; \ } break ; \ case MRI_float:{ float * fim = (float *) DSET_ARRAY((ds),(vv)) ; \ (ptr) = (void *)( fim + (ind) ) ; \ } break ; } break ; } while(0) Definition at line 133 of file 3dExtrema.c. |
Typedef Documentation
|
|
Function Documentation
|
Definition at line 338 of file 3dExtrema.c. References find_nearest_extrema(), new_extrema(), and extrema::next_extrema. Referenced by merge_extrema(), and new_extrema().
00339 { 00340 00341 new_extrema->next_extrema = head_extrema; 00342 00343 find_nearest_extrema (new_extrema, head_extrema); 00344 00345 return (new_extrema); 00346 } |
|
Definition at line 673 of file 3dExtrema.c. References merge_extrema(), extrema::nearest_dist, extrema::nearest_extrema, extrema::next_extrema, and sort_extrema(). Referenced by find_extrema().
00674 { 00675 const float MAX_DIST = 1.0e+30; 00676 00677 extrema * extrema_ptr = NULL; 00678 extrema * aextrema = NULL; 00679 extrema * bextrema = NULL; 00680 float min_dist; 00681 00682 00683 min_dist = 0.0; 00684 00685 while (min_dist < sep_dist) 00686 { 00687 /*----- Sort list of extrema -----*/ 00688 if (EX_sort) head_extrema = sort_extrema (head_extrema); 00689 00690 /*----- Find the two extrema which are closest together -----*/ 00691 min_dist = MAX_DIST; 00692 extrema_ptr = head_extrema; 00693 while (extrema_ptr != NULL) 00694 { 00695 if (extrema_ptr->nearest_dist < min_dist) 00696 { 00697 min_dist = extrema_ptr->nearest_dist; 00698 aextrema = extrema_ptr; 00699 bextrema = extrema_ptr->nearest_extrema; 00700 } 00701 extrema_ptr = extrema_ptr->next_extrema; 00702 } 00703 00704 /* 00705 printf ("min_dist = %f \n", min_dist); 00706 */ 00707 00708 00709 /*----- Merge these two extrema -----*/ 00710 if (min_dist < sep_dist) 00711 head_extrema = merge_extrema (aextrema, bextrema, head_extrema); 00712 } 00713 00714 return (head_extrema); 00715 } |
|
Definition at line 455 of file 3dExtrema.c. References extrema::centroid, extrema::count, EX_DIMENSION, i, initialize_extrema(), extrema::intensity, malloc, and MTEST. Referenced by merge_extrema().
00456 { 00457 extrema * abextrema = NULL; 00458 int na, nb; 00459 int i; 00460 00461 00462 /*----- Create new extrema -----*/ 00463 abextrema = initialize_extrema (); 00464 00465 00466 /*----- Sum counts of extrema -----*/ 00467 na = aextrema->count; 00468 nb = bextrema->count; 00469 abextrema->count = na + nb; 00470 00471 00472 /*----- Average of extrema intensities -----*/ 00473 abextrema->intensity = 00474 (na*aextrema->intensity + nb*bextrema->intensity) / (na+nb); 00475 00476 00477 abextrema->centroid = (float *) malloc (sizeof(float) * EX_DIMENSION); 00478 MTEST (abextrema->centroid); 00479 00480 00481 /*----- Average of extrema locations -----*/ 00482 for (i = 0; i < EX_DIMENSION; i++) 00483 abextrema->centroid[i] = 00484 (na*aextrema->centroid[i] + nb*bextrema->centroid[i]) / (na + nb); 00485 00486 00487 return (abextrema); 00488 } |
|
Definition at line 378 of file 3dExtrema.c. References extrema::centroid, and free. Referenced by remove_extrema(), and sort_extrema().
|
|
Definition at line 152 of file 3dExtrema.c. References PROGRAM_NAME. Referenced by EX_read_opts(), initialize_program(), process_all_datasets(), and write_bucket().
00153 { 00154 fprintf (stderr, "%s Error: %s \n", PROGRAM_NAME, message); 00155 exit(1); 00156 } |
|
Definition at line 1000 of file 3dExtrema.c. References argc, EX_data_thr, EX_error(), EX_GE, EX_GT, EX_interior, EX_LE, EX_LT, EX_mask_filename, EX_mask_thr, EX_maxima, EX_merge, EX_output_prefix, EX_quiet, EX_relation, EX_sep_dist, EX_session, EX_slice, EX_sort, EX_strict, malloc, MCW_strncpy, THD_MAX_NAME, and THD_MAX_PREFIX. Referenced by initialize_program().
01001 { 01002 int nopt = 1 ; 01003 char message[80]; /* error message */ 01004 01005 01006 while( nopt < argc ){ 01007 01008 /**** -prefix prefix ****/ 01009 if( strcmp(argv[nopt],"-prefix") == 0 || 01010 strcmp(argv[nopt],"-output") == 0 ){ 01011 nopt++ ; 01012 if( nopt >= argc ){ 01013 EX_error (" need argument after -prefix!"); 01014 } 01015 EX_output_prefix = (char *) malloc (sizeof(char) * THD_MAX_PREFIX); 01016 MCW_strncpy( EX_output_prefix , argv[nopt++] , THD_MAX_PREFIX ) ; 01017 continue ; 01018 } 01019 01020 01021 /**** -session directory ****/ 01022 if( strcmp(argv[nopt],"-session") == 0 ){ 01023 nopt++ ; 01024 if( nopt >= argc ){ 01025 EX_error (" need argument after -session!"); 01026 } 01027 EX_session = (char *) malloc (sizeof(char) * THD_MAX_NAME); 01028 MCW_strncpy( EX_session , argv[nopt++] , THD_MAX_NAME ) ; 01029 continue ; 01030 } 01031 01032 01033 /**** -quiet ****/ 01034 if( strcmp(argv[nopt],"-quiet") == 0 ){ 01035 EX_quiet = 1; 01036 nopt++ ; continue ; 01037 } 01038 01039 01040 /**** -minima ****/ 01041 if( strcmp(argv[nopt],"-minima") == 0 ){ 01042 EX_maxima = 0; 01043 nopt++; continue; 01044 } 01045 01046 01047 /**** -maxima ****/ 01048 if( strcmp(argv[nopt],"-maxima") == 0 ){ 01049 EX_maxima = 1; 01050 nopt++; continue; 01051 } 01052 01053 01054 /**** -strict ****/ 01055 if( strcmp(argv[nopt],"-strict") == 0 ){ 01056 EX_strict = 1; 01057 nopt++; continue; 01058 } 01059 01060 01061 /**** -partial ****/ 01062 if( strcmp(argv[nopt],"-partial") == 0 ){ 01063 EX_strict = 0; 01064 nopt++; continue; 01065 } 01066 01067 01068 /**** -interior ****/ 01069 if( strcmp(argv[nopt],"-interior") == 0 ){ 01070 EX_interior = 1; 01071 nopt++; continue; 01072 } 01073 01074 01075 /**** -closure ****/ 01076 if( strcmp(argv[nopt],"-closure") == 0 ){ 01077 EX_interior = 0; 01078 nopt++; continue; 01079 } 01080 01081 01082 /**** -slice ****/ 01083 if( strcmp(argv[nopt],"-slice") == 0 ){ 01084 EX_slice = 1; 01085 nopt++; continue; 01086 } 01087 01088 01089 /**** -volume ****/ 01090 if( strcmp(argv[nopt],"-volume") == 0 ){ 01091 EX_slice = 0; 01092 nopt++; continue; 01093 } 01094 01095 01096 /**** -sort ****/ 01097 if( strcmp(argv[nopt],"-sort") == 0 ){ 01098 EX_sort = 1; 01099 nopt++; continue; 01100 } 01101 01102 01103 /**** -mask_file mname ****/ 01104 if( strcmp(argv[nopt],"-mask_file") == 0 ){ 01105 nopt++ ; 01106 if( nopt >= argc ){ 01107 EX_error (" need 1 argument after -mask_file"); 01108 } 01109 01110 EX_mask_filename = (char *) malloc (sizeof(char) * THD_MAX_NAME); 01111 MCW_strncpy( EX_mask_filename , argv[nopt++] , THD_MAX_NAME ) ; 01112 continue; 01113 } 01114 01115 01116 /**** -mask_thr m ****/ 01117 if( strcmp(argv[nopt],"-mask_thr") == 0 ){ 01118 float fval; 01119 nopt++ ; 01120 if( nopt >= argc ){ 01121 EX_error (" need 1 argument after -mask_thr"); 01122 } 01123 sscanf (argv[nopt], "%f", &fval); 01124 if (fval < 0.0){ 01125 EX_error (" Require mask_thr >= 0.0 "); 01126 } 01127 EX_mask_thr = fval; 01128 nopt++; continue; 01129 01130 } 01131 01132 01133 /**** -data_thr d ****/ 01134 if( strcmp(argv[nopt],"-data_thr") == 0 ){ 01135 float fval; 01136 nopt++ ; 01137 if( nopt >= argc ){ 01138 EX_error (" need 1 argument after -data_thr"); 01139 } 01140 sscanf (argv[nopt], "%f", &fval); 01141 if (fval < 0.0){ 01142 EX_error (" Require data_thr >= 0.0 "); 01143 } 01144 EX_data_thr = fval; 01145 nopt++; continue; 01146 01147 } 01148 01149 01150 /**** -remove ****/ 01151 if( strcmp(argv[nopt],"-remove") == 0 ){ 01152 EX_merge = 1; 01153 nopt++; continue; 01154 } 01155 01156 01157 /**** -average ****/ 01158 if( strcmp(argv[nopt],"-average") == 0 ){ 01159 EX_merge = 2; 01160 nopt++; continue; 01161 } 01162 01163 01164 /**** -weight ****/ 01165 if( strcmp(argv[nopt],"-weight") == 0 ){ 01166 EX_merge = 3; 01167 nopt++; continue; 01168 } 01169 01170 01171 /**** -sep_dist d ****/ 01172 if( strcmp(argv[nopt],"-sep_dist") == 0 ){ 01173 float fval; 01174 nopt++ ; 01175 if( nopt >= argc ){ 01176 EX_error (" need 1 argument after -sep_dist"); 01177 } 01178 sscanf (argv[nopt], "%f", &fval); 01179 if (fval < 0.0){ 01180 EX_error (" Require data_thr >= 0.0 "); 01181 } 01182 EX_sep_dist = fval; 01183 nopt++; continue; 01184 01185 } 01186 01187 01188 /*----- Invalid option -----*/ 01189 if( argv[nopt][0] == '-' ){ 01190 sprintf (message, " Unknown option: %s ", argv[nopt]); 01191 EX_error (message); 01192 } 01193 01194 01195 /*----- Remaining inputs should be parameter datasets -----*/ 01196 break; 01197 01198 01199 } /* end of loop over command line arguments */ 01200 01201 01202 /*----- Check for valid input -----*/ 01203 if ((EX_merge == 3) && (EX_maxima == 0)) 01204 EX_error ("-weight option is not compatible with -minima option"); 01205 01206 01207 /*----- Set flag for binary relation -----*/ 01208 if ((EX_maxima == 1) && (EX_strict == 1)) EX_relation = EX_GT; 01209 if ((EX_maxima == 1) && (EX_strict == 0)) EX_relation = EX_GE; 01210 if ((EX_maxima == 0) && (EX_strict == 1)) EX_relation = EX_LT; 01211 if ((EX_maxima == 0) && (EX_strict == 0)) EX_relation = EX_LE; 01212 01213 01214 return (nopt) ; 01215 } |
|
Definition at line 930 of file 3dExtrema.c. References MASTER_SHORTHELP_STRING. Referenced by initialize_program().
00931 { 00932 printf( 00933 "This program finds local extrema (minima or maxima) of the input \n" 00934 "dataset values for each sub-brick of the input dataset. The extrema \n" 00935 "may be determined either for each volume, or for each individual slice.\n" 00936 "Only those voxels whose corresponding intensity value is greater than \n" 00937 "the user specified data threshold will be considered. \n" 00938 "\nUsage: 3dExtrema options datasets \n" 00939 "where the options are: \n" 00940 ) ; 00941 00942 printf( 00943 "-prefix pname = Use 'pname' for the output dataset prefix name. \n" 00944 " OR [default = NONE; only screen output] \n" 00945 "-output pname \n" 00946 " \n" 00947 "-session dir = Use 'dir' for the output dataset session directory. \n" 00948 " [default='./'=current working directory] \n" 00949 " \n" 00950 "-quiet = Flag to suppress screen output \n" 00951 " \n" 00952 "-mask_file mname = Use mask statistic from file mname. \n" 00953 " Note: If file mname contains more than 1 sub-brick, \n" 00954 " the mask sub-brick must be specified! \n" 00955 "-mask_thr m Only voxels whose mask statistic is greater \n" 00956 " than m in abolute value will be considered. \n" 00957 " \n" 00958 "-data_thr d Only voxels whose value (intensity) is greater \n" 00959 " than d in abolute value will be considered. \n" 00960 " \n" 00961 "-sep_dist d Min. separation distance [mm] for distinct extrema \n" 00962 " \n" 00963 "Choose type of extrema (one and only one choice): \n" 00964 "-minima Find local minima. \n" 00965 "-maxima Find local maxima. \n" 00966 " \n" 00967 "Choose form of binary relation (one and only one choice): \n" 00968 "-strict > for maxima, < for minima \n" 00969 "-partial >= for maxima, <= for minima \n" 00970 " \n" 00971 "Choose boundary criteria (one and only one choice): \n" 00972 "-interior Extrema must be interior points (not on boundary) \n" 00973 "-closure Extrema may be boudary points \n" 00974 " \n" 00975 "Choose domain for finding extrema (one and only one choice): \n" 00976 "-slice Each slice is considered separately \n" 00977 "-volume The volume is considered as a whole \n" 00978 " \n" 00979 "Choose option for merging of extrema (one and only one choice): \n" 00980 "-remove Remove all but strongest of neighboring extrema \n" 00981 "-average Replace neighboring extrema by average \n" 00982 "-weight Replace neighboring extrema by weighted average \n" 00983 " \n" 00984 "Command line arguments after the above are taken to be input datasets. \n" 00985 "\n") ; 00986 00987 printf("\n" MASTER_SHORTHELP_STRING ) ; 00988 00989 exit(0) ; 00990 00991 } |
|
Definition at line 270 of file 3dExtrema.c. References extrema::centroid, EX_DIMENSION, and i. Referenced by find_nearest_extrema().
|
|
Definition at line 758 of file 3dExtrema.c. References agglomerate_extrema(), EX_data_thr, EX_GE, EX_GT, EX_LE, EX_LT, EX_mask, EX_nx, EX_ny, EX_nz, EX_offset, EX_sep_dist, new_extrema(), nz, sort_extrema(), and to_3dmm(). Referenced by process_all_datasets().
00765 { 00766 int ix, jy, kz, ixyz; /* current voxel indices */ 00767 int it, ijk; /* neighboring voxel indices */ 00768 int nx, ny, nz, nxy, nxyz; /* numbers of voxels */ 00769 float fval; /* intensity of current voxel */ 00770 float * location = NULL; /* current voxel coordinates */ 00771 extrema * head_extrema = NULL; /* linked list of extrema */ 00772 int passed_test; /* flag for voxel is valid extema */ 00773 00774 00775 /*----- Initialize local variables -----*/ 00776 nx = EX_nx; ny = EX_ny; nz = EX_nz; 00777 nxy = nx * ny; nxyz = nx*ny*nz; 00778 00779 00780 /*----- Loop over voxels -----*/ 00781 for (ixyz = nfirst; ixyz < nlast; ixyz++) 00782 { 00783 00784 /*----- First, check if voxel is inside the mask -----*/ 00785 if (!EX_mask[ixyz]) continue; 00786 00787 /*----- Does voxel satisfy data threshold criterion? -----*/ 00788 fval = fvol[ixyz]; 00789 if (fabs(fval) < EX_data_thr) continue; 00790 00791 /*----- Begin loop over neighboring voxels -----*/ 00792 it = 0; 00793 passed_test = 1; 00794 while ((it < num_nv) && passed_test) 00795 { 00796 ijk = ixyz + EX_offset[it]; 00797 00798 /*----- Check for valid neighbor index -----*/ 00799 if ((ijk < nfirst) || (ijk >= nlast)) 00800 { 00801 if (EX_interior) passed_test = 0; 00802 } 00803 00804 /*----- Early exit if neighbor is not inside the mask -----*/ 00805 else if (!EX_mask[ijk]) 00806 { 00807 if (EX_interior) passed_test = 0; 00808 } 00809 00810 /*----- Test binary relation -----*/ 00811 else 00812 switch (EX_relation) 00813 { 00814 case EX_GT: 00815 if (fval <= fvol[ijk]) 00816 passed_test = 0; break; 00817 case EX_GE: 00818 if (fval < fvol[ijk]) 00819 passed_test = 0; break; 00820 case EX_LT: 00821 if (fval >= fvol[ijk]) 00822 passed_test = 0; break; 00823 case EX_LE: 00824 if (fval > fvol[ijk]) 00825 passed_test = 0; break; 00826 } 00827 00828 it++; 00829 } 00830 00831 00832 /*----- If extrema are found, save relevant information -----*/ 00833 if (passed_test) 00834 { 00835 location = to_3dmm (ixyz); 00836 head_extrema = new_extrema (location, fval, head_extrema); 00837 } 00838 } 00839 00840 00841 /*----- Agglomerate extrema -----*/ 00842 if (EX_sep_dist > 0.0) head_extrema = agglomerate_extrema (head_extrema, 00843 EX_sep_dist); 00844 00845 00846 /*----- Sort list of extrema -----*/ 00847 if (EX_sort) head_extrema = sort_extrema (head_extrema); 00848 00849 00850 return (head_extrema); 00851 } |
|
Definition at line 294 of file 3dExtrema.c. References extrema_distance(), extrema::nearest_dist, extrema::nearest_extrema, new_extrema(), and extrema::next_extrema. Referenced by add_extrema(), and remove_extrema().
00295 { 00296 const float MAX_DIST = 1.0e+30; 00297 00298 extrema * extrema_ptr = NULL; 00299 float dist; 00300 00301 00302 /*----- Initialize nearest extrema elements -----*/ 00303 new_extrema->nearest_dist = MAX_DIST; 00304 new_extrema->nearest_extrema = NULL; 00305 00306 00307 extrema_ptr = head_extrema; 00308 00309 while (extrema_ptr != NULL) 00310 { 00311 if (extrema_ptr != new_extrema) 00312 { 00313 dist = extrema_distance (new_extrema, extrema_ptr); 00314 00315 if (dist < new_extrema->nearest_dist) 00316 { 00317 new_extrema->nearest_dist = dist; 00318 new_extrema->nearest_extrema = extrema_ptr; 00319 } 00320 00321 if (dist < extrema_ptr->nearest_dist) 00322 { 00323 extrema_ptr->nearest_dist = dist; 00324 extrema_ptr->nearest_extrema = new_extrema; 00325 } 00326 } 00327 00328 extrema_ptr = extrema_ptr->next_extrema; 00329 } 00330 } |
|
Definition at line 859 of file 3dExtrema.c. References EX_nx, EX_nxy, EX_ny, EX_nz, THD_ivec3::ijk, THD_3dmm_to_3dind(), THD_coorder_to_dicom(), THD_dicomm_to_3dmm(), THREE_TO_IJK, and THD_fvec3::xyz. Referenced by save_extrema().
00860 { 00861 float x, y, z; 00862 THD_fvec3 fv; 00863 int ix, jy, kz; 00864 THD_ivec3 iv; 00865 int ixyz; 00866 00867 x = location[0]; y = location[1]; z = location[2]; 00868 00869 THD_coorder_to_dicom (&EX_cord, &x, &y, &z); 00870 00871 fv.xyz[0] = x; fv.xyz[1] = y; fv.xyz[2] = z; 00872 00873 fv = THD_dicomm_to_3dmm (EX_dset, fv); 00874 00875 iv = THD_3dmm_to_3dind (EX_dset, fv); 00876 00877 ix = iv.ijk[0]; jy = iv.ijk[1]; kz = iv.ijk[2]; 00878 00879 if (ix < 0) ix = 0; if (ix > EX_nx-1) ix = EX_nx-1; 00880 if (jy < 0) jy = 0; if (jy > EX_ny-1) jy = EX_ny-1; 00881 if (kz < 0) kz = 0; if (kz > EX_nz-1) kz = EX_nz-1; 00882 00883 ixyz = THREE_TO_IJK (ix, jy, kz, EX_nx, EX_nxy); 00884 00885 return (ixyz); 00886 00887 } |
|
Definition at line 164 of file 3dExtrema.c. References extrema::centroid, extrema::count, extrema::intensity, malloc, MTEST, extrema::nearest_dist, extrema::nearest_extrema, extrema::next_extrema, and extrema::sum. Referenced by average_extrema(), new_extrema(), sort_extrema(), and weight_extrema().
00165 { 00166 extrema * extrema_ptr = NULL; 00167 00168 extrema_ptr = (extrema *) malloc (sizeof(extrema)); 00169 MTEST (extrema_ptr); 00170 00171 extrema_ptr->intensity = 0.0; 00172 extrema_ptr->centroid = NULL; 00173 extrema_ptr->count = 0; 00174 extrema_ptr->sum = 0.0; 00175 extrema_ptr->nearest_dist = 0.0; 00176 extrema_ptr->nearest_extrema = NULL; 00177 extrema_ptr->next_extrema = NULL; 00178 00179 return (extrema_ptr); 00180 00181 } |
|
Definition at line 1224 of file 3dExtrema.c. References AFNI_logger(), argc, commandline, DOPEN, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_PRINCIPAL_VALUE, EDIT_coerce_scale_type(), EX_error(), EX_mask, EX_mask_filename, EX_mask_thr, EX_nx, EX_nxy, EX_nxyz, EX_ny, EX_nz, EX_offset, EX_quiet, EX_read_opts(), EX_Syntax(), free, malloc, MTEST, my_getenv(), nz, PROGRAM_NAME, SUB_POINTER, THD_coorder_fill(), THD_delete_3dim_dataset(), THD_open_dataset(), and tross_commandline().
01225 { 01226 const int MIN_NTHR = 10; /* minimum number of voxels above threshold */ 01227 01228 int iv; /* index number of sub-brick */ 01229 void * vfim = NULL; /* sub-brick data pointer */ 01230 float * ffim = NULL; /* sub-brick data in floating point format */ 01231 int ixyz, nthr; /* voxel indices */ 01232 int nx, ny, nz, nxy, nxyz = 0; /* numbers of voxels */ 01233 char message[80]; /* error message */ 01234 01235 01236 /*----- Save command line for history notes -----*/ 01237 commandline = tross_commandline( PROGRAM_NAME , argc,argv ) ; 01238 01239 01240 /*----- Does user request help menu? -----*/ 01241 if( argc < 2 || strcmp(argv[1],"-help") == 0 ) EX_Syntax() ; 01242 01243 01244 /*----- Add to program log -----*/ 01245 AFNI_logger (PROGRAM_NAME,argc,argv); 01246 01247 01248 /*----- Read input options -----*/ 01249 *nopt = EX_read_opts( argc , argv ) ; 01250 01251 01252 /*----- Get coordinate directions -----*/ 01253 THD_coorder_fill (my_getenv("AFNI_ORIENT"), &EX_cord); 01254 01255 01256 /*----- Open the mask dataset -----*/ 01257 if (EX_mask_filename != NULL) 01258 { 01259 if (!EX_quiet) printf ("Reading mask dataset: %s \n", EX_mask_filename); 01260 DOPEN (EX_dset, EX_mask_filename); 01261 01262 if (EX_dset == NULL) 01263 { 01264 sprintf (message, "Cannot open mask dataset %s", EX_mask_filename); 01265 EX_error (message); 01266 } 01267 01268 if (DSET_NVALS(EX_dset) != 1) 01269 EX_error ("Must specify single sub-brick for mask data"); 01270 01271 01272 /*----- Get dimensions of mask dataset -----*/ 01273 nx = DSET_NX(EX_dset); 01274 ny = DSET_NY(EX_dset); 01275 nz = DSET_NZ(EX_dset); 01276 nxy = nx * ny; nxyz = nx*ny*nz; 01277 01278 01279 /*----- Allocate memory for float data -----*/ 01280 ffim = (float *) malloc (sizeof(float) * nxyz); MTEST (ffim); 01281 01282 01283 /*----- Convert mask dataset sub-brick to floats (in ffim) -----*/ 01284 iv = DSET_PRINCIPAL_VALUE (EX_dset); 01285 SUB_POINTER (EX_dset, iv, 0, vfim); 01286 EDIT_coerce_scale_type (nxyz, DSET_BRICK_FACTOR(EX_dset,iv), 01287 DSET_BRICK_TYPE(EX_dset,iv), vfim, /* input */ 01288 MRI_float , ffim); /* output */ 01289 01290 01291 /*----- Allocate memory for mask volume -----*/ 01292 EX_mask = (byte *) malloc (sizeof(byte) * nxyz); 01293 MTEST (EX_mask); 01294 01295 01296 /*----- Create mask of voxels above mask threshold -----*/ 01297 nthr = 0; 01298 for (ixyz = 0; ixyz < nxyz; ixyz++) 01299 if (fabs(ffim[ixyz]) >= EX_mask_thr) 01300 { 01301 EX_mask[ixyz] = 1; 01302 nthr++; 01303 } 01304 else 01305 EX_mask[ixyz] = 0; 01306 01307 if (!EX_quiet) 01308 printf ("Number of voxels above mask threshold = %d \n", nthr); 01309 if (nthr < MIN_NTHR) 01310 { 01311 sprintf (message, 01312 "Only %d voxels above mask threshold. Cannot continue.", 01313 nthr); 01314 EX_error (message); 01315 } 01316 01317 01318 /*----- Delete floating point sub-brick -----*/ 01319 if (ffim != NULL) { free (ffim); ffim = NULL; } 01320 01321 /*----- Delete mask dataset -----*/ 01322 THD_delete_3dim_dataset (EX_dset, False); EX_dset = NULL ; 01323 01324 } 01325 01326 01327 /*----- Open first input dataset -----*/ 01328 { 01329 /*----- Check if this is an input option -----*/ 01330 if (argv[*nopt][0] == '-') 01331 EX_error ("ALL input options must precede ALL input datasets"); 01332 01333 /*----- Open the input dataset -----*/ 01334 if (!EX_quiet) printf ("Reading input dataset: %s \n", argv[*nopt]); 01335 EX_dset = THD_open_dataset(argv[*nopt]); 01336 01337 if (EX_dset == NULL) 01338 { 01339 sprintf (message, "Cannot open input dataset %s", argv[*nopt]); 01340 EX_error (message); 01341 } 01342 01343 /*----- Get dimensions of input dataset -----*/ 01344 if (nxyz == 0) 01345 { 01346 nx = DSET_NX(EX_dset); 01347 ny = DSET_NY(EX_dset); 01348 nz = DSET_NZ(EX_dset); 01349 nxy = nx * ny; nxyz = nx*ny*nz; 01350 } 01351 01352 /*----- Create mask, if not already done -----*/ 01353 if (EX_mask == NULL) 01354 { 01355 /*----- Allocate memory for mask volume -----*/ 01356 EX_mask = (byte *) malloc (sizeof(byte) * nxyz); 01357 MTEST (EX_mask); 01358 for (ixyz = 0; ixyz < nxyz; ixyz++) 01359 EX_mask[ixyz] = 1; 01360 } 01361 01362 } 01363 01364 01365 /*----- Save dimensions of dataset for compatibility test -----*/ 01366 EX_nx = nx; EX_ny = ny; EX_nz = nz; 01367 EX_nxy = nxy; EX_nxyz = nxyz; 01368 01369 01370 /*----- The offset array definitions were borrowed from plug_maxima -----*/ 01371 EX_offset[ 0] = +1; EX_offset[ 8] = nxy; EX_offset[17] = -nxy; 01372 EX_offset[ 1] = -1; EX_offset[ 9] = nxy+1; EX_offset[18] = -nxy+1; 01373 EX_offset[ 2] = nx; EX_offset[10] = nxy-1; EX_offset[19] = -nxy-1; 01374 EX_offset[ 3] = nx+1; EX_offset[11] = nxy+nx; EX_offset[20] = -nxy+nx; 01375 EX_offset[ 4] = nx-1; EX_offset[12] = nxy+nx+1; EX_offset[21] = -nxy+nx+1; 01376 EX_offset[ 5] = -nx; EX_offset[13] = nxy+nx-1; EX_offset[22] = -nxy+nx-1; 01377 EX_offset[ 6] = -nx+1; EX_offset[14] = nxy-nx; EX_offset[23] = -nxy-nx; 01378 EX_offset[ 7] = -nx-1; EX_offset[15] = nxy-nx+1; EX_offset[24] = -nxy-nx+1; 01379 EX_offset[16] = nxy-nx-1; EX_offset[25] = -nxy-nx-1; 01380 01381 } |
|
compute the overall minimum and maximum voxel values for a dataset Definition at line 1654 of file 3dExtrema.c. References addto_args(), argc, initialize_program(), machdep(), mainENTRY, output_results(), PRINT_VERSION, process_all_datasets(), PROGRAM_AUTHOR, PROGRAM_INITIAL, PROGRAM_LATEST, and PROGRAM_NAME.
01656 { 01657 int nopt; 01658 01659 01660 /*----- Identify software -----*/ 01661 #if 0 01662 printf ("\n\n"); 01663 printf ("Program: %s \n", PROGRAM_NAME); 01664 printf ("Author: %s \n", PROGRAM_AUTHOR); 01665 printf ("Initial Release: %s \n", PROGRAM_INITIAL); 01666 printf ("Latest Revision: %s \n", PROGRAM_LATEST); 01667 printf ("\n"); 01668 #else 01669 PRINT_VERSION("3dExtrema") ; mainENTRY("3dExtrema main") ; 01670 #endif 01671 01672 01673 /*-- 20 Apr 2001: addto the arglist, if user wants to [RWCox] --*/ 01674 machdep() ; 01675 { int new_argc ; char ** new_argv ; 01676 addto_args( argc , argv , &new_argc , &new_argv ) ; 01677 if( new_argv != NULL ){ argc = new_argc ; argv = new_argv ; } 01678 } 01679 01680 01681 /*----- Initialize program: get all operator inputs; 01682 create mask for voxels above mask threshold -----*/ 01683 initialize_program (argc, argv, &nopt); 01684 01685 01686 /*----- Process all datasets -----*/ 01687 process_all_datasets (argc, argv, nopt); 01688 01689 01690 /*----- Output the results -----*/ 01691 output_results (); 01692 01693 01694 exit(0) ; 01695 } |
|
Definition at line 541 of file 3dExtrema.c. References add_extrema(), average_extrema(), extrema::count, EX_maxima, extrema::intensity, remove_extrema(), and weight_extrema(). Referenced by agglomerate_extrema().
00543 { 00544 extrema * abextrema = NULL; 00545 00546 00547 switch (EX_merge) 00548 { 00549 case 1: /*----- Merge extrema by removing the weakest -----*/ 00550 00551 if ((EX_maxima && ((aextrema->intensity) > (bextrema->intensity))) 00552 || (!EX_maxima && ((aextrema->intensity) < (bextrema->intensity)))) 00553 { 00554 aextrema->count++; 00555 head_extrema = remove_extrema (bextrema, head_extrema); 00556 } 00557 else 00558 { 00559 bextrema->count++; 00560 head_extrema = remove_extrema (aextrema, head_extrema); 00561 } 00562 break; 00563 00564 00565 case 2: /*----- Merge extrema using average -----*/ 00566 00567 /*----- Merge two extrema into one new extrema -----*/ 00568 abextrema = average_extrema (aextrema, bextrema); 00569 00570 /*----- Remove the two original extrema from the linked list -----*/ 00571 head_extrema = remove_extrema (aextrema, head_extrema); 00572 head_extrema = remove_extrema (bextrema, head_extrema); 00573 00574 00575 /*----- Add the merged extrema to the linked list -----*/ 00576 head_extrema = add_extrema (abextrema, head_extrema); 00577 00578 break; 00579 00580 00581 case 3: /*----- Merge extrema using weighted average -----*/ 00582 00583 /*----- Merge two extrema into one new extrema -----*/ 00584 abextrema = weight_extrema (aextrema, bextrema); 00585 00586 /*----- Remove the two original extrema from the linked list -----*/ 00587 head_extrema = remove_extrema (aextrema, head_extrema); 00588 head_extrema = remove_extrema (bextrema, head_extrema); 00589 00590 00591 /*----- Add the merged extrema to the linked list -----*/ 00592 head_extrema = add_extrema (abextrema, head_extrema); 00593 00594 break; 00595 00596 } 00597 00598 return (head_extrema); 00599 00600 } |
|
Definition at line 354 of file 3dExtrema.c. References add_extrema(), extrema::centroid, extrema::count, initialize_extrema(), extrema::intensity, and extrema::sum. Referenced by add_extrema(), find_extrema(), and find_nearest_extrema().
00356 { 00357 extrema * extrema_ptr = NULL; 00358 00359 extrema_ptr = initialize_extrema (); 00360 00361 extrema_ptr->intensity = intensity; 00362 extrema_ptr->centroid = centroid; 00363 extrema_ptr->count = 1; 00364 extrema_ptr->sum = intensity; 00365 00366 head_extrema = add_extrema (extrema_ptr, head_extrema); 00367 00368 return (head_extrema); 00369 00370 } |
|
Definition at line 1616 of file 3dExtrema.c. References EX_nbricks, EX_nz, EX_output_prefix, EX_quiet, print_all_extrema(), and write_bucket(). Referenced by main().
01617 { 01618 int islice, ibrick; 01619 int nslices, nbricks; 01620 01621 01622 /*----- Initialize local variables -----*/ 01623 nbricks = EX_nbricks; 01624 nslices = EX_nz; 01625 01626 01627 /*----- Write extrema to screen -----*/ 01628 if (!EX_quiet) 01629 if (EX_slice) 01630 for (ibrick = 0; ibrick < nbricks; ibrick++) 01631 { 01632 for (islice = 0; islice < nslices; islice++) 01633 { 01634 print_all_extrema (ibrick, islice, 01635 EX_head_extrema[islice + ibrick*nslices]); 01636 } 01637 } 01638 else 01639 for (ibrick = 0; ibrick < nbricks; ibrick++) 01640 { 01641 print_all_extrema (ibrick, -1, EX_head_extrema[ibrick]); 01642 } 01643 01644 01645 /*----- Write extrema to bucket dataset -----*/ 01646 if (EX_output_prefix != NULL) 01647 write_bucket (); 01648 01649 } |
|
Definition at line 217 of file 3dExtrema.c. References extrema::next_extrema, print_extrema(), THD_coorder::xxor, THD_coorder::yyor, and THD_coorder::zzor. Referenced by output_results().
00218 { 00219 int index; 00220 00221 printf ("\n"); 00222 if (EX_maxima) 00223 printf ("Maxima "); 00224 else 00225 printf ("Minima "); 00226 00227 if (EX_slice) 00228 printf ("for Volume #%d and Slice #%d: \n", ivolume, islice); 00229 else 00230 printf ("for Volume #%d: \n", ivolume); 00231 00232 00233 if (extrema_ptr != NULL) 00234 { 00235 printf ("%5s", "Index"); 00236 printf ("%15s", "Intensity"); 00237 printf ("%6s[mm]", ORIENT_tinystr[EX_cord.xxor]); 00238 printf ("%6s[mm]", ORIENT_tinystr[EX_cord.yyor]); 00239 printf ("%6s[mm]", ORIENT_tinystr[EX_cord.zzor]); 00240 printf ("%10s", "Count"); 00241 printf ("%6s[mm]", "Dist"); 00242 printf ("\n"); 00243 00244 printf ( "%5s", "-----"); 00245 printf ("%15s", "---------"); 00246 printf ("%10s", "------"); 00247 printf ("%10s", "------"); 00248 printf ("%10s", "------"); 00249 printf ("%10s", "-----"); 00250 printf ("%10s", "--------"); 00251 printf ("\n"); 00252 } 00253 00254 index = 0; 00255 while (extrema_ptr != NULL) 00256 { 00257 index++; 00258 print_extrema (index, extrema_ptr); 00259 extrema_ptr = extrema_ptr->next_extrema; 00260 } 00261 } |
|
Definition at line 189 of file 3dExtrema.c. References extrema::centroid, extrema::count, EX_DIMENSION, extrema::intensity, and extrema::nearest_dist. Referenced by print_all_extrema().
00190 { 00191 int j; 00192 char str[30]; 00193 00194 sprintf (str, "%5d", index); 00195 printf ("%5s", str); 00196 00197 printf ("%15.3f", extrema_ptr->intensity); 00198 00199 for (j = 0; j < EX_DIMENSION; j++) 00200 printf ("%10.2f", extrema_ptr->centroid[j]); 00201 00202 00203 printf("%10d", extrema_ptr->count); 00204 00205 if (extrema_ptr->nearest_dist < 1.0e+20) 00206 printf ("%10.3f", extrema_ptr->nearest_dist); 00207 00208 printf ("\n"); 00209 } |
|
Definition at line 1389 of file 3dExtrema.c. References argc, DOPEN, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, EX_error(), EX_MAX_LL, EX_nbricks, EX_num_ll, EX_nx, EX_nxyz, EX_ny, EX_nz, EX_quiet, find_extrema(), free, malloc, MTEST, nz, SUB_POINTER, and THD_delete_3dim_dataset(). Referenced by main().
01390 { 01391 THD_3dim_dataset * input_dset=NULL; /* input dataset(s) */ 01392 01393 int iv; /* index number of sub-brick */ 01394 void * vfim = NULL; /* sub-brick data pointer */ 01395 float * ffim = NULL; /* sub-brick data in floating point format */ 01396 int ibrick, nbricks; /* sub-brick indices */ 01397 char message[80]; /* error message */ 01398 int nx, ny, nz, nxy, nxyz; /* numbers of voxels */ 01399 int kz, nfirst, nlast; /* range of voxel indices */ 01400 01401 01402 /*----- Initialize local variables -----*/ 01403 nx = EX_nx; ny = EX_ny; nz = EX_nz; 01404 nxy = nx * ny; nxyz = nx*ny*nz; 01405 01406 01407 /*----- Allocate memory for float data -----*/ 01408 ffim = (float *) malloc (sizeof(float) * EX_nxyz); MTEST (ffim); 01409 01410 01411 /*----- Begin loop over input datasets -----*/ 01412 EX_nbricks = 0; 01413 while (nopt < argc) 01414 { 01415 /*----- Check if this is an input option -----*/ 01416 if (argv[nopt][0] == '-') 01417 EX_error ("ALL input options must precede ALL input datasets"); 01418 01419 /*----- Open the input dataset -----*/ 01420 if (!EX_quiet) printf ("Reading input dataset: %s \n", argv[nopt]); 01421 DOPEN (input_dset, argv[nopt]); 01422 01423 if (input_dset == NULL) 01424 { 01425 sprintf (message, "Cannot open input dataset %s", argv[nopt]); 01426 EX_error (message); 01427 } 01428 01429 /*----- Test for dataset compatibility -----*/ 01430 if ((EX_nx != DSET_NX(input_dset)) || (EX_ny != DSET_NY(input_dset)) 01431 || (EX_nz != DSET_NZ(input_dset))) 01432 { 01433 sprintf (message, "Input dataset %s has incompatible dimensions", 01434 argv[nopt]); 01435 EX_error (message); 01436 } 01437 01438 01439 /*----- Get number of volumes specified for this dataset -----*/ 01440 nbricks = DSET_NVALS(input_dset); 01441 01442 01443 /*----- Loop over sub-bricks selected from input dataset -----*/ 01444 for (ibrick = 0; ibrick < nbricks; ibrick++) 01445 { 01446 if (!EX_quiet) printf ("Reading volume #%d \n", EX_nbricks); 01447 01448 SUB_POINTER (input_dset, ibrick, 0, vfim); 01449 EDIT_coerce_scale_type 01450 (EX_nxyz, DSET_BRICK_FACTOR(input_dset,ibrick), 01451 DSET_BRICK_TYPE(input_dset,ibrick), vfim, /* input */ 01452 MRI_float , ffim); /* output */ 01453 01454 if (EX_slice) /*----- Find extrema slice-by-slice -----*/ 01455 { 01456 for (kz = 0; kz < nz; kz++) 01457 { 01458 nfirst = kz*nxy; nlast = nfirst + nxy; 01459 EX_head_extrema[EX_num_ll] 01460 = find_extrema (ffim, 8, nfirst, nlast); 01461 EX_num_ll++; 01462 if (EX_num_ll >= EX_MAX_LL) 01463 EX_error ("Exceeded Max. Number of Linked Lists"); 01464 } 01465 } 01466 else /*----- Find extrema for entire volume -----*/ 01467 { 01468 EX_head_extrema[EX_num_ll] = find_extrema (ffim, 26, 0, nxyz); 01469 EX_num_ll++; 01470 if (EX_num_ll >= EX_MAX_LL) 01471 EX_error ("Exceeded Max. Number of Linked Lists"); 01472 } 01473 01474 /*----- Increment count of sub-bricks -----*/ 01475 EX_nbricks++; 01476 } 01477 01478 01479 /*----- Delete input dataset -----*/ 01480 THD_delete_3dim_dataset (input_dset, False); input_dset = NULL ; 01481 01482 nopt++; 01483 } 01484 01485 01486 /*----- Delete floating point sub-brick -----*/ 01487 if (ffim != NULL) { free (ffim); ffim = NULL; } 01488 01489 01490 if (!EX_quiet) printf ("Number of volumes = %d \n", EX_nbricks); 01491 if (EX_nbricks < 1) EX_error ("No input data?"); 01492 01493 01494 } |
|
Definition at line 400 of file 3dExtrema.c. References delete_extrema(), find_nearest_extrema(), extrema::nearest_extrema, and extrema::next_extrema. Referenced by merge_extrema().
00401 { 00402 extrema * extrema_ptr = NULL; 00403 extrema * next_extrema = NULL; 00404 00405 00406 if (head_extrema == NULL) return; 00407 00408 00409 /*----- Remove aextrema from list; reset pointers -----*/ 00410 if (head_extrema == aextrema) 00411 head_extrema = head_extrema->next_extrema; 00412 else 00413 { 00414 extrema_ptr = head_extrema; 00415 next_extrema = extrema_ptr->next_extrema; 00416 while (next_extrema != NULL) 00417 { 00418 if (next_extrema == aextrema) 00419 extrema_ptr->next_extrema = next_extrema->next_extrema; 00420 else 00421 extrema_ptr = next_extrema; 00422 00423 next_extrema = extrema_ptr->next_extrema; 00424 } 00425 } 00426 00427 00428 /*----- Recalculate distances to nearest extrema -----*/ 00429 if (head_extrema != NULL) 00430 { 00431 extrema_ptr = head_extrema; 00432 while (extrema_ptr != NULL) 00433 { 00434 if (extrema_ptr->nearest_extrema == aextrema) 00435 { 00436 find_nearest_extrema (extrema_ptr, head_extrema); 00437 } 00438 extrema_ptr = extrema_ptr->next_extrema; 00439 } 00440 } 00441 00442 00443 /*----- Delete aextrema -----*/ 00444 delete_extrema (aextrema); 00445 00446 return (head_extrema); 00447 } |
|
Definition at line 911 of file 3dExtrema.c. References extrema::next_extrema, and save_extrema(). Referenced by write_bucket().
00912 { 00913 byte iextrema = 0; 00914 00915 while (extrema_ptr != NULL) 00916 { 00917 iextrema++; 00918 save_extrema (extrema_ptr, iextrema, bar); 00919 extrema_ptr = extrema_ptr->next_extrema; 00920 } 00921 00922 } |
|
Definition at line 895 of file 3dExtrema.c. References extrema::centroid, and from_3dmm(). Referenced by save_all_extrema().
|
|
Definition at line 608 of file 3dExtrema.c. References delete_extrema(), EX_maxima, i, initialize_extrema(), extrema::intensity, mp, and extrema::next_extrema. Referenced by agglomerate_extrema(), and find_extrema().
00609 { 00610 extrema * i = NULL; 00611 extrema * ip = NULL; 00612 extrema * m = NULL; 00613 extrema * mp = NULL; 00614 extrema * j = NULL; 00615 extrema * jp = NULL; 00616 extrema * guard = NULL; 00617 00618 00619 /*----- Create guard extrema in case head extrema must be replaced -----*/ 00620 guard = initialize_extrema(); 00621 guard->next_extrema = head_extrema; 00622 ip = guard; 00623 00624 while (ip->next_extrema != NULL) 00625 { 00626 /*----- Initialize search for next largest extrema -----*/ 00627 i = ip->next_extrema; /* current top of list */ 00628 mp = ip; /* extrema pointing to next largest extrema */ 00629 m = i; /* next largest extrema */ 00630 jp = i; 00631 00632 /*----- Search through list for next largest extrema -----*/ 00633 while (jp->next_extrema != NULL) 00634 { 00635 j = jp->next_extrema; 00636 if ( ((EX_maxima) && ((j->intensity) > (m->intensity))) 00637 || ((!EX_maxima) && ((j->intensity) < (m->intensity))) ) 00638 { 00639 mp = jp; 00640 m = j; 00641 } 00642 jp = j; 00643 } 00644 00645 /*----- Now move next largest extrema to top of list -----*/ 00646 if (m != i) 00647 { 00648 ip->next_extrema = m; 00649 mp->next_extrema = m->next_extrema; 00650 m->next_extrema = i; 00651 i = m; 00652 } 00653 00654 /*----- Move down the list -----*/ 00655 ip = i; 00656 00657 } 00658 00659 00660 /*----- Replace head extrema -----*/ 00661 head_extrema = guard->next_extrema; 00662 delete_extrema (guard); 00663 00664 return (head_extrema); 00665 } |
|
Definition at line 723 of file 3dExtrema.c. References EX_DIMENSION, EX_nx, EX_nxy, THD_ivec3::ijk, IJK_TO_THREE, malloc, THD_3dind_to_3dmm(), THD_3dmm_to_dicomm(), THD_dicom_to_coorder(), and THD_fvec3::xyz. Referenced by find_extrema().
00724 { 00725 float * location = NULL; 00726 float x, y, z; 00727 int ix, jy, kz; 00728 THD_fvec3 fv; 00729 THD_ivec3 iv; 00730 00731 00732 location = (float *) malloc (sizeof(float) * EX_DIMENSION); 00733 00734 IJK_TO_THREE (ixyz, ix, jy, kz, EX_nx, EX_nxy); 00735 00736 iv.ijk[0] = ix; iv.ijk[1] = jy; iv.ijk[2] = kz; 00737 00738 fv = THD_3dind_to_3dmm (EX_dset, iv); 00739 00740 fv = THD_3dmm_to_dicomm (EX_dset, fv); 00741 00742 x = fv.xyz[0]; y = fv.xyz[1]; z = fv.xyz[2]; 00743 00744 THD_dicom_to_coorder (&EX_cord, &x, &y, &z); 00745 00746 location[0] = x; location[1] = y; location[2] = z; 00747 00748 return (location); 00749 } |
|
Definition at line 496 of file 3dExtrema.c. References extrema::centroid, extrema::count, EX_DIMENSION, i, initialize_extrema(), extrema::intensity, malloc, MTEST, and extrema::sum. Referenced by merge_extrema().
00497 { 00498 extrema * abextrema = NULL; 00499 float suma, sumb; 00500 int i; 00501 00502 00503 /*----- Create new extrema -----*/ 00504 abextrema = initialize_extrema (); 00505 00506 00507 /*----- Sum counts of extrema -----*/ 00508 abextrema->count = aextrema->count + bextrema->count; 00509 00510 00511 /*----- Sum intensities of extrema -----*/ 00512 suma = aextrema->sum; 00513 sumb = bextrema->sum; 00514 abextrema->sum = suma + sumb; 00515 00516 00517 /*----- Weighted average of extrema intensities -----*/ 00518 abextrema->intensity = 00519 (suma*aextrema->intensity + sumb*bextrema->intensity) / (suma + sumb); 00520 00521 00522 abextrema->centroid = (float *) malloc (sizeof(float) * EX_DIMENSION); 00523 MTEST (abextrema->centroid); 00524 00525 00526 /*----- Weighted average of extrema locations -----*/ 00527 for (i = 0; i < EX_DIMENSION; i++) 00528 abextrema->centroid[i] = 00529 (suma*aextrema->centroid[i] + sumb*bextrema->centroid[i]) / (suma+sumb); 00530 00531 00532 return (abextrema); 00533 } |
|
Definition at line 1502 of file 3dExtrema.c. References ADN_directory_name, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_type, commandline, DATABLOCK_MEM_MALLOC, DSET_BRIKNAME, DSET_HEADNAME, EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), EX_error(), EX_nbricks, EX_nxyz, EX_nz, EX_output_prefix, EX_quiet, EX_session, FUNC_BUCK_TYPE, HEAD_FUNC_TYPE, malloc, MTEST, nz, save_all_extrema(), THD_delete_3dim_dataset(), THD_is_file(), THD_load_statistics(), THD_write_3dim_dataset(), tross_Append_History(), and tross_Copy_History(). Referenced by output_results().
01504 { 01505 THD_3dim_dataset * new_dset = NULL; /* output bucket dataset */ 01506 int ixyz, nxyz; /* voxel indices */ 01507 int kz, nz; /* slice indices */ 01508 extrema * head_extrema = NULL; /* pointer to linked list of extrema */ 01509 byte ** bar = NULL; /* array of extrema sub-bricks */ 01510 int nbricks; /* number of extrema sub-bricks */ 01511 int ibrick; /* extrema sub-brick index */ 01512 int ierror; /* number of errors in editing data */ 01513 01514 char message[80]; /* error message */ 01515 01516 01517 /*----- Initialize local variables -----*/ 01518 nz = EX_nz; 01519 nxyz = EX_nxyz; 01520 nbricks = EX_nbricks; 01521 if (!EX_quiet) 01522 printf ("\nOutput dataset will have %d sub-bricks\n", nbricks); 01523 01524 01525 /*-- Make an empty copy of input dataset, for eventual output --*/ 01526 new_dset = EDIT_empty_copy (EX_dset); 01527 01528 01529 /*----- Record history of dataset -----*/ 01530 tross_Copy_History (EX_dset, new_dset); 01531 if( commandline != NULL ) tross_Append_History( new_dset , commandline ) ; 01532 01533 01534 /*----- Modify some structural properties. Note that the nbricks 01535 just make empty sub-bricks, without any data attached. -----*/ 01536 ierror = EDIT_dset_items (new_dset, 01537 ADN_prefix, EX_output_prefix, 01538 ADN_directory_name, EX_session, 01539 ADN_type, HEAD_FUNC_TYPE, 01540 ADN_func_type, FUNC_BUCK_TYPE, 01541 ADN_ntt, 0, /* no time */ 01542 ADN_nvals, nbricks, 01543 ADN_malloc_type, DATABLOCK_MEM_MALLOC , 01544 ADN_none ) ; 01545 01546 if( ierror > 0 ) 01547 { 01548 sprintf (message, 01549 " %d errors in attempting to create bucket dataset! ", 01550 ierror); 01551 EX_error (message); 01552 } 01553 01554 if (THD_is_file(DSET_HEADNAME(new_dset))) 01555 { 01556 sprintf (message, 01557 " Output dataset file %s already exists--cannot continue! ", 01558 DSET_HEADNAME(new_dset)); 01559 EX_error (message); 01560 } 01561 01562 01563 /*----- Allocate memory -----*/ 01564 bar = (byte **) malloc (sizeof(byte *) * nbricks); 01565 MTEST (bar); 01566 01567 01568 /*----- Save extrema into sub-bricks -----*/ 01569 for (ibrick = 0; ibrick < nbricks; ibrick++) 01570 { 01571 /*----- allocate memory for output sub-brick -----*/ 01572 bar[ibrick] = (byte *) malloc (sizeof(byte) * nxyz); 01573 MTEST (bar[ibrick]); 01574 01575 /*----- Save extrema into output sub-brick -----*/ 01576 for (ixyz = 0; ixyz < nxyz; ixyz++) 01577 bar[ibrick][ixyz] = 0; 01578 if (EX_slice) 01579 for (kz = 0; kz < nz; kz++) 01580 { 01581 head_extrema = EX_head_extrema[kz+ibrick*nz]; 01582 save_all_extrema (head_extrema, bar[ibrick]); 01583 } 01584 else 01585 { 01586 head_extrema = EX_head_extrema[ibrick]; 01587 save_all_extrema (head_extrema, bar[ibrick]); 01588 } 01589 01590 /*----- attach bar[ib] to be sub-brick #ibrick -----*/ 01591 EDIT_substitute_brick (new_dset, ibrick, MRI_byte, bar[ibrick]); 01592 01593 } 01594 01595 01596 /*----- Output the extrema dataset -----*/ 01597 if( !EX_quiet ) fprintf(stderr,"Computing sub-brick statistics\n") ; 01598 THD_load_statistics( new_dset ) ; 01599 01600 THD_write_3dim_dataset( NULL,NULL , new_dset , True ) ; 01601 if( !EX_quiet ) fprintf(stderr,"Wrote output dataset: %s\n", DSET_BRIKNAME(new_dset) ); 01602 01603 01604 /*----- Deallocate memory for extrema dataset -----*/ 01605 THD_delete_3dim_dataset( new_dset , False ) ; new_dset = NULL ; 01606 01607 01608 } |
Variable Documentation
|
Definition at line 99 of file 3dExtrema.c. Referenced by initialize_program(), and write_bucket(). |
|
Definition at line 69 of file 3dExtrema.c. |
|
Definition at line 85 of file 3dExtrema.c. Referenced by EX_read_opts(), and find_extrema(). |
|
Definition at line 101 of file 3dExtrema.c. |
|
Definition at line 88 of file 3dExtrema.c. |
|
Definition at line 78 of file 3dExtrema.c. Referenced by EX_read_opts(). |
|
Definition at line 97 of file 3dExtrema.c. Referenced by find_extrema(), and initialize_program(). |
|
Definition at line 93 of file 3dExtrema.c. Referenced by EX_read_opts(), and initialize_program(). |
|
Definition at line 84 of file 3dExtrema.c. Referenced by EX_read_opts(), and initialize_program(). |
|
Definition at line 76 of file 3dExtrema.c. Referenced by EX_read_opts(), merge_extrema(), and sort_extrema(). |
|
Definition at line 81 of file 3dExtrema.c. Referenced by EX_read_opts(). |
|
Definition at line 86 of file 3dExtrema.c. Referenced by output_results(), process_all_datasets(), and write_bucket(). |
|
Definition at line 89 of file 3dExtrema.c. Referenced by process_all_datasets(). |
|
Definition at line 71 of file 3dExtrema.c. Referenced by find_extrema(), from_3dmm(), initialize_program(), process_all_datasets(), and to_3dmm(). |
|
Definition at line 71 of file 3dExtrema.c. Referenced by from_3dmm(), initialize_program(), and to_3dmm(). |
|
Definition at line 71 of file 3dExtrema.c. Referenced by initialize_program(), process_all_datasets(), and write_bucket(). |
|
Definition at line 71 of file 3dExtrema.c. Referenced by find_extrema(), from_3dmm(), initialize_program(), and process_all_datasets(). |
|
Definition at line 71 of file 3dExtrema.c. Referenced by find_extrema(), from_3dmm(), initialize_program(), output_results(), process_all_datasets(), and write_bucket(). |
|
Definition at line 91 of file 3dExtrema.c. Referenced by find_extrema(), and initialize_program(). |
|
Definition at line 94 of file 3dExtrema.c. Referenced by EX_read_opts(), output_results(), and write_bucket(). |
|
Definition at line 74 of file 3dExtrema.c. Referenced by EX_read_opts(), initialize_program(), output_results(), process_all_datasets(), and write_bucket(). |
|
Definition at line 75 of file 3dExtrema.c. Referenced by EX_read_opts(). |
|
Definition at line 82 of file 3dExtrema.c. Referenced by EX_read_opts(), and find_extrema(). |
|
Definition at line 95 of file 3dExtrema.c. Referenced by EX_read_opts(), and write_bucket(). |
|
Definition at line 79 of file 3dExtrema.c. Referenced by EX_read_opts(). |
|
Definition at line 80 of file 3dExtrema.c. Referenced by EX_read_opts(). |
|
Definition at line 77 of file 3dExtrema.c. Referenced by EX_read_opts(). |