Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
mri_histog.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "mrilib.h"
00008
00009
00010
00011 void mri_histogram( MRI_IMAGE * im , float hbot,float htop ,
00012 int initialize , int nbin, int hist[] )
00013 {
00014 register int ih , npix , ii ;
00015 register float sbin ;
00016 MRI_IMAGE * lim ;
00017
00018 ENTRY("mri_histogram") ;
00019
00020 if( im == NULL || htop <= hbot || nbin < 2 ) EXRETURN ;
00021
00022
00023
00024 switch( im->kind ){
00025
00026 default: lim = mri_to_float(im) ; break ;
00027
00028 case MRI_byte: lim = mri_to_short(1.0,im) ; break ;
00029
00030 case MRI_short:
00031 case MRI_float: lim = im ; break ;
00032 }
00033
00034 npix = lim->nvox ;
00035 sbin = 0.999999 * nbin / (htop-hbot) ;
00036
00037 if( initialize ) for( ih=0 ; ih < nbin ; ih++ ) hist[ih] = 0 ;
00038
00039 switch( lim->kind ){
00040
00041 case MRI_short:{
00042 register short * shar = mri_data_pointer(lim) ;
00043
00044 for( ii=0 ; ii < npix ; ii++ ){
00045 ih = sbin * (shar[ii]-hbot) ;
00046 if( ih >=0 && ih < nbin ) hist[ih]++ ;
00047 }
00048 }
00049 break ;
00050
00051 case MRI_float:{
00052 register float * flar = mri_data_pointer(lim) ;
00053
00054 for( ii=0 ; ii < npix ; ii++ ){
00055 ih = sbin * (flar[ii]-hbot) ;
00056 if( ih >=0 && ih < nbin ) hist[ih]++ ;
00057 }
00058 }
00059 break ;
00060 }
00061
00062 if( lim != im ) mri_free( lim ) ;
00063 EXRETURN ;
00064 }