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  

edt_scl2max.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 /*---------------------------------------------------------------
00010    Linearly scale values so that largest value in volume is 10000
00011    (255 for byte data volumes)
00012 -----------------------------------------------------------------*/
00013 
00014 void MCW_scale_to_max( int nx, int ny, int nz , int ftype , void * fim )
00015 {
00016    register int nxyz = nx * ny * nz , ii ;
00017    register float fac ;
00018 
00019 ENTRY("MCW_scale_to_max") ;
00020 
00021    if( fim == NULL ) EXRETURN ;
00022 
00023    switch( ftype ){
00024 
00025       case MRI_byte:{
00026          register byte * bfar = (byte *) fim ;
00027          register byte max , val ;
00028          max = bfar[0] ;
00029          for( ii=1 ; ii < nxyz ; ii++ ){
00030             val = bfar[ii] ; if( val > max ) max = val ;
00031          }
00032          if( max == 0 ) EXRETURN ;
00033          fac = 255.0 / max ;
00034          for( ii=0 ; ii < nxyz ; ii++ ) bfar[ii] *= fac ;
00035       }
00036       break ;
00037 
00038       case MRI_short:{
00039          register short * sfar = (short *) fim ;
00040          register short max , val ;
00041          max = abs(sfar[0]) ;
00042          for( ii=1 ; ii < nxyz ; ii++ ){
00043             val = abs(sfar[ii]) ; if( val > max ) max = val ;
00044          }
00045          if( max == 0 ) EXRETURN ;
00046          fac = 10000.0 / max ;
00047          for( ii=0 ; ii < nxyz ; ii++ ) sfar[ii] *= fac ;
00048       }
00049       break ;
00050 
00051       case MRI_float:{
00052          register float * ffar = (float *) fim ;
00053          register float max , val ;
00054          max = fabs(ffar[0]) ;
00055          for( ii=1 ; ii < nxyz ; ii++ ){
00056             val = fabs(ffar[ii]) ; if( val > max ) max = val ;
00057          }
00058          if( max == 0.0 ) EXRETURN ;
00059          fac = 10000.0 / max ;
00060          for( ii=0 ; ii < nxyz ; ii++ ) ffar[ii] *= fac ;
00061       }
00062       break ;
00063 
00064       case MRI_complex:{
00065          register complex * cfar = (complex *) fim ;
00066          register float max , val ;
00067          max = CSQR(cfar[0]) ;
00068          for( ii=1 ; ii < nxyz ; ii++ ){
00069             val = CSQR(cfar[ii]) ; if( val > max ) max = val ;
00070          }
00071          if( max == 0.0 ) EXRETURN ;
00072          fac = 10000.0 / sqrt(max) ;
00073          for( ii=0 ; ii < nxyz ; ii++ ){
00074             cfar[ii].r *= fac ; cfar[ii].i *= fac ;
00075          }
00076       }
00077       break ;
00078    }
00079 
00080    EXRETURN ;
00081 }
 

Powered by Plone

This site conforms to the following standards: