Doxygen Source Code Documentation
mri_cut.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
MRI_IMAGE * | mri_cut_2D (MRI_IMAGE *im, int xa, int xb, int ya, int yb) |
MRI_IMAGE * | mri_cut_3D (MRI_IMAGE *im, int xa, int xb, int ya, int yb, int za, int zb) |
Function Documentation
|
Cut out sub-image [xa..xb,ya..yb] from the input. Returns NULL if inputs are incoherent. RWCox -- 13 April 1999. --------------------------------------------------------------------- Definition at line 16 of file mri_cut.c. References ENTRY, MRI_IMAGE::kind, MRI_COPY_AUX, mri_data_pointer(), mri_new(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::pixel_size, and RETURN. Referenced by ISQ_getimage(), ISQ_getoverlay(), ISQ_save_jpeg(), ISQ_saver_CB(), main(), mri_scramble(), and mri_uncat2D().
00017 { 00018 char * par , * qar , * irow , * orow ; 00019 MRI_IMAGE * qim ; 00020 int qx,qy , ps , xx,yy , nx, xps ; 00021 00022 ENTRY("mri_cut_2D") ; 00023 00024 /*-- sanity checks --*/ 00025 00026 if( im == NULL || xa < 0 || xb >= im->nx || xb < xa || 00027 ya < 0 || yb >= im->ny || yb < ya ) RETURN(NULL) ; 00028 00029 /*-- pointer to input data --*/ 00030 00031 par = (char *) mri_data_pointer( im ) ; 00032 if( par == NULL ) RETURN(NULL) ; /* sanity check */ 00033 00034 /*-- make output image --*/ 00035 00036 qx = xb - xa + 1 ; qy = yb - ya + 1 ; /* dimensions */ 00037 qim = mri_new( qx , qy , im->kind ) ; /* creation */ 00038 00039 ps = im->pixel_size ; xps = qx * ps ; /* xps = size of output row */ 00040 qar = (char *) mri_data_pointer( qim ) ; /* ptr to output data */ 00041 nx = im->nx ; 00042 00043 for( yy=ya ; yy <= yb ; yy++ ){ /* for each output row */ 00044 irow = par + (yy*nx+xa)*ps ; /* ptr to input */ 00045 orow = qar + (yy-ya)*xps ; /* ptr to output */ 00046 memcpy( orow , irow , xps ) ; /* copy input to output */ 00047 } 00048 00049 MRI_COPY_AUX(qim,im) ; 00050 RETURN(qim) ; 00051 } |
|
Cut out sub-image [xa..xb,ya..yb,za..zb] from the input. Returns NULL if inputs are incoherent. RWCox -- 06 Jun 2002. --------------------------------------------------------------------- Definition at line 58 of file mri_cut.c. References ENTRY, MRI_IMAGE::kind, MRI_COPY_AUX, mri_data_pointer(), mri_new_vol(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, MRI_IMAGE::pixel_size, and RETURN.
00060 { 00061 char * par , * qar , * irow , * orow ; 00062 MRI_IMAGE * qim ; 00063 int qx,qy,qz, ps , xx,yy,zz , nx,nxy , xps ; 00064 00065 ENTRY("mri_cut_3D") ; 00066 00067 /*-- sanity checks --*/ 00068 00069 if( im == NULL || xa < 0 || xb >= im->nx || xb < xa || 00070 ya < 0 || yb >= im->ny || yb < ya || 00071 za < 0 || zb >= im->nz || zb < za ) RETURN(NULL) ; 00072 00073 /*-- pointer to input data --*/ 00074 00075 par = (char *) mri_data_pointer( im ) ; 00076 if( par == NULL ) RETURN(NULL) ; /* sanity check */ 00077 00078 /*-- make output image --*/ 00079 00080 qx = xb - xa + 1; qy = yb - ya + 1; qz = zb - za + 1; /* dimensions */ 00081 qim = mri_new_vol( qx , qy , qz , im->kind ) ; /* creation */ 00082 00083 ps = im->pixel_size ; xps = qx * ps ; /* xps = size of output row */ 00084 qar = (char *) mri_data_pointer( qim ) ; /* ptr to output data */ 00085 nx = im->nx ; nxy = nx * im->ny ; 00086 00087 for( zz=za ; zz <= zb ; zz++ ){ /* for each ouput plane */ 00088 for( yy=ya ; yy <= yb ; yy++ ){ /* for each output row */ 00089 irow = par + (zz*nxy+yy*nx+xa)*ps ; /* ptr to input row */ 00090 orow = qar + ((zz-za)*qy+(yy-ya))*xps ; /* ptr to output row */ 00091 memcpy( orow , irow , xps ) ; /* copy input to output */ 00092 } 00093 } 00094 00095 MRI_COPY_AUX(qim,im) ; 00096 RETURN(qim) ; 00097 } |