Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

imand.c File Reference

#include "mrilib.h"
#include <string.h>

Go to the source code of this file.


Defines

#define ABS(x)   ( ((x)>=0) ? (x) : (-(x)) )

Functions

int main (int argc, char *argv[])

Define Documentation

#define ABS      ( ((x)>=0) ? (x) : (-(x)) )
 

Definition at line 10 of file imand.c.

Referenced by main(), mp_rle_huff_block(), and mp_rle_huff_pblock().


Function Documentation

int main int    argc,
char *    argv[]
 

\** File : SUMA.c

Author:
: Ziad Saad Date : Thu Dec 27 16:21:01 EST 2001
Purpose :

Input paramters :

Parameters:
param  Usage : SUMA ( )
Returns :
Returns:
Support :
See also:
OpenGL prog. Guide 3rd edition , varray.c from book's sample code
Side effects :

Definition at line 12 of file imand.c.

References ABS, argc, MRI_IMAGE::kind, machdep(), mri_data_pointer(), mri_free(), MRI_IS_2D, mri_read_just_one(), mri_write(), MRI_IMAGE::nx, nxim, MRI_IMAGE::ny, and nyim.

00013 {
00014    MRI_IMAGE *imin , *imout ;
00015    short *shin , *shout ;
00016    int nopt=1 , nxim , nyim , ii , kindim , npix , thresh=0 , nout ;
00017 
00018    if( argc < 4 || strncmp(argv[1],"-help",4) == 0 ){
00019       fprintf(stderr,"Usage: imand [-thresh #] input_images ... output_image\n"
00020                      "* Only pixels nonzero in all input images\n"
00021                      "* (and above the threshold, if given) will be output.\n" ) ;
00022       exit(0) ;
00023    }
00024 
00025    machdep() ;
00026 
00027    if( strncmp(argv[1],"-thresh",4) == 0 ){
00028       thresh = strtol( argv[2] , NULL , 0 ) ;
00029       thresh = ABS(thresh) ;
00030       nopt = 3 ;
00031       if( argc < 5 ){fprintf(stderr,"not enough files!\n");exit(1);}
00032    }
00033 
00034    imout = mri_read_just_one( argv[nopt++] ) ;
00035    if( imout == NULL ) exit(1) ;
00036    nxim   = imout->nx ;
00037    nyim   = imout->ny ;
00038    kindim = imout->kind ;
00039    npix   = nxim * nyim ;
00040    if( kindim != MRI_short || !MRI_IS_2D(imout) ){
00041       fprintf(stderr,"imand currently only works for 2D short images!\n") ;
00042       exit(1) ;
00043    }
00044    shout = mri_data_pointer( imout ) ;
00045    for( ii=0 ; ii < npix ; ii++ )
00046       if( ABS(shout[ii]) <= thresh ) shout[ii] = 0 ;
00047 
00048    while( nopt < argc-1 ){
00049 
00050       imin = mri_read_just_one( argv[nopt] ) ;
00051       if( imin == NULL ) exit(1) ;
00052       if( imin->nx!=nxim || imin->ny!=nyim || imin->kind!=kindim || !MRI_IS_2D(imin) ){
00053          fprintf(stderr,
00054                  "image %s doesn't conform to first image!\n",argv[nopt]) ;
00055          exit(1) ;
00056       }
00057       shin = mri_data_pointer( imin ) ;
00058 
00059       for( ii=0 ; ii < npix ; ii++ ){
00060          if( ABS(shin[ii]) <= thresh ){
00061             shout[ii] = 0 ;
00062           } else if( ((shout[ii] >  thresh) && (shin[ii] > shout[ii])) ||
00063                      ((shout[ii] < -thresh) && (shin[ii] < shout[ii]))   ){
00064             shout[ii] = shin[ii] ;
00065           }
00066       }
00067 
00068       mri_free( imin ) ;
00069       nopt++ ;
00070 
00071    } /* end of while loop */
00072 
00073    nout = 0 ;
00074    for( ii=0 ; ii < npix ; ii++ ) if( shout[ii] != 0 ) nout++ ;
00075 
00076    mri_write( argv[argc-1] , imout ) ;
00077 
00078    printf("number of nonzero pixels output = %d\n",nout) ;
00079    exit(0) ;
00080 }
 

Powered by Plone

This site conforms to the following standards: