Doxygen Source Code Documentation
        
Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search   
mri_to_mri.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 MRI_IMAGE * mri_to_mri( int datum , MRI_IMAGE * oldim )
00016 {
00017    MRI_IMAGE * newim ;
00018 
00019 ENTRY("mri_to_mri") ;
00020 
00021    if( oldim == NULL ) RETURN( NULL );  
00022 
00023    switch( datum ){
00024       default:
00025          fprintf(stderr,
00026            "\nUnsupported mri_to_mri conversion!\a\n") ;
00027          newim = NULL ;
00028       break ;
00029 
00030       case MRI_short:{
00031          double imtop ;
00032          imtop = mri_maxabs( oldim ) ;
00033 
00034          if( imtop <= 32767.0 )
00035             newim = mri_to_short( 1.0 , oldim ) ;
00036          else
00037             newim = mri_to_short_scl( 0.0 , 10000.0 , oldim ) ;
00038       }
00039       break ;
00040 
00041       case MRI_float:
00042          newim = mri_to_float( oldim ) ;
00043       break ;
00044 
00045       case MRI_byte:{
00046          float immin , immax ;
00047 
00048          if( oldim->kind == MRI_byte ){
00049             newim = mri_to_byte( oldim ) ;
00050          } else {
00051             immin = mri_min( oldim ) ; immax = mri_max( oldim ) ;
00052             if( immin >= 0 && immax < 256 )
00053                newim = mri_to_byte_scl( 1.0 , 0.0 , oldim ) ;
00054             else
00055                newim = mri_to_byte_scl( 0.0 , 255.0 , oldim ) ;
00056         }
00057       }
00058       break ;
00059 
00060       case MRI_complex:
00061          newim = mri_to_complex( oldim ) ;
00062       break ;
00063 
00064       case MRI_rgb:
00065          newim = mri_to_rgb( oldim ) ; 
00066       break ;
00067 
00068       case MRI_rgba:
00069          newim = mri_to_rgba( oldim ) ; 
00070       break ;
00071 
00072   }
00073   RETURN( newim );
00074 }
00075 
00076 
00077 
00078 
00079 
00080 
00081 MRI_IMAGE * mri_to_mri_scl( int datum , double factor , MRI_IMAGE * oldim )
00082 {
00083    MRI_IMAGE * newim ;
00084 
00085 ENTRY("mri_to_mri_scl") ;
00086 
00087    if( oldim == NULL ) RETURN( NULL );  
00088 
00089    switch( datum ){
00090       default:
00091          fprintf(stderr,
00092            "\nUnsupported mri_to_mri conversion!\a\n") ;
00093          newim = NULL ;
00094       break ;
00095 
00096       case MRI_short:
00097          newim = mri_to_short( factor , oldim ) ;
00098       break ;
00099 
00100       case MRI_float:
00101          newim = mri_scale_to_float( factor , oldim ) ;
00102       break ;
00103 
00104       case MRI_byte:
00105          newim = mri_to_byte_scl( factor , 0.0 , oldim ) ;
00106       break ;
00107 
00108       case MRI_complex:{
00109          complex * cxar ; int ii , nvox ;
00110          newim = mri_to_complex( oldim ) ;
00111          cxar = MRI_COMPLEX_PTR(newim) ;
00112          nvox = newim->nvox ;
00113          for( ii=0 ; ii < nvox ; ii++ ){
00114             cxar[ii].r *= factor ; cxar[ii].i *= factor ;
00115          }
00116       }
00117       break ;
00118   }
00119   RETURN( newim );
00120 }