Doxygen Source Code Documentation
mri_get_cmass.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
void | mri_get_cmass_2D (MRI_IMAGE *im, float *xcm, float *ycm) |
void | mri_get_cmass_3D (MRI_IMAGE *im, float *xcm, float *ycm, float *zcm) |
Function Documentation
|
not 7D SAFE * Definition at line 11 of file mri_get_cmass.c. References ENTRY, far, MRI_IMAGE::kind, MRI_FLOAT_PTR, mri_free(), mri_to_float(), MRI_IMAGE::nx, and MRI_IMAGE::ny. Referenced by main().
00012 { 00013 int ii,jj,joff , nx,ny ; 00014 float xx , yy , sum , val , *far ; 00015 MRI_IMAGE *flim ; 00016 00017 ENTRY("mri_get_cmass_2D") ; 00018 00019 if( im == NULL || xcm == NULL || ycm == NULL ) EXRETURN ; 00020 00021 if( im->kind != MRI_float ) flim = mri_to_float( im ) ; 00022 else flim = im ; 00023 00024 far = MRI_FLOAT_PTR(flim) ; 00025 nx = im->nx ; ny = im->ny ; 00026 00027 sum = xx = yy = 0.0 ; 00028 for( jj=0 ; jj < ny ; jj++ ){ 00029 joff = jj * nx ; 00030 for( ii=0 ; ii < nx ; ii++ ){ 00031 val = fabs(far[ii+joff]) ; 00032 sum += val ; 00033 xx += val * ii ; 00034 yy += val * jj ; 00035 } 00036 } 00037 00038 if( sum > 0.0 ){ xx /= sum ; yy /= sum ; } 00039 00040 if( flim != im ) mri_free(flim) ; 00041 00042 *xcm = xx ; *ycm = yy ; EXRETURN ; 00043 } |
|
Definition at line 47 of file mri_get_cmass.c. References ENTRY, far, MRI_IMAGE::kind, MRI_FLOAT_PTR, mri_free(), mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, nz, and MRI_IMAGE::nz. Referenced by THD_cmass().
00048 { 00049 int ii,jj,kk,koff,joff , nx,ny,nz,nxy ; 00050 float xx,yy,zz , sum , val , *far ; 00051 MRI_IMAGE *flim ; 00052 00053 ENTRY("mri_get_cmass_3D") ; 00054 00055 if( im == NULL || xcm == NULL || ycm == NULL || zcm == NULL ) EXRETURN ; 00056 00057 if( im->kind != MRI_float ) flim = mri_to_float( im ) ; 00058 else flim = im ; 00059 00060 far = MRI_FLOAT_PTR(flim) ; 00061 nx = im->nx ; ny = im->ny ; nz = im->nz ; nxy = nx*ny ; 00062 00063 sum = xx = yy = zz = 0.0 ; 00064 for( kk=0 ; kk < nz ; kk++ ){ 00065 koff = kk * nxy ; 00066 for( jj=0 ; jj < ny ; jj++ ){ 00067 joff = koff + jj * nx ; 00068 for( ii=0 ; ii < nx ; ii++ ){ 00069 val = fabs(far[ii+joff]) ; 00070 sum += val ; 00071 xx += val * ii ; 00072 yy += val * jj ; 00073 zz += val * kk ; 00074 } 00075 } 00076 } 00077 00078 if( sum > 0.0 ){ xx /= sum ; yy /= sum ; zz /= sum ; } 00079 else { xx = 0.5*(nx-1); yy=0.5*(ny-1); zz=0.5*(nz-1); } 00080 00081 if( flim != im ) mri_free(flim) ; 00082 00083 *xcm = xx ; *ycm = yy ; *zcm = zz ; EXRETURN ; 00084 } |