Doxygen Source Code Documentation
thd_makemask.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
byte * | THD_makemask (THD_3dim_dataset *mask_dset, int miv, float mask_bot, float mask_top) |
int | THD_countmask (int nvox, byte *mmm) |
Function Documentation
|
Count the number of nonzero voxels in a mask. ----------------------------------------------------------------------- Definition at line 103 of file thd_makemask.c. Referenced by BFIT_prepare_dataset(), CORREL_main(), get_cmask(), HISTO_main(), init_floatvector_array(), main(), MRG_read_opts(), mri_medianfilter(), read_input_data(), SCAT_main(), SUMA_FormAfnidset(), SUMA_Get_isosurface_datasets(), THD_orient_guess(), UC_read_opts(), and validate_datasets().
|
|
Make a byte mask from mask dataset: miv = sub-brick of input if( mask_bot <= mask_top ) then only nonzero values in this range will be used else all nonzero values in the mask will be used The input dataset should be byte-, short-, or float-valued. The output is a byte array with 1s in "hit" locations and 0s in other locations. The number of bytes is DSET_NVOX(mask_dset). This array should be free()-d someday. If NULL is returned, some grotesque error transpired. ----------------------------------------------------------------------- Definition at line 24 of file thd_makemask.c. References BYTEIZE, calloc, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NVOX, DSET_unload, free, ISVALID_DSET, mmm, and SHORTIZE. Referenced by BFIT_prepare_dataset(), CORREL_main(), get_options(), HI_read_opts(), HISTO_main(), init_floatvector_array(), main(), MRG_read_opts(), PC_read_opts(), read_input_data(), SCAT_main(), SUMA_FormAfnidset(), and UC_read_opts().
00026 { 00027 byte *mmm = NULL ; 00028 int nvox , ii ; 00029 00030 if( !ISVALID_DSET(mask_dset) || 00031 miv < 0 || 00032 miv >= DSET_NVALS(mask_dset) ) return NULL ; 00033 00034 nvox = DSET_NVOX(mask_dset) ; 00035 00036 DSET_load(mask_dset) ; if( !DSET_LOADED(mask_dset) ) return NULL ; 00037 00038 mmm = (byte *) calloc( sizeof(byte) * nvox , 1 ) ; 00039 00040 switch( DSET_BRICK_TYPE(mask_dset,miv) ){ 00041 default: 00042 free(mmm) ; DSET_unload(mask_dset) ; return NULL ; 00043 00044 case MRI_short:{ 00045 short mbot , mtop ; 00046 short *mar = (short *) DSET_ARRAY(mask_dset,miv) ; 00047 float mfac = DSET_BRICK_FACTOR(mask_dset,miv) ; 00048 if( mfac == 0.0 ) mfac = 1.0 ; 00049 if( mask_bot <= mask_top ){ 00050 mbot = SHORTIZE(mask_bot/mfac) ; 00051 mtop = SHORTIZE(mask_top/mfac) ; 00052 } else { 00053 mbot = (short) -MRI_TYPE_maxval[MRI_short] ; 00054 mtop = (short) MRI_TYPE_maxval[MRI_short] ; 00055 } 00056 for( ii=0 ; ii < nvox ; ii++ ) 00057 if( mar[ii] >= mbot && mar[ii] <= mtop && mar[ii] != 0 ) mmm[ii]=1; 00058 } 00059 break ; 00060 00061 case MRI_byte:{ 00062 byte mbot , mtop ; 00063 byte *mar = (byte *) DSET_ARRAY(mask_dset,miv) ; 00064 float mfac = DSET_BRICK_FACTOR(mask_dset,miv) ; 00065 if( mfac == 0.0 ) mfac = 1.0 ; 00066 if( mask_bot <= mask_top && mask_top > 0.0 ){ 00067 mbot = BYTEIZE(mask_bot/mfac) ; 00068 mtop = BYTEIZE(mask_top/mfac) ; 00069 } else { 00070 mbot = 0 ; 00071 mtop = (byte) MRI_TYPE_maxval[MRI_short] ; 00072 } 00073 for( ii=0 ; ii < nvox ; ii++ ) 00074 if( mar[ii] >= mbot && mar[ii] <= mtop && mar[ii] != 0 ) mmm[ii]=1; 00075 } 00076 break ; 00077 00078 case MRI_float:{ 00079 float mbot , mtop ; 00080 float *mar = (float *) DSET_ARRAY(mask_dset,miv) ; 00081 float mfac = DSET_BRICK_FACTOR(mask_dset,miv) ; 00082 if( mfac == 0.0 ) mfac = 1.0 ; 00083 if( mask_bot <= mask_top ){ 00084 mbot = (float) (mask_bot/mfac) ; 00085 mtop = (float) (mask_top/mfac) ; 00086 } else { 00087 mbot = -WAY_BIG ; 00088 mtop = WAY_BIG ; 00089 } 00090 for( ii=0 ; ii < nvox ; ii++ ) 00091 if( mar[ii] >= mbot && mar[ii] <= mtop && mar[ii] != 0 ) mmm[ii]=1; 00092 } 00093 break ; 00094 } 00095 00096 return mmm ; 00097 } |