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_complex_arith.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 /*-------------------------------------
00012      mode = 0 for normal multiplication
00013           = 1 for conjugation of g
00014 ---------------------------------------*/
00015 
00016 MRI_IMAGE *mri_multiply_complex( int mode , MRI_IMAGE *f , MRI_IMAGE* g )
00017 {
00018    register int ii , npix ;
00019    MRI_IMAGE *newImg ;
00020 
00021    if( f->nvox != g->nvox ){
00022       fprintf( stderr , "mri_multiply_complex shapes imcompatible!\n" ) ;
00023       MRI_FATAL_ERROR ;
00024    }
00025 
00026    if( f->kind != MRI_complex  ||  g->kind != MRI_complex ){
00027       fprintf( stderr , "mri_multiply_complex illegal image type!\n" ) ;
00028       MRI_FATAL_ERROR ;
00029    }
00030 
00031    newImg  = mri_new_conforming( f , MRI_complex ) ;
00032    npix = f->nvox ;
00033    MRI_COPY_AUX( newImg , f ) ;
00034 
00035    switch( mode ){
00036      case 0:
00037         for( ii=0 ; ii < npix ; ii++ ){
00038            newImg->im.complex_data[ii] =
00039             CMULT( f->im.complex_data[ii] , g->im.complex_data[ii] ) ;
00040         }
00041         break ;
00042 
00043       case 1:
00044          for( ii=0 ; ii < npix ; ii++ ){
00045             newImg->im.complex_data[ii] =
00046              CJMULT( f->im.complex_data[ii] , g->im.complex_data[ii] ) ;
00047          }
00048          break ;
00049 
00050       default:
00051          fprintf( stderr , "mri_multiply_complex illegal mode %d\n" , mode ) ;
00052          MRI_FATAL_ERROR ;
00053    }
00054    return newImg ;
00055 }
00056 
00057 /****************************************************************************/
00058 
00059 MRI_IMAGE *mri_complex_phase( MRI_IMAGE *im )
00060 {
00061    register int ii , npix ;
00062    MRI_IMAGE *newImg ;
00063 
00064    if( im->kind != MRI_complex ){
00065       fprintf( stderr , "mri_complex_phase illegal image type!\n" ) ;
00066       MRI_FATAL_ERROR ;
00067    }
00068 
00069    npix = im->nvox ;
00070    newImg  = mri_new_conforming( im , MRI_float ) ;
00071    MRI_COPY_AUX( newImg , im ) ;
00072 
00073    for( ii=0 ; ii < npix ; ii++ )
00074      newImg->im.float_data[ii] =
00075         atan2( im->im.complex_data[ii].i , im->im.complex_data[ii].r ) ;
00076 
00077    return newImg ;
00078 }
00079 
00080 /***************************************************************************/
00081 
00082 MRI_IMAGE *mri_complex_abs( MRI_IMAGE *im )
00083 {
00084    register int ii , npix ;
00085    MRI_IMAGE *newImg ;
00086 
00087    if( im->kind != MRI_complex ){
00088       fprintf( stderr , "mri_complex_abs illegal type!\n" ) ;
00089       MRI_FATAL_ERROR ;
00090    }
00091 
00092    npix = im->nvox ;
00093    newImg  = mri_new_conforming( im , MRI_float ) ;
00094    MRI_COPY_AUX( newImg , im ) ;
00095 
00096    for( ii=0 ; ii < npix ; ii++ )
00097       newImg->im.float_data[ii] = sqrt( CSQR( im->im.complex_data[ii] ) ) ;
00098 
00099    return newImg ;
00100 }
 

Powered by Plone

This site conforms to the following standards: