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_nsize.c File Reference

#include "mrilib.h"
#include "string.h"

Go to the source code of this file.


Functions

MRI_IMAGEmri_nsize (MRI_IMAGE *imin)

Function Documentation

MRI_IMAGE* mri_nsize MRI_IMAGE   imin
 

only works on short and byte images *

Definition at line 14 of file mri_nsize.c.

References EXIT, complex::i, MRI_IMAGE::kind, MAX, MRI_COPY_AUX, mri_data_pointer(), MRI_IS_2D, mri_new(), MRI_IMAGE::nx, MRI_IMAGE::ny, and complex::r.

Referenced by ISQ_saver_CB(), main(), mri_read_many_nsize(), and mri_read_nsize().

00015 {
00016    MRI_IMAGE * imout = NULL ;
00017    int nx , ny , ntop , nxpad , nypad , ix,jy,ioff , ii;
00018 
00019    if( imin == NULL ){
00020       fprintf(stderr,"\n*** mri_nsize: NULL image passed as input!\n") ;
00021       return NULL ;
00022    }
00023 
00024    if( ! MRI_IS_2D(imin) ){
00025       fprintf(stderr,"\n*** mri_nsize only works on 2D images!\n") ;
00026       EXIT(1) ;
00027    }
00028 
00029    nx   = imin->nx ;  ny = imin->ny ;
00030    ntop = MAX(nx,ny) ;
00031 
00032         if( ntop <=  32 ) ntop =  32 ;  /* next power of 2 */
00033    else if( ntop <=  64 ) ntop =  64 ;
00034    else if( ntop <= 128 ) ntop = 128 ;
00035    else if( ntop <= 256 ) ntop = 256 ;
00036    else if( ntop <= 512 ) ntop = 512 ;
00037    else if( ntop <=1024 ) ntop =1024 ;
00038    else {
00039       fprintf(stderr,"\n*** mri_nsize: cannot scale up %d x %d images!\n",nx,ny) ;
00040       return NULL ;
00041    }
00042 
00043    switch( imin->kind ){
00044 
00045       case MRI_short:{
00046          short * ptin , * ptout ;
00047          imout = mri_new( ntop,ntop , MRI_short ) ;
00048          ptin  = mri_data_pointer( imin ) ;
00049          ptout = mri_data_pointer( imout ) ;
00050 
00051          for( ii=0 ; ii < ntop*ntop ; ii++ ) ptout[ii] = 0 ;
00052 
00053          nxpad = (ntop-nx) / 2 ;
00054          nypad = (ntop-ny) / 2 ;
00055 
00056          for( jy=0 ; jy < ny ; jy++ ){
00057             ioff = (jy+nypad) * ntop + nxpad ;
00058             for( ix=0 ; ix < nx ; ix++ )
00059                ptout[ix+ioff] = ptin[ix+jy*nx] ;
00060          }
00061       }
00062       break ;
00063 
00064       case MRI_byte:{
00065          byte * ptin , * ptout ;
00066          imout = mri_new( ntop,ntop , MRI_byte ) ;
00067          ptin  = mri_data_pointer( imin ) ;
00068          ptout = mri_data_pointer( imout ) ;
00069 
00070          for( ii=0 ; ii < ntop*ntop ; ii++ ) ptout[ii] = 0 ;
00071 
00072          nxpad = (ntop-nx) / 2 ;
00073          nypad = (ntop-ny) / 2 ;
00074 
00075          for( jy=0 ; jy < ny ; jy++ ){
00076             ioff = (jy+nypad) * ntop + nxpad ;
00077             for( ix=0 ; ix < nx ; ix++ )
00078                ptout[ix+ioff] = ptin[ix+jy*nx] ;
00079          }
00080       }
00081       break ;
00082 
00083       case MRI_int:{
00084          int * ptin , * ptout ;
00085          imout = mri_new( ntop,ntop , MRI_int ) ;
00086          ptin  = mri_data_pointer( imin ) ;
00087          ptout = mri_data_pointer( imout ) ;
00088 
00089          for( ii=0 ; ii < ntop*ntop ; ii++ ) ptout[ii] = 0 ;
00090 
00091          nxpad = (ntop-nx) / 2 ;
00092          nypad = (ntop-ny) / 2 ;
00093 
00094          for( jy=0 ; jy < ny ; jy++ ){
00095             ioff = (jy+nypad) * ntop + nxpad ;
00096             for( ix=0 ; ix < nx ; ix++ )
00097                ptout[ix+ioff] = ptin[ix+jy*nx] ;
00098          }
00099       }
00100       break ;
00101 
00102       case MRI_float:{
00103          float * ptin , * ptout ;
00104          imout = mri_new( ntop,ntop , MRI_float ) ;
00105          ptin  = mri_data_pointer( imin ) ;
00106          ptout = mri_data_pointer( imout ) ;
00107 
00108          for( ii=0 ; ii < ntop*ntop ; ii++ ) ptout[ii] = 0 ;
00109 
00110          nxpad = (ntop-nx) / 2 ;
00111          nypad = (ntop-ny) / 2 ;
00112 
00113          for( jy=0 ; jy < ny ; jy++ ){
00114             ioff = (jy+nypad) * ntop + nxpad ;
00115             for( ix=0 ; ix < nx ; ix++ )
00116                ptout[ix+ioff] = ptin[ix+jy*nx] ;
00117          }
00118       }
00119       break ;
00120 
00121       case MRI_double:{
00122          double * ptin , * ptout ;
00123          imout = mri_new( ntop,ntop , MRI_double ) ;
00124          ptin  = mri_data_pointer( imin ) ;
00125          ptout = mri_data_pointer( imout ) ;
00126 
00127          for( ii=0 ; ii < ntop*ntop ; ii++ ) ptout[ii] = 0 ;
00128 
00129          nxpad = (ntop-nx) / 2 ;
00130          nypad = (ntop-ny) / 2 ;
00131 
00132          for( jy=0 ; jy < ny ; jy++ ){
00133             ioff = (jy+nypad) * ntop + nxpad ;
00134             for( ix=0 ; ix < nx ; ix++ )
00135                ptout[ix+ioff] = ptin[ix+jy*nx] ;
00136          }
00137       }
00138       break ;
00139 
00140       case MRI_complex:{
00141          complex * ptin , * ptout ;
00142          imout = mri_new( ntop,ntop , MRI_complex ) ;
00143          ptin  = mri_data_pointer( imin ) ;
00144          ptout = mri_data_pointer( imout ) ;
00145 
00146          for( ii=0 ; ii < ntop*ntop ; ii++ ) ptout[ii].r = ptout[ii].i = 0 ;
00147 
00148          nxpad = (ntop-nx) / 2 ;
00149          nypad = (ntop-ny) / 2 ;
00150 
00151          for( jy=0 ; jy < ny ; jy++ ){
00152             ioff = (jy+nypad) * ntop + nxpad ;
00153             for( ix=0 ; ix < nx ; ix++ )
00154                ptout[ix+ioff] = ptin[ix+jy*nx] ;
00155          }
00156       }
00157       break ;
00158    }
00159 
00160    MRI_COPY_AUX(imout,imin) ;
00161    return imout ;
00162 }
 

Powered by Plone

This site conforms to the following standards: