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_scalize.c

Go to the documentation of this file.
00001 #include "mrilib.h"
00002 
00003 /*! Scale a float image to an integer type [20 Oct 2003]:
00004      - inim   = MRI_float image
00005      - kind   = integer type to scale to (MRI_byte, MRI_short, MRI_int)
00006      - return = scaled image
00007      - *sfac  = scale factor (nonzero on input ==> smallest value allowed)
00008 */
00009 
00010 MRI_IMAGE * mri_scalize( MRI_IMAGE *inim , int kind , float *sfac )
00011 {
00012    float gtop , fac , fimfac ;
00013    MRI_IMAGE *outim ;
00014 
00015 ENTRY("mri_scalize") ;
00016 
00017    if( inim == NULL            ||
00018        inim->kind != MRI_float ||
00019       sfac == NULL             ||
00020       !MRI_IS_INT_TYPE(kind)     ) RETURN(NULL) ;
00021 
00022    fac = *sfac ; if( fac < 0.0 ) fac = 0.0 ;
00023 
00024    gtop = MCW_vol_amax( inim->nvox,1,1,MRI_float,MRI_FLOAT_PTR(inim) ) ;
00025    if( gtop == 0.0 ){
00026      fimfac = fac ;
00027    } else {
00028      fimfac = gtop / MRI_TYPE_maxval[kind] ;
00029      if( fimfac < fac ) fimfac = fac ;
00030    }
00031    outim = mri_new_conforming( inim , kind ) ;
00032    if( fimfac > 0.0 )
00033      EDIT_coerce_scale_type( inim->nvox , 1.0/fimfac ,
00034                              MRI_float , MRI_FLOAT_PTR(inim) ,
00035                              outim->kind , mri_data_pointer(outim) ) ;
00036    *sfac = fimfac ; RETURN(outim) ;
00037 }
 

Powered by Plone

This site conforms to the following standards: