Doxygen Source Code Documentation
ftosh.c File Reference
#include <string.h>
#include "mrilib.h"
Go to the source code of this file.
Defines | |
#define | MAX_NAME 64 |
Functions | |
void | FTOSH_syntax (char *) |
void | FTOSH_getopts (int, char *argv[]) |
int | main (int argc, char *argv[]) |
Variables | |
float | FT_tval = 32000.0 |
float | FT_bval = 0.0 |
float | FT_sval = 0.0 |
int | FT_start = 1 |
int | FT_step = 1 |
int | FT_nsize = 0 |
char | FT_pname [MAX_NAME] = "sh." |
char | FT_sname [MAX_NAME] = "\0" |
MRI_IMARR * | FT_imts = NULL |
Define Documentation
|
|
Function Documentation
|
Definition at line 88 of file ftosh.c. References argc, FT_bval, FT_nsize, FT_pname, FT_sname, FT_start, FT_step, FT_sval, FT_tval, FTOSH_syntax(), MRI_IMARR::imarr, MRI_IMAGE::kind, mri_data_pointer(), mri_free(), mri_read_many_files(), mri_to_float(), MRI_IMARR::num, MRI_IMAGE::nx, MRI_IMAGE::ny, and strtod(). Referenced by main().
00089 { 00090 int nopt = 1 , kk , nx,ny , ii,npix ; 00091 MRI_IMAGE * tim ; 00092 float * tar ; 00093 float bmax , bdif ; 00094 00095 /*---- scan options that start with a - -----*/ 00096 00097 while( nopt < argc && argv[nopt][0] == '-' ){ 00098 00099 /** -prefix pname **/ 00100 00101 if( strncmp(argv[nopt],"-prefix",5) == 0 ){ 00102 if( ++nopt >= argc ) FTOSH_syntax("-prefix needs a name!") ; 00103 strcpy( FT_pname , argv[nopt] ) ; 00104 kk = strlen(FT_pname) ; 00105 if( kk > 0 && FT_pname[kk-1] != '.' ){ 00106 FT_pname[kk] = '.' ; 00107 FT_pname[kk+1] = '\0' ; 00108 } 00109 nopt++ ; continue ; /* skip to next arg */ 00110 } 00111 00112 /** -suffix pname **/ 00113 00114 if( strncmp(argv[nopt],"-suffix",5) == 0 ){ 00115 if( ++nopt >= argc ) FTOSH_syntax("-suffix needs a name!") ; 00116 strcpy( FT_sname , argv[nopt] ) ; 00117 nopt++ ; continue ; /* skip to next arg */ 00118 } 00119 00120 /** -scale sval **/ 00121 00122 if( strncmp(argv[nopt],"-scale",5) == 0 ){ 00123 char * ch ; 00124 if( ++nopt >= argc ) FTOSH_syntax("-scale needs a value!"); 00125 FT_sval = strtod( argv[nopt] , &ch ) ; 00126 if( *ch != '\0' || FT_sval == 0.0 ) 00127 FTOSH_syntax("value after -scale is illegal!") ; 00128 nopt++ ; continue ; /* skip to next arg */ 00129 } 00130 00131 /** -base bval **/ 00132 00133 if( strncmp(argv[nopt],"-base",5) == 0 ){ 00134 char * ch ; 00135 if( ++nopt >= argc ) FTOSH_syntax("-base needs a value!"); 00136 FT_bval = strtod( argv[nopt] , &ch ) ; 00137 if( *ch != '\0' ) FTOSH_syntax("value after -base is illegal!") ; 00138 nopt++ ; continue ; /* skip to next arg */ 00139 } 00140 00141 /** -top tval **/ 00142 00143 if( strncmp(argv[nopt],"-top",4) == 0 ){ 00144 char * ch ; 00145 if( ++nopt >= argc ) FTOSH_syntax("-top needs a value!"); 00146 FT_tval = strtod( argv[nopt] , &ch ) ; 00147 if( *ch != '\0' || FT_tval == 0.0 ) 00148 FTOSH_syntax("value after -top is illegal!") ; 00149 nopt++ ; continue ; /* skip to next arg */ 00150 } 00151 00152 /** -start si **/ 00153 00154 if( strncmp(argv[nopt],"-start",5) == 0 ){ 00155 char * ch ; 00156 if( ++nopt >= argc ) FTOSH_syntax("-start needs a value!"); 00157 FT_start = strtol( argv[nopt] , &ch , 10 ) ; 00158 if( *ch != '\0' || FT_start < 0 ) 00159 FTOSH_syntax("value after -start is illegal!") ; 00160 nopt++ ; continue ; /* skip to next arg */ 00161 } 00162 00163 /** -step ss **/ 00164 00165 if( strncmp(argv[nopt],"-step",5) == 0 ){ 00166 char * ch ; 00167 if( ++nopt >= argc ) FTOSH_syntax("-step needs a value!"); 00168 FT_step = strtol( argv[nopt] , &ch , 10 ) ; 00169 if( *ch != '\0' || FT_step < 0 ) 00170 FTOSH_syntax("value after -step is illegal!") ; 00171 nopt++ ; continue ; /* skip to next arg */ 00172 } 00173 00174 /** -nsize **/ 00175 00176 if( strncmp(argv[nopt],"-nsize",5) == 0 ){ 00177 FT_nsize = 1 ; 00178 nopt++ ; continue ; /* skip to next arg */ 00179 } 00180 00181 /** illegal option **/ 00182 00183 fprintf(stderr,"*** illegal command line option: %s\n",argv[nopt]) ; 00184 FTOSH_syntax("type ftosh -help for more details") ; 00185 00186 } 00187 00188 /*----- rest of inputs are image files -----*/ 00189 00190 FT_imts = mri_read_many_files( argc-nopt , argv+nopt ) ; 00191 if( FT_imts == NULL ) FTOSH_syntax("cannot continue without input images!") ; 00192 00193 #if 0 00194 /* check images for consistency */ 00195 00196 nx = FT_imts->imarr[0]->nx ; 00197 ny = FT_imts->imarr[0]->ny ; 00198 00199 for( kk=1 ; kk < FT_imts->num ; kk++ ){ 00200 if( nx != FT_imts->imarr[kk]->nx || ny != FT_imts->imarr[kk]->ny ){ 00201 fprintf(stderr,"*** image %d not conformant to image 0\n",kk) ; 00202 FTOSH_syntax("cannot continue with images whose sizes differ!") ; 00203 } 00204 } 00205 #endif 00206 00207 /* convert all input images to floats, if needed; ALSO, if */ 00208 /* FT_sval is zero, must find the maximum abs(input-FT_bval) */ 00209 00210 bmax = 0.0 ; 00211 for( kk=0 ; kk < FT_imts->num ; kk++ ){ 00212 00213 if( FT_imts->imarr[kk]->kind != MRI_float ){ 00214 tim = mri_to_float( FT_imts->imarr[kk] ) ; 00215 mri_free( FT_imts->imarr[kk] ) ; 00216 FT_imts->imarr[kk] = tim ; 00217 } 00218 00219 if( FT_sval == 0.0 ){ 00220 tim = FT_imts->imarr[kk] ; tar = mri_data_pointer( tim ) ; 00221 nx = tim->nx ; ny = tim->ny ; npix = nx*ny ; 00222 for( ii=0 ; ii < npix ; ii++ ){ 00223 bdif = fabs( tar[ii]-FT_bval ) ; 00224 if( bmax < bdif ) bmax = bdif ; 00225 } 00226 } 00227 } 00228 00229 if( FT_sval == 0.0 ){ 00230 if( bmax == 0.0 ){ 00231 fprintf(stderr,"*** all input images are == %g\n",FT_bval) ; 00232 FTOSH_syntax("can't autoscale them!") ; 00233 } 00234 FT_sval = FT_tval / bmax ; 00235 printf("** max abs(input-%g) = %g --> scale factor = %g/%g = %g\n", 00236 FT_bval , bmax , FT_tval,bmax , FT_sval ) ; 00237 } 00238 00239 return ; 00240 } |
|
illegal option * Definition at line 244 of file ftosh.c. Referenced by FTOSH_getopts(), and main().
00245 { 00246 if( str != NULL ){ 00247 fprintf(stderr,"*** %s\a\n",str) ; 00248 exit(-1) ; 00249 } 00250 00251 printf( 00252 "Usage: ftosh [options] image_files ...\n" 00253 "\n" 00254 " where the image_files are in the same format to3d accepts\n" 00255 " and where the options are\n" 00256 "\n" 00257 " -prefix pname: The output files will be named in the format\n" 00258 " -suffix sname: 'pname.index.sname' where 'pname' and 'sname'\n" 00259 " -start si: are strings given by the first 2 options.\n" 00260 " -step ss: 'index' is a number, given by 'si+(i-1)*ss'\n" 00261 " for the i-th output file, for i=1,2,...\n" 00262 " *** Default pname = 'sh'\n" 00263 " *** Default sname = nothing at all\n" 00264 " *** Default si = 1\n" 00265 " *** Default ss = 1\n" 00266 "\n" 00267 " -nsize: Enforce the 'normal size' option, to make\n" 00268 " the output images 64x64, 128x128, or 256x256.\n" 00269 "\n" 00270 " -scale sval: 'sval' and 'bval' are numeric values; if\n" 00271 " -base bval: sval is given, then the output images are\n" 00272 " -top tval: formed by scaling the inputs by the formula\n" 00273 " 'output = sval*(input-bval)'.\n" 00274 " *** Default sval is determined by finding\n" 00275 " V = largest abs(input-bval) in all the input\n" 00276 " images and then sval = tval / V.\n" 00277 " *** Default tval is 32000; note that tval is only\n" 00278 " used if sval is not given on the command line.\n" 00279 " *** Default bval is 0.\n" 00280 ) ; 00281 exit(0) ; 00282 } |
|
\** File : SUMA.c
Input paramters :
Definition at line 33 of file ftosh.c. References argc, FT_bval, FT_pname, FT_sname, FT_start, FT_step, FT_sval, FTOSH_getopts(), FTOSH_syntax(), MRI_IMARR::imarr, machdep(), mri_data_pointer(), mri_free(), mri_new(), mri_nsize(), mri_write(), name, MRI_IMARR::num, MRI_IMAGE::nx, and MRI_IMAGE::ny.
00034 { 00035 int ii , nx , ny , npix , kk ; 00036 MRI_IMAGE * tim , * sim ; 00037 float * tar ; 00038 short * sar ; 00039 char name[256] ; 00040 00041 /*----- read inputs -----*/ 00042 00043 printf( 00044 "ftosh: convert float images to shorts, by RW Cox\n") ; 00045 00046 machdep() ; 00047 00048 if( argc < 2 || strcmp(argv[1],"-help") == 0 ) FTOSH_syntax(NULL) ; 00049 00050 FTOSH_getopts( argc , argv ) ; 00051 00052 /*----- convert and write each image -----*/ 00053 00054 for( kk=0 ; kk < FT_imts->num ; kk++ ){ 00055 tim = FT_imts->imarr[kk] ; tar = mri_data_pointer( tim ) ; 00056 nx = tim->nx ; ny = tim->ny ; npix = nx*ny ; 00057 sim = mri_new( nx , ny , MRI_short ) ; sar = mri_data_pointer( sim ) ; 00058 00059 for( ii=0 ; ii < npix ; ii++ ) 00060 sar[ii] = (short) ( FT_sval * ( tar[ii] - FT_bval ) + 0.499 ) ; 00061 00062 mri_free( tim ) ; 00063 if( FT_nsize ){ 00064 tim = mri_nsize( sim ) ; mri_free( sim ) ; sim = tim ; 00065 } 00066 00067 if( strlen(FT_pname) > 0 && strlen(FT_sname) > 0 ){ 00068 sprintf( name , "%s%04d.%s" , 00069 FT_pname , FT_start + kk*FT_step , FT_sname ) ; 00070 } else if( strlen(FT_pname) > 0 ){ 00071 sprintf( name , "%s%04d" , FT_pname , FT_start + kk*FT_step ) ; 00072 } else if( strlen(FT_sname) > 0 ){ 00073 sprintf( name , "%04d.%s" , FT_start + kk*FT_step , FT_sname ) ; 00074 } else { 00075 sprintf( name , "%04d" , FT_start + kk*FT_step ) ; 00076 } 00077 00078 printf("-- writing %dx%d image %s\n",nx,ny,name) ; 00079 mri_write( name , sim ) ; 00080 mri_free( sim ) ; 00081 } 00082 00083 exit(0) ; 00084 } |
Variable Documentation
|
Definition at line 15 of file ftosh.c. Referenced by FTOSH_getopts(), and main(). |
|
|
|
Definition at line 19 of file ftosh.c. Referenced by FTOSH_getopts(). |
|
Definition at line 21 of file ftosh.c. Referenced by FTOSH_getopts(), and main(). |
|
Definition at line 22 of file ftosh.c. Referenced by FTOSH_getopts(), and main(). |
|
Definition at line 17 of file ftosh.c. Referenced by FTOSH_getopts(), and main(). |
|
Definition at line 18 of file ftosh.c. Referenced by FTOSH_getopts(), and main(). |
|
Definition at line 16 of file ftosh.c. Referenced by FTOSH_getopts(), and main(). |
|
Definition at line 14 of file ftosh.c. Referenced by FTOSH_getopts(). |