Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
mri_thresh.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "mrilib.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016 void mri_threshold( double thbot, double thtop, MRI_IMAGE *thrim, MRI_IMAGE *im )
00017 {
00018 register int ii , npix ;
00019
00020 ENTRY("mri_threshold") ;
00021
00022 if( thrim == NULL || im == NULL ||
00023 thrim->nvox != im->nvox || thbot >= thtop ) EXRETURN ;
00024
00025 npix = im->nvox ;
00026
00027 switch( thrim->kind ){
00028
00029 default: EXRETURN ;
00030
00031 case MRI_byte:{
00032 MRI_IMAGE *qim = mri_to_short(1.0,thrim) ;
00033 mri_threshold( thbot,thtop , qim , im ) ;
00034 mri_free(qim) ;
00035 EXRETURN ;
00036 }
00037
00038 case MRI_short:{
00039 register short th1 , th2 ;
00040 register short *thar = MRI_SHORT_PTR(thrim) ;
00041 th1 = SHORTIZE(thbot) ; th2 = SHORTIZE(thtop) ;
00042
00043 switch( im->kind ){
00044
00045 default: EXRETURN ;
00046
00047 case MRI_byte:{
00048 register byte *ar = MRI_BYTE_PTR(im) ;
00049 for( ii=0 ; ii < npix ; ii++ )
00050 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ;
00051 EXRETURN ;
00052 }
00053
00054 case MRI_rgb:{
00055 register byte *ar = MRI_RGB_PTR(im) ;
00056 for( ii=0 ; ii < npix ; ii++ )
00057 if( thar[ii] > th1 && thar[ii] < th2 ){
00058 ar[3*ii] = ar[3*ii+1] = ar[3*ii+2] = 0 ;
00059 }
00060 EXRETURN ;
00061 }
00062
00063 case MRI_short:{
00064 register short *ar = MRI_SHORT_PTR(im) ;
00065 for( ii=0 ; ii < npix ; ii++ )
00066 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ;
00067 EXRETURN ;
00068 }
00069
00070 case MRI_int:{
00071 register int *ar = MRI_INT_PTR(im) ;
00072 for( ii=0 ; ii < npix ; ii++ )
00073 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ;
00074 EXRETURN ;
00075 }
00076
00077 case MRI_float:{
00078 register float *ar = MRI_FLOAT_PTR(im) ;
00079 for( ii=0 ; ii < npix ; ii++ )
00080 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0f ;
00081 EXRETURN ;
00082 }
00083
00084 case MRI_double:{
00085 register double *ar = MRI_DOUBLE_PTR(im) ;
00086 for( ii=0 ; ii < npix ; ii++ )
00087 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0 ;
00088 EXRETURN ;
00089 }
00090
00091 case MRI_complex:{
00092 register complex *ar = MRI_COMPLEX_PTR(im) ;
00093 for( ii=0 ; ii < npix ; ii++ )
00094 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii].r = ar[ii].i = 0.0f ;
00095 EXRETURN ;
00096 }
00097 }
00098 }
00099
00100 case MRI_float:{
00101 register float th1 , th2 ;
00102 register float *thar = MRI_FLOAT_PTR(thrim) ;
00103 th1 = thbot ; th2 = thtop ;
00104
00105 switch( im->kind ){
00106
00107 default: EXRETURN ;
00108
00109 case MRI_byte:{
00110 register byte *ar = MRI_BYTE_PTR(im) ;
00111 for( ii=0 ; ii < npix ; ii++ )
00112 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ;
00113 EXRETURN ;
00114 }
00115
00116 case MRI_rgb:{
00117 register byte *ar = MRI_RGB_PTR(im) ;
00118 for( ii=0 ; ii < npix ; ii++ )
00119 if( thar[ii] > th1 && thar[ii] < th2 ){
00120 ar[3*ii] = ar[3*ii+1] = ar[3*ii+2] = 0 ;
00121 }
00122 EXRETURN ;
00123 }
00124
00125 case MRI_short:{
00126 register short *ar = MRI_SHORT_PTR(im) ;
00127 for( ii=0 ; ii < npix ; ii++ )
00128 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ;
00129 EXRETURN ;
00130 }
00131
00132 case MRI_int:{
00133 register int *ar = MRI_INT_PTR(im) ;
00134 for( ii=0 ; ii < npix ; ii++ )
00135 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ;
00136 EXRETURN ;
00137 }
00138
00139 case MRI_float:{
00140 register float *ar = MRI_FLOAT_PTR(im) ;
00141 for( ii=0 ; ii < npix ; ii++ )
00142 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0f ;
00143 EXRETURN ;
00144 }
00145
00146 case MRI_double:{
00147 register double *ar = MRI_DOUBLE_PTR(im) ;
00148 for( ii=0 ; ii < npix ; ii++ )
00149 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0 ;
00150 EXRETURN ;
00151 }
00152
00153 case MRI_complex:{
00154 register complex *ar = MRI_COMPLEX_PTR(im) ;
00155 for( ii=0 ; ii < npix ; ii++ )
00156 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii].r = ar[ii].i = 0.0f ;
00157 EXRETURN ;
00158 }
00159 }
00160 }
00161
00162 }
00163
00164 EXRETURN ;
00165 }