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  

mri_histog.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #include "mrilib.h"
00008 
00009 /*** 7D SAFE ***/
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    /* can handle shorts and floats;  all else -> convert to float */
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 ) ;  /* toss temporary array */
00063    EXRETURN ;
00064 }
 

Powered by Plone

This site conforms to the following standards: