Doxygen Source Code Documentation
mrilib.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "mcw_malloc.h"
#include "debugtrace.h"
#include "Amalloc.h"
#include "coxplot.h"
#include "cdflib.h"
#include "mcw_glob.h"
#include "list_struct.h"
#include "thd_iochan.h"
#include "3ddata.h"
#include "thd_maker.h"
#include "editvol.h"
#include "cs.h"
#include "multivector.h"
#include "afni_environ.h"
#include "AFNI_label.h"
Go to the source code of this file.
Data Structures | |
struct | complex |
struct | floatvec |
struct | floatvecvec |
struct | int_pair |
struct | int_triple |
struct | intvec |
struct | MRI_2dalign_basis |
union | MRI_DATA |
struct | MRI_IMAGE |
struct | MRI_IMARR |
struct | rgba |
struct | rgbyte |
struct | SYM_irange |
Defines | |
#define | MRILIB_7D |
#define | COXEMAIL "rwcox@nih.gov" |
#define | CLEAR_MRILIB_globals |
#define | PI 3.14159265358979323846 |
#define | WAY_BIG 1.e+10 |
#define | FLDIF(x, y) ( fabs(x-y) > 1.e-4 * (fabs(x)+fabs(y)) ) |
#define | MAX(a, b) (((a)<(b)) ? (b) : (a)) |
#define | MIN(a, b) (((a)>(b)) ? (b) : (a)) |
#define | LOAD_rgba(s, rr, gg, bb, aa) ((s).r=(rr),(s).g=(gg),(s).b=(bb),(s).a=(bb)) |
#define | UNLOAD_rgba(s, rr, gg, bb, aa) ((rr)=(s).r,(gg)=(s).g,(bb)=(s).b,(aa)=(s).a) |
#define | BYTE_TO_ZONE(b) (0.00392157*(b)) |
#define | ZONE_TO_BYTE(z) ((byte)(255.49*(z))) |
#define | MRI_KIND MRI_TYPE ; |
#define | MRI_type MRI_TYPE ; |
#define | MRI_kind MRI_TYPE ; |
#define | MRI_rgbyte MRI_rgb |
#define | LAST_MRI_TYPE 7 |
#define | MRI_type_name MRI_TYPE_name |
#define | MRI_TYPE_NAME(iimm) MRI_TYPE_name[(iimm)->kind] |
#define | MRI_maxbyte 255 |
#define | MRI_maxshort 32767 |
#define | MRI_maxint 2147483647 |
#define | SHORTIZE(xx) |
#define | BYTEIZE(xx) |
#define | MRI_IS_INT_TYPE(typ) ((typ) < 3) |
#define | RGBZEQ(q) ( (q).r==0 && (q).g==0 && (q).b==0 ) |
#define | RGBZAS(q) ( (q).r = (q).g = (q).b = 0 ) |
#define | RGBYTE_TO_INT(rgb) ( (rgb).r << 16 | (rgb).g << 8 | (rgb).b ) |
#define | INT_TO_RGB(q) |
#define | USE_MRI_DELAY |
#define | INPUT_DELAY 1 |
#define | BSWAP_DELAY 2 |
#define | MRI_COPY_AUX(nn, oo) |
#define | MRI_IS_1D(iq) ((iq)->ny == 1) |
#define | MRI_IS_2D(iq) ((iq)->ny > 1 && (iq)->nz == 1) |
#define | MRI_IS_3D(iq) ((iq)->nz > 1 && (iq)->nt == 1) |
#define | MRI_IS_4D(iq) ((iq)->nt > 1 && (iq)->nu == 1) |
#define | MRI_DIMENSIONALITY(iq) |
#define | MRI_BYTE_PTR(iq) ((iq)->im.byte_data) |
#define | MRI_SHORT_PTR(iq) ((iq)->im.short_data) |
#define | MRI_INT_PTR(iq) ((iq)->im.int_data) |
#define | MRI_FLOAT_PTR(iq) ((iq)->im.float_data) |
#define | MRI_DOUBLE_PTR(iq) ((iq)->im.double_data) |
#define | MRI_COMPLEX_PTR(iq) ((iq)->im.complex_data) |
#define | MRI_RGB_PTR(iq) ((iq)->im.rgb_data) |
#define | MRI_RGBA_PTR(iq) ((iq)->im.rgba_data) |
#define | MRI_BYTE_2D(iq, ix, jy) MRI_BYTE_PTR(iq)[(ix)+(jy)*(iq)->nx] |
#define | MRI_SHORT_2D(iq, ix, jy) MRI_SHORT_PTR(iq)[(ix)+(jy)*(iq)->nx] |
#define | MRI_INT_2D(iq, ix, jy) MRI_INT_PTR(iq)[(ix)+(jy)*(iq)->nx] |
#define | MRI_FLOAT_2D(iq, ix, jy) MRI_FLOAT_PTR(iq)[(ix)+(jy)*(iq)->nx] |
#define | MRI_DOUBLE_2D(iq, ix, jy) MRI_DOUBLE_PTR(iq)[(ix)+(jy)*(iq)->nx] |
#define | MRI_COMPLEX_2D(iq, ix, jy) MRI_COMPLEX_PTR(iq)[(ix)+(jy)*(iq)->nx] |
#define | FLOAT_TO_BYTE(fff) ( ((fff)<=0.0) ? (0) : ((fff)>=255.5) ? (255) : (byte)((fff)+0.49) ) |
#define | SHORT_TO_BYTE(fff) ( ((fff)<=0) ? (0) : ((fff)>=255) ? (255) : (byte)(fff) ) |
#define | FLOAT_TO_SHORT(fff) ((short)(fff)) |
#define | IMAGE_IN_IMARR(name, nn) ((name)->imarr[(nn)]) |
#define | IMARR_SUBIMAGE IMAGE_IN_IMARR |
#define | IMARR_SUBIM IMAGE_IN_IMARR |
#define | IMARR_COUNT(name) ((name)->num) |
#define | IMARR_LASTIM(name) ((name)->imarr[(name)->num-1]) |
#define | IMARR_FIRSTIM(name) ((name)->imarr[0]) |
#define | INC_IMARR 32 |
#define | INIT_IMARR(name) |
#define | ADDTO_IMARR(name, imm) |
#define | FREE_IMARR(name) |
#define | DESTROY_IMARR(name) |
#define | TRUNCATE_IMARR(name, qq) |
#define | CMPLX(x, y) ( MRI_cxa.r = (x) , MRI_cxa.i = (y) , MRI_cxa ) |
#define | CADD(u, v) |
#define | CADDTO(u, v) ( u.r += v.r , u.i += v.i ) |
#define | CSUB(u, v) |
#define | CSUBFROM(u, v) ( u.r -= v.r , u.i -= v.i ) |
#define | CMULT(u, v) |
#define | CMULTBY(u, v) |
#define | CJMULT(u, v) |
#define | CJMULTBY(u, v) |
#define | CMADD(u, v, w) |
#define | CEXPIT(t) ( MRI_cxc.r = cos(t) , MRI_cxc.i = sin(t) , MRI_cxc ) |
#define | MEDIAN(a, b, c) |
#define | OSFSUM(p, q, r) (0.70*(p)+0.15*((q)+(r))) |
#define | OSFILT(a, b, c) |
#define | TRUE (1) |
#define | FALSE (0) |
#define | MRI_BILINEAR (1) |
#define | MRI_LINEAR (1) |
#define | MRI_BICUBIC (2) |
#define | MRI_CUBIC (2) |
#define | MRI_FOURIER (3) |
#define | MRI_NN (0) |
#define | MRI_QUINTIC (4) |
#define | MRI_HEPTIC (5) |
#define | MRI_TSSHIFT (6) |
#define | MRI_FOURIER_NOPAD (66) |
#define | SQR(x) ((x)*(x)) |
#define | CSQR(z) (SQR(z.r)+SQR(z.i)) |
#define | CABS(z) sqrt(CSQR(z)) |
#define | CARG(z) ( ((z).r!=0.0 || (z).i!=0.0) ? atan2((z).i,(z).r) : 0.0 ) |
#define | CUNITIZE(z) ( MRI_fla=CABS(z) , z.r=z.r/MRI_fla , z.i=z.i/MRI_fla ) |
#define | WHOAMI |
#define | IMHEADER(f) |
#define | MRI_FATAL_ERROR {fprintf(stderr,"in file: %s at line %d\n",__FILE__,__LINE__);EXIT(1);} |
#define | mri_clear_data_pointer(iq) mri_fix_data_pointer(NULL,(iq)) |
#define | mri_zero_image(iq) memset(mri_data_pointer(iq),0,(iq)->nvox*(iq)->pixel_size) |
#define | mri_new_conforming(iq, kk) |
#define | mri_empty_conforming(iq, kk) |
#define | FILT_FFT_WRAPAROUND 1 |
#define | ALIGN_DFSPACE_TYPE 1 |
#define | ALIGN_DFTIME_TYPE 2 |
#define | ALIGN_VERBOSE_CODE 1 |
#define | ALIGN_NOITER_CODE 2 |
#define | ALIGN_REGISTER_CODE 4 |
#define | ALIGN_DETREND_CODE 8 |
#define | ALIGN_DOBOTH_CODE 16 |
#define | ALIGN_DEBUG_CODE 32 |
#define | ALIGN_FREEUP_CODE 64 |
#define | ALIGN_BILINEAR_CODE 128 |
#define | ALIGN_FOURIER_CODE 256 |
#define | MRI_ROT_0 1 |
#define | MRI_ROT_90 2 |
#define | MRI_ROT_180 4 |
#define | MRI_ROT_270 8 |
#define | MRI_FLMADD 128 |
#define | LSB_FIRST 1 |
#define | MSB_FIRST 2 |
#define | NATIVE_ORDER -1 |
#define | REVERSE_ORDER(bord) (3-(bord)) |
#define | ORDER_LEN 9 |
#define | LSB_FIRST_STRING "LSB_FIRST" |
#define | MSB_FIRST_STRING "MSB_FIRST" |
#define | NATIVE_STRING "NATIVE_ORDER" |
#define | BYTE_ORDER_STRING(qq) |
#define | QG(x) (0.5*erfc(x/1.414213562373095)) |
#define | erfcinv(y) (0.70710678*qginv(0.5*y)) |
#define | normal_t2z(x) (x) |
#define | KILL_floatvec(fv) |
#define | KILL_intvec(fv) |
#define | INLINE |
#define | RESTRICT |
#define | PRINT_VERSION(pp) INFO_message("Program %s: AFNI version=%s",(pp),AFNI_VERSION_LABEL) |
#define | WROTE_DSET_MSG(dd, ss) INFO_message("Output dataset %s {%s}",DSET_BRIKNAME(dd),(ss)) |
#define | WROTE_DSET(dd) INFO_message("Output dataset %s",DSET_BRIKNAME(dd)) |
Typedefs | |
typedef unsigned char | byte |
typedef enum MRI_TYPE | MRI_TYPE |
typedef complex | complex |
typedef rgbyte | rgbyte |
typedef MRI_DATA | MRI_DATA |
typedef MRI_IMAGE | MRI_IMAGE |
typedef MRI_IMARR | MRI_IMARR |
Enumerations | |
enum | MRI_TYPE { MRI_byte, MRI_short, MRI_int, MRI_float, MRI_double, MRI_complex, MRI_rgb, MRI_rgba } |
Functions | |
void | mri_input_delay (MRI_IMAGE *) |
void | mri_purge_delay (MRI_IMAGE *) |
void | mri_add_fname_delay (char *, MRI_IMAGE *) |
MRI_IMARR * | mri_read_file_delay (char *) |
MRI_IMARR * | mri_read_3D_delay (char *) |
int | mri_equal (MRI_IMAGE *, MRI_IMAGE *) |
MRI_IMARR * | mri_read_analyze75 (char *) |
MRI_IMARR * | mri_read_siemens (char *) |
MRI_IMARR * | mri_read3D_analyze75 (char *) |
MRI_IMAGE * | mri_read_stuff (char *) |
void | mri_inflate_pbm (MRI_IMAGE *) |
void | mri_add_name (char *, MRI_IMAGE *) |
MRI_IMAGE ** | mri_stat_seq (MRI_IMAGE *) |
MRI_IMAGE * | mri_edit_image (float pthr, float power, MRI_IMAGE *im) |
MRI_IMARR * | mri_read_mpeg (char *) |
int | mri_isgray (MRI_IMAGE *) |
int | mri_imcount_mpeg (char *) |
void | cfft (int, int, float *, float *) |
void | cfft2d (int, int, int, float *, float *) |
void | csfft_cox (int, int, complex *) |
void | csfft_many (int, int, int, complex *) |
int | csfft_nextup (int) |
int | csfft_nextup_one35 (int) |
int | csfft_nextup_even (int) |
void | csfft_scale_inverse (int) |
void | csfft_use_fftw (int) |
void | mri_fftshift (MRI_IMAGE *, float, float, float, int) |
void * | mri_data_pointer (MRI_IMAGE *) |
void | mri_free (MRI_IMAGE *) |
void | mri_fix_data_pointer (void *, MRI_IMAGE *) |
char * | mri_dicom_header (char *) |
void | mri_dicom_pxlarr (off_t *, unsigned int *) |
void | mri_dicom_noname (int) |
void | mri_dicom_nohex (int) |
void | mri_dicom_setvm (int) |
void | mri_dicom_seterr (int) |
MRI_IMARR * | mri_read_dicom (char *) |
int | mri_imcount_dicom (char *) |
char * | mri_dicom_sexinfo (void) |
int | mri_possibly_dicom (char *) |
MRI_IMAGE * | mri_zeropad_3D (int, int, int, int, int, int, MRI_IMAGE *) |
MRI_IMAGE * | mri_zeropad_2D (int, int, int, int, MRI_IMAGE *) |
double | mri_max (MRI_IMAGE *) |
double | mri_min (MRI_IMAGE *) |
double | mri_maxabs (MRI_IMAGE *) |
MRI_IMAGE * | mri_cut_2D (MRI_IMAGE *, int, int, int, int) |
MRI_IMAGE * | mri_cut_3D (MRI_IMAGE *, int, int, int, int, int, int) |
void | upsample_7 (int, int, float *, float *) |
void | upsample_1 (int, int, float *, float *) |
MRI_IMAGE * | mri_dup2D (int, MRI_IMAGE *) |
void | mri_dup2D_mode (int) |
void | mri_move_guts (MRI_IMAGE *, MRI_IMAGE *) |
MRI_IMAGE * | mri_copy (MRI_IMAGE *) |
MRI_IMAGE * | mri_expand_2D (int, MRI_IMAGE *) |
MRI_IMAGE * | mri_new (int, int, MRI_TYPE) |
MRI_IMAGE * | mri_read (char *) |
MRI_IMAGE * | mri_read_ge4 (char *) |
int | mri_write (char *, MRI_IMAGE *) |
int | mri_write_pnm (char *, MRI_IMAGE *) |
int | mri_write_jpg (char *, MRI_IMAGE *) |
int | mri_write_7D (char *, MRI_IMAGE *) |
int | mri_datum_size (MRI_TYPE typ) |
MRI_IMAGE * | mri_read_ascii (char *) |
MRI_IMAGE * | mri_read_ascii_ragged (char *, float) |
int | mri_write_ascii (char *, MRI_IMAGE *) |
int | mri_write_raw (char *, MRI_IMAGE *) |
void | mri_write_analyze (char *, MRI_IMAGE *) |
MRI_IMAGE * | mri_read_1D (char *) |
int | mri_write_1D (char *, MRI_IMAGE *) |
MRI_IMAGE * | mri_1D_fromstring (char *) |
int | setup_mri_write_angif (void) |
int | mri_write_angif (char *, MRI_IMARR *) |
MRI_IMAGE * | mri_colorsetup (int, int, int, int) |
MRI_IMAGE * | mri_new_vol (int, int, int, MRI_TYPE) |
MRI_IMAGE * | mri_new_vol_empty (int, int, int, MRI_TYPE) |
MRI_IMAGE * | mri_new_7D_generic (int nx, int ny, int nz, int nt, int nu, int nv, int nw, MRI_TYPE kind, int make_space) |
MRI_IMARR * | mri_read_3D (char *) |
MRI_IMARR * | mri_read_3A (char *) |
MRI_IMARR * | mri_read_file (char *) |
int | mri_imcount (char *) |
MRI_IMARR * | mri_read_many_files (int nf, char *fn[]) |
MRI_IMARR * | mri_read_ppm3 (char *fname) |
MRI_IMAGE * | mri_read_ppm (char *fname) |
void | mri_read_ppm_header (char *, int *, int *) |
MRI_IMAGE * | mri_read_just_one (char *fname) |
MRI_IMAGE * | mri_read_nsize (char *fname) |
MRI_IMARR * | mri_read_many_nsize (int nf, char *fn[]) |
void | init_MCW_sizes (void) |
char * | imsized_fname (char *fname) |
long | mri_filesize (char *pathname) |
char * | my_strdup (char *str) |
void | mri_overlay_2D (MRI_IMAGE *, MRI_IMAGE *, int, int) |
void | mri_swapbytes (MRI_IMAGE *) |
void | swap_twobytes (int n, void *ar) |
void | swap_fourbytes (int n, void *ar) |
void | swap_eightbytes (int n, void *ar) |
MRI_IMAGE * | mri_to_float (MRI_IMAGE *) |
MRI_IMAGE * | mri_to_short (double, MRI_IMAGE *) |
MRI_IMAGE * | mri_to_short_scl (double, double, MRI_IMAGE *) |
MRI_IMAGE * | mri_to_short_sclip (double, double, int, int, MRI_IMAGE *) |
MRI_IMAGE * | mri_to_complex (MRI_IMAGE *) |
MRI_IMAGE * | mri_to_byte (MRI_IMAGE *) |
MRI_IMAGE * | mri_to_byte_scl (double, double, MRI_IMAGE *) |
MRI_IMAGE * | mri_to_rgb (MRI_IMAGE *) |
MRI_IMAGE * | mri_3to_rgb (MRI_IMAGE *, MRI_IMAGE *, MRI_IMAGE *) |
MRI_IMARR * | mri_rgb_to_3float (MRI_IMAGE *) |
MRI_IMARR * | mri_rgb_to_3byte (MRI_IMAGE *) |
MRI_IMAGE * | mri_sharpen_rgb (float, MRI_IMAGE *) |
MRI_IMAGE * | mri_flatten_rgb (MRI_IMAGE *) |
void | mri_invert_inplace (MRI_IMAGE *) |
MRI_IMAGE * | mri_to_rgba (MRI_IMAGE *) |
MRI_IMAGE * | mri_pair_to_complex (MRI_IMAGE *, MRI_IMAGE *) |
MRI_IMARR * | mri_complex_to_pair (MRI_IMAGE *) |
MRI_IMAGE * | mri_to_complex_ext (MRI_IMAGE *, int, int, int) |
MRI_IMAGE * | mri_scale_to_float (float, MRI_IMAGE *) |
void | mri_threshold (double, double, MRI_IMAGE *, MRI_IMAGE *) |
MRI_IMAGE * | mri_mult_to_float (float *, MRI_IMAGE *) |
MRI_IMAGE * | mri_scalize (MRI_IMAGE *, int, float *) |
MRI_IMAGE * | mri_multiply_complex (int, MRI_IMAGE *, MRI_IMAGE *) |
MRI_IMAGE * | mri_complex_phase (MRI_IMAGE *) |
MRI_IMAGE * | mri_to_mri (int, MRI_IMAGE *) |
MRI_IMAGE * | mri_to_mri_scl (int, double, MRI_IMAGE *) |
MRI_IMAGE * | mri_complex_abs (MRI_IMAGE *) |
void | mri_fft_complex (int, float, MRI_IMAGE *) |
float * | mri_setup_taper (int, float) |
MRI_IMAGE * | mri_warp (MRI_IMAGE *, int, int, int, void func(float, float, float *, float *)) |
MRI_IMAGE * | mri_warp_bicubic (MRI_IMAGE *, int, int, void func(float, float, float *, float *)) |
MRI_IMAGE * | mri_warp_bilinear (MRI_IMAGE *, int, int, void func(float, float, float *, float *)) |
MRI_IMAGE * | mri_resize (MRI_IMAGE *, int, int) |
MRI_IMAGE * | mri_resize_NN (MRI_IMAGE *, int, int) |
MRI_IMAGE * | mri_squareaspect (MRI_IMAGE *) |
MRI_IMAGE * | mri_rotate (MRI_IMAGE *, float, float, float, float) |
MRI_IMAGE * | mri_rotate_bilinear (MRI_IMAGE *, float, float, float, float) |
MRI_IMAGE * | mri_rota (MRI_IMAGE *, float, float, float) |
MRI_IMAGE * | mri_rota_bilinear (MRI_IMAGE *, float, float, float) |
MRI_IMAGE * | mri_rota_shear (MRI_IMAGE *, float, float, float) |
MRI_IMAGE * | mri_rota_variable (int, MRI_IMAGE *, float, float, float) |
MRI_IMAGE * | mri_aff2d_byte (MRI_IMAGE *, int, float, float, float, float) |
MRI_IMAGE * | mri_aff2d_rgb (MRI_IMAGE *, int, float, float, float, float) |
void | mri_scale_inplace (float, MRI_IMAGE *) |
void | ft_shift2 (int, int, float, float *, float, float *) |
MRI_IMAGE * | mri_float_func (int, int, float, float, float, float, float(*func)(float, float)) |
void | mri_histogram (MRI_IMAGE *, float, float, int, int, int h[]) |
void | mri_histobyte (MRI_IMAGE *, int *) |
void | mri_histoshort_all (MRI_IMAGE *, int *) |
void | mri_histoshort_nonneg (MRI_IMAGE *, int *) |
void | mri_percents (MRI_IMAGE *, int nper, float per[]) |
MRI_IMAGE * | mri_flatten (MRI_IMAGE *) |
float | mri_quantile (MRI_IMAGE *im, float alpha) |
void | qsort_short (int, short *) |
void | qsort_float (int, float *) |
void | qsort_pair (int, float *, int *) |
void | qsort_int (int, int *) |
void | isort_short (int, short *) |
void | isort_float (int, float *) |
void | isort_pair (int, float *, int *) |
MRI_IMAGE * | mri_nsize (MRI_IMAGE *) |
float * | mri_lsqfit (MRI_IMAGE *fitim, MRI_IMARR *refim, MRI_IMAGE *) |
double * | mri_startup_lsqfit (MRI_IMARR *, MRI_IMAGE *) |
float * | mri_delayed_lsqfit (MRI_IMAGE *, MRI_IMARR *, double *) |
float * | lsqfit (int, float *, float *, int, float *ref[]) |
double * | startup_lsqfit (int, float *, int, float *ref[]) |
float * | delayed_lsqfit (int, float *, int, float *ref[], double *) |
MRI_IMAGE * | mri_sobel (int, int, MRI_IMAGE *) |
MRI_IMAGE * | mri_sharpen (float, int, MRI_IMAGE *) |
MRI_IMAGE * | mri_transpose (MRI_IMAGE *) |
MRI_IMAGE * | mri_filt_fft (MRI_IMAGE *im, float, int, int, int) |
MRI_IMAGE * | mri_medianfilter (MRI_IMAGE *, float, byte *, int) |
MRI_IMAGE * | mri_cat2D (int, int, int, void *, MRI_IMARR *) |
MRI_IMARR * | mri_uncat2D (int, int, MRI_IMAGE *im) |
MRI_IMAGE * | mri_shift_1D (MRI_IMAGE *im, float shift) |
MRI_IMARR * | mri_align_dfspace (MRI_IMAGE *, MRI_IMAGE *, MRI_IMARR *, int, float *, float *, float *) |
MRI_IMARR * | mri_align_dftime (MRI_IMAGE *, MRI_IMAGE *, MRI_IMARR *, int, float *, float *, float *) |
void | mri_align_params (int, float, float, float, float, float, float) |
void | mri_align_method (int, int, int) |
void | mri_get_cmass_2D (MRI_IMAGE *, float *, float *) |
void | mri_get_cmass_3D (MRI_IMAGE *, float *, float *, float *) |
void | mri_2dalign_params (int, float, float, float, float, float, float) |
void | mri_2dalign_method (int, int, int) |
MRI_2dalign_basis * | mri_2dalign_setup (MRI_IMAGE *, MRI_IMAGE *) |
MRI_IMAGE * | mri_2dalign_one (MRI_2dalign_basis *, MRI_IMAGE *, float *, float *, float *) |
MRI_IMARR * | mri_2dalign_many (MRI_IMAGE *, MRI_IMAGE *, MRI_IMARR *, float *, float *, float *) |
void | mri_2dalign_cleanup (MRI_2dalign_basis *) |
MRI_IMAGE * | mri_flippo (int rot, int mirror, MRI_IMAGE *im) |
MRI_IMAGE * | mri_flip3D (int, int, int, MRI_IMAGE *inim) |
int | mri_short_order (void) |
int | mri_int_order (void) |
void | mri_swap2 (int, short *) |
void | mri_swap4 (int, int *) |
void | mri_drawline (MRI_IMAGE *im, int x0, int y0, int x1, int y1, byte r, byte g, byte b) |
void | mri_drawfilledrectangle (MRI_IMAGE *im, int x, int y, int width, int height, byte r, byte g, byte b) |
void | mri_drawemptyrectangle (MRI_IMAGE *im, int x, int y, int width, int height, byte r, byte g, byte b) |
void | mri_drawtext (MRI_IMAGE *im, int x, int y, int height, int angle, char *s, byte r, byte g, byte b) |
void | mri_draw_opacity (float) |
void | set_memplot_RGB_box (int xbot, int ybot, int xtop, int ytop) |
void | memplot_to_RGB_sef (MRI_IMAGE *im, MEM_plotdata *mp, int start, int end, int freee) |
double | lnbeta (double, double) |
double | incbeta (double, double, double, double) |
double | incbeta_inverse (double, double, double, double) |
double | qginv (double) |
double | qg (double) |
double | log10qg (double) |
double | student_t2p (double, double) |
double | student_p2t (double, double) |
double | student_t2z (double, double) |
double | correl_t2p (double, double, double, double) |
double | correl_t2z (double, double, double, double) |
double | correl_p2t (double, double, double, double) |
double | studave_t2p (double, double, double) |
double | studave_t2z (double, double, double) |
double | studave_p2t (double, double, double) |
double | fstat_p2t (double, double, double) |
double | fstat_t2p (double, double, double) |
double | fstat_t2z (double, double, double) |
double | normal_t2p (double zz) |
double | normal_p2t (double qq) |
double | chisq_t2p (double xx, double dof) |
double | chisq_t2z (double xx, double dof) |
double | chisq_p2t (double qq, double dof) |
double | beta_t2p (double xx, double aa, double bb) |
double | beta_t2z (double xx, double aa, double bb) |
double | beta_p2t (double qq, double aa, double bb) |
double | binomial_t2p (double ss, double ntrial, double ptrial) |
double | binomial_t2z (double ss, double ntrial, double ptrial) |
double | binomial_p2t (double qq, double ntrial, double ptrial) |
double | gamma_t2p (double xx, double sh, double sc) |
double | gamma_t2z (double xx, double sh, double sc) |
double | gamma_p2t (double qq, double sh, double sc) |
double | poisson_t2p (double xx, double lambda) |
double | poisson_t2z (double xx, double lambda) |
double | poisson_p2t (double qq, double lambda) |
floatvecvec * | SYM_expand_ranges (int nlast, int nrang, SYM_irange *rang, char *str) |
MRI_IMAGE * | THD_average_timeseries (MCW_cluster_array *, THD_3dim_dataset *) |
MRI_IMAGE * | THD_average_one_timeseries (MCW_cluster *, THD_3dim_dataset *) |
MRI_IMAGE * | mri_warp3D_cubic (MRI_IMAGE *, int, int, int, void func(float, float, float, float *, float *, float *)) |
MRI_IMAGE * | mri_warp3D_linear (MRI_IMAGE *, int, int, int, void func(float, float, float, float *, float *, float *)) |
MRI_IMAGE * | mri_warp3D_NN (MRI_IMAGE *, int, int, int, void func(float, float, float, float *, float *, float *)) |
MRI_IMAGE * | mri_warp3D (MRI_IMAGE *, int, int, int, void func(float, float, float, float *, float *, float *)) |
void | mri_warp3D_method (int) |
void | mri_warp3D_zerout (int) |
void | mri_warp3D_set_womask (MRI_IMAGE *) |
MRI_IMAGE * | mri_warp3D_quintic (MRI_IMAGE *, int, int, int, void func(float, float, float, float *, float *, float *)) |
MRI_IMAGE * | mri_warp3D_affine (MRI_IMAGE *, THD_vecmat) |
MRI_IMAGE * | mri_warp3D_resize (MRI_IMAGE *, int, int, int) |
double | mri_entropy16 (MRI_IMAGE *) |
double | mri_entropy8 (MRI_IMAGE *) |
Variables | |
char | MRILIB_orients [] |
float | MRILIB_zoff |
float | MRILIB_tr |
float | MRILIB_xoff |
float | MRILIB_yoff |
int | use_MRILIB_zoff |
int | use_MRILIB_xoff |
int | use_MRILIB_yoff |
int | use_MRILIB_xcos |
int | use_MRILIB_ycos |
int | use_MRILIB_zcos |
float | MRILIB_xcos [3] |
float | MRILIB_ycos [3] |
float | MRILIB_zcos [3] |
int | use_MRILIB_slicespacing |
float | MRILIB_slicespacing |
char * | MRI_TYPE_name [8] |
float | MRI_TYPE_maxval [7] |
rgbyte | tEMp_rgbyte_aAa |
float | MRI_fla |
complex | MRI_cxa |
complex | MRI_cxb |
complex | MRI_cxc |
int | MRI_mm |
Define Documentation
|
|
Definition at line 841 of file mrilib.h. Referenced by get_line_opt(). |
|
Definition at line 839 of file mrilib.h. Referenced by get_line_opt(), mri_align_dfspace(), and REG_command_line(). |
|
Definition at line 837 of file mrilib.h. Referenced by REG_command_line(). |
|
Definition at line 831 of file mrilib.h. Referenced by main(), and REG_command_line(). |
|
Definition at line 832 of file mrilib.h. Referenced by main(), and REG_command_line(). |
|
Definition at line 838 of file mrilib.h. Referenced by REG_command_line(). |
|
|
|
|
|
Definition at line 835 of file mrilib.h. Referenced by get_line_opt(), mri_align_dfspace(), and REG_command_line(). |
|
Definition at line 836 of file mrilib.h. Referenced by get_line_opt(), IMREG_main(), main(), and mri_align_dfspace(). |
|
Definition at line 834 of file mrilib.h. Referenced by mri_align_dfspace(), and REG_command_line(). |
|
|
|
Value: ( ((qq)==LSB_FIRST) ? LSB_FIRST_STRING \ : ((qq)==MSB_FIRST) ? MSB_FIRST_STRING \ : "Illegal Value" ) Definition at line 902 of file mrilib.h. Referenced by RT_process_info(), and THD_datablock_from_atr(). |
|
Scale a byte [0..255] to a float in [0..1). |
|
Value: ( ((xx) < 0.0) ? (byte)0 \ : ((xx) > 255.0) ? (byte)255 : (byte)rint(xx) ) Definition at line 153 of file mrilib.h. Referenced by ISQ_process_mri(), main(), MASKAVE_main(), mri_to_byte(), mri_to_byte_scl(), mri_to_short_sclip(), SUMA_FormAfnidset(), THD_insert_series(), THD_load_datablock(), THD_makemask(), and thd_mask_from_brick(). |
|
|
Value: Return complex u+v |
|
complex u += v |
|
Definition at line 521 of file mrilib.h. Referenced by cx_scramble(), and ISQ_process_mri(). |
|
Return complex exp(I*t) Definition at line 476 of file mrilib.h. Referenced by fft_shift2(), ft_shift2(), and main(). |
|
Value: Return complex u * conjg(v)Definition at line 461 of file mrilib.h. Referenced by FFT_2dchirpz(), and mri_multiply_complex(). |
|
Value: complex u *= conjg(v) |
|
Value: do{ MRILIB_orients[0]='\0'; \ MRILIB_zoff=MRILIB_xoff=MRILIB_yoff=MRILIB_tr=0.0; \ use_MRILIB_xoff=use_MRILIB_yoff=use_MRILIB_zoff=0; \ use_MRILIB_xcos=use_MRILIB_ycos=use_MRILIB_zcos=0; \ use_MRILIB_slicespacing=0; \ } while(0) Definition at line 36 of file mrilib.h. Referenced by main(), and T3D_read_images(). |
|
Value: complex w += u*v |
|
Return a complex from two floats. Definition at line 430 of file mrilib.h. Referenced by DRAW_into_dataset(), and main(). |
|
Value: Return complex u*vDefinition at line 451 of file mrilib.h. Referenced by FFT_2dchirpz(), fft_shift2(), ft_shift2(), and mri_multiply_complex(). |
|
Value: complex u *= v |
|
Definition at line 12 of file mrilib.h. Referenced by DRAW_help_CB(), and ISQ_saver_CB(). |
|
Definition at line 519 of file mrilib.h. Referenced by autocorr(), main(), MCW_scale_to_max(), MCW_vol_amax(), mri_complex_abs(), mri_max(), mri_maxabs(), mri_min(), THD_get_brick_stats(), THD_load_datablock(), and ts_to_ftime(). |
|
Value: Return complex u-v |
|
complex u -= v |
|
complex z /= abs(z) |
|
|
|
|
|
|
Definition at line 818 of file mrilib.h. Referenced by mri_2dalign_one(), mri_2dalign_setup(), mri_align_crao(), mri_align_dfspace(), and mri_filt_fft(). |
|
Are 2 floats significantly different? Definition at line 63 of file mrilib.h. Referenced by ISQ_make_image(), ISQ_make_montage(), and main(). |
|
Definition at line 347 of file mrilib.h. Referenced by EDIT_coerce_scale_type(), and EDIT_coerce_type(). |
|
|
|
Value: Free the MRI_IMARR struct (but not the images within).Definition at line 402 of file mrilib.h. Referenced by AFNI_read_images(), AFNI_read_inputs(), AFNI_rescan_timeseries_CB(), avg_epochs(), drive_MCW_grapher(), DSETN_func(), main(), mri_affine_bicubic(), mri_dup2D(), mri_lsqfit(), mri_read_just_one(), mri_read_many_files(), mri_read_many_nsize(), mri_read_mpeg(), mri_read_siemens(), mri_rgba_composite_two(), mri_rgba_composite_VA(), mri_rota(), mri_rota_bilinear(), mri_rota_shear(), mri_shift2D_bilinear(), mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), mri_warp3D_quintic(), NUD_rotate(), PH_redraw(), PLUTO_imseq_popim(), REG_command_line(), RT_start_dataset(), T3D_read_images(), TFIM_getopts(), THD_delete_datablock(), and THD_get_many_timeseries(). |
|
Get the nn-th image from the image array "name". Definition at line 367 of file mrilib.h. Referenced by avg_epochs(), main(), mri_affine_bicubic(), mri_dup2D(), mri_read_just_one(), mri_read_many_nsize(), mri_read_nsize(), mri_rota(), mri_rota_bilinear(), mri_rota_shear(), mri_shift2D_bilinear(), and NUD_rotate(). |
|
|
|
|
Definition at line 375 of file mrilib.h. Referenced by SNAP_store_image(). |
|
|
|
|
|
|
|
|
|
|
|
|
Value: ( tEMp_rgbyte_aAa.r = ((q) >> 16) & 0xff , \ tEMp_rgbyte_aAa.g = ((q) >> 8) & 0xff , \ tEMp_rgbyte_aAa.b = (q) & 0xff , tEMp_rgbyte_aAa ) |
|
Value: Definition at line 1010 of file mrilib.h. Referenced by decode_linebuf(), mri_read_ascii(), mri_read_ascii_ragged(), and SYM_expand_ranges(). |
|
Value: |
|
The last MRI_TYPE yet defined. |
|
|
|
|
|
Definition at line 898 of file mrilib.h. Referenced by main(), THD_datablock_from_atr(), THD_dataset_info(), THD_enviro_write_order(), THD_init_one_datablock(), and THD_write_datablock(). |
|
|
|
Value: ( MRI_mm = 4*((a)<(b)) + 2*((a)<(c)) + ((b)<(c)) , \ (MRI_mm==3||MRI_mm==4) ? (a) : \ (MRI_mm==7||MRI_mm==0) ? (b) : (c) ) Definition at line 484 of file mrilib.h. Referenced by main(), and median3_func(). |
|
|
|
Definition at line 508 of file mrilib.h. Referenced by main(), mri_resize(), mri_rota_variable(), mri_warp(), REG_command_line(), and RT_registration_2D_setup(). |
|
Definition at line 506 of file mrilib.h. Referenced by main(), mri_resize(), mri_rota_variable(), mri_warp(), REG_command_line(), and RT_registration_2D_setup(). |
|
|
|
|
|
Set the data pointer in an MRI_IMAGE to NULL. Definition at line 603 of file mrilib.h. Referenced by AFNI_make_widgets(), BFIT_compute(), BFIT_main(), cleanup_rtinp(), CORREL_main(), IMREG_main(), main(), mri_purge_delay(), NUD_doall_CB(), NUD_update_base(), T3D_fix_dataset_dimen(), THD_autonudge(), THD_load_datablock(), THD_purge_datablock(), THD_purge_one_brick(), and THD_write_datablock(). |
|
|
|
|
|
Value: ( (nn)->dx = (oo)->dx , (nn)->dy = (oo)->dy , (nn)->dz = (oo)->dz , \ (nn)->dt = (oo)->dt , (nn)->du = (oo)->du , (nn)->dv = (oo)->dv , \ (nn)->dw = (oo)->dw , \ (nn)->xo = (oo)->xo , (nn)->yo = (oo)->yo , (nn)->zo = (oo)->zo , \ (nn)->to = (oo)->to , (nn)->uo = (oo)->uo , (nn)->vo = (oo)->vo , \ (nn)->wo = (oo)->wo , \ mri_add_name( (oo)->name , (nn) ) ) |
|
Definition at line 509 of file mrilib.h. Referenced by main(), mri_3dalign_one(), mri_brainormalize(), mri_warp3D(), RT_registration_3D_setup(), SHIFT_set_method(), THD_rota_method(), and VL_command_line(). |
|
Value: ( ((iq)->ny == 1) ? 1 : ((iq)->nz == 1) ? 2 : \ ((iq)->nt == 1) ? 3 : ((iq)->nu == 1) ? 4 : \ ((iq)->nv == 1) ? 5 : ((iq)->nw == 1) ? 6 : 7 ) |
|
|
|
|
|
Value: mri_new_7D_generic( (iq)->nx, (iq)->ny, (iq)->nz , (iq)->nt , \ (iq)->nu, (iq)->nv, (iq)->nw , (kk) , FALSE ) Definition at line 669 of file mrilib.h. Referenced by EDIT_substitute_brick(), and main(). |
|
Definition at line 540 of file mrilib.h. Referenced by mri_3to_rgb(), mri_complex_abs(), mri_complex_phase(), mri_fft_complex(), mri_mult_to_float(), mri_multiply_complex(), mri_new_7D_generic(), mri_resize(), mri_scale_to_float(), mri_to_byte(), mri_to_byte_scl(), mri_to_complex(), mri_to_float(), mri_to_short(), mri_to_short_sclip(), and mri_warp(). |
|
|
|
|
|
|
|
Definition at line 510 of file mrilib.h. Referenced by apply_xshear(), apply_yshear(), apply_zshear(), main(), mri_3dalign_one(), mri_rota_variable(), new_RT_input(), REG_command_line(), SHIFT_set_method(), THD_rota_method(), and VL_command_line(). |
|
Definition at line 516 of file mrilib.h. Referenced by apply_xshear(), apply_yshear(), apply_zshear(), main(), and THD_rota_method(). |
|
Definition at line 513 of file mrilib.h. Referenced by main(), mri_3dalign_one(), new_RT_input(), RT_registration_2D_setup(), SHIFT_set_method(), THD_rota_method(), and VL_command_line(). |
|
|
|
|
|
Check if MRI_IMAGE is 1D (ny=1) |
|
Check if MRI_IMAGE is 2D (nz=1) |
|
Check if MRI_IMAGE is 3D (nt=1) |
|
Check if MRI_IMAGE is 4D (nu=1) |
|
Determine if a MRI_TYPE is an integer type. |
|
|
|
|
|
Definition at line 507 of file mrilib.h. Referenced by main(), mri_warp3D(), mri_warp3d_align_one(), mri_warp3D_align_setup(), NUD_rotate(), RT_registration_3D_setup(), SHIFT_set_method(), THD_rota_method(), and VL_command_line(). |
|
Max value of a byte. |
|
Max value of an int. |
|
Max value of a short. |
|
|
Definition at line 511 of file mrilib.h. Referenced by apply_xshear(), apply_yshear(), apply_zshear(), main(), mri_brainormalize(), mri_warp3D(), NUD_rotate(), SHIFT_set_method(), THD_rota_byte_mode(), THD_rota_method(), and VL_command_line(). |
|
Definition at line 512 of file mrilib.h. Referenced by main(), mri_3dalign_one(), mri_warp3D(), RT_registration_2D_setup(), SHIFT_set_method(), THD_rota_method(), and VL_command_line(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 514 of file mrilib.h. Referenced by apply_xshear(), apply_yshear(), apply_zshear(), SHIFT_set_method(), THD_rota_byte_mode(), and THD_rota_method(). |
|
|
|
Definition at line 127 of file mrilib.h. Referenced by adwarp_refashion_dataset(), AFNI_func_overlay(), AFNI_refashion_dataset(), and mri_overlay_2D(). |
|
Definition at line 125 of file mrilib.h. Referenced by CALC_read_opts(), EDIT_one_dataset(), main(), and thd_mask_from_brick(). |
|
Set all pixels in MRI_IMAGE to zero. Definition at line 607 of file mrilib.h. Referenced by FD_brick_to_series(). |
|
|
|
|
|
Definition at line 899 of file mrilib.h. Referenced by main(), THD_datablock_from_atr(), THD_dataset_info(), THD_enviro_write_order(), THD_init_one_datablock(), and THD_write_datablock(). |
|
|
|
Definition at line 900 of file mrilib.h. Referenced by main(). |
|
Definition at line 982 of file mrilib.h. Referenced by THD_stat_to_zscore(). |
|
Definition at line 897 of file mrilib.h. Referenced by THD_datablock_from_atr(), and THD_init_one_datablock(). |
|
Value: ( MRI_mm = 4*((a)<(b)) + 2*((a)<(c)) + ((b)<(c)) , \ (MRI_mm==3||MRI_mm==4) ? OSFSUM(a,b,c) : \ (MRI_mm==7||MRI_mm==0) ? OSFSUM(b,a,c) : OSFSUM(c,a,b) ) Definition at line 494 of file mrilib.h. Referenced by AFNI_gra_send_CB(), and osfilt3_func(). |
|
Order-statistic filter of 3. |
|
|
|
Definition at line 1108 of file mrilib.h. Referenced by get_options(), identify_software(), and main(). |
|
|
|
|
|
Definition at line 895 of file mrilib.h. Referenced by main(), THD_open_analyze(), THD_open_ctfmri(), and THD_open_ctfsam(). |
|
Convert one RBG triple (rgbyte) to a single int. |
|
Definition at line 182 of file mrilib.h. Referenced by mri_edgize(). |
|
Definition at line 181 of file mrilib.h. Referenced by mri_edgize(). |
|
Definition at line 350 of file mrilib.h. Referenced by EDIT_coerce_type(). |
|
Value: ( ((xx) < -32767.0) ? (short)-32767 \ : ((xx) > 32767.0) ? (short) 32767 : (short)rint(xx) ) Definition at line 148 of file mrilib.h. Referenced by main(), MASKAVE_main(), mri_brainormalize(), mri_threshold(), mri_to_short(), mri_to_short_sclip(), SUMA_FormAfnidset(), THD_insert_series(), THD_load_datablock(), THD_makemask(), and thd_mask_from_brick(). |
|
Definition at line 518 of file mrilib.h. Referenced by BFIT_compute(), main(), MASKAVE_main(), mri_align_crao(), normalize_doublevector(), normalize_floatvector(), PCOR_get_mcor(), PCOR_get_pcor(), PCOR_get_pcor_and_coef(), report_evaluation(), and VOLREG_main(). |
|
|
|
Value: do{ int nn ; \ if( (name) != NULL && qq < (name)->num ){ \ for( nn=qq ; nn < (name)->num ; nn++ ) mri_free((name)->imarr[nn]); \ (name)->num = qq ; \ } } while(0) Definition at line 416 of file mrilib.h. Referenced by evolve_bitvector_array(), and mri_read_dicom(). |
|
|
|
Mar 1996: Extended to images up to 7D; Not all routines work with images > 2D -- check top of file for "7D SAFE" comments * |
|
A big number (anything over this is infinity). |
|
|
|
Definition at line 1116 of file mrilib.h. Referenced by main(). |
|
|
|
Scale a float in [0..1] to a byte in [0..255]. |
Typedef Documentation
|
The MRI_byte data type. |
|
I suppose that the next C makes this pleonastic. |
|
A union type to hold all possible MRI_IMAGE types. This was created before I really understood how to use void *. |
|
Stores one image (1D to 7D). Why 7D, you ask? Well, I originally only had 2D images here. When extending AFNI from 3D to 3D+time and buckets, I thought that I might use 4D images (x,y,z,t) as the basic element. Instead, I decided to use an array of 3D images (in a THD_datablock), but by then I'd extended this typedef to allow (x,y,z,t,u,v,w) dimensioned arrays. I don't think anyplace ever uses more than 3D images, though. |
|
Array of MRI_IMAGE pointers. |
|
Integer flags for different image types. Sometimes called the "datum". |
|
Triple to hold RGB bytes. |
Enumeration Type Documentation
|
Integer flags for different image types. Sometimes called the "datum". Definition at line 106 of file mrilib.h.
00106 { 00107 MRI_byte , MRI_short , MRI_int , 00108 MRI_float , MRI_double , MRI_complex , MRI_rgb , MRI_rgba } MRI_TYPE ; |
Function Documentation
|
Definition at line 612 of file mri_stats.c. References a, cdfbet(), p, and q. Referenced by BFIT_compute(), main(), process_sample(), and THD_pval_to_stat().
00613 { 00614 int which , status ; 00615 double p,q,x,y,a,b,bound ; 00616 00617 if( qq <= 0.0 ) return 0.9999 ; 00618 if( qq >= 0.999999 ) return 0.0 ; 00619 00620 which = 2 ; 00621 p = 1.0 - qq ; 00622 q = qq ; 00623 x = 0.0 ; 00624 y = 1.0 ; 00625 a = aa ; 00626 b = bb ; 00627 00628 cdfbet( &which , &p , &q , &x , &y , &a , &b , &status , &bound ) ; 00629 00630 return x ; 00631 } |
|
Definition at line 583 of file mri_stats.c. References a, cdfbet(), p, and q. Referenced by beta_t2z(), BFIT_compute(), BFIT_main(), and THD_stat_to_pval().
00584 { 00585 int which , status ; 00586 double p,q,x,y,a,b,bound ; 00587 00588 which = 1 ; 00589 p = 0.0 ; 00590 q = 0.0 ; 00591 x = xx ; 00592 y = 1.0 - xx ; 00593 a = aa ; 00594 b = bb ; 00595 00596 cdfbet( &which , &p , &q , &x , &y , &a , &b , &status , &bound ) ; 00597 00598 if( status == 0 ) return q ; 00599 else return 1.0 ; 00600 } |
|
Definition at line 605 of file mri_stats.c. References beta_t2p(), and qginv(). Referenced by THD_stat_to_zscore().
|
|
Definition at line 668 of file mri_stats.c. References cdfbin(), p, q, and xn. Referenced by main(), and THD_pval_to_stat().
00669 { 00670 int which , status ; 00671 double p,q, s,xn,pr,ompr,bound ; 00672 00673 if( qq <= 0.0 ) return 99.99 ; 00674 if( qq >= 0.999999 ) return 0.0 ; 00675 00676 which = 2 ; 00677 p = 1.0 - qq ; 00678 q = qq ; 00679 s = 0.0 ; 00680 xn = ntrial ; 00681 pr = ptrial ; 00682 ompr = 1.0 - ptrial ; 00683 00684 cdfbin( &which , &p , &q , &s , &xn , &pr , &ompr , &status , &bound ) ; 00685 00686 if( status == 0 ) return s ; 00687 else return 0.0 ; 00688 } |
|
Definition at line 639 of file mri_stats.c. References cdfbin(), p, q, and xn. Referenced by binomial_t2z(), and THD_stat_to_pval().
00640 { 00641 int which , status ; 00642 double p,q, s,xn,pr,ompr,bound ; 00643 00644 which = 1 ; 00645 p = 0.0 ; 00646 q = 0.0 ; 00647 s = ss ; 00648 xn = ntrial ; 00649 pr = ptrial ; 00650 ompr = 1.0 - ptrial ; 00651 00652 cdfbin( &which , &p , &q , &s , &xn , &pr , &ompr , &status , &bound ) ; 00653 00654 if( status == 0 ) return q ; 00655 else return 1.0 ; 00656 } |
|
Definition at line 661 of file mri_stats.c. References binomial_t2p(), and qginv(). Referenced by THD_stat_to_zscore().
00662 { 00663 double pp ; 00664 pp = 0.5 * binomial_t2p( ss , ntrial , ptrial ) ; 00665 return qginv(pp) ; 00666 } |
|
Definition at line 23 of file mri_cfft.c. Referenced by cfft2d().
00025 { 00026 #define IDMAX 1024 00027 #define LIDMAX 10 00028 static int idold = -999 ; 00029 register int i0,i1,i2,i4,i5,m0, id = idim; 00030 float f1,f3,f4,f5,al,co,si,md = mode; 00031 static int n,m[LIDMAX]; 00032 static float f2,c[IDMAX/2],s[IDMAX/2]; 00033 00034 /**** preparations if id has changed since last call ****/ 00035 00036 if (idold != id) { 00037 idold = id ; 00038 /* check for power of 2 */ 00039 for( i4=4 ; i4 <= IDMAX ; i4 *= 2 ){ 00040 if( id == i4 )break ; 00041 } 00042 if( id != i4 ){ 00043 fprintf(stderr,"\n In cfft : illegal idim=%d\n",idim); 00044 exit(1) ; 00045 } 00046 f2 = id; 00047 n = log(f2)/log(2.) + .5; 00048 m[n-1] = 1; 00049 al = 2.*PI/f2; 00050 co = cos(al); 00051 si = sin(al); 00052 c[0] = 1.; 00053 s[0] = 0.; 00054 for(i4 = 1; i4 < 512; i4++) { 00055 c[i4] = c[i4-1]*co - s[i4-1]*si; 00056 s[i4] = s[i4-1]*co + c[i4-1]*si; 00057 } 00058 for(i4 = n-1; i4 >= 1; i4--) m[i4-1] = m[i4]*2; 00059 } 00060 00061 /**** Main loop starts here ****/ 00062 00063 for(i0 = 0; i0 < n; i0++) { 00064 i1 = 0; 00065 m0 = m[i0]; 00066 for(i2 = 0; i2 < m[n-i0-1]; i2++) { 00067 f4 = c[i1]; 00068 f5 = s[i1]*md; 00069 for(i4 = 2*m0*i2; i4 < m0*(2*i2+1); i4++) { 00070 f3 = xr[i4+m0]*f4 - xi[i4+m0]*f5; 00071 f1 = xi[i4+m0]*f4 + xr[i4+m0]*f5; 00072 xr[i4+m0] = xr[i4] - f3; 00073 xr[i4] += f3; 00074 xi[i4+m0] = xi[i4] - f1; 00075 xi[i4] += f1; 00076 } 00077 for(i4 = 1; i4 < n; i4++) { 00078 i5 = i4; 00079 if (i1 < m[i4]) goto i1_plus1; 00080 i1 -= m[i4]; 00081 } 00082 i1_plus1: i1 += m[i5]; 00083 } 00084 } 00085 i1 = 0; 00086 for(i4 = 0; i4 < id; i4++) { 00087 if (i1 > i4) { 00088 f3 = xr[i4]; 00089 f1 = xi[i4]; 00090 xr[i4] = xr[i1]; 00091 xi[i4] = xi[i1]; 00092 xr[i1] = f3; 00093 xi[i1] = f1; 00094 } 00095 for(i2 = 0; i2 < n; i2++) { 00096 i5 = i2; 00097 if (i1 < m[i2]) goto i1_plus2; 00098 i1 -= m[i2]; 00099 } 00100 i1_plus2: i1 += m[i5]; 00101 } 00102 00103 if (md > 0.) { 00104 f1 = 1./f2; 00105 for(i4 = 0; i4 < id; i4++) { 00106 xr[i4] *= f1; 00107 xi[i4] *= f1; 00108 } 00109 } 00110 return; 00111 } |
|
Definition at line 116 of file mri_cfft.c. References cfft(), free, and malloc. Referenced by mri_fft_complex().
00118 { 00119 float *rbuf , *ibuf ; 00120 register int ii , jj , jbase ; 00121 00122 rbuf = (float *)malloc( ny * sizeof(float) ) ; 00123 ibuf = (float *)malloc( ny * sizeof(float) ) ; 00124 if( rbuf == NULL || ibuf == NULL ){ 00125 fprintf(stderr,"malloc error in cfft2d\n") ; 00126 exit(1) ; 00127 } 00128 00129 for( jj=0 ; jj < ny ; jj++ ){ 00130 jbase = nx * jj ; 00131 cfft( mode , nx , &xr[jbase] , &xi[jbase] ) ; 00132 } 00133 00134 for( ii=0 ; ii < nx ; ii++ ){ 00135 for( jj=0 ; jj < ny ; jj++ ){ 00136 rbuf[jj] = xr[ii + jj*nx] ; 00137 ibuf[jj] = xi[ii + jj*nx] ; 00138 } 00139 cfft( mode , ny , rbuf , ibuf ) ; 00140 for( jj=0 ; jj < ny ; jj++ ){ 00141 xr[ii+jj*nx] = rbuf[jj] ; 00142 xi[ii+jj*nx] = ibuf[jj] ; 00143 } 00144 } 00145 00146 free(rbuf) ; free(ibuf) ; 00147 return ; 00148 } |
|
Definition at line 554 of file mri_stats.c. References cdfchi(), p, and q. Referenced by THD_pval_to_stat().
00555 { 00556 int which , status ; 00557 double p,q,x,df,bound ; 00558 00559 if( qq <= 0.0 ) return 999.9 ; 00560 if( qq >= 0.999999 ) return 0.0 ; 00561 00562 which = 2 ; 00563 p = 1.0 - qq ; 00564 q = qq ; 00565 x = 0.0 ; 00566 df = dof ; 00567 00568 cdfchi( &which , &p , &q , &x , &df , &status , &bound ) ; 00569 return x ; 00570 } |
|
Definition at line 534 of file mri_stats.c. References cdfchi(), p, and q. Referenced by BFIT_compute(), chisq_t2z(), and THD_stat_to_pval().
|
|
Definition at line 572 of file mri_stats.c. References chisq_t2p(), and qginv(). Referenced by THD_stat_to_zscore().
|
|
Definition at line 71 of file mri_stats.c. References incbeta_inverse(), and lnbeta(). Referenced by THD_pval_to_stat().
00072 { 00073 double bb , binv , rho ; 00074 00075 if( pp <= 0.0 ) return 0.999 ; 00076 if( pp >= 0.999999 ) return 0.0 ; 00077 00078 if( nsam <= nfit+nort || nfit < 1.0 || nort < 1.0 ) return 0.0 ; 00079 00080 bb = lnbeta( 0.5*nfit , 0.5*(nsam-nfit-nort) ) ; 00081 binv = incbeta_inverse( pp, 0.5*(nsam-nfit-nort) , 0.5*nfit , bb ) ; 00082 rho = sqrt(1.0-binv) ; 00083 return rho ; 00084 } |
|
Definition at line 86 of file mri_stats.c. References incbeta(), and lnbeta(). Referenced by CORREL_main(), correl_t2z(), and THD_stat_to_pval().
00087 { 00088 double bb , xx , pp ; 00089 00090 if( rho <= 0.0 || 00091 nsam <= nfit+nort || nfit < 1.0 || nort < 1.0 ) return 1.0 ; 00092 00093 if( rho >= 0.9999999 ) return 0.0 ; 00094 00095 bb = lnbeta( 0.5*nfit , 0.5*(nsam-nfit-nort) ) ; 00096 xx = 1.0 - rho*rho ; 00097 pp = incbeta( xx , 0.5*(nsam-nfit-nort) , 0.5*nfit , bb ) ; 00098 return pp ; 00099 } |
|
Definition at line 104 of file mri_stats.c. References correl_t2p(), and qginv(). Referenced by THD_stat_to_zscore().
00105 { 00106 double pp , xx ; 00107 pp = 0.5 * correl_t2p( fabs(rho) , nsam , nfit , nort ) ; 00108 xx = qginv(pp) ; 00109 return ( (rho > 0) ? xx : -xx ) ; 00110 } |
|
Referenced by absfft_func(), autocorr(), csfft_many(), EDIT_blur_volume_3d(), fft2D_func(), fft_3dec(), fft_5dec(), fft_shift2(), filter(), ft_shift2(), main(), mri_fft2D(), mri_filt_fft(), POWER_main(), and ts_to_ftime(). |
|
Main loop starts here * Definition at line 355 of file csfft.c. References csfft_cox(), csfft_trigconsts(), fft_3dec(), fft_5dec(), complex::i, i1, i2, nold, complex::r, and xc. Referenced by main().
00356 { 00357 register unsigned int m, n, i0, i1, i2, i3, k , iv ; 00358 register complex *r0, *r1, *csp , *xcx; 00359 register float co, si, f0, f1, f2, f3, f4; 00360 00361 if( nvec == 1 ){ csfft_cox( mode , idim , xc ) ; return ; } 00362 00363 if( idim % 3 == 0 ){ /* Aug 1999 */ 00364 for( m=0 ; m < nvec ; m++ ) 00365 fft_3dec( mode , idim , xc + m*idim ) ; 00366 return ; 00367 } else if( idim % 5 == 0 ){ 00368 for( m=0 ; m < nvec ; m++ ) 00369 fft_5dec( mode , idim , xc + m*idim ) ; 00370 return ; 00371 } 00372 00373 /** perhaps initialize **/ 00374 00375 if( nold != idim ) csfft_trigconsts( idim ) ; 00376 00377 n = idim; 00378 i2 = idim >> 1; 00379 i1 = 0; 00380 csp = (mode > 0) ? csplus : csminus ; /* choose const array */ 00381 00382 for (i0=0; i0 < n; i0 ++) { 00383 if ( i1 > i0 ) { 00384 for( iv=0,xcx=xc ; iv < nvec ; iv++,xcx+=n ){ 00385 r0 = xcx + i0; r1 = xcx + i1; 00386 f1 = r0->r; f2 = r0->i; 00387 r0->r = r1->r; r0->i = r1->i; 00388 r1->r = f1; r1->i = f2; 00389 } 00390 } 00391 m = i2; 00392 while ( m && !(i1 < m) ) { i1 -= m; m >>= 1; } 00393 i1 += m; 00394 } 00395 00396 #define I00 00397 #ifdef I00 00398 # define I0BOT 1 00399 #else 00400 # define I0BOT 0 00401 #endif 00402 00403 m = 1; 00404 k = 0; 00405 while (n > m) { 00406 i3 = m << 1; 00407 00408 #ifdef I00 00409 /* handle i0=0 case [co=1,si=0] in special code */ 00410 00411 for (i1=0; i1 < n; i1 += i3) { 00412 for( iv=0,r0=xc+i1 ; iv < nvec ; iv++,r0+=n ){ 00413 r1 = r0 + m; 00414 f1 = r1->r ; f3 = r1->i ; 00415 f2 = r0->r ; f4 = r0->i ; 00416 r1->r = f2 - f1 ; r1->i = f4 - f3 ; 00417 r0->r = f2 + f1 ; r0->i = f4 + f3 ; 00418 } 00419 } 00420 k++; 00421 #endif 00422 00423 for (i0=I0BOT; i0 < m; i0 ++) { 00424 co = (csp + k)->r; si = (csp + k)->i; 00425 for (i1=i0; i1 < n; i1 += i3) { 00426 for( iv=0,r0=xc+i1 ; iv < nvec ; iv++,r0+=n ){ 00427 r1 = r0 + m; 00428 #if 1 00429 f1 = r1->r * co - r1->i * si ; 00430 f3 = r1->r * si + r1->i * co ; 00431 #else 00432 f1 = r1->r * co ; f2 = r1->i * si ; 00433 f3 = r1->r * si ; f4 = r1->i * co ; 00434 f1 -= f2 ; f3 += f4 ; 00435 #endif 00436 f2 = r0->r ; f4 = r0->i ; 00437 r1->r = f2 - f1 ; r1->i = f4 - f3 ; 00438 r0->r = f2 + f1 ; r0->i = f4 + f3 ; 00439 } 00440 } 00441 k++; 00442 } 00443 m = i3; 00444 } 00445 return ; 00446 } |
|
Referenced by absfft_func(), csfft_nextup_even(), csfft_nextup_one35(), and main(). |
|
Definition at line 2247 of file csfft.c. References csfft_nextup(). Referenced by apply_xshear(), apply_yshear(), and apply_zshear().
02248 { 02249 int jj = idim ; 02250 do{ 02251 jj = csfft_nextup(jj) ; 02252 if( jj%2 == 1 ) jj++ ; 02253 else return jj ; 02254 } while(1) ; 02255 return 0 ; /* cannot be reached */ 02256 } |
|
Referenced by apply_xshear(), apply_yshear(), apply_zshear(), autocorr(), EDIT_blur_volume_3d(), fft2D_func(), filter(), main(), mri_fft2D(), POWER_main(), THD_dataset_tshift(), and ts_to_ftime(). |
|
Referenced by autocorr(), and main(). |
|
Definition at line 28 of file csfft.c. References use_fftw. Referenced by main().
00028 { use_fftw = uf; return; } |
|
------------------------------------------------------------------ Given the data from startup_lsqfit, finish the job. ------------------------------------------------------------------* Definition at line 313 of file mri_lsqfit.c. References free, malloc, and ref. Referenced by LSQ_worker(), main(), and mri_delayed_lsqfit().
00315 { 00316 int ii , jj ; 00317 float *alpha = NULL ; 00318 double *rr = NULL ; 00319 register double sum ; 00320 00321 if( nref < 1 || veclen < nref || 00322 data == NULL || ref == NULL || cc == NULL ) return NULL ; 00323 00324 /*** form RHS vector into rr ***/ 00325 00326 rr = DBLEVEC(nref) ; if( rr == NULL ) return NULL ; 00327 00328 for( ii=0 ; ii < nref ; ii++ ){ 00329 sum = 0.0 ; 00330 for( jj=0 ; jj < veclen ; jj++ ) sum += ref[ii][jj] * data[jj] ; 00331 rr[ii] = sum ; 00332 } 00333 00334 /*** forward solve ***/ 00335 00336 for( ii=0 ; ii < nref ; ii++ ){ 00337 sum = rr[ii] ; 00338 for( jj=0 ; jj < ii ; jj++ ) sum -= CC(ii,jj) * rr[jj] ; 00339 rr[ii] = sum / CC(ii,ii) ; 00340 } 00341 00342 /*** backward solve ***/ 00343 00344 for( ii=nref-1 ; ii >= 0 ; ii-- ){ 00345 sum = rr[ii] ; 00346 for( jj=ii+1 ; jj < nref ; jj++ ) sum -= CC(jj,ii) * rr[jj] ; 00347 rr[ii] = sum / CC(ii,ii) ; 00348 } 00349 00350 /*** put result into alpha ***/ 00351 00352 alpha = (float *) malloc( sizeof(float) * nref ) ; if( alpha == NULL ) return NULL ; 00353 for( ii=0 ; ii < nref ; ii++ ) alpha[ii] = rr[ii] ; 00354 00355 /*** cleanup and exit ***/ 00356 00357 free(rr) ; 00358 return alpha ; 00359 } |
|
Definition at line 169 of file mri_stats.c. Referenced by THD_pval_to_stat().
00170 { 00171 int which , status ; 00172 double p , q , f , dfn , dfd , bound ; 00173 00174 if( pp <= 0.0 ) return 999.99 ; 00175 if( pp >= 0.999999 ) return 0.0 ; 00176 00177 which = 2 ; 00178 p = 1.0 - pp ; /* 20 Jan 1999: p and q were switched! */ 00179 q = pp ; 00180 f = 0.0 ; 00181 dfn = dofnum ; 00182 dfd = dofden ; 00183 00184 cdff( &which , &p , &q , &f , &dfn , &dfd , &status , &bound ) ; 00185 00186 if( status == 0 ) return f ; 00187 else return 0.0 ; 00188 } |
|
Definition at line 1285 of file NLfit.c. Referenced by fstat_t2z(), report_results(), and THD_stat_to_pval().
01286 { 01287 int which , status ; 01288 double p , q , f , dfn , dfd , bound ; 01289 01290 which = 1 ; 01291 p = 0.0 ; 01292 q = 0.0 ; 01293 f = ff ; 01294 dfn = dofnum ; 01295 dfd = dofden ; 01296 01297 cdff( &which , &p , &q , &f , &dfn , &dfd , &status , &bound ) ; 01298 01299 if( status == 0 ) return q ; 01300 else return 1.0 ; 01301 } |
|
Definition at line 211 of file mri_stats.c. References fstat_t2p(), and qginv(). Referenced by THD_stat_to_zscore().
|
|
other initialization * Definition at line 298 of file mri_affine.c. References CEXPIT, CMULT, csfft_cox(), free, complex::i, malloc, and complex::r. Referenced by ft_xshear(), and ft_yshear().
00299 { 00300 static int nupold=0 ; 00301 static complex * row=NULL , * cf=NULL , * cg=NULL ; 00302 00303 int ii , nby2=nup/2 , n21=nby2+1 ; 00304 complex fac , gac ; 00305 float sf , sg , dk ; 00306 00307 /* make new memory for row storage? */ 00308 00309 if( nup > nupold ){ 00310 if( row != NULL ){ free(row) ; free(cf) ; free(cg) ; } 00311 row = (complex *) malloc( sizeof(complex) * nup ) ; 00312 cf = (complex *) malloc( sizeof(complex) * n21 ) ; 00313 cg = (complex *) malloc( sizeof(complex) * n21 ) ; 00314 nupold = nup ; 00315 } 00316 00317 /* FFT the pair of rows */ 00318 00319 for( ii=0 ; ii < n ; ii++ ){ row[ii].r = f[ii] ; row[ii].i = g[ii] ; } 00320 for( ; ii < nup ; ii++ ){ row[ii].r = row[ii].i = 0.0 ; } 00321 00322 csfft_cox( -1 , nup , row ) ; 00323 00324 /* untangle FFT coefficients from row into cf,cg */ 00325 00326 cf[0].r = 2.0 * row[0].r ; cf[0].i = 0.0 ; /* twice too big */ 00327 cg[0].r = 2.0 * row[0].i ; cg[0].i = 0.0 ; 00328 for( ii=1 ; ii < nby2 ; ii++ ){ 00329 cf[ii].r = row[ii].r + row[nup-ii].r ; 00330 cf[ii].i = row[ii].i - row[nup-ii].i ; 00331 cg[ii].r = row[ii].i + row[nup-ii].i ; 00332 cg[ii].i = -row[ii].r + row[nup-ii].r ; 00333 } 00334 cf[nby2].r = 2.0 * row[nby2].r ; cf[nby2].i = 0.0 ; 00335 cg[nby2].r = 2.0 * row[nby2].i ; cg[nby2].i = 0.0 ; 00336 00337 /* phase shift both rows (cf,cg) */ 00338 00339 dk = (2.0*PI) / nup ; 00340 sf = -af * dk ; sg = -ag * dk ; 00341 for( ii=1 ; ii <= nby2 ; ii++ ){ 00342 fac = CEXPIT(ii*sf) ; cf[ii] = CMULT( fac , cf[ii] ) ; 00343 gac = CEXPIT(ii*sg) ; cg[ii] = CMULT( gac , cg[ii] ) ; 00344 } 00345 cf[nby2].i = 0.0 ; cg[nby2].i = 0.0 ; 00346 00347 /* retangle the coefficients from 2 rows */ 00348 00349 row[0].r = cf[0].r ; row[0].i = cg[0].r ; 00350 for( ii=1 ; ii < nby2 ; ii++ ){ 00351 row[ii].r = cf[ii].r - cg[ii].i ; 00352 row[ii].i = cf[ii].i + cg[ii].r ; 00353 row[nup-ii].r = cf[ii].r + cg[ii].i ; 00354 row[nup-ii].i = -cf[ii].i + cg[ii].r ; 00355 } 00356 row[nby2].r = cf[nby2].r ; 00357 row[nby2].i = cg[nby2].r ; 00358 00359 /* inverse FFT and store back in output arrays */ 00360 00361 csfft_cox( 1 , nup , row ) ; 00362 00363 sf = 0.5 / nup ; /* 0.5 to allow for twice too big above */ 00364 for( ii=0 ; ii < n ; ii++ ){ 00365 f[ii] = sf * row[ii].r ; g[ii] = sf * row[ii].i ; 00366 } 00367 00368 return ; 00369 } |
|
Definition at line 722 of file mri_stats.c. References cdfgam(), p, q, scale, and shape. Referenced by THD_pval_to_stat().
00723 { 00724 int which , status ; 00725 double p,q, x,shape,scale,bound ; 00726 00727 if( qq <= 0.0 ) return 999.9 ; 00728 if( qq >= 0.999999 ) return 0.0 ; 00729 00730 which = 2 ; 00731 p = 1.0 - qq ; 00732 q = qq ; 00733 x = 0.0 ; 00734 shape = sh ; 00735 scale = sc ; 00736 00737 cdfgam( &which , &p , &q , &x , &shape , &scale , &status , &bound ) ; 00738 00739 return x ; 00740 } |
|
Definition at line 694 of file mri_stats.c. References cdfgam(), p, q, scale, and shape. Referenced by gamma_t2z(), and THD_stat_to_pval().
00695 { 00696 int which , status ; 00697 double p,q, x,shape,scale,bound ; 00698 00699 which = 1 ; 00700 p = 0.0 ; 00701 q = 0.0 ; 00702 x = xx ; 00703 shape = sh ; 00704 scale = sc ; 00705 00706 cdfgam( &which , &p , &q , &x , &shape , &scale , &status , &bound ) ; 00707 00708 if( status == 0 ) return q ; 00709 else return 1.0 ; 00710 } |
|
Definition at line 715 of file mri_stats.c. References gamma_t2p(), and qginv(). Referenced by THD_stat_to_zscore().
|
|
Check if a filesize fits an MCW_IMSIZE setup.
Definition at line 1597 of file mri_read.c. References EXIT, MCW_imsize::head, init_MCW_sizes(), malloc, MAX_MCW_IMSIZE, MCW_imsize_good, mri_filesize(), my_strdup(), and MCW_imsize::size. Referenced by mri_imcount(), mri_read_file(), mri_read_file_delay(), and mri_read_just_one().
01598 { 01599 int num , lll ; 01600 long len ; 01601 char * new_name ; 01602 01603 init_MCW_sizes() ; 01604 if( MCW_imsize_good == 0 ){ 01605 new_name = my_strdup(fname) ; /* nothing to fit */ 01606 return new_name ; /* --> return copy of old name */ 01607 } 01608 01609 len = mri_filesize( fname ) ; 01610 if( len <= 0 ){ 01611 new_name = my_strdup(fname) ; /* not an existing filename */ 01612 return new_name ; /* --> return copy of old name */ 01613 } 01614 01615 for( num=0 ; num < MAX_MCW_IMSIZE ; num++ ){ /* check each possibility */ 01616 01617 if( imsize[num].size <= 0 ) continue ; /* skip to next one */ 01618 01619 if( imsize[num].head < 0 && len == imsize[num].size ){ /* fixed size fit */ 01620 01621 lll = strlen(fname) + strlen(imsize[num].prefix) + 4 ; 01622 new_name = (char *) malloc( sizeof(char) * lll ) ; 01623 if( new_name == NULL ){ 01624 fprintf(stderr,"\n*** Can't malloc in imsized_fname! ***\a\n"); 01625 EXIT(1) ; 01626 } 01627 sprintf( new_name , "%s%s" , imsize[num].prefix , fname ) ; 01628 return new_name ; 01629 01630 } else if( (len-imsize[num].head) % imsize[num].size == 0 ){ 01631 int count = (len-imsize[num].head) / imsize[num].size ; 01632 01633 if( count < 1 ) continue ; /* skip to next one */ 01634 01635 lll = strlen(fname) + strlen(imsize[num].prefix) + 32 ; 01636 new_name = (char *) malloc( sizeof(char) * lll ) ; 01637 if( new_name == NULL ){ 01638 fprintf(stderr,"\n*** Can't malloc in imsized_fname! ***\a\n"); 01639 EXIT(1) ; 01640 } 01641 sprintf( new_name , "%s%d:%s" , imsize[num].prefix , count , fname ) ; 01642 return new_name ; 01643 } 01644 01645 } 01646 01647 new_name = my_strdup(fname) ; /* no fit --> return copy of old name */ 01648 return new_name ; 01649 } |
|
Definition at line 237 of file p2t.c.
00238 { 00239 double betain , psq , cx , xx,pp,qq , term,ai , temp , rx ; 00240 int indx , ns ; 00241 00242 if( p <= ZERO || q <= ZERO || x < ZERO || x > ONE ) return -1.0 ; 00243 00244 if( x == ZERO ) return ZERO ; 00245 if( x == ONE ) return ONE ; 00246 00247 /** change tail if necessary and determine s **/ 00248 00249 psq = p+q ; 00250 cx = ONE-x ; 00251 if( p < psq*x ){ 00252 xx = cx ; 00253 cx = x ; 00254 pp = q ; 00255 qq = p ; 00256 indx = 1 ; 00257 } else { 00258 xx = x ; 00259 pp = p ; 00260 qq = q ; 00261 indx = 0 ; 00262 } 00263 00264 term = ONE ; 00265 ai = ONE ; 00266 betain = ONE ; 00267 ns = qq + cx*psq ; 00268 00269 /** use soper's reduction formulae **/ 00270 00271 rx = xx/cx ; 00272 00273 lab3: 00274 temp = qq-ai ; 00275 if(ns == 0) rx = xx ; 00276 00277 lab4: 00278 term = term*temp*rx/(pp+ai) ; 00279 betain = betain+term ; 00280 temp = fabs(term) ; 00281 if(temp <= ACU && temp <= ACU*betain) goto lab5 ; 00282 00283 ai = ai+ONE ; 00284 ns = ns-1 ; 00285 if(ns >= 0) goto lab3 ; 00286 temp = psq ; 00287 psq = psq+ONE ; 00288 goto lab4 ; 00289 00290 lab5: 00291 betain = betain*exp(pp*log(xx)+(qq-ONE)*log(cx)-beta)/pp ; 00292 if(indx) betain=ONE-betain ; 00293 00294 return betain ; 00295 } |
|
Definition at line 325 of file p2t.c.
00326 { 00327 int indx , iex ; 00328 double fpu , xinbta , a,pp,qq, r,y,t,s,h,w , acu , 00329 yprev,prev,sq , g,adj,tx,xin ; 00330 00331 fpu = pow(10.0,SAE) ; 00332 00333 if( p <= ZERO || q <= ZERO || alpha < ZERO || alpha > ONE ) return -1.0 ; 00334 00335 if( alpha == ZERO ) return ZERO ; 00336 if( alpha == ONE ) return ONE ; 00337 00338 /** change tail if necessary **/ 00339 00340 if( alpha > 0.5 ){ 00341 a = ONE-alpha ; 00342 pp = q ; 00343 qq = p ; 00344 indx = 1 ; 00345 } else { 00346 a = alpha ; 00347 pp = p ; 00348 qq = q ; 00349 indx = 0 ; 00350 } 00351 00352 /** calculate the initial approximation **/ 00353 00354 lab2: 00355 r = sqrt(-log(a*a)) ; 00356 y = r - (2.30753 + 0.27061*r) / (ONE+(0.99229+0.04481*r)*r) ; 00357 if(pp > ONE && qq > ONE) goto lab5 ; 00358 00359 r = qq+qq ; 00360 t = ONE/(9.0*qq) ; 00361 t = r * pow( (ONE-t+y*sqrt(t)) , 3.0 ) ; 00362 if( t <= ZERO ) goto lab3 ; 00363 00364 t = (FOUR*pp+r-TWO)/t ; 00365 if( t <= ONE ) goto lab4 ; 00366 00367 xinbta = ONE-TWO/(t+ONE) ; goto lab6 ; 00368 00369 lab3: 00370 xinbta = ONE-exp((log((ONE-a)*qq)+beta)/qq) ; goto lab6 ; 00371 00372 lab4: 00373 xinbta = exp((log(a*pp)+beta)/pp) ; goto lab6 ; 00374 00375 lab5: 00376 r = (y*y-THREE)/SIX ; 00377 s = ONE/(pp+pp-ONE) ; 00378 t = ONE/(qq+qq-ONE) ; 00379 h = TWO/(s+t) ; 00380 w = y*sqrt(h+r)/h-(t-s)*(r+FIVE/SIX-TWO/(THREE*h)) ; 00381 xinbta = pp/(pp+qq*exp(w+w)) ; 00382 00383 /** solve for x by a modified newton-raphson method **/ 00384 00385 lab6: 00386 r = ONE-pp ; 00387 t = ONE-qq ; 00388 yprev = ZERO ; 00389 sq = ONE ; 00390 prev = ONE ; 00391 if(xinbta < 0.0001) xinbta = 0.0001 ; 00392 if(xinbta > 0.9999) xinbta = 0.9999 ; 00393 00394 #if 0 00395 iex = -5.0 / (pp*pp) - 1.0/(a*a) - 13.0 ; if( iex < SAE ) iex = SAE ; 00396 acu = pow(10.0,iex) ; 00397 #else 00398 acu = fpu ; 00399 #endif 00400 00401 lab7: 00402 y = incbeta( xinbta , pp,qq,beta ) ; 00403 if( y < ZERO ) return -1.0 ; 00404 xin = xinbta ; 00405 y = (y-a)*exp(beta+r*log(xin)+t*log(ONE-xin)) ; 00406 if(y*yprev <= ZERO) prev = MAX(sq, fpu) ; 00407 g = ONE ; 00408 00409 lab9: 00410 adj = g*y ; 00411 sq = adj*adj ; 00412 if(sq >= prev) goto lab10 ; 00413 tx = xinbta-adj ; 00414 if(tx >= ZERO && tx <= ONE) goto lab11 ; 00415 00416 lab10: 00417 g = g/THREE ; goto lab9 ; 00418 00419 lab11: 00420 if(tx == ZERO || tx == ONE ) goto lab10 ; 00421 if(prev <= acu || y*y <= acu || fabs(xinbta-tx) < fpu) goto lab12 ; 00422 xinbta = tx ; 00423 yprev = y ; 00424 goto lab7 ; 00425 00426 lab12: 00427 xinbta = tx ; 00428 if (indx) xinbta = ONE-xinbta ; 00429 #if 0 00430 printf("alpha = %g incbeta = %g\n",alpha, incbeta(xinbta,p,q,beta) ); 00431 #endif 00432 return xinbta ; 00433 } |
|
Set up MCW_SIZE_# database for input. This implements the facility for the user to define MCW_IMSIZE_1 (or AFNI_IMSIZE_1) et cetera, for pre-defining a relationship between a file size in bytes and a 3D: prefix. This function is only called once to setup the table.
Definition at line 1514 of file mri_read.c. References EXIT, free, MCW_imsize::head, malloc, MAX_MCW_IMSIZE, MCW_imsize_good, my_getenv(), MCW_imsize::prefix, and MCW_imsize::size. Referenced by imsized_fname().
01515 { 01516 int num , count ; 01517 char ename[32] ; 01518 char * str ; 01519 01520 if( MCW_imsize_good >= 0 ) return ; 01521 01522 MCW_imsize_good = 0 ; 01523 01524 for( num=0 ; num < MAX_MCW_IMSIZE ; num++ ){ /* look for environment string */ 01525 01526 imsize[num].size = -1 ; 01527 01528 /* try to find environment variable with the num-th name */ 01529 01530 sprintf( ename , "AFNI_IMSIZE_%d" , num+1 ) ; 01531 str = my_getenv( ename ) ; 01532 01533 if( str == NULL ){ 01534 sprintf( ename , "MCW_IMSIZE_%d" , num+1 ) ; 01535 str = my_getenv( ename ) ; 01536 if( str == NULL ) continue ; 01537 } 01538 01539 imsize[num].prefix = (char *) malloc( sizeof(char) * strlen(str) ) ; 01540 if( imsize[num].prefix == NULL ){ 01541 fprintf(stderr,"\n*** Can't malloc in init_MCW_sizes! ***\a\n"); 01542 EXIT(1) ; 01543 } 01544 01545 if( str[0] != '%' ){ /* e.g., 16096=3D:-1:0:64:64:1: */ 01546 01547 imsize[num].head = -1 ; 01548 count = sscanf( str , "%d=%s" , &(imsize[num].size) , imsize[num].prefix ) ; 01549 if( count != 2 || imsize[num].size < 2 || strlen(imsize[num].prefix) < 2 ){ 01550 free( imsize[num].prefix ) ; 01551 fprintf(stderr,"bad environment %s = %s\n" , 01552 ename , str ) ; 01553 } 01554 01555 } else { /* e.g., %16096+0=3D:0:7904:64:64: */ 01556 01557 count = sscanf( str+1 , "%d+%d=%s" , 01558 &(imsize[num].size) , &(imsize[num].head) , imsize[num].prefix ) ; 01559 01560 if( count != 3 || imsize[num].size < 2 || 01561 imsize[num].head < 0 || strlen(imsize[num].prefix) < 2 ){ 01562 01563 free( imsize[num].prefix ) ; 01564 fprintf(stderr,"bad environment %s = %s\n" , 01565 ename , str ) ; 01566 } 01567 } 01568 01569 MCW_imsize_good ++ ; 01570 } 01571 01572 return ; 01573 } |
|
Definition at line 250 of file mri_percents.c. Referenced by median21_box_func(), median9_box_func(), osfilt9_box_func(), qsort_float(), winsor21_box_func(), and winsor9_box_func().
00251 { 00252 register int j , p ; /* array indices */ 00253 register float temp ; /* a[j] holding place */ 00254 register float * a = ar ; 00255 00256 if( n < 2 || ar == NULL ) return ; 00257 00258 for( j=1 ; j < n ; j++ ){ 00259 00260 if( a[j] < a[j-1] ){ /* out of order */ 00261 p = j ; 00262 temp = a[j] ; 00263 do{ 00264 a[p] = a[p-1] ; /* at this point, a[p-1] > temp, so move it up */ 00265 p-- ; 00266 } while( p > 0 && temp < a[p-1] ) ; 00267 a[p] = temp ; /* finally, put temp in its place */ 00268 } 00269 } 00270 return ; 00271 } |
|
Definition at line 350 of file mri_percents.c. Referenced by qsort_pair().
00351 { 00352 register int j , p ; /* array indices */ 00353 register float temp ; /* a[j] holding place */ 00354 register int itemp ; 00355 register float * a = ar ; 00356 register int *ia = iar ; 00357 00358 if( n < 2 || ar == NULL || iar == NULL ) return ; 00359 00360 for( j=1 ; j < n ; j++ ){ 00361 00362 if( a[j] < a[j-1] ){ /* out of order */ 00363 p = j ; 00364 temp = a[j] ; itemp = ia[j] ; 00365 do{ 00366 a[p] = a[p-1] ; ia[p] = ia[p-1] ; 00367 p-- ; 00368 } while( p > 0 && temp < a[p-1] ) ; 00369 a[p] = temp ; ia[p] = itemp ; 00370 } 00371 } 00372 return ; 00373 } |
|
Definition at line 50 of file mri_percents.c. Referenced by qsort_short().
00051 { 00052 register int j , p ; /* array indices */ 00053 register short temp ; /* a[j] holding place */ 00054 register short * a = ar ; 00055 00056 if( n < 2 || ar == NULL ) return ; 00057 00058 for( j=1 ; j < n ; j++ ){ 00059 00060 if( a[j] < a[j-1] ){ /* out of order */ 00061 p = j ; 00062 temp = a[j] ; 00063 do{ 00064 a[p] = a[p-1] ; /* at this point, a[p-1] > temp, so move it up */ 00065 p-- ; 00066 } while( p > 0 && temp < a[p-1] ) ; 00067 a[p] = temp ; /* finally, put temp in its place */ 00068 } 00069 } 00070 return ; 00071 } |
|
if the math library doesn't have the log(gamma(x)) function (as on Linux, for example) Definition at line 219 of file p2t.c.
|
|
Definition at line 445 of file mri_stats.c. Referenced by main().
|
|
Definition at line 122 of file mri_lsqfit.c. Referenced by huber_func(), mri_lsqfit(), and THD_generic_detrend().
00124 { 00125 int ii , jj , kk ; 00126 float *alpha = NULL ; 00127 double *cc = NULL , *rr = NULL ; 00128 double sum ; 00129 00130 /** macros will be used in routines below, as well! **/ 00131 00132 #define DBLEVEC(ll) (double *) malloc( sizeof(double) * (ll) ) 00133 #define DISCARD(xx) if( xx != NULL ){free(xx); xx = NULL;} 00134 #define CLEANUP {DISCARD(cc); DISCARD(rr);} 00135 00136 if( nref < 1 || veclen < nref || data == NULL || ref == NULL ) return NULL ; 00137 00138 /*** form RHS vector into rr ***/ 00139 00140 rr = DBLEVEC(nref) ; 00141 cc = DBLEVEC(nref*nref) ; 00142 if( rr == NULL || cc == NULL ){ CLEANUP ; return NULL ; } 00143 00144 if( wt != NULL ){ 00145 for( ii=0 ; ii < nref ; ii++ ){ 00146 sum = 0.0 ; 00147 for( jj=0 ; jj < veclen ; jj++ ) sum += ref[ii][jj] * wt[jj] * data[jj] ; 00148 rr[ii] = sum ; 00149 } 00150 } else { 00151 for( ii=0 ; ii < nref ; ii++ ){ 00152 sum = 0.0 ; 00153 for( jj=0 ; jj < veclen ; jj++ ) sum += ref[ii][jj] * data[jj] ; 00154 rr[ii] = sum ; 00155 } 00156 } 00157 00158 /*** form coefficient matrix into cc */ 00159 00160 #define CC(i,j) cc[(i)+(j)*nref] 00161 00162 if( wt != NULL ){ 00163 for( jj=0 ; jj < nref ; jj++ ){ 00164 for( ii=0 ; ii <= jj ; ii++ ){ 00165 sum = 0.0 ; 00166 for( kk=0 ; kk < veclen ; kk++ ) sum += ref[ii][kk] * ref[jj][kk] * wt[kk] ; 00167 CC(ii,jj) = CC(jj,ii) = sum ; 00168 } 00169 } 00170 } else { 00171 for( jj=0 ; jj < nref ; jj++ ){ 00172 for( ii=0 ; ii <= jj ; ii++ ){ 00173 sum = 0.0 ; 00174 for( kk=0 ; kk < veclen ; kk++ ) sum += ref[ii][kk] * ref[jj][kk] ; 00175 CC(ii,jj) = CC(jj,ii) = sum ; 00176 } 00177 } 00178 } 00179 00180 /*** Choleski decompose cc ***/ 00181 00182 for( ii=0 ; ii < nref ; ii++ ){ 00183 for( jj=0 ; jj < ii ; jj++ ){ 00184 sum = CC(ii,jj) ; 00185 for( kk=0 ; kk < jj ; kk++ ) sum -= CC(ii,kk) * CC(jj,kk) ; 00186 CC(ii,jj) = sum / CC(jj,jj) ; 00187 } 00188 sum = CC(ii,ii) ; 00189 for( kk=0 ; kk < ii ; kk++ ) sum -= CC(ii,kk) * CC(ii,kk) ; 00190 if( sum <= 0.0 ){ CLEANUP ; return NULL ; } 00191 CC(ii,ii) = sqrt(sum) ; 00192 } 00193 00194 /*** forward solve ***/ 00195 00196 for( ii=0 ; ii < nref ; ii++ ){ 00197 sum = rr[ii] ; 00198 for( jj=0 ; jj < ii ; jj++ ) sum -= CC(ii,jj) * rr[jj] ; 00199 rr[ii] = sum / CC(ii,ii) ; 00200 } 00201 00202 /*** backward solve ***/ 00203 00204 for( ii=nref-1 ; ii >= 0 ; ii-- ){ 00205 sum = rr[ii] ; 00206 for( jj=ii+1 ; jj < nref ; jj++ ) sum -= CC(jj,ii) * rr[jj] ; 00207 rr[ii] = sum / CC(ii,ii) ; 00208 } 00209 00210 /*** put result into alpha ***/ 00211 00212 alpha = (float *) malloc( sizeof(float) * nref ) ; 00213 for( ii=0 ; ii < nref ; ii++ ) alpha[ii] = rr[ii] ; 00214 00215 /*** cleanup and exit ***/ 00216 00217 CLEANUP ; return alpha ; 00218 } |
|
Actually do the rendering of a memplot into an RGB image.
Definition at line 41 of file mri_coxplot.c. References MEM_plotdata::aspect, box_xbot, box_xtop, box_ybot, box_ytop, COL_TO_BBB, COL_TO_GGG, COL_TO_RRR, ENTRY, MRI_IMAGE::kind, MEMPLOT_COL, MEMPLOT_NLINE, MEMPLOT_TH, MEMPLOT_X1, MEMPLOT_X2, MEMPLOT_Y1, MEMPLOT_Y2, mp, mri_draw_opacity(), mri_drawfilledrectangle(), mri_drawline(), MRI_IMAGE::nx, MRI_IMAGE::ny, set_memplot_RGB_box(), skip, x2, y1, and ZO_TO_TFS. Referenced by ISQ_save_jpeg(), ISQ_saver_CB(), and PLOT_matrix_gray().
00043 { 00044 byte rrr=0,ggg=0,bbb=0 ; 00045 int ii , nline , same ; 00046 float old_thick , old_color , new_color , new_thick ; 00047 float scal,xscal,yscal , xoff,yoff ; 00048 int x1,y1 , x2,y2 ; 00049 int skip ; 00050 00051 ENTRY("memplot_to_RGB_sef") ; 00052 00053 /*--- check for madness ---*/ 00054 00055 if( im == NULL || im->kind != MRI_rgb || mp == NULL ) EXRETURN ; 00056 00057 if( start < 0 ) start = 0 ; 00058 00059 nline = MEMPLOT_NLINE(mp) ; 00060 if( nline < 1 || start >= nline ) EXRETURN ; 00061 00062 if( end <= start || end > nline ) end = nline ; 00063 00064 /*--- compute scaling from memplot objective 00065 coordinates to RGB window coordinates ---*/ 00066 00067 if( box_xbot >= box_xtop || box_ybot >= box_ytop ){ 00068 00069 xscal = im->nx / mp->aspect ; /* aspect = x-axis objective size */ 00070 yscal = im->ny / 1.0 ; /* 1.0 = y-axis objective size */ 00071 xoff = yoff = 0.499 ; 00072 00073 } else { /* scale to a given sub-box in the window */ 00074 00075 xscal = box_xtop - box_xbot ; 00076 yscal = box_ytop - box_ybot ; 00077 xoff = box_xbot + 0.499 ; 00078 yoff = box_ybot + 0.499 ; 00079 } 00080 00081 if( !freee ){ /* no aspect freedom ==> */ 00082 if( yscal < xscal ) xscal = yscal ; /* use smaller scaling */ 00083 else yscal = xscal ; 00084 } 00085 scal = sqrt(fabs(xscal*yscal)) ; 00086 00087 old_color = -1.0 ; /* these don't occur naturally */ 00088 old_thick = -THCODE_INVALID ; 00089 00090 /*--- loop over lines, scale and plot ---*/ 00091 00092 mri_draw_opacity( 1.0 ) ; 00093 00094 for( ii=start ; ii < end ; ii++ ){ 00095 00096 skip = 0 ; 00097 00098 /* check if need to change color or thickness of line */ 00099 00100 new_color = MEMPLOT_COL(mp,ii) ; 00101 if( new_color != old_color ){ 00102 float rr=COL_TO_RRR(new_color) , 00103 gg=COL_TO_GGG(new_color) , bb=COL_TO_BBB(new_color) ; 00104 00105 #if 0 00106 fprintf(stderr,"Changing color to %f %f %f\n",rr,gg,bb) ; 00107 #endif 00108 00109 rrr = ZO_TO_TFS(rr) ; ggg = ZO_TO_TFS(gg) ; bbb = ZO_TO_TFS(bb) ; 00110 old_color = new_color ; 00111 } 00112 00113 new_thick = MEMPLOT_TH(mp,ii) ; 00114 if( new_thick < 0.0 ){ /* special negative thickness codes */ 00115 int thc = (int)(-new_thick) ; 00116 switch( thc ){ 00117 case THCODE_RECT:{ /* rectangle */ 00118 int xb,yb , xt,yt ; 00119 int w,h ; 00120 x1 = rint( xoff + xscal * MEMPLOT_X1(mp,ii) ) ; 00121 x2 = rint( xoff + xscal * MEMPLOT_X2(mp,ii) ) ; 00122 y1 = rint( yoff + yscal * (1.0 - MEMPLOT_Y1(mp,ii)) ) ; 00123 y2 = rint( yoff + yscal * (1.0 - MEMPLOT_Y2(mp,ii)) ) ; 00124 if( x1 < x2 ){ xb=x1; xt=x2; } else { xb=x2; xt=x1; } 00125 if( y1 < y2 ){ yb=y1; yt=y2; } else { yb=y2; yt=y1; } 00126 w = xt-xb+1 ; h = yt-yb+1 ; 00127 mri_drawfilledrectangle( im , xb,yb , w,h , rrr,ggg,bbb ) ; 00128 skip = 1 ; 00129 } 00130 break ; 00131 00132 case THCODE_OPAC:{ /* opacity [22 Jul 2004] */ 00133 mri_draw_opacity( MEMPLOT_X1(mp,ii) ) ; 00134 skip = 1 ; 00135 } 00136 break ; 00137 } 00138 00139 } else if( new_thick != old_thick ){ /* normal case: change line thickness */ 00140 00141 old_thick = new_thick ; /* thickness not used at this time */ 00142 00143 } 00144 00145 /* scale coords to ints (also see zzphph.f) */ 00146 00147 if( !skip ){ 00148 x1 = (int)( xoff + xscal * MEMPLOT_X1(mp,ii) ) ; 00149 x2 = (int)( xoff + xscal * MEMPLOT_X2(mp,ii) ) ; 00150 y1 = (int)( yoff + yscal * (1.0 - MEMPLOT_Y1(mp,ii)) ) ; 00151 y2 = (int)( yoff + yscal * (1.0 - MEMPLOT_Y2(mp,ii)) ) ; 00152 00153 /* draw it */ 00154 00155 mri_drawline( im , x1,y1 , x2,y2 , rrr,ggg,bbb ) ; 00156 } 00157 } 00158 00159 set_memplot_RGB_box(0,0,0,0) ; /* clear box */ 00160 EXRETURN ; 00161 } |
|
Produce a 1D (float) image from a string of the form "20@1,10@0,5@1". ------------------------------------------------------------------------------- Definition at line 7 of file mri_fromstring.c. References ENTRY, far, free, malloc, mri_fix_data_pointer(), mri_new_vol_empty(), NI_decode_string_list(), NI_delete_str_array, NI_str_array::num, realloc, RETURN, and NI_str_array::str. Referenced by mri_read_1D(), and mri_read_ascii().
00008 { 00009 int ii,nnn,count , ntot=0 ; 00010 float *far , value ; 00011 NI_str_array *sar ; 00012 char sep ; 00013 MRI_IMAGE *flim ; 00014 00015 ENTRY("mri_1D_fromstring") ; 00016 00017 sar = NI_decode_string_list( str , ",;" ) ; 00018 if( sar == NULL ) RETURN(NULL) ; 00019 if( sar->num == 0 ){ NI_delete_str_array(sar); RETURN(NULL); } 00020 00021 far = (float *) malloc(sizeof(float)) ; 00022 for( ii=0 ; ii < sar->num ; ii++ ){ 00023 00024 if( strstr(sar->str[ii],"@") != NULL || /* if has one of the */ 00025 strstr(sar->str[ii],"x") != NULL || /* allowed separator */ 00026 strstr(sar->str[ii],"X") != NULL || /* characters, then */ 00027 strstr(sar->str[ii],"*") != NULL ){ /* scan for count@value */ 00028 00029 nnn = sscanf( sar->str[ii] , "%d%c%f" , &count , &sep , &value ) ; 00030 if( nnn != 3 || count < 1 ){ free(far); RETURN(NULL); } 00031 00032 } else { /* just scan for value */ 00033 count = 1 ; 00034 nnn = sscanf( sar->str[ii] , "%f" , &value ) ; 00035 if( nnn != 1 ){ free(far); RETURN(NULL); } 00036 } 00037 00038 far = (float *) realloc( far , sizeof(float)*(ntot+count) ) ; 00039 for( nnn=0 ; nnn < count ; nnn++ ) far[nnn+ntot] = value ; 00040 ntot += count ; 00041 00042 } 00043 00044 NI_delete_str_array(sar) ; 00045 flim = mri_new_vol_empty( ntot,1,1 , MRI_float ) ; 00046 mri_fix_data_pointer( far , flim ) ; 00047 RETURN(flim) ; 00048 } |
|
Definition at line 296 of file mri_2dalign.c. References MRI_2dalign_basis::chol_fine_fitim, MRI_2dalign_basis::chol_fitim, DESTROY_IMARR, MRI_2dalign_basis::fine_fitim, MRI_2dalign_basis::fitim, and free. Referenced by cleanup_rtinp(), mri_2dalign_many(), and RT_registration_2D_close().
00297 { 00298 if( basis == NULL ) return ; 00299 00300 if( basis->fitim != NULL ){ DESTROY_IMARR( basis->fitim ) ; } 00301 if( basis->chol_fitim != NULL ){ free(basis->chol_fitim) ; } 00302 00303 if( basis->fine_fitim != NULL ){ DESTROY_IMARR( basis->fine_fitim ) ; } 00304 if( basis->chol_fine_fitim != NULL ){ free(basis->chol_fine_fitim) ; } 00305 00306 free(basis) ; return ; 00307 } |
|
Definition at line 274 of file mri_2dalign.c. References ADDTO_IMARR, MRI_IMARR::imarr, INIT_IMARR, mri_2dalign_cleanup(), mri_2dalign_one(), mri_2dalign_setup(), and MRI_IMARR::num. Referenced by main().
00276 { 00277 int kim ; 00278 MRI_IMAGE * tim ; 00279 MRI_IMARR * alim ; 00280 MRI_2dalign_basis * basis ; 00281 00282 basis = mri_2dalign_setup( im , imwt ) ; 00283 if( basis == NULL ) return NULL ; 00284 00285 INIT_IMARR( alim ) ; 00286 00287 for( kim=0 ; kim < ims->num ; kim++ ){ 00288 tim = mri_2dalign_one( basis , ims->imarr[kim] , dx+kim , dy+kim , phi+kim ) ; 00289 ADDTO_IMARR(alim,tim) ; 00290 } 00291 00292 mri_2dalign_cleanup( basis ) ; 00293 return alim ; 00294 } |
|
Definition at line 66 of file mri_2dalign.c. References almode_coarse, almode_fine, and almode_reg. Referenced by RT_registration_2D_setup().
00067 { 00068 if( coarse > 0 ) almode_coarse = coarse ; 00069 if( fine > 0 ) almode_fine = fine ; 00070 if( reg > 0 ) almode_reg = reg ; 00071 return ; 00072 } |
|
Definition at line 189 of file mri_2dalign.c. References MRI_2dalign_basis::chol_fine_fitim, MRI_2dalign_basis::chol_fitim, DFAC, dfilt_sigma, dxy_thresh, FILT_FFT_WRAPAROUND, fine_dxy_thresh, MRI_2dalign_basis::fine_fitim, fine_phi_thresh, fine_sigma, fit, MRI_2dalign_basis::fitim, free, max_iter, mri_delayed_lsqfit(), mri_filt_fft(), mri_free(), MRI_ROTA_COARSE, MRI_ROTA_FINE, MRI_ROTA_REG, mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, and phi_thresh. Referenced by mri_2dalign_many(), and RT_registration_2D_onevol().
00191 { 00192 MRI_IMARR * fitim ; 00193 double * chol_fitim=NULL ; 00194 MRI_IMARR * fine_fitim =NULL ; 00195 double * chol_fine_fitim=NULL ; 00196 00197 float * fit , *dfit ; 00198 int nx,ny , ii,jj , joff , iter , good ; 00199 int use_fine_fit = (fine_sigma > 0.0) ; 00200 MRI_IMAGE * im2 , * bim2 , * tim ; 00201 00202 nx = im->nx ; ny = im->ny ; 00203 00204 fitim = basis->fitim ; 00205 chol_fitim = basis->chol_fitim ; 00206 fine_fitim = basis->fine_fitim ; 00207 chol_fine_fitim = basis->chol_fine_fitim ; 00208 00209 /*-- register the image: coarsely --*/ 00210 00211 im2 = mri_to_float( im ) ; 00212 bim2 = mri_filt_fft( im2, dfilt_sigma, 0,0, FILT_FFT_WRAPAROUND ) ; 00213 fit = mri_delayed_lsqfit( bim2 , fitim , chol_fitim ) ; 00214 mri_free( bim2 ) ; 00215 00216 iter = 0 ; 00217 good = ( fabs(fit[1]) > dxy_thresh || 00218 fabs(fit[2]) > dxy_thresh || fabs(fit[3]) > phi_thresh ) ; 00219 00220 /*-- iterate coarse fit --*/ 00221 00222 while( good ){ 00223 tim = MRI_ROTA_COARSE( im2 , fit[1] , fit[2] , fit[3]*DFAC ) ; 00224 bim2 = mri_filt_fft( tim, dfilt_sigma, 0,0, FILT_FFT_WRAPAROUND ) ; 00225 dfit = mri_delayed_lsqfit( bim2 , fitim , chol_fitim ) ; 00226 mri_free( bim2 ) ; mri_free( tim ) ; 00227 00228 fit[1] += dfit[1] ; 00229 fit[2] += dfit[2] ; 00230 fit[3] += dfit[3] ; 00231 00232 good = (++iter < max_iter) && 00233 ( fabs(dfit[1]) > dxy_thresh || 00234 fabs(dfit[2]) > dxy_thresh || fabs(dfit[3]) > phi_thresh ) ; 00235 00236 free(dfit) ; dfit = NULL ; 00237 } /* end while */ 00238 00239 /*-- perform fine adjustments --*/ 00240 00241 if( use_fine_fit ){ 00242 good = 1 ; 00243 while( good ){ 00244 tim = MRI_ROTA_FINE( im2 , fit[1] , fit[2] , fit[3]*DFAC ) ; 00245 bim2 = mri_filt_fft( tim, fine_sigma, 0,0, FILT_FFT_WRAPAROUND ) ; 00246 dfit = mri_delayed_lsqfit( bim2 , fine_fitim , chol_fine_fitim ) ; 00247 mri_free( bim2 ) ; mri_free( tim ) ; 00248 00249 fit[1] += dfit[1] ; 00250 fit[2] += dfit[2] ; 00251 fit[3] += dfit[3] ; 00252 00253 good = (++iter < max_iter) && 00254 ( fabs(dfit[1]) > fine_dxy_thresh || 00255 fabs(dfit[2]) > fine_dxy_thresh || fabs(dfit[3]) > fine_phi_thresh ) ; 00256 00257 free(dfit) ; dfit = NULL ; 00258 } /* end while */ 00259 } 00260 00261 /*-- save final alignment parameters --*/ 00262 00263 if( dx != NULL ) *dx = fit[1] ; 00264 if( dy != NULL ) *dy = fit[2] ; 00265 if( phi!= NULL ) *phi= fit[3]*DFAC ; 00266 00267 /*-- do the actual realignment --*/ 00268 00269 tim = MRI_ROTA_REG( im2 , fit[1],fit[2],fit[3]*DFAC ) ; 00270 mri_free( im2 ) ; 00271 return tim ; 00272 } |
|
Definition at line 41 of file mri_2dalign.c. References DFILT_SIGMA, dfilt_sigma, DXY_THRESH, dxy_thresh, FINE_DXY_THRESH, fine_dxy_thresh, FINE_PHI_THRESH, fine_phi_thresh, fine_sigma, MAX_ITER, max_iter, PHI_THRESH, and phi_thresh. Referenced by REG_command_line().
00044 { 00045 if( maxite > 0 ) max_iter = maxite ; else max_iter = MAX_ITER ; 00046 if( sig > 0.0 ) dfilt_sigma = sig ; else dfilt_sigma = DFILT_SIGMA ; 00047 if( dxy > 0.0 ) dxy_thresh = dxy ; else dxy_thresh = DXY_THRESH ; 00048 if( dph > 0.0 ) phi_thresh = dph ; else phi_thresh = PHI_THRESH ; 00049 00050 fine_sigma = fsig ; 00051 if( fdxy > 0.0 ) fine_dxy_thresh = fdxy ; else fine_dxy_thresh = FINE_DXY_THRESH ; 00052 if( fdph > 0.0 ) fine_phi_thresh = fdph ; else fine_phi_thresh = FINE_PHI_THRESH ; 00053 00054 return ; 00055 } |
|
Definition at line 85 of file mri_2dalign.c. References ADDTO_IMARR, MRI_2dalign_basis::chol_fine_fitim, MRI_2dalign_basis::chol_fitim, DFAC, dfilt_sigma, FILT_FFT_WRAPAROUND, MRI_2dalign_basis::fine_fitim, fine_sigma, MRI_2dalign_basis::fitim, imbase, INIT_IMARR, malloc, mri_data_pointer(), mri_filt_fft(), MRI_FLOAT_PTR, mri_free(), MRI_IS_2D, mri_new(), mri_startup_lsqfit(), mri_to_float(), MRI_IMAGE::nx, and MRI_IMAGE::ny. Referenced by mri_2dalign_many(), and RT_registration_2D_setup().
00086 { 00087 MRI_IMAGE * im1 , *bim,*xim,*yim,*tim , *bim2 , * im2 , *imww ; 00088 float *tar,*xar,*yar ; 00089 int nx,ny , ii,jj , joff ; 00090 int use_fine_fit = (fine_sigma > 0.0) ; 00091 float hnx,hny ; 00092 00093 MRI_IMARR * fitim =NULL; 00094 double * chol_fitim=NULL ; 00095 MRI_IMARR * fine_fitim =NULL ; 00096 double * chol_fine_fitim=NULL ; 00097 MRI_2dalign_basis * bout = NULL ; 00098 00099 if( ! MRI_IS_2D(imbase) ){ 00100 fprintf(stderr,"\n*** mri_2dalign_setup: cannot use nD images!\a\n") ; 00101 return NULL ; 00102 } 00103 00104 im1 = mri_to_float( imbase ) ; 00105 nx = im1->nx ; hnx = 0.5 * nx ; 00106 ny = im1->ny ; hny = 0.5 * ny ; 00107 00108 bim = mri_filt_fft( im1, dfilt_sigma, 0, 0, FILT_FFT_WRAPAROUND ) ; /* smooth */ 00109 xim = mri_filt_fft( im1, dfilt_sigma, 1, 0, FILT_FFT_WRAPAROUND ) ; /* d/dx */ 00110 yim = mri_filt_fft( im1, dfilt_sigma, 0, 1, FILT_FFT_WRAPAROUND ) ; /* d/dy */ 00111 00112 tim = mri_new( nx , ny , MRI_float ) ; /* x * d/dy - y * d/dx */ 00113 tar = mri_data_pointer( tim ) ; /* which is d/d(theta) */ 00114 xar = mri_data_pointer( xim ) ; 00115 yar = mri_data_pointer( yim ) ; 00116 for( jj=0 ; jj < ny ; jj++ ){ 00117 joff = jj * nx ; 00118 for( ii=0 ; ii < nx ; ii++ ){ 00119 tar[ii+joff] = DFAC * ( (ii-hnx) * yar[ii+joff] 00120 - (jj-hny) * xar[ii+joff] ) ; 00121 } 00122 } 00123 INIT_IMARR ( fitim ) ; 00124 ADDTO_IMARR( fitim , bim ) ; 00125 ADDTO_IMARR( fitim , xim ) ; 00126 ADDTO_IMARR( fitim , yim ) ; 00127 ADDTO_IMARR( fitim , tim ) ; 00128 00129 if( imwt == NULL ) imww = mri_to_float( bim ) ; /* 28 Oct 1996 */ 00130 else imww = mri_to_float( imwt ) ; 00131 00132 tar = MRI_FLOAT_PTR(imww) ; 00133 for( ii=0 ; ii < nx*ny ; ii++ ) tar[ii] = fabs(tar[ii]) ; /* 16 Nov 1998 */ 00134 00135 chol_fitim = mri_startup_lsqfit( fitim , imww ) ; 00136 mri_free(imww) ; 00137 00138 if( use_fine_fit ){ 00139 bim = mri_filt_fft( im1, fine_sigma, 0, 0, FILT_FFT_WRAPAROUND ) ; /* smooth */ 00140 xim = mri_filt_fft( im1, fine_sigma, 1, 0, FILT_FFT_WRAPAROUND ) ; /* d/dx */ 00141 yim = mri_filt_fft( im1, fine_sigma, 0, 1, FILT_FFT_WRAPAROUND ) ; /* d/dy */ 00142 00143 tim = mri_new( nx , ny , MRI_float ) ; /* x * d/dy - y * d/dx */ 00144 tar = mri_data_pointer( tim ) ; /* which is d/d(theta) */ 00145 xar = mri_data_pointer( xim ) ; 00146 yar = mri_data_pointer( yim ) ; 00147 for( jj=0 ; jj < ny ; jj++ ){ 00148 joff = jj * nx ; 00149 for( ii=0 ; ii < nx ; ii++ ){ 00150 tar[ii+joff] = DFAC * ( (ii-hnx) * yar[ii+joff] 00151 - (jj-hny) * xar[ii+joff] ) ; 00152 } 00153 } 00154 INIT_IMARR ( fine_fitim ) ; 00155 ADDTO_IMARR( fine_fitim , bim ) ; 00156 ADDTO_IMARR( fine_fitim , xim ) ; 00157 ADDTO_IMARR( fine_fitim , yim ) ; 00158 ADDTO_IMARR( fine_fitim , tim ) ; 00159 00160 if( imwt == NULL ) imww = mri_to_float( bim ) ; /* 03 Oct 1997 */ 00161 else imww = mri_to_float( imwt ) ; 00162 00163 tar = MRI_FLOAT_PTR(imww) ; 00164 for( ii=0 ; ii < nx*ny ; ii++ ) tar[ii] = fabs(tar[ii]) ; 00165 00166 chol_fine_fitim = mri_startup_lsqfit( fine_fitim , imww ) ; 00167 mri_free(imww) ; 00168 } 00169 00170 mri_free(im1) ; 00171 00172 bout = (MRI_2dalign_basis *) malloc( sizeof(MRI_2dalign_basis) ) ; 00173 bout->fitim = fitim ; 00174 bout->chol_fitim = chol_fitim ; 00175 bout->fine_fitim = fine_fitim ; 00176 bout->chol_fine_fitim = chol_fine_fitim ; 00177 return bout ; 00178 } |
|
Definition at line 66 of file mri_to_rgb.c. References ENTRY, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COPY_AUX, MRI_FATAL_ERROR, MRI_FLOAT_PTR, mri_new_conforming, MRI_IMAGE::nvox, and RETURN. Referenced by mri_dup2D(), mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), mri_warp3D_quintic(), mri_warp_bicubic(), and NUD_rotate().
00067 { 00068 MRI_IMAGE *newim ; 00069 register int ii , npix ; 00070 register byte * rgb ; 00071 00072 ENTRY("mri_3to_rgb") ; 00073 00074 if( rim == NULL || bim == NULL || gim == NULL ) RETURN( NULL ); 00075 00076 newim = mri_new_conforming( rim , MRI_rgb ) ; rgb = MRI_BYTE_PTR(newim) ; 00077 npix = rim->nvox ; 00078 00079 switch( rim->kind ){ 00080 00081 case MRI_byte:{ 00082 byte * rr=MRI_BYTE_PTR(rim), * gg=MRI_BYTE_PTR(gim), * bb=MRI_BYTE_PTR(bim) ; 00083 for( ii=0 ; ii < npix ; ii++ ){ 00084 rgb[3*ii ] = rr[ii] ; 00085 rgb[3*ii+1] = gg[ii] ; 00086 rgb[3*ii+2] = bb[ii] ; 00087 } 00088 } 00089 break ; 00090 00091 case MRI_float:{ 00092 float * rr=MRI_FLOAT_PTR(rim), * gg=MRI_FLOAT_PTR(gim), * bb=MRI_FLOAT_PTR(bim) ; 00093 for( ii=0 ; ii < npix ; ii++ ){ 00094 rgb[3*ii ] = rr[ii] ; 00095 rgb[3*ii+1] = gg[ii] ; 00096 rgb[3*ii+2] = bb[ii] ; 00097 } 00098 } 00099 break ; 00100 00101 default: 00102 fprintf(stderr,"mri_3to_rgb: unrecognized image conversion %d\n",rim->kind) ; 00103 MRI_FATAL_ERROR ; 00104 } 00105 00106 MRI_COPY_AUX(newim,rim) ; 00107 RETURN( newim ); 00108 } |
|
Definition at line 34 of file mri_add_name.c. References ENTRY, MRI_IMAGE::fname, free, and malloc. Referenced by mri_read_3D_delay().
00035 { 00036 int ll ; 00037 00038 ENTRY("mri_add_fname_delay") ; 00039 00040 if( im == NULL ) EXRETURN ; /* 29 Mar 2002 */ 00041 00042 if( im->fname != NULL ){ free( im->fname ) ; im->fname = NULL ; } 00043 00044 if( str == NULL ) EXRETURN ; 00045 00046 ll = strlen(str) ; if( ll <= 0 ) EXRETURN ; 00047 00048 im->fname = (char *) malloc( ll+1 ) ; 00049 strcpy( im->fname , str ) ; 00050 EXRETURN ; 00051 } |
|
|
Affine transform a 2D image, using bilinear interpolation: If flag == 0 [ xout ] = [ axx axy ] [ xin ] [ yout ] = [ ayx ayy ] [ yin ] If flag == 1 [ xin ] = [ axx axy ] [ xout ] [ yin ] = [ ayx ayy ] [ yout ] These are index coordinates, not spatial. ---------------------------------------------------------------------- Definition at line 42 of file mri_aff2d.c. References ENTRY, far, FINS, invert2d(), MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COPY_AUX, MRI_IS_2D, mri_new(), MRI_IMAGE::nx, MRI_IMAGE::ny, and RETURN. Referenced by project_byte_mip().
00044 { 00045 float bxx,bxy,byx,byy , xbase,ybase , xx,yy , fx,fy ; 00046 float f_j00,f_jp1 , wt_00,wt_p1 ; 00047 int ii,jj , nx,ny , ix,jy ; 00048 MRI_IMAGE *newImg ; 00049 byte *far , *nar ; 00050 00051 ENTRY("mri_aff2d_byte") ; 00052 00053 if( im == NULL || !MRI_IS_2D(im) || im->kind != MRI_byte ){ 00054 fprintf(stderr,"*** mri_aff2d_byte only works on 2D byte images!\n"); 00055 RETURN( NULL ); 00056 } 00057 00058 if( flag == 0 ){ 00059 invert2d( axx,axy,ayx,ayy , &bxx,&bxy,&byx,&byy ) ; 00060 } else { 00061 bxx = axx ; bxy = axy ; byx = ayx ; byy = ayy ; 00062 } 00063 if( (bxx == 0.0 && bxy == 0.0) || (byx == 0.0 && byy == 0.0) ){ 00064 fprintf(stderr,"*** mri_aff2d_byte: input matrix is singular!\n") ; 00065 RETURN( NULL ); 00066 } 00067 00068 nx = im->nx ; ny = im->ny ; 00069 xbase = 0.5*nx*(1.0-bxx) - 0.5*ny*bxy ; 00070 ybase = 0.5*ny*(1.0-byy) - 0.5*nx*byx ; 00071 00072 far = MRI_BYTE_PTR(im) ; /* input image data */ 00073 newImg = mri_new( nx , nx , MRI_byte ) ; /* output image */ 00074 nar = MRI_BYTE_PTR(newImg) ; /* output image data */ 00075 00076 /*** loop over output points and warp to them ***/ 00077 00078 for( jj=0 ; jj < nx ; jj++ ){ 00079 xx = xbase-bxx + bxy * jj ; 00080 yy = ybase-byx + byy * jj ; 00081 for( ii=0 ; ii < nx ; ii++ ){ 00082 00083 xx += bxx ; /* get x,y in original image */ 00084 yy += byx ; 00085 00086 ix = (xx >= 0.0) ? ((int) xx) : ((int) xx)-1 ; /* floor */ 00087 jy = (yy >= 0.0) ? ((int) yy) : ((int) yy)-1 ; 00088 00089 fx = xx-ix ; wt_00 = 1.0 - fx ; wt_p1 = fx ; 00090 00091 if( ix >= 0 && ix < nx-1 && jy >= 0 && jy < ny-1 ){ 00092 byte *fy00 , *fyp1 ; 00093 00094 fy00 = far + (ix + jy*nx) ; fyp1 = fy00 + nx ; 00095 00096 f_j00 = wt_00 * fy00[0] + wt_p1 * fy00[1] ; 00097 f_jp1 = wt_00 * fyp1[0] + wt_p1 * fyp1[1] ; 00098 00099 } else { 00100 f_j00 = wt_00 * FINS(ix,jy ) + wt_p1 * FINS(ix+1,jy ) ; 00101 f_jp1 = wt_00 * FINS(ix,jy+1) + wt_p1 * FINS(ix+1,jy+1) ; 00102 } 00103 00104 fy = yy-jy ; nar[ii+jj*nx] = (1.0-fy) * f_j00 + fy * f_jp1 ; 00105 00106 } 00107 } 00108 00109 MRI_COPY_AUX(newImg,im) ; 00110 RETURN( newImg ) ; 00111 } |
|
Same as mri_aff2d_byte(), but for RGB images [11 Dec 2000]. ------------------------------------------------------------------------ Definition at line 134 of file mri_aff2d.c. References BINS, ENTRY, far, GINS, invert2d(), MRI_IMAGE::kind, MRI_COPY_AUX, MRI_IS_2D, mri_new(), MRI_RGB_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, and RINS. Referenced by CREN_render().
00136 { 00137 float bxx,bxy,byx,byy , xbase,ybase , xx,yy , fx,fy ; 00138 float f_j00r,f_jp1r , f_j00g,f_jp1g , f_j00b,f_jp1b , wt_00,wt_p1 ; 00139 int jj , nx,ny , ix,jy ; 00140 MRI_IMAGE *newImg ; 00141 byte *far , *nar ; 00142 register int ii ; 00143 00144 ENTRY("mri_aff2d_rgb") ; 00145 00146 if( im == NULL || !MRI_IS_2D(im) || im->kind != MRI_rgb ){ 00147 fprintf(stderr,"*** mri_aff2d_rgb only works on 2D RGB images!\n"); 00148 RETURN( NULL ); 00149 } 00150 00151 if( flag == 0 ){ 00152 invert2d( axx,axy,ayx,ayy , &bxx,&bxy,&byx,&byy ) ; 00153 } else { 00154 bxx = axx ; bxy = axy ; byx = ayx ; byy = ayy ; 00155 } 00156 if( (bxx == 0.0 && bxy == 0.0) || (byx == 0.0 && byy == 0.0) ){ 00157 fprintf(stderr,"*** mri_aff2d_byte: input matrix is singular!\n") ; 00158 RETURN( NULL ); 00159 } 00160 00161 nx = im->nx ; ny = im->ny ; 00162 xbase = 0.5*nx*(1.0-bxx) - 0.5*ny*bxy ; 00163 ybase = 0.5*ny*(1.0-byy) - 0.5*nx*byx ; 00164 00165 far = MRI_RGB_PTR(im) ; /* input image data */ 00166 newImg = mri_new( nx , nx , MRI_rgb ) ; /* output image */ 00167 nar = MRI_RGB_PTR(newImg) ; /* output image data */ 00168 00169 /*** loop over output points and warp to them ***/ 00170 00171 for( jj=0 ; jj < nx ; jj++ ){ 00172 xx = xbase-bxx + bxy * jj ; 00173 yy = ybase-byx + byy * jj ; 00174 for( ii=0 ; ii < nx ; ii++ ){ 00175 00176 xx += bxx ; /* get x,y in original image */ 00177 yy += byx ; 00178 00179 ix = (xx >= 0.0) ? ((int) xx) : ((int) xx)-1 ; /* floor */ 00180 jy = (yy >= 0.0) ? ((int) yy) : ((int) yy)-1 ; 00181 00182 fx = xx-ix ; wt_00 = 1.0 - fx ; wt_p1 = fx ; 00183 00184 if( ix >= 0 && ix < nx-1 && jy >= 0 && jy < ny-1 ){ 00185 byte *fy00 , *fyp1 ; 00186 00187 fy00 = far + 3*(ix+jy*nx) ; fyp1 = fy00 + 3*nx ; 00188 00189 f_j00r = wt_00 * fy00[0] + wt_p1 * fy00[3] ; 00190 f_j00g = wt_00 * fy00[1] + wt_p1 * fy00[4] ; 00191 f_j00b = wt_00 * fy00[2] + wt_p1 * fy00[5] ; 00192 00193 f_jp1r = wt_00 * fyp1[0] + wt_p1 * fyp1[3] ; 00194 f_jp1g = wt_00 * fyp1[1] + wt_p1 * fyp1[4] ; 00195 f_jp1b = wt_00 * fyp1[2] + wt_p1 * fyp1[5] ; 00196 00197 } else { 00198 f_j00r = wt_00 * RINS(ix,jy ) + wt_p1 * RINS(ix+1,jy ) ; 00199 f_j00g = wt_00 * GINS(ix,jy ) + wt_p1 * GINS(ix+1,jy ) ; 00200 f_j00b = wt_00 * BINS(ix,jy ) + wt_p1 * BINS(ix+1,jy ) ; 00201 00202 f_jp1r = wt_00 * RINS(ix,jy+1) + wt_p1 * RINS(ix+1,jy+1) ; 00203 f_jp1g = wt_00 * GINS(ix,jy+1) + wt_p1 * GINS(ix+1,jy+1) ; 00204 f_jp1b = wt_00 * BINS(ix,jy+1) + wt_p1 * BINS(ix+1,jy+1) ; 00205 } 00206 00207 fy = yy-jy ; 00208 nar[3*ii+ 3*jj*nx ] = (1.0-fy) * f_j00r + fy * f_jp1r ; 00209 nar[3*ii+(3*jj*nx+1)] = (1.0-fy) * f_j00g + fy * f_jp1g ; 00210 nar[3*ii+(3*jj*nx+2)] = (1.0-fy) * f_j00b + fy * f_jp1b ; 00211 00212 } 00213 } 00214 00215 MRI_COPY_AUX(newImg,im) ; 00216 RETURN( newImg ); 00217 } |
|
Referenced by get_line_opt(), IMREG_main(), and main(). |
|
Referenced by main(). |
|
Definition at line 75 of file mri_align.c. References almode_coarse, almode_fine, and almode_reg. Referenced by REG_command_line().
00076 { 00077 if( coarse > 0 ) almode_coarse = coarse ; 00078 if( fine > 0 ) almode_fine = fine ; 00079 if( reg > 0 ) almode_reg = reg ; 00080 return ; 00081 } |
|
Definition at line 50 of file mri_align.c. References DFILT_SIGMA, dfilt_sigma, DXY_THRESH, dxy_thresh, FINE_DXY_THRESH, fine_dxy_thresh, FINE_PHI_THRESH, fine_phi_thresh, fine_sigma, MAX_ITER, max_iter, PHI_THRESH, and phi_thresh. Referenced by IMREG_main(), and REG_command_line().
00053 { 00054 if( maxite > 0 ) max_iter = maxite ; else max_iter = MAX_ITER ; 00055 if( sig > 0.0 ) dfilt_sigma = sig ; else dfilt_sigma = DFILT_SIGMA ; 00056 if( dxy > 0.0 ) dxy_thresh = dxy ; else dxy_thresh = DXY_THRESH ; 00057 if( dph > 0.0 ) phi_thresh = dph ; else phi_thresh = PHI_THRESH ; 00058 00059 fine_sigma = fsig ; 00060 if( fdxy > 0.0 ) fine_dxy_thresh = fdxy ; else fine_dxy_thresh = FINE_DXY_THRESH ; 00061 if( fdph > 0.0 ) fine_phi_thresh = fdph ; else fine_phi_thresh = FINE_PHI_THRESH ; 00062 00063 return ; 00064 } |
|
Definition at line 19 of file mri_cat2D.c. References ENTRY, complex::i, IMARR_SUBIMAGE, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COMPLEX_PTR, mri_data_pointer(), MRI_DOUBLE_PTR, MRI_FLOAT_PTR, MRI_INT_PTR, mri_new(), MRI_RGB_PTR, MRI_SHORT_PTR, mri_to_mri(), MRI_IMARR::num, MRI_IMAGE::nx, MRI_IMAGE::ny, complex::r, and RETURN. Referenced by ISQ_make_montage(), and PH_redraw().
00020 { 00021 int nx , ny , ii , jj , kind , ij , nxout , nyout , ijoff , jout,iout ; 00022 MRI_IMAGE * imout , * imin ; 00023 void * vout ; 00024 00025 ENTRY("mri_cat2D") ; 00026 00027 /*--- sanity checks ---*/ 00028 00029 if( mx < 1 || my < 1 || imar == NULL || imar->num < mx*my ) RETURN( NULL ); 00030 if( gap < 0 || (gap > 0 && gapval == NULL) ) RETURN( NULL ); 00031 00032 for( ij=0 ; ij < mx*my ; ij++ ){ /* find first non-empty image */ 00033 imin = IMARR_SUBIMAGE(imar,ij) ; 00034 if( imin != NULL ) break ; 00035 } 00036 if( ij == mx*my ) RETURN( NULL ); /* all are empty! */ 00037 00038 kind = imin->kind ; 00039 nx = imin->nx ; 00040 ny = imin->ny ; 00041 00042 if( mx==1 && my==1 ){ /* 1x1 case (shouldn't happen) */ 00043 imout = mri_to_mri( kind , imin ) ; /* Just copy input to output */ 00044 RETURN( imout ); 00045 } 00046 00047 for( ij=0 ; ij < mx*my ; ij++ ){ /* check for consistency */ 00048 imin = IMARR_SUBIMAGE(imar,ij) ; 00049 if( imin != NULL && 00050 (imin->kind != kind || imin->nx != nx || imin->ny != ny) ) 00051 RETURN( NULL ); 00052 } 00053 00054 nxout = mx * nx + (mx-1) * gap ; 00055 nyout = my * ny + (my-1) * gap ; 00056 imout = mri_new( nxout , nyout , kind ) ; 00057 vout = mri_data_pointer( imout ) ; 00058 00059 ij = 0 ; 00060 for( jj=0 ; jj < my ; jj++ ){ /* loop over rows */ 00061 for( ii=0 ; ii < mx ; ii++ , ij++ ){ /* loop over columns */ 00062 00063 imin = IMARR_SUBIMAGE(imar,ij) ; 00064 ijoff = ii * (nx+gap) + jj * (ny+gap) * nxout ; 00065 00066 /*--- NULL image ==> fill this spot with zeroes ---*/ 00067 00068 if( imin == NULL || mri_data_pointer(imin) == NULL ){ 00069 switch( kind ){ 00070 case MRI_byte:{ 00071 byte * pout = ((byte *) vout); 00072 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00073 (void) memset( pout+ijoff , 0 , sizeof(byte)*nx ) ; 00074 } break ; 00075 00076 case MRI_rgb:{ /* 11 Feb 1999 */ 00077 byte * pout = ((byte *) vout); 00078 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00079 (void) memset( pout+(3*ijoff) , 0 , sizeof(byte)*(3*nx) ) ; 00080 } break ; 00081 00082 case MRI_short:{ 00083 short * pout = ((short *) vout); 00084 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00085 (void) memset( pout+ijoff , 0 , sizeof(short)*nx ) ; 00086 } break ; 00087 00088 case MRI_int:{ 00089 int * pout = ((int *) vout); 00090 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00091 (void) memset( pout+ijoff , 0 , sizeof(int)*nx ) ; 00092 } break ; 00093 00094 case MRI_float:{ 00095 float * pout = ((float *) vout); 00096 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00097 for( iout=0 ; iout < nx ; iout++ ) 00098 pout[iout+ijoff] = 0 ; 00099 } break ; 00100 00101 case MRI_double:{ 00102 double * pout = ((double *) vout); 00103 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00104 for( iout=0 ; iout < nx ; iout++ ) 00105 pout[iout+ijoff] = 0 ; 00106 } break ; 00107 00108 case MRI_complex:{ 00109 complex * pout = ((complex *) vout); 00110 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00111 for( iout=0 ; iout < nx ; iout++ ) 00112 pout[iout+ijoff].r = pout[iout+ijoff].i = 0 ; 00113 } break ; 00114 } 00115 00116 /*--- Copy input image data into place ---*/ 00117 00118 } else { 00119 switch( kind ){ 00120 case MRI_byte:{ 00121 byte * pout = ((byte *) vout) , 00122 * pin = (byte *) MRI_BYTE_PTR(imin) ; 00123 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00124 memcpy( pout+ijoff , pin , sizeof(byte)*nx ) , pin += nx ; 00125 } break ; 00126 00127 case MRI_rgb:{ /* 11 Feb 1999 */ 00128 byte * pout = ((byte *) vout) , 00129 * pin = (byte *) MRI_RGB_PTR(imin) ; 00130 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00131 memcpy( pout+(3*ijoff) , pin , sizeof(byte)*(3*nx) ) , pin += 3*nx ; 00132 } break ; 00133 00134 case MRI_short:{ 00135 short * pout = ((short *) vout) , 00136 * pin = (short *) MRI_SHORT_PTR(imin) ; 00137 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00138 memcpy( pout+ijoff , pin , sizeof(short)*nx ) , pin += nx ; 00139 } break ; 00140 00141 case MRI_int:{ 00142 int * pout = ((int *) vout) , 00143 * pin = (int *) MRI_INT_PTR(imin) ; 00144 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00145 memcpy( pout+ijoff , pin , sizeof(int)*nx ) , pin += nx ; 00146 } break ; 00147 00148 case MRI_float:{ 00149 float * pout = ((float *) vout) , 00150 * pin = (float *) MRI_FLOAT_PTR(imin) ; 00151 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00152 memcpy( pout+ijoff , pin , sizeof(float)*nx ) , pin += nx ; 00153 } break ; 00154 00155 case MRI_double:{ 00156 double * pout = ((double *) vout) , 00157 * pin = (double *) MRI_DOUBLE_PTR(imin) ; 00158 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00159 memcpy( pout+ijoff , pin , sizeof(double)*nx ) , pin += nx ; 00160 } break ; 00161 00162 case MRI_complex:{ 00163 complex * pout = ((complex *) vout) , 00164 * pin = (complex *) MRI_COMPLEX_PTR(imin) ; 00165 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout ) 00166 memcpy( pout+ijoff , pin , sizeof(complex)*nx ) , pin += nx ; 00167 } break ; 00168 } 00169 } 00170 } 00171 } 00172 00173 /******************* Deal with the gaps *******************/ 00174 00175 if( gap > 0 ){ 00176 00177 /**** put value into gap after each row ****/ 00178 00179 ii = nxout * gap ; 00180 for( jj=0 ; jj < my-1 ; jj++ ){ 00181 ijoff = (ny + jj * (ny+gap)) * nxout ; 00182 switch( kind ){ 00183 case MRI_byte:{ 00184 byte gval = *((byte *)gapval) , * pout = ((byte *) vout) ; 00185 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ; 00186 } break ; 00187 00188 case MRI_rgb:{ /* 11 Feb 1999 */ 00189 byte rval = *(((byte *)gapval) ) , 00190 gval = *(((byte *)gapval)+1) , 00191 bval = *(((byte *)gapval)+2) , * pout = ((byte *) vout) ; 00192 00193 for( ij=0 ; ij < ii ; ij++ ){ 00194 pout[3*(ij+ijoff) ] = rval ; 00195 pout[3*(ij+ijoff)+1] = gval ; 00196 pout[3*(ij+ijoff)+2] = bval ; 00197 } 00198 } break ; 00199 00200 case MRI_short:{ 00201 short gval = *((short *)gapval) , * pout = ((short *) vout) ; 00202 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ; 00203 } break ; 00204 00205 case MRI_float:{ 00206 float gval = *((float *)gapval) , * pout = ((float *) vout) ; 00207 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ; 00208 } break ; 00209 00210 case MRI_int:{ 00211 int gval = *((int *)gapval) , * pout = ((int *) vout) ; 00212 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ; 00213 } break ; 00214 00215 case MRI_double:{ 00216 double gval = *((double *)gapval) , * pout = ((double *) vout) ; 00217 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ; 00218 } break ; 00219 00220 case MRI_complex:{ 00221 complex gval = *((complex *)gapval) , * pout = ((complex *) vout) ; 00222 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ; 00223 } break ; 00224 } 00225 } 00226 00227 /**** put value into gap after each column ****/ 00228 00229 for( ii=0 ; ii < mx-1 ; ii++ ){ 00230 ijoff = nx + ii*(nx+gap) ; 00231 switch( kind ){ 00232 case MRI_byte:{ 00233 byte gval = *((byte *)gapval) , * pout = ((byte *) vout) ; 00234 for( ij=0 ; ij < gap ; ij++ , ijoff++ ) 00235 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ; 00236 } break ; 00237 00238 case MRI_rgb:{ /* 11 Feb 1999 */ 00239 byte rval = *(((byte *)gapval) ) , 00240 gval = *(((byte *)gapval)+1) , 00241 bval = *(((byte *)gapval)+2) , * pout = ((byte *) vout) ; 00242 00243 for( ij=0 ; ij < gap ; ij++ , ijoff++ ) 00244 for( jj=0 ; jj < nyout ; jj++ ){ 00245 pout[3*(jj*nxout+ijoff) ] = rval ; 00246 pout[3*(jj*nxout+ijoff)+1] = gval ; 00247 pout[3*(jj*nxout+ijoff)+2] = bval ; 00248 } 00249 } break ; 00250 00251 case MRI_short:{ 00252 short gval = *((short *)gapval) , * pout = ((short *) vout) ; 00253 for( ij=0 ; ij < gap ; ij++ , ijoff++ ) 00254 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ; 00255 } break ; 00256 00257 case MRI_float:{ 00258 float gval = *((float *)gapval) , * pout = ((float *) vout) ; 00259 for( ij=0 ; ij < gap ; ij++ , ijoff++ ) 00260 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ; 00261 } break ; 00262 00263 case MRI_int:{ 00264 int gval = *((int *)gapval) , * pout = ((int *) vout) ; 00265 for( ij=0 ; ij < gap ; ij++ , ijoff++ ) 00266 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ; 00267 } break ; 00268 00269 case MRI_double:{ 00270 double gval = *((double *)gapval) , * pout = ((double *) vout) ; 00271 for( ij=0 ; ij < gap ; ij++ , ijoff++ ) 00272 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ; 00273 } break ; 00274 00275 case MRI_complex:{ 00276 complex gval = *((complex *)gapval) , * pout = ((complex *) vout) ; 00277 for( ij=0 ; ij < gap ; ij++ , ijoff++ ) 00278 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ; 00279 } break ; 00280 } 00281 } 00282 } 00283 00284 RETURN( imout ); 00285 } |
|
Definition at line 7 of file mri_colorsetup.c. References rgbyte::b, rgbyte::g, mri_new(), MRI_RGB_PTR, and rgbyte::r. Referenced by ISQ_saver_CB().
00008 { 00009 MRI_IMAGE *im ; 00010 rgbyte *ar ; 00011 int rr,gg,bb , nn ; 00012 float rac,gac,bac ; 00013 00014 im = mri_new( ngray + nrr*ngg*nbb - 1 , 1 , MRI_rgb ) ; 00015 ar = (rgbyte *) MRI_RGB_PTR(im) ; 00016 00017 gac = 255.9f / ngray ; nn = 0 ; /* actually, ngray+1 levels */ 00018 for( gg=0 ; gg <= ngray ; gg++,nn++ ){ 00019 ar[nn].r = ar[nn].g = ar[nn].b = (byte)(gac*gg) ; 00020 } 00021 00022 rac = 255.9f/(nrr-1) ; gac = 255.9f/(ngg-1) ; bac=255.9f/(nbb-1) ; 00023 00024 for( bb=0 ; bb < nbb ; bb++ ){ /* skip the all black and */ 00025 for( gg=0 ; gg < ngg ; gg++ ){ /* the all white colors */ 00026 for( rr=0 ; rr < nrr ; rr++ ){ 00027 if( rr==0 && gg==0 && bb==0 ) continue ; 00028 if( rr==nrr-1 && gg==ngg-1 && bb==nbb-1 ) continue ; 00029 ar[nn].r = (byte)(rac*rr) ; 00030 ar[nn].g = (byte)(gac*gg) ; 00031 ar[nn].b = (byte)(bac*bb) ; nn++ ; 00032 } } } 00033 00034 return im ; 00035 } |
|
Definition at line 82 of file mri_complex_arith.c. References MRI_DATA::complex_data, CSQR, MRI_DATA::float_data, MRI_IMAGE::im, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_new_conforming, and MRI_IMAGE::nvox.
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 } |
|
Definition at line 59 of file mri_complex_arith.c. References MRI_DATA::complex_data, MRI_DATA::float_data, complex::i, MRI_IMAGE::im, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_new_conforming, MRI_IMAGE::nvox, and complex::r.
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 } |
|
Definition at line 229 of file mri_to_complex.c. References ADDTO_IMARR, ENTRY, complex::i, INIT_IMARR, MRI_IMAGE::kind, MRI_COMPLEX_PTR, MRI_FLOAT_PTR, mri_new_conforming, MRI_IMAGE::nvox, complex::r, and RETURN. Referenced by mri_affine_bicubic(), mri_dup2D(), mri_rota(), mri_rota_bilinear(), mri_rota_shear(), mri_shift2D_bilinear(), mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), and mri_warp3D_quintic().
00230 { 00231 MRI_IMARR * imarr ; 00232 MRI_IMAGE * rim , * iim ; 00233 register int ii , nvox ; 00234 register float * rar , * iar ; 00235 register complex * car ; 00236 00237 ENTRY("mri_complex_to_pair") ; 00238 00239 if( cim == NULL || cim->kind != MRI_complex ) RETURN( NULL ); 00240 00241 rim = mri_new_conforming( cim , MRI_float ) ; rar = MRI_FLOAT_PTR(rim) ; 00242 iim = mri_new_conforming( cim , MRI_float ) ; iar = MRI_FLOAT_PTR(iim) ; 00243 car = MRI_COMPLEX_PTR(cim) ; 00244 nvox = cim->nvox ; 00245 00246 for( ii=0 ; ii < nvox ; ii++ ){ rar[ii] = car[ii].r ; iar[ii] = car[ii].i ; } 00247 00248 INIT_IMARR(imarr) ; 00249 ADDTO_IMARR(imarr,rim) ; 00250 ADDTO_IMARR(imarr,iim) ; 00251 00252 RETURN( imarr ); 00253 } |
|
|
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 } |
|
|
Return the size (bytes) of one data element of the given type. --------------------------------------------------------------------------- Definition at line 85 of file mri_free.c. References typ. Referenced by adwarp_refashion_dataset(), AFNI_read_images(), AFNI_refashion_dataset(), EDIT_main(), EDIT_volpad(), main(), mri_read3D_analyze75(), mri_read_analyze75(), mri_zeropad_2D(), r_fill_resampled_data_brick(), RT_process_info(), RT_start_dataset(), s2v_nodes2volume(), T3D_create_widgets(), T3D_fix_dataset_dimen(), T3D_read_images(), T3D_swap_CB(), THD_add_bricks(), THD_copy_dset_subs(), THD_extract_array(), THD_get_dset_row(), THD_load_mpeg(), THD_open_analyze(), THD_subbrick_to_niml(), THD_write_minc(), write_afni_data(), write_afni_fict(), and write_afni_fizt().
00086 { 00087 switch( typ ){ 00088 case MRI_byte: return sizeof(byte) ; 00089 case MRI_short: return sizeof(short) ; 00090 case MRI_int: return sizeof(int) ; 00091 case MRI_float: return sizeof(float) ; 00092 case MRI_double: return sizeof(double) ; 00093 case MRI_complex: return sizeof(complex) ; 00094 case MRI_rgb: return 3*sizeof(byte) ; 00095 case MRI_rgba: return sizeof(rgba) ; 00096 default: return 0 ; 00097 } 00098 } |
|
Definition at line 418 of file mri_lsqfit.c. References delayed_lsqfit(), ENTRY, fit, free, MRI_IMARR::imarr, malloc, MRI_FLOAT_PTR, MRI_IMARR::num, MRI_IMAGE::nvox, and RETURN. Referenced by mri_2dalign_one(), mri_3dalign_one(), and mri_align_dfspace().
00419 { 00420 int ii , npix,nref ; 00421 float * fit ; 00422 static float ** refar = NULL ; 00423 static int nrefar = -1 ; 00424 00425 ENTRY("mri_delayed_lsqfit") ; 00426 00427 nref = refim->num ; 00428 npix = refim->imarr[0]->nvox ; 00429 00430 if( nrefar < nref ){ 00431 if( refar != NULL ) free(refar) ; 00432 refar = (float **) malloc( sizeof(float *) * nref ) ; 00433 nrefar = nref ; 00434 } 00435 if( refar == NULL ){ 00436 fprintf(stderr,"mri_delayed_lsqfit: malloc failure for refar!\a\n"); RETURN(NULL); 00437 } 00438 00439 for( ii=0 ; ii < nref ; ii++ ) 00440 refar[ii] = MRI_FLOAT_PTR(refim->imarr[ii]) ; 00441 00442 fit = delayed_lsqfit( npix , MRI_FLOAT_PTR(fitim) , nref , refar , cc ) ; 00443 RETURN(fit) ; 00444 } |
|
Definition at line 204 of file l_mri_dicom_hdr.c.
00205 { 00206 DCM_OBJECT * object; 00207 CONDITION cond; 00208 CTNBOOLEAN verbose = FALSE , 00209 exitFlag = FALSE, 00210 formatFlag = FALSE; 00211 unsigned long 00212 options = DCM_ORDERLITTLEENDIAN; 00213 long vmLimit = rwc_vm ; /* 28 Oct 2002 */ 00214 LST_HEAD* fileNames = 0; 00215 UTL_FILEITEM* p = NULL; 00216 00217 char *ppp=NULL ; 00218 00219 ENTRY("mri_dicom_header") ; 00220 00221 if( fname == NULL ) RETURN(NULL) ; 00222 00223 RWC_set_endianosity() ; 00224 00225 { char *eee = getenv("AFNI_TRACE") ; 00226 if( eee!=NULL && (*eee=='y' || *eee=='Y') ) verbose = TRUE ; 00227 } 00228 00229 DCM_Debug(verbose); 00230 00231 RWC_clear_pbuf() ; pxl_len = 0 ; pxl_off = 0 ; 00232 00233 STATUS(fname) ; 00234 rwc_fd = -1 ; 00235 cond = DCM_OpenFile(fname, options, &object); 00236 if (cond != DCM_NORMAL && ((options & DCM_PART10FILE) == 0)) { 00237 STATUS("DCM_OpenFile open failed; try again as Part 10") ; 00238 (void) DCM_CloseObject(&object); 00239 (void) COND_PopCondition(TRUE); 00240 if( rwc_fd >= 0 ){ close(rwc_fd); rwc_fd = -1; } 00241 cond = DCM_OpenFile(fname, options | DCM_PART10FILE, &object); 00242 } 00243 if (cond == DCM_NORMAL) { 00244 STATUS("DCM_OpenFile is good") ; 00245 RWC_printf("DICOM File: %s\n", fname); 00246 if (formatFlag) 00247 cond = DCM_FormatElements(&object, vmLimit, ""); 00248 else 00249 cond = DCM_DumpElements(&object, vmLimit); 00250 } else { 00251 STATUS("DCM_OpenFile failed") ; 00252 } 00253 (void) DCM_CloseObject(&object); 00254 (void) COND_PopCondition(TRUE); 00255 00256 if( pbuf != NULL ){ 00257 ppp = strdup(pbuf) ; RWC_clear_pbuf() ; 00258 } 00259 00260 if( rwc_fd >= 0 ){ close(rwc_fd); rwc_fd = -1; } 00261 00262 RETURN(ppp); 00263 } |
|
Definition at line 174 of file l_mri_dicom_hdr.c.
00175 { 00176 if( ii ) 00177 rwc_opt |= RWC_NOHEX_MASK ; 00178 else if( rwc_opt & RWC_NOHEX_MASK ) 00179 rwc_opt ^= RWC_NOHEX_MASK ; 00180 } |
|
Definition at line 166 of file l_mri_dicom_hdr.c.
00167 { 00168 if( ii ) 00169 rwc_opt |= RWC_NONAME_MASK ; 00170 else if( rwc_opt & RWC_NONAME_MASK ) 00171 rwc_opt ^= RWC_NONAME_MASK ; 00172 } |
|
Definition at line 154 of file l_mri_dicom_hdr.c.
|
|
Definition at line 195 of file l_mri_dicom_hdr.c. References rwc_err. Referenced by main(), and mri_imcount().
00196 { 00197 rwc_err = vv ; /* 07 May 2003: an error will subtract 1 from rwc_err */ 00198 } |
|
Definition at line 186 of file l_mri_dicom_hdr.c. References rwc_vm. Referenced by main().
00187 { 00188 rwc_vm = vv ; 00189 } |
|
Definition at line 23 of file mri_read_dicom.c. References str_sexinfo. Referenced by main().
00023 { return str_sexinfo; } /* 23 Dec 2002 */ |
|
Definition at line 26 of file mri_drawing.c. References opa. Referenced by memplot_to_RGB_sef().
00026 { if( val >= 0.0 && val <= 1.0 ) opa = val ; } |
|
Definition at line 680 of file mri_drawing.c. References ENTRY, MRI_IMAGE::kind, MRI_RGB_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, ppmd_line(), and r.
00683 { 00684 register int cx, cy, cwidth, cheight, col, row; 00685 00686 ENTRY("mri_drawemptyrectangle") ; 00687 if( im == NULL || im->kind != MRI_rgb ) EXRETURN ; 00688 00689 /* Clip. */ 00690 cx = x; cy = y; cwidth = width; cheight = height; 00691 if ( cx < 0 ) { cx = 0; cwidth += x; } 00692 if ( cy < 0 ) { cy = 0; cheight += y; } 00693 if ( cx + cwidth > im->nx ) cwidth = im->nx - cx; 00694 if ( cy + cheight > im->ny ) cheight = im->ny - cy; 00695 00696 ppmd_line( MRI_RGB_PTR(im),im->nx,im->ny,cx ,cy ,cx+width,cy ,r,g,b); 00697 ppmd_line( MRI_RGB_PTR(im),im->nx,im->ny,cx+width,cy ,cx+width,cy+height,r,g,b); 00698 ppmd_line( MRI_RGB_PTR(im),im->nx,im->ny,cx+width,cy+height,cx ,cy+height,r,g,b); 00699 ppmd_line( MRI_RGB_PTR(im),im->nx,im->ny,cx ,cy+height,cx ,cy ,r,g,b); 00700 EXRETURN ; 00701 } |
|
Definition at line 668 of file mri_drawing.c. References ENTRY, MRI_IMAGE::kind, MRI_RGB_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, ppmd_filledrectangle(), and r. Referenced by memplot_to_RGB_sef().
00671 { 00672 ENTRY("mri_drawfilledrectangle") ; 00673 if( im == NULL || im->kind != MRI_rgb ) EXRETURN ; 00674 ppmd_filledrectangle( MRI_RGB_PTR(im), im->nx, im->ny, x,y,width,height, r,g,b ) ; 00675 EXRETURN ; 00676 } |
|
Draw a line into an RGB image.
Definition at line 658 of file mri_drawing.c. References ENTRY, MRI_IMAGE::kind, MRI_RGB_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, ppmd_line(), r, x0, y0, and y1. Referenced by memplot_to_RGB_sef().
|
|
Draw text into an RGB image.
Definition at line 712 of file mri_drawing.c. References ENTRY, MRI_IMAGE::kind, MRI_RGB_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, ppmd_text(), and r.
|
|
Definition at line 44 of file mri_dup.c. References AFNI_yesenv(), ENTRY, EXIT, free, FREE_IMARR, IMAGE_IN_IMARR, MRI_IMAGE::kind, malloc, MAX_NUP, mri_3to_rgb(), MRI_BYTE_PTR, mri_complex_to_pair(), MRI_COPY_AUX, mri_dup2D_mode(), mri_dup2D_rgb2(), mri_dup2D_rgb3(), mri_dup2D_rgb4(), mri_dup2D_rgb_NN(), MRI_FLOAT_PTR, mri_free(), mri_max(), mri_min(), mri_new(), mri_pair_to_complex(), mri_rgb_to_3byte(), MRI_SHORT_PTR, mri_to_float(), mri_to_mri(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, upsample_1by2(), upsample_1by3(), upsample_1by4(), and usammer. Referenced by AFNI_faceup(), ISQ_save_jpeg(), ISQ_saver_CB(), ISQ_show_zoom(), and main().
00045 { 00046 MRI_IMAGE *flim , *newim ; 00047 float *flar , *newar , *cold , *cnew ; 00048 int nx,ny , nxup,nyup , ii,jj,kk, NNmode = 0 ; 00049 00050 ENTRY("mri_dup2D") ; 00051 /*-- sanity checks --*/ 00052 00053 if( nup < 1 || nup > MAX_NUP || imin == NULL ) RETURN( NULL ); 00054 00055 if( nup == 1 ){ newim = mri_to_mri( imin->kind, imin ); RETURN(newim); } 00056 00057 /* does the user want neighbor interpolation? 22 Feb 2004 [rickr] */ 00058 if ( AFNI_yesenv("AFNI_IMAGE_ZOOM_NN") ) { 00059 mri_dup2D_mode(0); 00060 NNmode = 1; 00061 } 00062 00063 /*-- complex-valued images: do each part separately --*/ 00064 00065 if( imin->kind == MRI_complex ){ 00066 MRI_IMARR *impair ; MRI_IMAGE *rim, *iim, *tim ; 00067 00068 impair = mri_complex_to_pair( imin ) ; 00069 if( impair == NULL ){ 00070 fprintf(stderr,"*** mri_complex_to_pair fails in mri_dup2D!\n"); EXIT(1); 00071 } 00072 rim = IMAGE_IN_IMARR(impair,0) ; 00073 iim = IMAGE_IN_IMARR(impair,1) ; FREE_IMARR(impair) ; 00074 tim = mri_dup2D( nup, rim ); mri_free( rim ); rim = tim ; 00075 tim = mri_dup2D( nup, iim ); mri_free( iim ); iim = tim ; 00076 newim = mri_pair_to_complex( rim , iim ) ; 00077 mri_free( rim ) ; mri_free( iim ) ; 00078 MRI_COPY_AUX(newim,imin) ; 00079 RETURN(newim) ; 00080 } 00081 00082 /*-- 14 Mar 2002: RGB image up by 2..4, all colors at once --*/ 00083 00084 if( imin->kind == MRI_rgb ){ 00085 MRI_IMAGE *qqim=NULL ; 00086 if ( NNmode ) 00087 qqim = mri_dup2D_rgb_NN(imin, nup); /* 22 Feb 2004 [rickr] */ 00088 else { 00089 switch(nup){ 00090 case 4: qqim = mri_dup2D_rgb4(imin); break; /* special purpose fast codes */ 00091 case 3: qqim = mri_dup2D_rgb3(imin); break; /* using fixed pt arithmetic */ 00092 case 2: qqim = mri_dup2D_rgb2(imin); break; 00093 00094 /*-- other factors: do each color separately as a byte image --*/ 00095 default:{ 00096 MRI_IMARR *imtriple ; MRI_IMAGE *rim, *gim, *bim, *tim ; 00097 00098 imtriple = mri_rgb_to_3byte( imin ) ; 00099 if( imtriple == NULL ){ 00100 fprintf(stderr,"*** mri_rgb_to_3byte fails in mri_dup2D!\n"); RETURN(NULL); 00101 } 00102 rim = IMAGE_IN_IMARR(imtriple,0) ; 00103 gim = IMAGE_IN_IMARR(imtriple,1) ; 00104 bim = IMAGE_IN_IMARR(imtriple,2) ; FREE_IMARR(imtriple) ; 00105 tim = mri_dup2D( nup, rim ); mri_free(rim); rim = tim; 00106 tim = mri_dup2D( nup, gim ); mri_free(gim); gim = tim; 00107 tim = mri_dup2D( nup, bim ); mri_free(bim); bim = tim; 00108 newim = mri_3to_rgb( rim, gim, bim ) ; 00109 mri_free(rim) ; mri_free(gim) ; mri_free(bim) ; 00110 MRI_COPY_AUX(newim,imin) ; 00111 qqim = newim ; 00112 } 00113 break ; 00114 } 00115 } 00116 00117 RETURN(qqim) ; 00118 } 00119 00120 /*-- Special case: byte-valued image upsampled by 2/3/4 [13 Mar 2002] --*/ 00121 00122 if( imin->kind == MRI_byte && nup <= 4 ){ 00123 void (*usbyte)(int,byte *,byte *) = NULL ; 00124 byte *bar=MRI_BYTE_PTR(imin) , *bnew , *cold, *cnew ; 00125 nx = imin->nx; ny = imin->ny; nxup = nx*nup; nyup = ny*nup ; 00126 newim = mri_new( nxup,nyup , MRI_byte ); bnew = MRI_BYTE_PTR(newim); 00127 switch( nup ){ 00128 case 2: usbyte = upsample_1by2 ; break ; /* special fast codes */ 00129 case 3: usbyte = upsample_1by3 ; break ; 00130 case 4: usbyte = upsample_1by4 ; break ; 00131 } 00132 for( jj=0 ; jj < ny ; jj++ ) /* upsample rows */ 00133 usbyte( nx , bar+jj*nx , bnew+jj*nxup ) ; 00134 cold = (byte *) malloc( sizeof(byte) * ny ) ; 00135 cnew = (byte *) malloc( sizeof(byte) * nyup ) ; 00136 for( ii=0 ; ii < nxup ; ii++ ){ /* upsample cols */ 00137 for( jj=0 ; jj < ny ; jj++ ) cold[jj] = bnew[ii+jj*nxup] ; 00138 usbyte( ny , cold , cnew ) ; 00139 for( jj=0 ; jj < nyup ; jj++ ) bnew[ii+jj*nxup] = cnew[jj] ; 00140 } 00141 free(cold); free(cnew); MRI_COPY_AUX(newim,imin); RETURN(newim); 00142 } 00143 00144 /*-- otherwise, make sure we operate on a float image --*/ 00145 00146 if( imin->kind == MRI_float ) flim = imin ; 00147 else flim = mri_to_float( imin ) ; 00148 00149 flar = MRI_FLOAT_PTR(flim) ; 00150 00151 nx = flim->nx ; ny = flim->ny ; nxup = nx*nup ; nyup = ny*nup ; 00152 newim = mri_new( nxup , nyup , MRI_float ) ; 00153 newar = MRI_FLOAT_PTR(newim) ; 00154 00155 /*-- upsample rows --*/ 00156 00157 for( jj=0 ; jj < ny ; jj++ ) 00158 usammer( nup , nx , flar + jj*nx , newar + jj*nxup ) ; 00159 00160 if( flim != imin ) mri_free(flim) ; 00161 00162 /*-- upsample columns --*/ 00163 00164 cold = (float *) malloc( sizeof(float) * ny ) ; 00165 cnew = (float *) malloc( sizeof(float) * nyup ) ; 00166 if( cold == NULL || cnew == NULL ){ 00167 fprintf(stderr,"*** mri_dup2D malloc failure!\n"); EXIT(1); 00168 } 00169 00170 for( ii=0 ; ii < nxup ; ii++ ){ 00171 for( jj=0 ; jj < ny ; jj++ ) cold[jj] = newar[ii + jj*nxup] ; 00172 usammer( nup , ny , cold , cnew ) ; 00173 for( jj=0 ; jj < nyup ; jj++ ) newar[ii+jj*nxup] = cnew[jj] ; 00174 } 00175 00176 free(cold) ; free(cnew) ; 00177 00178 /*-- type convert output, if necessary --*/ 00179 00180 switch( imin->kind ){ 00181 00182 case MRI_byte:{ 00183 byte * bar ; MRI_IMAGE * bim ; float fmin , fmax ; 00184 00185 bim = mri_new( nxup,nyup , MRI_byte ) ; bar = MRI_BYTE_PTR(bim) ; 00186 fmin = mri_min(imin) ; fmax = mri_max(imin) ; 00187 for( ii=0 ; ii < newim->nvox ; ii++ ) 00188 bar[ii] = (newar[ii] < fmin) ? fmin 00189 : (newar[ii] > fmax) ? fmax : newar[ii] ; 00190 mri_free(newim) ; newim = bim ; 00191 } 00192 break ; 00193 00194 case MRI_short:{ 00195 short * sar ; MRI_IMAGE * sim ; float fmin , fmax ; 00196 00197 sim = mri_new( nxup,nyup , MRI_short ) ; sar = MRI_SHORT_PTR(sim) ; 00198 fmin = mri_min(imin) ; fmax = mri_max(imin) ; 00199 for( ii=0 ; ii < newim->nvox ; ii++ ) 00200 sar[ii] = (newar[ii] < fmin) ? fmin 00201 : (newar[ii] > fmax) ? fmax : newar[ii] ; 00202 mri_free(newim) ; newim = sim ; 00203 } 00204 break ; 00205 00206 case MRI_float:{ 00207 float fmin , fmax ; 00208 00209 fmin = mri_min(imin) ; fmax = mri_max(imin) ; 00210 for( ii=0 ; ii < newim->nvox ; ii++ ) 00211 if( newar[ii] < fmin ) newar[ii] = fmin ; 00212 else if( newar[ii] > fmax ) newar[ii] = fmax ; 00213 } 00214 } 00215 00216 /*-- finito --*/ 00217 00218 MRI_COPY_AUX(newim,imin) ; 00219 RETURN( newim ); 00220 } |
|
Definition at line 31 of file mri_dup.c. References upsample_1(), upsample_7(), usammer, and usammer_mode. Referenced by mri_dup2D().
00032 { 00033 switch( mm ){ 00034 case 1: usammer = upsample_1 ; break ; 00035 default: usammer = upsample_7 ; break ; 00036 } 00037 usammer_mode = mm ; 00038 } |
|
Definition at line 17 of file mri_edit.c. References ENTRY, fa, MAX, MRI_COPY_AUX, mri_data_pointer(), mri_max(), mri_min(), mri_to_float(), MRI_IMAGE::nvox, and RETURN. Referenced by ISQ_process_mri().
00018 { 00019 int ii , npix , nsum ; 00020 float val ; 00021 MRI_IMAGE *imqq ; 00022 float *flin ; 00023 00024 ENTRY("mri_edit_image") ; 00025 00026 imqq = mri_to_float( imin ) ; 00027 flin = mri_data_pointer( imqq ) ; 00028 npix = imqq->nvox ; 00029 00030 if( (power==0.0 || power==1.0) && (pthr==0.0) ) RETURN(imqq) ; 00031 00032 if( pthr > 0.0 && pthr < 1.0 ){ 00033 register float sum , fa , scl,fmax ; 00034 register int nsum ; 00035 00036 fmax = fabs(mri_max(imqq)) ; 00037 val = fabs(mri_min(imqq)) ; 00038 fmax = MAX(fmax,val) ; 00039 val = pthr * fmax ; /* average pixels > pthr * max */ 00040 sum = 0.0 ; 00041 nsum = 0 ; 00042 00043 for( ii=0 ; ii < npix ; ii++ ){ 00044 fa = flin[ii] = fabs(flin[ii]) ; 00045 if( fa > val ){ sum += fa ; nsum++ ; } 00046 } 00047 val = pthr * sum / nsum ; /* set threshold based on this */ 00048 00049 #ifdef HARD_THRESH 00050 for( ii=0 ; ii < npix ; ii++ ) if(flin[ii] < val) flin[ii] = 0.0 ; 00051 #else 00052 scl = fmax / (fmax-val) ; 00053 for( ii=0 ; ii < npix ; ii++ ){ 00054 fa = flin[ii] ; 00055 flin[ii] = (fa < val) ? (0.0) : (scl*(fa-val)) ; 00056 } 00057 #endif 00058 } /* end of if(pthr) */ 00059 00060 if( power != 0.0 && power != 1.0 ){ 00061 for( ii=0 ; ii < npix ; ii++ ) flin[ii] = pow( fabs(flin[ii]) , power ) ; 00062 } 00063 00064 MRI_COPY_AUX(imqq,imin) ; 00065 RETURN(imqq) ; 00066 } |
|
Definition at line 8 of file mri_entropy16.c. References calloc, ENTRY, free, l, mri_data_pointer(), MRI_IMAGE::nvox, MRI_IMAGE::pixel_size, RETURN, and SNUM. Referenced by ISQ_statify_one().
00009 { 00010 register int *scount , snum , ii ; 00011 register unsigned short *sar ; 00012 register double sum ; 00013 00014 ENTRY("mri_entropy16") ; 00015 00016 if( im == NULL ) RETURN(0.0l) ; 00017 00018 sar = (unsigned short *) mri_data_pointer( im ) ; 00019 if( sar == NULL ) RETURN(0.0l) ; 00020 00021 snum = (im->nvox * im->pixel_size) / 2 ; if( snum < 2 ) RETURN(0.0l) ; 00022 scount = (int *) calloc( sizeof(int),SNUM ) ; 00023 00024 for( ii=0 ; ii < snum ; ii++ ) scount[sar[ii]]++ ; 00025 00026 sum = 0.0 ; 00027 for( ii=0 ; ii < SNUM ; ii++ ) 00028 if( scount[ii] > 0 ) sum += scount[ii] * log((double)scount[ii]) ; 00029 00030 free( (void *)scount ) ; 00031 00032 sum = -(sum - snum*log((double)snum)) / ( log(2.0l) * snum ) ; 00033 RETURN(sum) ; 00034 } |
|
Definition at line 41 of file mri_entropy16.c. References BNUM, bnum, calloc, ENTRY, free, l, mri_data_pointer(), MRI_IMAGE::nvox, MRI_IMAGE::pixel_size, and RETURN. Referenced by ISQ_statify_one().
00042 { 00043 register int *bcount , bnum , ii ; 00044 register byte *bar ; 00045 register double sum ; 00046 00047 ENTRY("mri_entropy8") ; 00048 00049 if( im == NULL ) RETURN(0.0l) ; 00050 00051 bar = (byte *) mri_data_pointer( im ) ; 00052 if( bar == NULL ) RETURN(0.0l) ; 00053 00054 bnum = (im->nvox * im->pixel_size) ; if( bnum < 2 ) RETURN(0.0l) ; 00055 bcount = (int *) calloc( sizeof(int),BNUM ) ; 00056 00057 for( ii=0 ; ii < bnum ; ii++ ) bcount[bar[ii]]++ ; 00058 00059 sum = 0.0 ; 00060 for( ii=0 ; ii < BNUM ; ii++ ) 00061 if( bcount[ii] > 0 ) sum += bcount[ii] * log((double)bcount[ii]) ; 00062 00063 free( (void *)bcount ) ; 00064 00065 sum = -(sum - bnum*log((double)bnum)) / ( log(2.0l) * bnum ) ; 00066 RETURN(sum) ; 00067 } |
|
Test if 2 images are equal. Returns 1 if they are, 0 if they are not. [30 Jun 2003] Definition at line 6 of file mri_equal.c. References ENTRY, MRI_IMAGE::kind, memcmp(), mri_data_pointer(), MRI_IMAGE::nvox, MRI_IMAGE::pixel_size, and RETURN. Referenced by SNAP_store_image().
00007 { 00008 char *aar , *bar ; 00009 int nn ; 00010 00011 ENTRY("mri_equal") ; 00012 00013 if( aim == bim ) RETURN( 1 ); 00014 if( aim == NULL || bim == NULL ) RETURN( 0 ); 00015 00016 if( aim->nvox != bim->nvox ) RETURN( 0 ); 00017 if( aim->kind != bim->kind ) RETURN( 0 ); 00018 00019 aar = mri_data_pointer(aim) ; if( aar == NULL ) RETURN( 0 ); 00020 bar = mri_data_pointer(bim) ; if( bar == NULL ) RETURN( 0 ); 00021 00022 nn = memcmp( aar , bar , aim->nvox * aim->pixel_size ) ; 00023 if( nn != 0 ) nn = 0 ; 00024 else nn = 1 ; 00025 RETURN( nn); 00026 } |
|
Definition at line 40 of file mri_copy.c. References ENTRY, MRI_IMAGE::kind, mri_copy(), MRI_COPY_AUX, mri_data_pointer(), mri_new(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, MRI_IMAGE::pixel_size, and RETURN.
00041 { 00042 MRI_IMAGE *newim ; 00043 int nx,ny , nxup,nyup , ii,jj, pp,qq , ds ; 00044 char *nar , *iar ; 00045 00046 ENTRY("mri_expand") ; 00047 00048 /*-- sanity checks --*/ 00049 00050 if( nup < 1 || imin == NULL || imin->nz > 1 ) RETURN(NULL); 00051 00052 if( nup == 1 ){ newim = mri_copy(imin); RETURN(newim); } 00053 00054 iar = (char *)mri_data_pointer(imin) ; if( iar == NULL ) RETURN(NULL); 00055 00056 nx = imin->nx ; nxup = nx*nup ; 00057 ny = imin->ny ; nyup = ny*nup ; 00058 00059 newim = mri_new( nxup,nyup , imin->kind ) ; 00060 nar = (char *)mri_data_pointer(newim) ; 00061 ds = imin->pixel_size ; 00062 00063 for( jj=0 ; jj < nyup ; jj++ ){ 00064 qq = jj / nup ; 00065 for( ii=0 ; ii < nxup ; ii++ ){ 00066 pp = ii / nup ; 00067 memcpy( nar + (ii+jj*nxup)*ds , iar + (pp+qq*nx)*ds , ds ) ; 00068 } 00069 } 00070 00071 MRI_COPY_AUX( newim , imin ) ; 00072 RETURN(newim) ; 00073 } |
|
Definition at line 19 of file mri_fft_complex.c. References cfft2d(), free, complex::i, MRI_IMAGE::kind, malloc, mri_data_pointer(), MRI_FATAL_ERROR, MRI_IS_2D, mri_setup_taper(), MRI_IMAGE::nx, MRI_IMAGE::ny, and complex::r.
00020 { 00021 float *rbuf , *ibuf , *xtap , *ytap ; 00022 complex *cxim ; 00023 int ii , jj , npix , jbase , nx,ny ; 00024 00025 if( im->kind != MRI_complex ){ 00026 fprintf( stderr , "mri_fft_complex only works on complex images!\n" ) ; 00027 MRI_FATAL_ERROR ; 00028 } 00029 00030 if( ! MRI_IS_2D(im) ){ 00031 fprintf(stderr,"mri_fft_complex only works on 2D images!\n") ; 00032 MRI_FATAL_ERROR ; 00033 } 00034 00035 /*** set up buffers ***/ 00036 00037 npix = im->nx * im->ny ; /* number of pixels */ 00038 rbuf = (float *)malloc( sizeof(float) * npix ) ; /* real and imag buffs */ 00039 ibuf = (float *)malloc( sizeof(float) * npix ) ; 00040 cxim = mri_data_pointer( im ) ; /* easy acces to im */ 00041 00042 for( ii=0 ; ii < npix ; ii++ ){ 00043 rbuf[ii] = cxim[ii].r ; 00044 ibuf[ii] = cxim[ii].i ; 00045 } 00046 00047 /*** taper buffers, if desired ***/ 00048 00049 if( taper > 0.0 && taper <= 1.0 ){ 00050 nx = im->nx ; 00051 ny = im->ny ; 00052 xtap = mri_setup_taper( nx , taper ) ; 00053 00054 /*** 00055 printf( "taper" ) ; 00056 for( ii=0 ; ii < nx ; ii++ ){ 00057 if( (ii%5) == 0 ) printf("\n") ; 00058 printf( "%12.4e " , xtap[ii] ) ; 00059 } 00060 printf("\n") ; 00061 ***/ 00062 00063 if( nx == ny ) ytap = xtap ; 00064 else ytap = mri_setup_taper( ny , taper ) ; 00065 00066 for( jj=0 ; jj < ny ; jj++ ){ 00067 jbase = jj * nx ; 00068 for( ii=0 ; ii < nx ; ii++ ){ 00069 rbuf[ii] *= xtap[ii] * ytap[jj] ; 00070 ibuf[ii] *= xtap[ii] * ytap[jj] ; 00071 } 00072 } 00073 free( xtap ) ; 00074 if( ytap != xtap ) free(ytap) ; 00075 } 00076 00077 /*** FFT buffers and copy them back to original image ***/ 00078 00079 cfft2d( mode , im->nx , im->ny , rbuf,ibuf ) ; 00080 00081 for( ii=0 ; ii < npix ; ii++ ){ 00082 cxim[ii].r = rbuf[ii] ; 00083 cxim[ii].i = ibuf[ii] ; 00084 } 00085 00086 return ; 00087 } |
|
|
|
Return the size of a file in bytes.
Definition at line 1659 of file mri_read.c. Referenced by imsized_fname(), main(), mri_imcount_mpeg(), and mri_read_mpeg().
01660 { 01661 static struct stat buf ; 01662 int ii ; 01663 01664 if( pathname == NULL ) return -1 ; 01665 ii = stat( pathname , &buf ) ; if( ii != 0 ) return -1 ; 01666 return buf.st_size ; 01667 } |
|
Definition at line 36 of file mri_filt_fft.c. References csfft_cox(), MRI_IMAGE::dx, MRI_IMAGE::dy, EXIT, FILT_FFT_WRAPAROUND, GET_AS_BIG, complex::i, mri_data_pointer(), MRI_IS_2D, mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, complex::r, and tt. Referenced by main(), mri_2dalign_one(), mri_2dalign_setup(), mri_align_crao(), and mri_align_dfspace().
00038 { 00039 int jj, nby2 , nx,ny ; 00040 float dk , aa , k , fac , dx,dy ; 00041 register int ii , nup ; 00042 register float * bfim ; 00043 00044 static int cx_size = 0 ; /* workspaces (will hang around between calls) */ 00045 static int gg_size = 0 ; 00046 static complex * cx = NULL ; 00047 static float * gg = NULL ; 00048 00049 MRI_IMAGE * flim ; 00050 float * flar ; 00051 00052 /*** initialize ***/ 00053 00054 if( im == NULL ){ 00055 fprintf(stderr,"*** mri_filt_fft: NULL input image\n") ; 00056 return NULL ; 00057 } 00058 00059 if( sigma < 0.0 ){ 00060 fprintf(stderr,"*** mri_filt_fft: Illegal control parameters input\n"); 00061 return NULL ; 00062 } 00063 00064 if( ! MRI_IS_2D(im) ){ 00065 fprintf(stderr,"*** mri_filt_fft: Only works on 2D images\n") ; 00066 EXIT(1) ; 00067 } 00068 00069 nx = im->nx ; ny = im->ny ; 00070 dx = fabs(im->dx) ; if( dx == 0.0 ) dx = 1.0 ; 00071 dy = fabs(im->dy) ; if( dy == 0.0 ) dy = 1.0 ; 00072 00073 aa = sigma * sigma * 0.5 ; 00074 00075 flim = mri_to_float( im ) ; /* will be output */ 00076 flar = mri_data_pointer( flim ) ; 00077 00078 if( sigma == 0.0 && diffx == 0 && diffy == 0 ) return flim ; /* no action! */ 00079 00080 /*** do x-direction ***/ 00081 00082 if( (code & FILT_FFT_WRAPAROUND) == 0 ){ 00083 nup = nx + (int)(3.0 * sigma / dx) ; /* min FFT length */ 00084 } else { 00085 nup = nx ; 00086 } 00087 ii = 4 ; while( ii < nup ){ ii *= 2 ; } /* next power of 2 larger */ 00088 nup = ii ; nby2 = nup / 2 ; 00089 00090 GET_AS_BIG(cx,complex,nup) ; GET_AS_BIG(gg,float,nup) ; 00091 00092 dk = (2.0*PI) / (nup * dx) ; 00093 fac = 1.0 / nup ; 00094 gg[0] = fac ; 00095 if( aa > 0.0 ){ 00096 for( ii=1 ; ii<=nby2 ; ii++ ){ k=ii*dk; gg[nup-ii]=gg[ii]=fac*exp(-aa*k*k); } 00097 } else { 00098 for( ii=1 ; ii < nup ; ii++ ) gg[ii] = fac ; 00099 } 00100 00101 if( diffx ){ 00102 gg[0] = gg[nby2] = 0.0 ; 00103 for( ii=1 ; ii < nby2 ; ii++ ){ k=ii*dk ; gg[ii] *= k ; gg[nup-ii] *= (-k) ; } 00104 } 00105 00106 /** July 19 1995: double up on FFTs **/ 00107 00108 for( jj=0 ; jj < ny ; jj+=2 ){ 00109 bfim = flar + jj*nx ; 00110 if( jj == ny-1 ) 00111 for( ii=0 ; ii<nx ; ii++){ cx[ii].r = bfim[ii] ; cx[ii].i = 0.0 ; } /* copy in */ 00112 else 00113 for( ii=0 ; ii<nx ; ii++){ cx[ii].r = bfim[ii] ; cx[ii].i = bfim[ii+nx] ; } 00114 for( ii=nx; ii<nup; ii++){ cx[ii].r = cx[ii].i = 0.0 ; } /* zero pad */ 00115 csfft_cox( -1 , nup , cx ) ; /* FFT */ 00116 for( ii=0 ; ii<nup; ii++){ cx[ii].r *= gg[ii] ; cx[ii].i *= gg[ii] ; } /* filter */ 00117 if( diffx ){ 00118 float tt ; 00119 for( ii=0 ; ii < nup ; ii++ ){ 00120 tt = cx[ii].r ; cx[ii].r = -cx[ii].i ; cx[ii].i = tt ; /* mult by i */ 00121 } 00122 } 00123 csfft_cox( 1 , nup , cx ) ; /* inv FFT */ 00124 if( jj == ny-1 ) 00125 for( ii=0 ; ii<nx ; ii++){ bfim[ii] = cx[ii].r ; } /* copy out */ 00126 else 00127 for( ii=0 ; ii<nx ; ii++){ bfim[ii] = cx[ii].r ; bfim[ii+nx] = cx[ii].i ; } 00128 } 00129 00130 /*** do y-direction ***/ 00131 00132 if( (code & FILT_FFT_WRAPAROUND) == 0 ){ 00133 nup = ny + (int)(3.0 * sigma / dy) ; /* min FFT length */ 00134 } else { 00135 nup = ny ; 00136 } 00137 ii = 2 ; while( ii < nup ){ ii *= 2 ; } /* next power of 2 larger */ 00138 nup = ii ; nby2 = nup / 2 ; 00139 00140 GET_AS_BIG(cx,complex,nup) ; GET_AS_BIG(gg,float,nup) ; 00141 00142 dk = (2.0*PI) / (nup * dy) ; 00143 fac = 1.0 / nup ; 00144 gg[0] = fac ; 00145 00146 if( aa > 0.0 ){ 00147 for( ii=1 ; ii<=nby2 ; ii++ ){ k=ii*dk; gg[nup-ii]=gg[ii]=fac*exp(-aa*k*k); } 00148 } else { 00149 for( ii=1 ; ii < nup ; ii++ ) gg[ii] = fac ; 00150 } 00151 00152 if( diffy ){ 00153 gg[0] = gg[nby2] = 0.0 ; 00154 for( ii=1 ; ii < nby2 ; ii++ ){ k=ii*dk ; gg[ii] *= k ; gg[nup-ii] *= (-k) ; } 00155 } 00156 00157 for( jj=0 ; jj < nx ; jj+=2 ){ 00158 bfim = flar + jj ; 00159 if( jj == nx-1 ) 00160 for( ii=0 ; ii<ny ; ii++){ cx[ii].r = bfim[ii*nx] ; cx[ii].i = 0.0 ; } 00161 else 00162 for( ii=0 ; ii<ny ; ii++){ cx[ii].r = bfim[ii*nx] ; cx[ii].i = bfim[ii*nx+1] ; } 00163 for( ii=ny; ii<nup; ii++){ cx[ii].r = cx[ii].i = 0.0 ; } 00164 csfft_cox( -1 , nup , cx ) ; 00165 for( ii=0 ; ii<nup; ii++){ cx[ii].r *= gg[ii] ; cx[ii].i *= gg[ii] ; } 00166 if( diffy ){ 00167 float tt ; 00168 for( ii=0 ; ii < nup ; ii++ ){ 00169 tt = cx[ii].r ; cx[ii].r = -cx[ii].i ; cx[ii].i = tt ; /* multiply by i */ 00170 } 00171 } 00172 csfft_cox( 1 , nup , cx ) ; 00173 if( jj == nx-1 ) 00174 for( ii=0 ; ii<ny ; ii++){ bfim[ii*nx] = cx[ii].r ; } 00175 else 00176 for( ii=0 ; ii<ny ; ii++){ bfim[ii*nx] = cx[ii].r ; bfim[ii*nx+1] = cx[ii].i ; } 00177 } 00178 00179 /*** done! ***/ 00180 00181 return flim ; 00182 } |
|
|
Definition at line 539 of file mri_percents.c. References far, MRI_COPY_AUX, MRI_FLOAT_PTR, mri_free(), MRI_INT_PTR, mri_new(), mri_new_conforming, mri_to_float(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, and qsort_pair(). Referenced by ISQ_process_mri(), and mri_flatten_rgb().
00540 { 00541 MRI_IMAGE * flim , * intim , * outim ; 00542 float * far , * outar ; 00543 int * iar ; 00544 int ii , nvox , ibot,itop , nvox1 ; 00545 float fac , val ; 00546 00547 #ifdef DEBUG 00548 printf("Entry: mri_flatten\n") ; 00549 #endif 00550 00551 if( im == NULL ) return NULL ; 00552 00553 /*** make an image that is just the voxel index in its array ***/ 00554 /*** also, make the output image while we are at it ***/ 00555 00556 #ifdef MRILIB_7D 00557 nvox = im->nvox ; 00558 intim = mri_new_conforming( im , MRI_int ) ; 00559 outim = mri_new_conforming( im , MRI_float ) ; 00560 #else 00561 nvox = im->nx * im->ny ; 00562 intim = mri_new( im->nx , im->ny , MRI_int ) ; 00563 outim = mri_new( im->nx , im->ny , MRI_float ) ; 00564 #endif 00565 00566 iar = MRI_INT_PTR(intim) ; outar = MRI_FLOAT_PTR(outim) ; 00567 00568 for( ii=0 ; ii < nvox ; ii++ ) iar[ii] = ii ; 00569 00570 /*** copy the input data to a floating point image ***/ 00571 00572 flim = mri_to_float( im ) ; far = MRI_FLOAT_PTR(flim) ; 00573 00574 /*** sort this image, with the index array being carried along 00575 so that we know where every pixel came from originally ***/ 00576 00577 qsort_pair( nvox , far , iar ) ; 00578 00579 /*** The "far" array is now sorted. Thus, if the pixel that was in 00580 voxel i is now in voxel j, then its place in the histogram is 00581 j/nvox. The only difficulty is that there may be ties. We need 00582 to resolve these ties so that pixels with the same intensity 00583 don't get different output values. We do this by scanning 00584 through far, finding blocks of equal values, and replacing 00585 them by their average position in the histogram. 00586 ***/ 00587 00588 fac = 1.0 / nvox ; nvox1 = nvox - 1 ; 00589 00590 for( ibot=0 ; ibot < nvox1 ; ){ 00591 00592 /** if this value is unique, just set the value and move on **/ 00593 00594 val = far[ibot] ; itop = ibot+1 ; 00595 if( val != far[itop] ){ 00596 far[ibot] = fac * ibot ; 00597 ibot++ ; continue ; 00598 } 00599 00600 /** scan itop up until value is distinct **/ 00601 00602 for( ; itop < nvox1 && val == far[itop] ; itop++ ) ; /* nada */ 00603 00604 val = 0.5*fac * (ibot+itop-1) ; 00605 for( ii=ibot ; ii < itop ; ii++ ) far[ii] = val ; 00606 ibot = itop ; 00607 } 00608 far[nvox1] = 1.0 ; 00609 00610 /*** now propagate these values back to the output image ***/ 00611 00612 for( ii=0 ; ii < nvox ; ii++ ) outar[iar[ii]] = far[ii] ; 00613 00614 mri_free( flim ) ; mri_free( intim ) ; 00615 00616 MRI_COPY_AUX( outim , im ) ; 00617 return outim ; 00618 } |
|
Definition at line 218 of file mri_to_rgb.c. References ENTRY, far, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COPY_AUX, mri_flatten(), MRI_FLOAT_PTR, mri_free(), mri_new_conforming, mri_to_float(), MRI_IMAGE::nvox, and RETURN. Referenced by ISQ_process_mri().
00219 { 00220 MRI_IMAGE * flim , * shim , * newim ; 00221 byte * iar , * nar ; 00222 float * sar , * far ; 00223 int ii , nvox , rr,gg,bb ; 00224 float fac ; 00225 00226 ENTRY("mri_flatten_rgb") ; 00227 00228 if( im == NULL ) RETURN( NULL ); 00229 00230 if( im->kind != MRI_rgb ) RETURN( mri_flatten(im) ); 00231 00232 flim = mri_to_float( im ) ; /* intensity of input */ 00233 shim = mri_flatten( flim ) ; /* flatten intensity */ 00234 newim = mri_new_conforming( im , MRI_rgb ) ; /* will be output */ 00235 00236 nar = MRI_BYTE_PTR(newim) ; iar = MRI_BYTE_PTR(im) ; 00237 far = MRI_FLOAT_PTR(flim) ; sar = MRI_FLOAT_PTR(shim) ; 00238 nvox = newim->nvox ; 00239 00240 for( ii=0 ; ii < nvox ; ii++ ){ 00241 if( far[ii] <= 0.0 || sar[ii] <= 0.0 ){ 00242 nar[3*ii] = nar[3*ii+1] = nar[3*ii+2] = 0 ; 00243 } else { 00244 fac = 255.9 * sar[ii] / far[ii] ; /* will be positive */ 00245 rr = fac * iar[3*ii] ; 00246 gg = fac * iar[3*ii+1] ; 00247 bb = fac * iar[3*ii+2] ; 00248 nar[3*ii ] = (rr > 255) ? 255 : rr ; 00249 nar[3*ii+1] = (gg > 255) ? 255 : gg ; 00250 nar[3*ii+2] = (bb > 255) ? 255 : bb ; 00251 } 00252 } 00253 00254 mri_free(flim) ; mri_free(shim) ; 00255 00256 MRI_COPY_AUX(newim,im) ; 00257 RETURN( newim ); 00258 } |
|
Flip a 3D image. The (outx,outy,outz) parameters specify the direction of the output axes relative to the input axes:
If the input image doesn't have a data array, then the output image won't either. ------------------------------------------------------------------------ Definition at line 23 of file mri_flip3D.c. References abs, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, free, MRI_IMAGE::kind, mri_copy(), mri_data_pointer(), mri_fix_data_pointer(), mri_new_vol(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, MRI_IMAGE::pixel_size, and RETURN. Referenced by main(), and mri_brainormalize().
00024 { 00025 MRI_IMAGE *outim ; 00026 int ii,jj,kk , dsiz , nxin,nyin,nzin , nxout,nyout,nzout ; 00027 int nxyin , nxyout , ijk_out , ijk_in ; 00028 int ax,bx,cx,dx , ay,by,cy,dy , az,bz,cz,dz , aa,bb,cc,dd ; 00029 char *inar , *outar ; 00030 float delx,dely,delz ; 00031 00032 ENTRY("mri_flip3D") ; 00033 00034 /* check inputs for correctness */ 00035 00036 if( inim == NULL || outx == 0 || outy == 0 || outz == 0 ) RETURN( NULL ); 00037 ii = abs(outx) ; jj = abs(outy) ; kk = abs(outz) ; 00038 if( ii > 3 || jj > 3 || kk > 3 ) RETURN( NULL ); 00039 if( ii == jj || ii == kk || jj == kk ) RETURN( NULL ); 00040 if( ii+jj+kk != 6 ) RETURN( NULL ); 00041 00042 if( outx==1 && outy==2 && outz==3 ) RETURN( mri_copy(inim) ); /* easy case */ 00043 00044 nxin = inim->nx ; 00045 nyin = inim->ny ; nxyin = nxin*nyin ; 00046 nzin = inim->nz ; 00047 00048 /* setup so that i_out = ax + bx*i_in + cx*j_in + dx*k_in, 00049 for i_in=0..nxin-1, j_in=0..nyin-1, k_in=0..nzin-1, 00050 and then similarly for y and z axes */ 00051 00052 switch( outx ){ 00053 case 1: ax=0 ; bx= 1; cx= 0; dx= 0; nxout=nxin; delx=inim->dx; break; 00054 case -1: ax=nxin-1; bx=-1; cx= 0; dx= 0; nxout=nxin; delx=inim->dx; break; 00055 case 2: ax=0 ; bx= 0; cx= 1; dx= 0; nxout=nyin; delx=inim->dy; break; 00056 case -2: ax=nyin-1; bx= 0; cx=-1; dx= 0; nxout=nyin; delx=inim->dy; break; 00057 case 3: ax=0 ; bx= 0; cx= 0; dx= 1; nxout=nzin; delx=inim->dz; break; 00058 case -3: ax=nzin-1; bx= 0; cx= 0; dx=-1; nxout=nzin; delx=inim->dz; break; 00059 default: RETURN( NULL ); 00060 } 00061 switch( outy ){ 00062 case 1: ay=0 ; by= 1; cy= 0; dy= 0; nyout=nxin; dely=inim->dx; break; 00063 case -1: ay=nxin-1; by=-1; cy= 0; dy= 0; nyout=nxin; dely=inim->dx; break; 00064 case 2: ay=0 ; by= 0; cy= 1; dy= 0; nyout=nyin; dely=inim->dy; break; 00065 case -2: ay=nyin-1; by= 0; cy=-1; dy= 0; nyout=nyin; dely=inim->dy; break; 00066 case 3: ay=0 ; by= 0; cy= 0; dy= 1; nyout=nzin; dely=inim->dz; break; 00067 case -3: ay=nzin-1; by= 0; cy= 0; dy=-1; nyout=nzin; dely=inim->dz; break; 00068 default: RETURN( NULL ); 00069 } 00070 switch( outz ){ 00071 case 1: az=0 ; bz= 1; cz= 0; dz= 0; nzout=nxin; delz=inim->dx; break; 00072 case -1: az=nxin-1; bz=-1; cz= 0; dz= 0; nzout=nxin; delz=inim->dx; break; 00073 case 2: az=0 ; bz= 0; cz= 1; dz= 0; nzout=nyin; delz=inim->dy; break; 00074 case -2: az=nyin-1; bz= 0; cz=-1; dz= 0; nzout=nyin; delz=inim->dy; break; 00075 case 3: az=0 ; bz= 0; cz= 0; dz= 1; nzout=nzin; delz=inim->dz; break; 00076 case -3: az=nzin-1; bz= 0; cz= 0; dz=-1; nzout=nzin; delz=inim->dz; break; 00077 default: RETURN( NULL ); 00078 } 00079 nxyout = nxout*nyout ; 00080 00081 /* 3D index ijk_out = i_out + nxout*j_out + nxyout*k_out 00082 00083 = (ax + bx*i_in + cx*j_in + dx*k_in) 00084 +(ay + by*i_in + cy*j_in + dy*k_in)*nxout 00085 +(az + bz*i_in + cz*j_in + dz*k_in)*nxyout 00086 00087 = (ax+ay*nxout+az*nxyout) 00088 +(bx+by*nxout+bz*nxyout)*i_in 00089 +(cx+cy*nxout+cz*nxyout)*j_in 00090 +(dx+dy*nxout+dz*nxyout)*k_in 00091 00092 = aa + bb*i_in + cc*j_in + dd*k_in */ 00093 00094 inar = mri_data_pointer( inim ) ; 00095 outim = mri_new_vol( nxout,nyout,nzout , inim->kind ) ; 00096 00097 outim->dx = delx ; outim->dy = dely ; outim->dz = delz ; 00098 00099 outar = mri_data_pointer( outim ) ; 00100 00101 if( inar == NULL ){ /* empty input ==> empty output */ 00102 free(outar) ; mri_fix_data_pointer(NULL,outim ); RETURN(outim); 00103 } 00104 00105 dsiz = outim->pixel_size ; /* size of each voxel in bytes */ 00106 00107 aa = (ax+ay*nxout+az*nxyout)*dsiz ; /* same as aa, etc. in above */ 00108 bb = (bx+by*nxout+bz*nxyout)*dsiz ; /* comment, but scaled to be */ 00109 cc = (cx+cy*nxout+cz*nxyout)*dsiz ; /* address offset in bytes */ 00110 dd = (dx+dy*nxout+dz*nxyout)*dsiz ; 00111 00112 for( ijk_in=kk=0 ; kk < nzin ; kk++ ){ 00113 for( jj=0 ; jj < nyin ; jj++ ){ 00114 for( ii=0 ; ii < nxin ; ii++,ijk_in+=dsiz ){ 00115 ijk_out = aa + bb*ii + cc*jj + dd*kk ; 00116 memcpy( outar+ijk_out , inar+ijk_in , dsiz ) ; 00117 } 00118 } 00119 } 00120 00121 RETURN(outim) ; 00122 } |
|
Definition at line 19 of file mri_flippo.c. References MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, i1, i2, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COMPLEX_PTR, MRI_DOUBLE_PTR, MRI_FLOAT_PTR, MRI_INT_PTR, MRI_IS_2D, mri_new(), MRI_RGB_PTR, MRI_RGBA_PTR, MRI_SHORT_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, and s2. Referenced by AFNI_slice_flip(), ISQ_make_image(), ISQ_manufacture_one(), ISQ_process_mri(), ISQ_saver_CB(), main(), and plot_image_surface().
00020 { 00021 MRI_IMAGE * flim ; 00022 int nx,ny , fopt , nxout,nyout ; 00023 register int d1,d2,s1,s2,e1,e2,jb , i1,i2 ; 00024 float new_dx , new_dy ; 00025 00026 ENTRY("mri_flippo") ; 00027 /** sanity check **/ 00028 00029 if( im == NULL ) RETURN( NULL ); 00030 if( rot == MRI_ROT_0 && mirror == FALSE ) RETURN( im ); 00031 00032 if( ! MRI_IS_2D(im) ){ 00033 fprintf(stderr,"\n*** mri_flippo only works with 2D images!\n") ; 00034 RETURN( im ); 00035 } 00036 00037 nx = im->nx ; ny = im->ny ; 00038 new_dx = im->dx ; new_dy = im->dy ; 00039 00040 /* set the values to control the copy order: 00041 nxout = x dimen in output 00042 nyout = y dimen in output 00043 d1 = stepsize in original data in the new x direction 00044 d2 = stepsize in original data in the new y direction 00045 s1 = index in original data of new (0,0) point 00046 00047 also, flip the dimensions for the 90 and 270 rotates 00048 */ 00049 00050 fopt = (mirror) ? (rot+MRI_FLMADD) : (rot) ; 00051 switch( fopt ){ 00052 00053 default: RETURN(im); /* should not happen */ 00054 00055 case (MRI_ROT_90): /* ROT_90, no mirror */ 00056 nxout = ny ; nyout = nx ; 00057 d1 = nx ; s1 = nx-1 ; d2 = -1 ; new_dx = im->dy ; new_dy = im->dx ; 00058 break ; 00059 00060 case (MRI_ROT_180): /* ROT_180, no mirror */ 00061 nxout = nx ; nyout = ny ; 00062 d1 = -1 ; s1 = nx*ny-1 ; d2 = -nx ; 00063 break ; 00064 00065 case (MRI_ROT_270): /* ROT_270, no mirror */ 00066 nxout = ny ; nyout = nx ; 00067 d1 = -nx ; s1 = nx*(ny-1) ; d2 = 1 ; new_dx = im->dy ; new_dy = im->dx ; 00068 break ; 00069 00070 case (MRI_ROT_0+MRI_FLMADD): /* ROT_0, mirror */ 00071 nxout = nx ; nyout = ny ; 00072 d1 = -1 ; s1 = nx-1 ; d2 = nx ; 00073 break ; 00074 00075 case (MRI_ROT_90+MRI_FLMADD): /* ROT_90, mirror */ 00076 nxout = ny ; nyout = nx ; 00077 d1 = -nx ; s1 = nx*ny-1 ; d2 = -1 ; new_dx = im->dy ; new_dy = im->dx ; 00078 break ; 00079 00080 case (MRI_ROT_180+MRI_FLMADD): /* ROT_180, mirror */ 00081 nxout = nx ; nyout = ny ; 00082 d1 = 1 ; s1 = nx*(ny-1) ; d2 = -nx ; 00083 break ; 00084 00085 case (MRI_ROT_270+MRI_FLMADD): /* ROT_270, mirror */ 00086 nxout = ny ; nyout = nx ; 00087 d1 = nx ; s1 = 0 ; d2 = 1 ; new_dx = im->dy ; new_dy = im->dx ; 00088 break ; 00089 00090 } 00091 00092 flim = mri_new( nxout , nyout , im->kind ) ; 00093 00094 jb = 0 ; 00095 s2 = 0 ; 00096 e1 = s1 + nxout * d1 ; 00097 e2 = s2 + nyout * d2 ; 00098 00099 switch( im->kind ){ 00100 00101 case MRI_byte:{ 00102 register byte * inar = MRI_BYTE_PTR(im) ; 00103 register byte * flar = MRI_BYTE_PTR(flim) ; 00104 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00105 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ; 00106 } 00107 break ; 00108 00109 case MRI_rgb:{ /* 11 Feb 1999 */ 00110 register byte * inar = MRI_RGB_PTR(im) ; 00111 register byte * flar = MRI_RGB_PTR(flim) ; 00112 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00113 for( i1=s1 ; i1 != e1 ; i1 += d1 ){ 00114 flar[jb++] = inar[3*(i2+i1) ] ; 00115 flar[jb++] = inar[3*(i2+i1)+1] ; 00116 flar[jb++] = inar[3*(i2+i1)+2] ; 00117 } 00118 } 00119 break ; 00120 00121 case MRI_short:{ 00122 register short * inar = MRI_SHORT_PTR(im) ; 00123 register short * flar = MRI_SHORT_PTR(flim) ; 00124 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00125 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ; 00126 } 00127 break ; 00128 00129 case MRI_int:{ 00130 register int * inar = MRI_INT_PTR(im) ; 00131 register int * flar = MRI_INT_PTR(flim) ; 00132 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00133 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ; 00134 } 00135 break ; 00136 00137 case MRI_rgba:{ 00138 register rgba * inar = MRI_RGBA_PTR(im) ; 00139 register rgba * flar = MRI_RGBA_PTR(flim) ; 00140 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00141 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ; 00142 } 00143 break ; 00144 00145 case MRI_float:{ 00146 register float * inar = MRI_FLOAT_PTR(im) ; 00147 register float * flar = MRI_FLOAT_PTR(flim) ; 00148 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00149 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ; 00150 } 00151 break ; 00152 00153 case MRI_double:{ 00154 register double * inar = MRI_DOUBLE_PTR(im) ; 00155 register double * flar = MRI_DOUBLE_PTR(flim) ; 00156 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00157 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ; 00158 } 00159 break ; 00160 00161 case MRI_complex:{ 00162 register complex * inar = MRI_COMPLEX_PTR(im) ; 00163 register complex * flar = MRI_COMPLEX_PTR(flim) ; 00164 for( i2=s2 ; i2 != e2 ; i2 += d2 ) 00165 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ; 00166 } 00167 break ; 00168 00169 } 00170 00171 flim->dx = new_dx ; flim->dy = new_dy ; flim->dz = im->dz ; 00172 RETURN( flim ) ; 00173 } |
|
Definition at line 13 of file mri_float_func.c. References func, mri_data_pointer(), and mri_new().
00017 { 00018 int ii , jj , jpos ; 00019 float yy ; 00020 MRI_IMAGE * im ; 00021 float * flim ; 00022 00023 im = mri_new( nx ,ny , MRI_float ) ; 00024 flim = mri_data_pointer( im ) ; 00025 00026 for( jj=0 ; jj < ny ; jj++ ){ 00027 jpos = nx * jj ; 00028 yy = yzero + jj * dy ; 00029 for( ii=0 ; ii < nx ; ii++ ){ 00030 flim[ii+jpos] = func( xzero + ii*dx , yy ) ; 00031 } 00032 } 00033 00034 return im ; 00035 } |
|
|
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, MRI_IMAGE::nz, and 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 } |
|
int hist[256] * Definition at line 13 of file mri_histobyte.c. References ENTRY, MRI_IMAGE::kind, MRI_BYTE_PTR, and MRI_IMAGE::nvox. Referenced by main(), RCREND_reload_dataset(), and REND_reload_dataset().
00014 { 00015 register int ih , npix , ii ; 00016 byte * bar ; 00017 00018 ENTRY("mri_histobyte") ; 00019 00020 if( im == NULL || im->kind != MRI_byte || hist == NULL ) EXRETURN ; 00021 00022 npix = im->nvox ; 00023 bar = MRI_BYTE_PTR(im) ; 00024 00025 for( ih=0 ; ih < 256 ; ih++ ) hist[ih] = 0 ; 00026 00027 for( ii=0 ; ii < npix ; ii++ ) 00028 hist[ bar[ii] ] ++ ; 00029 00030 EXRETURN ; 00031 } |
|
Definition at line 11 of file mri_histog.c. References ENTRY, MRI_IMAGE::kind, mri_data_pointer(), mri_free(), mri_to_float(), mri_to_short(), and MRI_IMAGE::nvox. Referenced by BFIT_compute(), BFIT_main(), CORREL_main(), HISTO_main(), ISQ_process_mri(), ISQ_statify_one(), RCREND_reload_dataset(), and REND_reload_dataset().
00013 { 00014 register int ih , npix , ii ; 00015 register float sbin ; 00016 MRI_IMAGE * lim ; 00017 00018 ENTRY("mri_histogram") ; 00019 00020 if( im == NULL || htop <= hbot || nbin < 2 ) EXRETURN ; 00021 00022 /* can handle shorts and floats; all else -> convert to float */ 00023 00024 switch( im->kind ){ 00025 00026 default: lim = mri_to_float(im) ; break ; 00027 00028 case MRI_byte: lim = mri_to_short(1.0,im) ; break ; 00029 00030 case MRI_short: 00031 case MRI_float: lim = im ; break ; 00032 } 00033 00034 npix = lim->nvox ; 00035 sbin = 0.999999 * nbin / (htop-hbot) ; 00036 00037 if( initialize ) for( ih=0 ; ih < nbin ; ih++ ) hist[ih] = 0 ; 00038 00039 switch( lim->kind ){ 00040 00041 case MRI_short:{ 00042 register short * shar = mri_data_pointer(lim) ; 00043 00044 for( ii=0 ; ii < npix ; ii++ ){ 00045 ih = sbin * (shar[ii]-hbot) ; 00046 if( ih >=0 && ih < nbin ) hist[ih]++ ; 00047 } 00048 } 00049 break ; 00050 00051 case MRI_float:{ 00052 register float * flar = mri_data_pointer(lim) ; 00053 00054 for( ii=0 ; ii < npix ; ii++ ){ 00055 ih = sbin * (flar[ii]-hbot) ; 00056 if( ih >=0 && ih < nbin ) hist[ih]++ ; 00057 } 00058 } 00059 break ; 00060 } 00061 00062 if( lim != im ) mri_free( lim ) ; /* toss temporary array */ 00063 EXRETURN ; 00064 } |
|
Definition at line 10 of file mri_histoshort.c. References ENTRY, MRI_IMAGE::kind, MRI_SHORT_PTR, NUM_SHORT, MRI_IMAGE::nvox, and OFF_SHORT.
00011 { 00012 register int ih , npix , ii ; 00013 short * sar ; 00014 00015 ENTRY("mri_histoshort_all") ; 00016 00017 if( im == NULL || im->kind != MRI_short || hist == NULL ) EXRETURN ; 00018 00019 npix = im->nvox ; 00020 sar = MRI_SHORT_PTR(im) ; 00021 00022 for( ih=0 ; ih < NUM_SHORT ; ih++ ) hist[ih] = 0 ; 00023 00024 for( ii=0 ; ii < npix ; ii++ ) 00025 hist[ sar[ii]+OFF_SHORT ] ++ ; 00026 00027 EXRETURN ; 00028 } |
|
Definition at line 32 of file mri_histoshort.c. References ENTRY, MRI_IMAGE::kind, MRI_SHORT_PTR, MRI_IMAGE::nvox, and OFF_SHORT.
00033 { 00034 register int ih , npix , ii ; 00035 short * sar ; 00036 00037 ENTRY("mri_histoshort_nonneg") ; 00038 00039 if( im == NULL || im->kind != MRI_short || hist == NULL ) EXRETURN ; 00040 00041 npix = im->nvox ; 00042 sar = MRI_SHORT_PTR(im) ; 00043 00044 for( ih=0 ; ih < OFF_SHORT ; ih++ ) hist[ih] = 0 ; 00045 00046 for( ii=0 ; ii < npix ; ii++ ) 00047 if( sar[ii] >= 0 ) hist[ sar[ii] ] ++ ; 00048 00049 EXRETURN ; 00050 } |
|
Definition at line 1198 of file mri_read.c. References ENTRY, free, imsized_fname(), mri_dicom_seterr(), mri_imcount_analyze75(), mri_imcount_dicom(), mri_imcount_mpeg(), mri_imcount_siemens(), nz, and RETURN. Referenced by AFNI_read_images(), and T3D_read_images().
01199 { 01200 int hglobal , himage , nx , ny , nz , ngood ; 01201 char fname[256]="\0" ; 01202 char * new_fname ; 01203 01204 ENTRY("mri_imcount") ; 01205 01206 if( tname == NULL ) RETURN( 0 ); 01207 new_fname = imsized_fname( tname ) ; 01208 if( new_fname == NULL ) RETURN( 0 ); 01209 01210 /*** a 3D filename ***/ 01211 01212 if( strlen(new_fname) > 9 && new_fname[0] == '3' && new_fname[1] == 'D' && 01213 (new_fname[2] == ':' || new_fname[3] == ':') ){ 01214 /* check for ':', too 3 Jan 2005 [rickr] */ 01215 switch( new_fname[2] ){ 01216 01217 default: 01218 case ':': 01219 ngood = sscanf( new_fname , "3D:%d:%d:%d:%d:%d:%s" , 01220 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01221 break ; 01222 01223 case 's': 01224 ngood = sscanf( new_fname , "3Ds:%d:%d:%d:%d:%d:%s" , 01225 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01226 break ; 01227 01228 case 'b': 01229 ngood = sscanf( new_fname , "3Db:%d:%d:%d:%d:%d:%s" , 01230 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01231 break ; 01232 01233 case 'f': 01234 ngood = sscanf( new_fname , "3Df:%d:%d:%d:%d:%d:%s" , 01235 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01236 break ; 01237 01238 case 'd': /* 06 Feb 2003 */ 01239 ngood = sscanf( new_fname , "3Dd:%d:%d:%d:%d:%d:%s" , 01240 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01241 break ; 01242 01243 case 'i': 01244 ngood = sscanf( new_fname , "3Di:%d:%d:%d:%d:%d:%s" , 01245 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01246 break ; 01247 01248 case 'c': 01249 ngood = sscanf( new_fname , "3Dc:%d:%d:%d:%d:%d:%s" , 01250 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01251 break ; 01252 01253 case 'r': 01254 ngood = sscanf( new_fname , "3Dr:%d:%d:%d:%d:%d:%s" , 01255 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 01256 break ; 01257 } 01258 01259 free( new_fname ) ; 01260 if( ngood < 6 || himage < 0 || 01261 nx <= 0 || ny <= 0 || nz <= 0 || 01262 strlen(fname) <= 0 ) RETURN( 0 ); 01263 else RETURN( nz ); 01264 } 01265 01266 /*** a 3A filename ***/ 01267 01268 if( strlen(new_fname) > 9 && 01269 new_fname[0] == '3' && new_fname[1] == 'A' && new_fname[3] == ':' ){ 01270 01271 switch( new_fname[2] ){ 01272 01273 default: ngood = 0 ; break ; 01274 01275 case 's': 01276 ngood = sscanf( new_fname, "3As:%d:%d:%d:%s", &nx, &ny, &nz, fname ) ; 01277 break ; 01278 01279 case 'b': 01280 ngood = sscanf( new_fname, "3Ab:%d:%d:%d:%s", &nx, &ny, &nz, fname ) ; 01281 break ; 01282 01283 case 'f': 01284 ngood = sscanf( new_fname, "3Af:%d:%d:%d:%s", &nx, &ny, &nz, fname ) ; 01285 break ; 01286 } 01287 01288 free( new_fname ) ; 01289 if( ngood < 4 || nx <= 0 || ny <= 0 || nz <= 0 || strlen(fname) <= 0 ) RETURN( 0 ); 01290 else RETURN( nz ); 01291 } 01292 01293 /*** 05 Feb 2001: deal with ANALYZE .hdr files ***/ 01294 01295 if( strstr(new_fname,".hdr") != NULL || 01296 strstr(new_fname,".HDR") != NULL ){ 01297 01298 nz = mri_imcount_analyze75( new_fname ) ; 01299 if( nz > 0 ){ free(new_fname); RETURN(nz); } 01300 } 01301 01302 if( strstr(new_fname,".ima") != NULL || 01303 strstr(new_fname,".IMA") != NULL ){ /* 12 Mar 2001 */ 01304 01305 nz = mri_imcount_siemens( new_fname ) ; 01306 if( nz > 0 ){ free(new_fname); RETURN(nz); } 01307 } 01308 01309 if( strstr(new_fname,".mpg" ) != NULL || /* 03 Dec 2003 */ 01310 strstr(new_fname,".MPG" ) != NULL || 01311 strstr(new_fname,".mpeg") != NULL || 01312 strstr(new_fname,".MPEG") != NULL ){ 01313 01314 nz = mri_imcount_mpeg( new_fname ) ; 01315 if( nz > 0 ){ free(new_fname); RETURN(nz); } 01316 } 01317 01318 /*** 19 Jul 2002: see if it is a DICOM file ***/ 01319 01320 mri_dicom_seterr(0) ; 01321 nz = mri_imcount_dicom( new_fname ) ; /* cf. mri_read_dicom.c */ 01322 mri_dicom_seterr(1) ; 01323 if( nz > 0 ){ free(new_fname); RETURN(nz); } 01324 01325 /*** not recognized ***/ 01326 01327 free(new_fname) ; RETURN(1) ; /* assume it has 1 image in it, somewhere */ 01328 } |
|
Count images in a DICOM file, if possible. -------------------------------------------------------------------------------- Definition at line 1146 of file mri_read_dicom.c. References AFMALL, E_BITS_ALLOCATED, E_COLUMNS, E_ID_IMAGE_TYPE, E_ID_MANUFACTURER, E_NUMBER_OF_FRAMES, E_PHOTOMETRIC_INTERPRETATION, E_ROWS, E_SAMPLES_PER_PIXEL, E_SIEMENS_2, elist, ENTRY, extract_bytes_from_file(), free, get_siemens_extra_info(), Siemens_extra_info::good, Siemens_extra_info::mosaic_num, mri_dicom_header(), mri_dicom_nohex(), mri_dicom_noname(), mri_dicom_pxlarr(), mri_possibly_dicom(), NUM_ELIST, nz, RETURN, str_sexinfo, and THD_filesize(). Referenced by main(), and mri_imcount().
01147 { 01148 char *ppp , *ddd ; 01149 off_t poff ; 01150 unsigned int plen ; 01151 char *epos[NUM_ELIST] ; 01152 int ii , ee , bpp , datum ; 01153 int nx,ny,nz ; 01154 01155 int mosaic=0 , mos_nx,mos_ny , mos_ix,mos_iy,mos_nz ; /* 28 Oct 2002 */ 01156 Siemens_extra_info sexinfo ; /* 02 Dec 2002 */ 01157 01158 char *sexi_start; /* KRH 25 Jul 2003 */ 01159 char *sexi_end; 01160 01161 ENTRY("mri_imcount_dicom") ; 01162 01163 if( str_sexinfo != NULL ){ free(str_sexinfo); str_sexinfo=NULL; } 01164 01165 if( !mri_possibly_dicom(fname) ) RETURN(0) ; /* 07 May 2003 */ 01166 01167 /* extract the header from the file (cf. mri_dicom_hdr.[ch]) */ 01168 01169 mri_dicom_nohex(1) ; mri_dicom_noname(1) ; 01170 ppp = mri_dicom_header( fname ) ; 01171 if( ppp == NULL ) RETURN(0); 01172 01173 /* find out where the pixel array is in the file */ 01174 01175 mri_dicom_pxlarr( &poff , &plen ) ; 01176 if( plen <= 0 ){ free(ppp) ; RETURN(0); } 01177 01178 /* check if file is actually this big */ 01179 01180 { unsigned int psiz , fsiz ; 01181 fsiz = THD_filesize( fname ) ; 01182 psiz = (unsigned int)(poff) + plen ; 01183 if( fsiz < psiz ){ free(ppp) ; RETURN(0); } 01184 } 01185 01186 /* find positions in header of elements we care about */ 01187 01188 for( ee=0 ; ee < NUM_ELIST ; ee++ ) 01189 epos[ee] = strstr(ppp,elist[ee]) ; 01190 01191 /* see if the header has the elements we absolutely need */ 01192 01193 if( epos[E_ROWS] == NULL || 01194 epos[E_COLUMNS] == NULL || 01195 epos[E_BITS_ALLOCATED] == NULL ){ free(ppp) ; RETURN(0); } 01196 01197 /* check if we have 1 sample per pixel (can't deal with 3 or 4 now) */ 01198 01199 if( epos[E_SAMPLES_PER_PIXEL] != NULL ){ 01200 ddd = strstr(epos[E_SAMPLES_PER_PIXEL],"//") ; 01201 if( ddd == NULL ){ free(ppp) ; RETURN(0); } 01202 ii = 0 ; sscanf(ddd+2,"%d",&ii) ; 01203 if( ii != 1 ){ free(ppp) ; RETURN(0); } 01204 } 01205 01206 /* check if photometric interpretation is MONOCHROME (don't like PALETTE) */ 01207 01208 if( epos[E_PHOTOMETRIC_INTERPRETATION] != NULL ){ 01209 ddd = strstr(epos[E_PHOTOMETRIC_INTERPRETATION],"MONOCHROME") ; 01210 if( ddd == NULL ){ free(ppp) ; RETURN(0); } 01211 } 01212 01213 /* check if we have 8, 16, or 32 bits per pixel */ 01214 01215 ddd = strstr(epos[E_BITS_ALLOCATED],"//") ; 01216 if( ddd == NULL ){ free(ppp); RETURN(0); } 01217 bpp = 0 ; sscanf(ddd+2,"%d",&bpp) ; 01218 switch( bpp ){ 01219 default: free(ppp) ; RETURN(0); /* bad value */ 01220 case 8: datum = MRI_byte ; break ; 01221 case 16: datum = MRI_short; break ; 01222 case 32: datum = MRI_int ; break ; 01223 } 01224 bpp /= 8 ; /* now bytes per pixel, instead of bits */ 01225 01226 /* get nx, ny, nz */ 01227 01228 ddd = strstr(epos[E_ROWS],"//") ; 01229 if( ddd == NULL ){ free(ppp) ; RETURN(0); } 01230 nx = 0 ; sscanf(ddd+2,"%d",&nx) ; 01231 if( nx < 2 ){ free(ppp) ; RETURN(0); } 01232 01233 ddd = strstr(epos[E_COLUMNS],"//") ; 01234 if( ddd == NULL ){ free(ppp) ; RETURN(0); } 01235 ny = 0 ; sscanf(ddd+2,"%d",&ny) ; 01236 if( ny < 2 ){ free(ppp) ; RETURN(0); } 01237 01238 nz = 0 ; 01239 if( epos[E_NUMBER_OF_FRAMES] != NULL ){ 01240 ddd = strstr(epos[E_NUMBER_OF_FRAMES],"//") ; 01241 if( ddd != NULL ) sscanf(ddd+2,"%d",&nz) ; 01242 } 01243 if( nz == 0 ) nz = plen / (bpp*nx*ny) ; 01244 01245 /*-- 28 Oct 2002: Check if this is a Siemens mosaic. --*/ 01246 /*-- 02 Dec 2002: Don't use Acquisition Matrix anymore; 01247 instead, use the Siemens extra info 01248 in epos[E_SIEMENS_2]. --*/ 01249 /*-- 24 Dec 2002: Extract str_sexinfo even if not a mosaic. --*/ 01250 01251 if( epos[E_ID_MANUFACTURER] != NULL && 01252 strstr(epos[E_ID_MANUFACTURER],"SIEMENS") != NULL && 01253 epos[E_SIEMENS_2] != NULL ){ 01254 01255 int len=0,loc=0 , aa,bb ; 01256 sscanf(epos[E_SIEMENS_2],"%x%x%d [%d" , &aa,&bb , &len,&loc ) ; 01257 if( len > 0 && loc > 0 ){ 01258 FILE *fp = fopen( fname , "rb" ) ; 01259 if( fp != NULL ){ 01260 str_sexinfo = extract_bytes_from_file( fp, (off_t)loc, (size_t)len, 1 ) ; 01261 fclose(fp) ; 01262 } 01263 } 01264 } 01265 01266 if( epos[E_ID_IMAGE_TYPE] != NULL && 01267 strstr(epos[E_ID_IMAGE_TYPE],"MOSAIC") != NULL && 01268 str_sexinfo != NULL ){ 01269 01270 /* 31 Oct 2002: extract extra Siemens info from file */ 01271 01272 /* KRH 25 Jul 2003 if start and end markers are present for 01273 * Siemens extra info, cut string down to those boundaries */ 01274 01275 sexi_start = strstr(str_sexinfo, "### ASCCONV BEGIN ###"); 01276 sexi_end = strstr(str_sexinfo, "### ASCCONV END ###"); 01277 if ((sexi_start != NULL) && (sexi_end != NULL)) { 01278 char *sexi_tmp; 01279 int sexi_size; 01280 01281 sexi_size = sexi_end - sexi_start + 19 ; 01282 sexi_tmp = AFMALL( char, sexi_size ); 01283 memcpy(sexi_tmp,sexi_start,sexi_size); 01284 free(str_sexinfo); 01285 str_sexinfo = sexi_tmp; 01286 } 01287 /* end KRH 25 Jul 2003 change */ 01288 01289 sexinfo.good = 0 ; /* start by marking it as bad */ 01290 get_siemens_extra_info( str_sexinfo , &sexinfo ) ; 01291 01292 if( sexinfo.good ){ /* if data is good */ 01293 01294 nz = sexinfo.mosaic_num ; 01295 01296 } /* end of if sexinfo was good */ 01297 01298 else { /* warn if sexinfo was bad */ 01299 static int nwarn=0 ; 01300 if( nwarn < NWMAX ) 01301 fprintf(stderr,"++ DICOM WARNING: indecipherable SIEMENS MOSAIC info (%s) in file %s\n", 01302 elist[E_SIEMENS_2] , fname ) ; 01303 if( nwarn == NWMAX ) 01304 fprintf(stderr,"++ DICOM NOTICE: no more SIEMENS MOSAIC info messages will be printed\n"); 01305 nwarn++ ; 01306 } 01307 01308 } /* end of if a Siemens mosaic */ 01309 01310 free(ppp) ; RETURN(nz); 01311 } |
|
Count number of images in an MPEG file. Must have program mpegtoppm in the path. [03 Dec 2003] Definition at line 112 of file mri_read_mpeg.c. References AFMALL, ENTRY, free, mpeg_filter, mpeg_setup(), mri_filesize(), RETURN, THD_is_directory(), THD_mkdir(), and tmpdir. Referenced by mri_imcount().
00113 { 00114 char *pg , **ff , *fn ; 00115 int ii , nf=0 ; 00116 FILE *fp ; 00117 00118 ENTRY("mri_imcount_mpeg") ; 00119 00120 /*--- check input for OK-ness ---*/ 00121 00122 if( fname == NULL || *fname == '\0' ) RETURN( 0 ); 00123 ii = mri_filesize(fname) ; 00124 if( ii <= 0 ) RETURN( 0 ); 00125 00126 mpeg_setup() ; 00127 00128 if( mpeg_filter == NULL ) RETURN( 0 ); /* can't filter? */ 00129 00130 /*--- create the filter for this file and run it to create .ppm files ---*/ 00131 00132 pg = AFMALL( char, strlen(fname)+strlen(mpeg_filter)+64) ; /* string to hold filter */ 00133 fn = AFMALL( char, strlen(fname)+32) ; 00134 sprintf(fn,"-count %s",fname) ; 00135 sprintf( pg , mpeg_filter , fn ) ; 00136 free(fn) ; 00137 THD_mkdir( tmpdir ) ; /* create the temp directory */ 00138 if( !THD_is_directory(tmpdir) ){ free(pg); RETURN(0); } /* can't? */ 00139 00140 system( pg ) ; /* run the command */ 00141 00142 /*-- open the COUNT file in the temp directory --*/ 00143 00144 sprintf( pg , "%sCOUNT" , tmpdir ) ; 00145 fp = fopen(pg,"rb") ; 00146 if( fp != NULL ){ fscanf(fp,"%d",&nf); fclose(fp); remove(pg); } 00147 remove( tmpdir ) ; free(pg) ; 00148 RETURN( nf ); 00149 } |
|
Inflate data from PBM to PGM, in place. ---------------------------------------------------------------------------- Definition at line 234 of file mri_read_stuff.c. References ENTRY, MRI_IMAGE::kind, MRI_BYTE_PTR, mri_free(), mri_new(), MRI_IMAGE::nx, and MRI_IMAGE::ny. Referenced by mri_read_stuff().
00235 { 00236 MRI_IMAGE *qim ; 00237 byte *qimar , *imar ; 00238 int ii,jj , nx,ny , nbrow , i8 ; 00239 byte bmask[8] = { 1<<7 , 1<<6 , 1<<5 , 1<<4 , 1<<3 , 1<<2 , 1<<1 , 1 } ; 00240 00241 ENTRY("mri_inflate_pbm") ; 00242 00243 if( im == NULL || im->kind != MRI_byte ) EXRETURN ; 00244 00245 nx = im->nx ; ny = im->ny ; 00246 qim = mri_new( nx , ny , MRI_byte ) ; 00247 qimar = MRI_BYTE_PTR(qim) ; 00248 imar = MRI_BYTE_PTR(im) ; 00249 00250 nbrow = nx/8 ; if( 8*nbrow < nx ) nbrow++ ; 00251 00252 for( jj=0 ; jj < ny ; jj++ ) 00253 for( ii=0 ; ii < nx ; ii++ ){ 00254 i8 = ii >> 3 ; 00255 qimar[ii+jj*nx] = ( imar[(i8)+jj*nbrow] & bmask[ii&7] ) != 0 ; 00256 } 00257 00258 memcpy( imar , qimar , nx*ny ) ; mri_free( qim ) ; 00259 EXRETURN ; 00260 } |
|
mark as set for delay input * Definition at line 3165 of file mri_read.c. References MRI_IMAGE::fname, MRI_IMAGE::foffset, MRI_IMAGE::fondisk, malloc, mri_fix_data_pointer(), mri_swapbytes(), MRI_IMAGE::nvox, MRI_IMAGE::pixel_size, SEEK_SET, and MRI_IMAGE::was_swapped. Referenced by mri_data_pointer().
03166 { 03167 FILE * imfile=NULL ; 03168 void * imar ; 03169 03170 /** if no delay input file, 03171 or is marked as already read in, do nothing **/ 03172 03173 if( im->fname == NULL || 03174 (im->fondisk & INPUT_DELAY) == 0 ) return ; 03175 03176 /** open the delay input file [06 Mar 2001: maybe not] **/ 03177 03178 if( strcmp(im->fname,"ALLZERO") != 0 ){ 03179 imfile = fopen( im->fname , "r" ) ; 03180 if( imfile == NULL ){ 03181 fprintf( stderr , "couldn't open delayed image file %s\n" , im->fname ) ; 03182 return ; 03183 } 03184 } 03185 03186 /** make space for the array **/ 03187 03188 imar = (void *) malloc( im->nvox * im->pixel_size ) ; 03189 if( imar == NULL ){ 03190 fprintf( stderr , 03191 "malloc fails for delayed image from file %s\n" , im->fname ) ; 03192 if( imfile != NULL ) fclose( imfile ) ; 03193 return ; 03194 } 03195 mri_fix_data_pointer( imar , im ) ; 03196 03197 /** read from the file into the array **/ 03198 03199 if( imfile != NULL ){ 03200 fseek( imfile , im->foffset , SEEK_SET ) ; 03201 fread( imar , im->pixel_size , im->nvox , imfile ) ; 03202 fclose( imfile ) ; 03203 } else { 03204 memset( imar , 0 , im->nvox * im->pixel_size ) ; /* 06 Mar 2001 */ 03205 } 03206 03207 /** swap bytes, if so marked **/ 03208 03209 if( (im->fondisk & BSWAP_DELAY) ){ 03210 mri_swapbytes( im ) ; 03211 im->was_swapped = 1 ; /* 07 Mar 2002 */ 03212 } 03213 03214 /** mark as already read from disk **/ 03215 03216 im->fondisk ^= INPUT_DELAY ; 03217 03218 #if 0 03219 fprintf(stderr,"delayed input from file %s at offset %d\n",im->fname,im->foffset); 03220 #endif 03221 return ; 03222 } |
|
Definition at line 25 of file mri_order.c.
00026 { 00027 union { unsigned char bb[4] ; 00028 int ii ; } fred ; 00029 00030 fred.bb[0] = 1 ; fred.bb[1] = fred.bb[2] = fred.bb[3] = 0 ; 00031 00032 return (fred.ii == 1) ? LSB_FIRST : MSB_FIRST ; 00033 } |
|
Definition at line 262 of file mri_to_rgb.c. References ENTRY, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_RGB_PTR, and MRI_IMAGE::nvox. Referenced by AFNI_splashup().
00263 { 00264 register byte *bar ; 00265 register int ii , nbar ; 00266 00267 ENTRY("mri_invert_inplace") ; 00268 00269 if( im == NULL ) EXRETURN ; 00270 switch( im->kind ){ 00271 default: EXRETURN ; 00272 case MRI_byte: nbar = im->nvox ; bar = MRI_BYTE_PTR(im) ; break ; 00273 case MRI_rgb: nbar = 3*im->nvox ; bar = MRI_RGB_PTR(im) ; break ; 00274 } 00275 for( ii=0 ; ii < nbar ; ii++ ) bar[ii] = 255 - bar[ii] ; 00276 EXRETURN ; 00277 } |
|
Returns 1 if the image is RGB and R=G=B for all voxels, otherwise returns 0. [03 Dec 2003] Definition at line 6 of file mri_isgray.c. References ENTRY, MRI_IMAGE::kind, MRI_RGB_PTR, MRI_IMAGE::nvox, and RETURN. Referenced by mri_read_mpeg().
00007 { 00008 register int nvox , ii ; 00009 register byte *bar ; 00010 00011 ENTRY("mri_isgray") ; 00012 00013 if( im == NULL || im->kind != MRI_rgb ) RETURN( 0 ); 00014 00015 nvox = im->nvox ; 00016 bar = MRI_RGB_PTR(im) ; 00017 for( ii=0 ; ii < nvox ; ii++ ) 00018 if( bar[3*ii] != bar[3*ii+1] || 00019 bar[3*ii] != bar[3*ii+2] ) RETURN( 0 ); 00020 00021 RETURN( 1 ) ; 00022 } |
|
Definition at line 18 of file mri_lsqfit.c. References ADDTO_IMARR, ENTRY, fit, free, FREE_IMARR, MRI_IMARR::imarr, INIT_IMARR, MRI_IMAGE::kind, lsqfit(), malloc, mri_data_pointer(), mri_free(), mri_to_float(), MRI_IMARR::num, MRI_IMAGE::nvox, and RETURN. Referenced by main(), and mri_align_dfspace().
00019 { 00020 float *fit = NULL ; /* will be the output */ 00021 MRI_IMAGE *ffitim , *tim , *wim ; /* local versions of inputs */ 00022 MRI_IMARR *frefim ; 00023 00024 int ii , jj , npix,nref ; 00025 float **refar , *fitar , *war ; 00026 00027 ENTRY("mri_lsqfit") ; 00028 00029 /****---- check inputs, convert to float type if needed ----****/ 00030 00031 if( fitim == NULL ){ 00032 fprintf(stderr,"mri_lsqfit: NULL fitim!\a\n"); RETURN(NULL); 00033 } 00034 00035 if( fitim->kind == MRI_float ) ffitim = fitim ; 00036 else ffitim = mri_to_float( fitim ) ; 00037 npix = ffitim->nvox ; 00038 fitar = mri_data_pointer(ffitim) ; 00039 00040 if( wtim == NULL ){ 00041 wim = NULL ; 00042 war = NULL ; 00043 } else if( wtim->kind == MRI_float ){ 00044 wim = wtim ; 00045 war = mri_data_pointer( wim ) ; 00046 if( wim->nvox != npix ){ 00047 fprintf(stderr,"mri_lsqfit: MISMATCH wtim\a\n"); RETURN(NULL); 00048 } 00049 } else { 00050 wim = mri_to_float( wtim ) ; 00051 war = mri_data_pointer( wim ) ; 00052 if( wim->nvox != npix ){ 00053 fprintf(stderr,"mri_lsqfit: MISMATCH wtim\a\n"); RETURN(NULL); 00054 } 00055 } 00056 00057 if( refim == NULL || refim->num < 1 ){ 00058 fprintf(stderr,"mri_lsqfit: NULL refim!\a\n"); RETURN(NULL); 00059 } 00060 00061 nref = refim->num ; 00062 00063 INIT_IMARR(frefim) ; 00064 refar = (float **) malloc( sizeof(float *) * nref ) ; 00065 if( refar == NULL ){ 00066 fprintf(stderr,"mri_lsqfit: malloc failure for refar!\a\n"); RETURN(NULL); 00067 } 00068 00069 for( ii=0 ; ii < nref ; ii++ ){ 00070 if( refim->imarr[ii] == NULL ){ 00071 fprintf(stderr,"mri_lsqfit: NULL refim[%d]!\a\n",ii); RETURN(NULL); 00072 } 00073 if( refim->imarr[ii]->nvox != npix ){ 00074 fprintf(stderr,"mri_lsqfit: MISMATCH refim[%d]!\a\n",ii); RETURN(NULL); 00075 } 00076 if( refim->imarr[ii]->kind == MRI_float ) tim = refim->imarr[ii] ; 00077 else tim = mri_to_float(refim->imarr[ii]) ; 00078 ADDTO_IMARR(frefim,tim) ; 00079 refar[ii] = mri_data_pointer(tim) ; 00080 } 00081 00082 /****---- get coefficients ----****/ 00083 00084 fit = lsqfit( npix , fitar , war , nref , refar ) ; 00085 00086 /****---- clean up and exit ----****/ 00087 00088 if( ffitim != fitim ) mri_free( ffitim ) ; 00089 if( wim != NULL && wim != wtim ) mri_free( wim ) ; 00090 for( ii=0 ; ii < nref ; ii++ ){ 00091 if( frefim->imarr[ii] != refim->imarr[ii] ) mri_free( frefim->imarr[ii] ) ; 00092 } 00093 FREE_IMARR(frefim) ; 00094 free(refar) ; 00095 00096 RETURN(fit) ; 00097 } |
|
Definition at line 12 of file mri_max.c. References MRI_DATA::byte_data, MRI_DATA::complex_data, CSQR, MRI_DATA::double_data, double_max, MRI_DATA::float_data, float_max, MRI_IMAGE::im, MRI_DATA::int_data, int_max, MRI_IMAGE::kind, MAX, MRI_IMAGE::nvox, MRI_DATA::rgb_data, MRI_DATA::short_data, short_max, and top. Referenced by HISTO_main(), ISQ_process_mri(), ISQ_statify_one(), main(), mri_3dalign_one(), mri_3dalign_setup(), mri_align_crao(), mri_dup2D(), mri_edit_image(), mri_maxabs(), mri_quantile(), mri_rgb_transform_nD(), mri_sharpen(), mri_to_byte(), mri_to_byte_scl(), mri_to_mri(), mri_to_short_sclip(), mri_warp3D_align_setup(), mri_write_analyze(), T3D_read_images(), and write_images().
00013 { 00014 register int ii , npix ; 00015 byte byte_max = 0 ; 00016 short short_max = -32767 ; /* 23 Oct 1998: changed from 0 */ 00017 int int_max = -2147483647 ; /* ditto */ 00018 float float_max = -1.e+38 ; /* changed from -9999999.0 */ 00019 double double_max = -1.e+38 ; /* ditto */ 00020 00021 npix = im->nvox ; 00022 00023 switch( im->kind ){ 00024 00025 case MRI_byte: 00026 for( ii=0 ; ii < npix ; ii++ ) 00027 byte_max = MAX( byte_max , im->im.byte_data[ii] ) ; 00028 return (double) byte_max ; 00029 00030 case MRI_short: 00031 for( ii=0 ; ii < npix ; ii++ ) 00032 short_max = MAX( short_max , im->im.short_data[ii] ) ; 00033 return (double) short_max ; 00034 00035 case MRI_int: 00036 for( ii=0 ; ii < npix ; ii++ ) 00037 int_max = MAX( int_max , im->im.int_data[ii] ) ; 00038 return (double) int_max ; 00039 00040 case MRI_float: 00041 for( ii=0 ; ii < npix ; ii++ ) 00042 float_max = MAX( float_max , im->im.float_data[ii] ) ; 00043 return (double) float_max ; 00044 00045 case MRI_double: 00046 for( ii=0 ; ii < npix ; ii++ ) 00047 double_max = MAX( double_max , im->im.double_data[ii] ) ; 00048 return double_max ; 00049 00050 case MRI_complex: 00051 for( ii=0 ; ii < npix ; ii++ ) 00052 float_max = MAX( float_max , CSQR(im->im.complex_data[ii]) ) ; 00053 return sqrt(float_max) ; 00054 00055 case MRI_rgb:{ 00056 byte *rgb = im->im.rgb_data ; 00057 double val , top=0.0 ; 00058 for( ii=0 ; ii < npix ; ii++ ){ /* scale to brightness */ 00059 val = 0.299 * rgb[3*ii] /* between 0 and 255 */ 00060 + 0.587 * rgb[3*ii+1] 00061 + 0.114 * rgb[3*ii+2] ; 00062 if( val > top ) top = val ; 00063 } 00064 return top ; 00065 } 00066 00067 default: 00068 fprintf( stderr , "mri_max: unknown image kind\n" ) ; 00069 } 00070 return 0 ; 00071 } |
|
Definition at line 73 of file mri_max.c. References abs, MRI_DATA::byte_data, MRI_DATA::complex_data, CSQR, MRI_DATA::double_data, double_max, MRI_DATA::float_data, MRI_IMAGE::im, MRI_DATA::int_data, int_max, MRI_IMAGE::kind, MAX, mri_max(), MRI_IMAGE::nvox, and MRI_DATA::short_data. Referenced by AFNI_func_overlay(), main(), mri_brainormalize(), mri_to_mri(), mri_to_short(), PH_loadim(), PR_type_scale(), and THD_cliplevel().
00074 { 00075 register int ii , npix ; 00076 byte byte_max = 0 ; 00077 int int_max = 0 ; 00078 double double_max = 0.0 ; 00079 00080 npix = im->nvox ; 00081 00082 switch( im->kind ){ 00083 00084 case MRI_byte: 00085 for( ii=0 ; ii < npix ; ii++ ) 00086 byte_max = MAX( byte_max , im->im.byte_data[ii] ) ; 00087 return (double) byte_max ; 00088 00089 case MRI_short: 00090 for( ii=0 ; ii < npix ; ii++ ) 00091 int_max = MAX( int_max , abs(im->im.short_data[ii]) ) ; 00092 return (double) int_max ; 00093 00094 case MRI_int: 00095 for( ii=0 ; ii < npix ; ii++ ) 00096 int_max = MAX( int_max , abs(im->im.int_data[ii]) ) ; 00097 return (double) int_max ; 00098 00099 case MRI_float: 00100 for( ii=0 ; ii < npix ; ii++ ) 00101 double_max = MAX( double_max , fabs(im->im.float_data[ii]) ) ; 00102 return double_max ; 00103 00104 case MRI_double: 00105 for( ii=0 ; ii < npix ; ii++ ) 00106 double_max = MAX( double_max , fabs(im->im.double_data[ii]) ) ; 00107 return double_max ; 00108 00109 case MRI_complex: 00110 for( ii=0 ; ii < npix ; ii++ ) 00111 double_max = MAX( double_max , CSQR(im->im.complex_data[ii]) ) ; 00112 return sqrt(double_max) ; 00113 00114 case MRI_rgb: 00115 return mri_max( im ) ; 00116 00117 default: 00118 fprintf( stderr , "mri_max: unknown image kind\n" ) ; 00119 } 00120 return 0 ; 00121 } |
|
Compute the median filter of an input image. Output image is always in float format. ------------------------------------------------------------------------- Definition at line 10 of file mri_medianfilter.c. References ADDTO_CLUSTER, ENTRY, fout, free, MCW_cluster::i, MCW_cluster::j, MCW_cluster::k, KILL_CLUSTER, MRI_IMAGE::kind, malloc, MCW_build_mask(), mri_data_pointer(), MRI_FLOAT_PTR, mri_free(), mri_new_conforming, mri_to_float(), MCW_cluster::num_pt, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, nz, qmed_float(), RETURN, SKIPVOX, and THD_countmask(). Referenced by main().
00011 { 00012 MRI_IMAGE *imout ; 00013 float *fin , *fout , *tmp ; 00014 short *sin ; byte *bin ; void *vin ; 00015 short *di , *dj , *dk ; 00016 int nd, ii,jj,kk, ip,jp,kp, nx,ny,nz, nxy, ijk, dd,nt,pjk, kd ; 00017 MCW_cluster *cl ; 00018 00019 ENTRY("mri_medianfilter") ; 00020 00021 if( imin == NULL || irad < 1.0 ) RETURN(NULL) ; 00022 00023 /** if not a good input data type, floatize and try again **/ 00024 00025 if( imin->kind != MRI_float && 00026 imin->kind != MRI_short && 00027 imin->kind != MRI_byte ){ 00028 00029 MRI_IMAGE *qim ; 00030 qim = mri_to_float( imin ) ; 00031 imout = mri_medianfilter( qim , irad , mask , verb ) ; 00032 mri_free( qim ) ; 00033 RETURN(imout) ; 00034 } 00035 00036 /** build cluster of points for median-izing **/ 00037 00038 if( irad < 1.01 ) irad = 1.01 ; 00039 cl = MCW_build_mask( 0,0,0 , 1.0,1.0,1.0 , irad ) ; 00040 00041 if( cl == NULL || cl->num_pt < 6 ){ KILL_CLUSTER(cl); RETURN(NULL); } 00042 00043 ADDTO_CLUSTER(cl,0,0,0,0) ; 00044 00045 di = cl->i ; dj = cl->j ; dk = cl->k ; nd = cl->num_pt ; 00046 nx = imin->nx ; ny = imin->ny ; nz = imin->nz ; nxy = nx*ny ; 00047 00048 if( verb ){ 00049 fprintf(stderr,"++ Median mask=%d",nd) ; 00050 if( mask != NULL ) 00051 fprintf(stderr," Data mask=%d",THD_countmask(nxy*nz,mask)) ; 00052 } 00053 00054 imout = mri_new_conforming( imin , MRI_float ) ; 00055 fout = MRI_FLOAT_PTR( imout ) ; 00056 vin = mri_data_pointer( imin ) ; 00057 tmp = (float *) malloc(sizeof(float)*nd) ; 00058 switch( imin->kind ){ 00059 case MRI_float: fin = (float *)vin ; break ; 00060 case MRI_short: sin = (short *)vin ; break ; 00061 case MRI_byte : bin = (byte *)vin ; break ; 00062 } 00063 00064 if( verb ){ kd = (int)rint(0.03*nz); if( kd < 1 ) kd = 1; } 00065 00066 for( kk=0 ; kk < nz ; kk++ ){ 00067 if( verb && kk%kd == 0 ) fprintf(stderr,".") ; 00068 for( jj=0 ; jj < ny ; jj++ ){ 00069 for( ii=0 ; ii < nx ; ii++ ){ 00070 ijk = ii + jj*nx + kk*nxy ; 00071 if( SKIPVOX(ijk) ){ fout[ijk] = 0.0; continue; } 00072 00073 /* extract neighborhood values */ 00074 00075 switch( imin->kind ){ 00076 case MRI_float: 00077 for( nt=dd=0 ; dd < nd ; dd++ ){ 00078 ip = ii+di[dd] ; if( ip < 0 || ip >= nx ) continue ; 00079 jp = jj+dj[dd] ; if( jp < 0 || jp >= ny ) continue ; 00080 kp = kk+dk[dd] ; if( kp < 0 || kp >= nz ) continue ; 00081 pjk = ip+jp*nx+kp*nxy ; 00082 if( SKIPVOX(pjk) ) continue ; 00083 tmp[nt++] = fin[pjk] ; 00084 } 00085 break ; 00086 case MRI_short: 00087 for( nt=dd=0 ; dd < nd ; dd++ ){ 00088 ip = ii+di[dd] ; if( ip < 0 || ip >= nx ) continue ; 00089 jp = jj+dj[dd] ; if( jp < 0 || jp >= ny ) continue ; 00090 kp = kk+dk[dd] ; if( kp < 0 || kp >= nz ) continue ; 00091 pjk = ip+jp*nx+kp*nxy ; 00092 if( SKIPVOX(pjk) ) continue ; 00093 tmp[nt++] = sin[pjk] ; 00094 } 00095 break ; 00096 case MRI_byte: 00097 for( nt=dd=0 ; dd < nd ; dd++ ){ 00098 ip = ii+di[dd] ; if( ip < 0 || ip >= nx ) continue ; 00099 jp = jj+dj[dd] ; if( jp < 0 || jp >= ny ) continue ; 00100 kp = kk+dk[dd] ; if( kp < 0 || kp >= nz ) continue ; 00101 pjk = ip+jp*nx+kp*nxy ; 00102 if( SKIPVOX(pjk) ) continue ; 00103 tmp[nt++] = bin[pjk] ; 00104 } 00105 break ; 00106 } 00107 00108 fout[ijk] = qmed_float( nt , tmp ) ; /* the actual median-izing */ 00109 }}} 00110 if( verb ) fprintf(stderr,"\n") ; 00111 00112 KILL_CLUSTER(cl); free((void *)tmp); /* toss the trash */ 00113 RETURN(imout) ; 00114 } |
|
Definition at line 123 of file mri_max.c. References MRI_DATA::byte_data, MRI_DATA::complex_data, CSQR, MRI_DATA::double_data, double_min, MRI_DATA::float_data, float_min, MRI_IMAGE::im, MRI_DATA::int_data, int_min, MRI_IMAGE::kind, MIN, MRI_IMAGE::nvox, MRI_DATA::rgb_data, MRI_DATA::short_data, and short_min. Referenced by HISTO_main(), ISQ_process_mri(), ISQ_statify_one(), main(), mri_3dalign_one(), mri_dup2D(), mri_edit_image(), mri_quantile(), mri_sharpen(), mri_to_byte(), mri_to_byte_scl(), mri_to_mri(), mri_to_short_sclip(), mri_write_analyze(), T3D_read_images(), and write_images().
00124 { 00125 register int ii , npix ; 00126 byte byte_min = 255 ; 00127 short short_min = 32767 ; 00128 int int_min = 2147483647 ; 00129 float float_min = 1.e+38 ; 00130 double double_min = 1.e+38 ; 00131 00132 npix = im->nvox ; 00133 00134 switch( im->kind ){ 00135 00136 case MRI_byte: 00137 for( ii=0 ; ii < npix ; ii++ ) 00138 byte_min = MIN( byte_min , im->im.byte_data[ii] ) ; 00139 return (double) byte_min ; 00140 00141 case MRI_short: 00142 for( ii=0 ; ii < npix ; ii++ ) 00143 short_min = MIN( short_min , im->im.short_data[ii] ) ; 00144 return (double) short_min ; 00145 00146 case MRI_int: 00147 for( ii=0 ; ii < npix ; ii++ ) 00148 int_min = MIN( int_min , im->im.int_data[ii] ) ; 00149 return (double) int_min ; 00150 00151 case MRI_float: 00152 for( ii=0 ; ii < npix ; ii++ ) 00153 float_min = MIN( float_min , im->im.float_data[ii] ) ; 00154 return (double) float_min ; 00155 00156 case MRI_double: 00157 for( ii=0 ; ii < npix ; ii++ ) 00158 double_min = MIN( double_min , im->im.double_data[ii] ) ; 00159 return double_min ; 00160 00161 case MRI_complex: 00162 for( ii=0 ; ii < npix ; ii++ ) 00163 float_min = MIN( float_min , CSQR(im->im.complex_data[ii]) ) ; 00164 return sqrt(float_min) ; 00165 00166 case MRI_rgb:{ 00167 byte *rgb = im->im.rgb_data ; 00168 double val , bot=255.9 ; 00169 for( ii=0 ; ii < npix ; ii++ ){ /* scale to brightness */ 00170 val = 0.299 * rgb[3*ii] /* between 0 and 255 */ 00171 + 0.587 * rgb[3*ii+1] 00172 + 0.114 * rgb[3*ii+2] ; 00173 if( val < bot ) bot = val ; 00174 } 00175 return bot ; 00176 } 00177 00178 default: 00179 fprintf( stderr , "mri_min: unknown image kind\n" ) ; 00180 } 00181 return 0 ; 00182 } |
|
Replace the guts of MRI_IMAGE struct qim with those of zim. Afterwards, what's left of zim is mri_free()-ed, so don't ever refer to it again. If you want a copy of an image, use mri_copy() instead. --------------------------------------------------------------------------- Definition at line 106 of file mri_free.c. References ENTRY, MRI_IMAGE::fname, free, mri_data_pointer(), mri_fix_data_pointer(), and MRI_IMAGE::name. Referenced by DSETN_func().
00107 { 00108 void *ptr ; 00109 00110 ENTRY("mri_move_guts") ; 00111 00112 if( qim == NULL || zim == NULL ) EXRETURN ; /* stupid caller */ 00113 00114 /* destroy the contents inside qim, if any */ 00115 00116 #ifdef USE_MRI_DELAY 00117 if( qim->fname != NULL ) free(qim->fname) ; 00118 #endif 00119 if( qim->name != NULL ) free(qim->name) ; 00120 ptr = mri_data_pointer(qim) ; 00121 if( ptr != NULL ) free(ptr) ; 00122 00123 /* put the contents of zim in their place */ 00124 00125 *qim = *zim ; 00126 00127 /* NULL out the contents of zim, then free() it */ 00128 00129 mri_fix_data_pointer( NULL , zim ) ; 00130 zim->name = NULL ; 00131 #ifdef USE_MRI_DELAY 00132 zim->fname = NULL ; 00133 #endif 00134 free(zim) ; EXRETURN ; 00135 } |
|
Definition at line 163 of file mri_to_float.c. References MRI_DATA::byte_data, CABS, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, FAC, MRI_DATA::float_data, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_new_conforming, MRI_IMAGE::nvox, RETURN, and MRI_DATA::short_data. Referenced by FD_brick_to_series(), and THD_extract_many_series().
00164 { 00165 MRI_IMAGE *newim ; 00166 register int ii , npix ; 00167 00168 ENTRY("mri_mult_to_float") ; 00169 00170 newim = mri_new_conforming( oldim , MRI_float ) ; 00171 npix = oldim->nvox ; 00172 00173 switch( oldim->kind ){ 00174 00175 case MRI_byte: 00176 for( ii=0 ; ii < npix ; ii++ ) 00177 newim->im.float_data[ii] = FAC(ii) * oldim->im.byte_data[ii] ; 00178 break ; 00179 00180 case MRI_short: 00181 for( ii=0 ; ii < npix ; ii++ ) 00182 newim->im.float_data[ii] = FAC(ii) * oldim->im.short_data[ii] ; 00183 break ; 00184 00185 case MRI_int: 00186 for( ii=0 ; ii < npix ; ii++ ) 00187 newim->im.float_data[ii] = FAC(ii) * oldim->im.int_data[ii] ; 00188 break ; 00189 00190 case MRI_float: 00191 for( ii=0 ; ii < npix ; ii++ ) 00192 newim->im.float_data[ii] = FAC(ii) * oldim->im.float_data[ii] ; 00193 break ; 00194 00195 case MRI_double: 00196 for( ii=0 ; ii < npix ; ii++ ) 00197 newim->im.float_data[ii] = FAC(ii) * oldim->im.double_data[ii] ; 00198 break ; 00199 00200 case MRI_complex: 00201 for( ii=0 ; ii < npix ; ii++ ) 00202 newim->im.float_data[ii] = FAC(ii) * CABS(oldim->im.complex_data[ii]) ; 00203 break ; 00204 00205 default: 00206 fprintf( stderr , "mri_to_float: unrecognized image kind\n" ) ; 00207 MRI_FATAL_ERROR ; 00208 } 00209 00210 MRI_COPY_AUX(newim,oldim) ; 00211 RETURN( newim ); 00212 } |
|
Definition at line 16 of file mri_complex_arith.c. References CJMULT, CMULT, MRI_DATA::complex_data, MRI_IMAGE::im, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_new_conforming, and MRI_IMAGE::nvox.
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 } |
|
|
Definition at line 41 of file mri_new.c. References MRI_DATA::byte_data, calloc, MRI_DATA::complex_data, MRI_DATA::double_data, MRI_IMAGE::dt, MRI_IMAGE::du, MRI_IMAGE::dv, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, MRI_DATA::float_data, MRI_IMAGE::fname, MRI_IMAGE::foffset, MRI_IMAGE::fondisk, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, mri_data_pointer(), MRI_FATAL_ERROR, MRI_IMAGE::name, MRI_IMAGE::nt, MRI_IMAGE::nu, MRI_IMAGE::nv, MRI_IMAGE::nvox, MRI_IMAGE::nw, MRI_IMAGE::nx, MRI_IMAGE::nxy, MRI_IMAGE::nxyz, MRI_IMAGE::nxyzt, MRI_IMAGE::ny, MRI_IMAGE::nz, nz, MRI_IMAGE::pixel_size, RETURN, MRI_DATA::rgb_data, MRI_DATA::rgba_data, MRI_DATA::short_data, MRI_IMAGE::to, MRI_IMAGE::uo, MRI_IMAGE::vo, MRI_IMAGE::was_swapped, MRI_IMAGE::wo, MRI_IMAGE::xo, MRI_IMAGE::yo, and MRI_IMAGE::zo. Referenced by mri_new(), mri_new_vol(), mri_new_vol_empty(), mri_try_7D(), and niml_to_mri().
00044 { 00045 MRI_IMAGE *newim ; 00046 int npix ; 00047 00048 ENTRY("mri_new_7D_generic") ; 00049 00050 newim = (MRI_IMAGE *)calloc( 1, sizeof(MRI_IMAGE) ) ; 00051 00052 if( newim == NULL ){ 00053 fprintf( stderr , "malloc failure for new image pointer\n" ) ; 00054 MRI_FATAL_ERROR ; 00055 } 00056 00057 if( nx < 1 ) nx = 1 ; /* 18 Mar 2005: fix stupid user problems */ 00058 if( ny < 1 ) ny = 1 ; 00059 if( nz < 1 ) nz = 1 ; 00060 if( nt < 1 ) nt = 1 ; 00061 if( nu < 1 ) nu = 1 ; 00062 if( nv < 1 ) nv = 1 ; 00063 if( nw < 1 ) nw = 1 ; 00064 00065 newim->nx = nx ; 00066 newim->ny = ny ; newim->nxy = nx*ny ; 00067 newim->nz = nz ; newim->nxyz = nx*ny*nz ; 00068 newim->nt = nt ; newim->nxyzt = nx*ny*nz*nt ; 00069 newim->nu = nu ; 00070 newim->nv = nv ; 00071 newim->nw = nw ; newim->nvox = newim->nxyzt * nu*nv*nw ; 00072 00073 newim->kind = kind ; 00074 newim->name = NULL ; 00075 00076 newim->dx = newim->dy = newim->dz = 00077 newim->dt = newim->du = newim->dv = 1.0 ; /* default dimensions */ 00078 00079 newim->dw = -666.0 ; /* 05 Feb 2001 - flag that dimensions aren't set */ 00080 00081 newim->xo = newim->yo = newim->zo = 00082 newim->to = newim->uo = newim->vo = newim->wo = 0.0 ; /* default offsets */ 00083 00084 newim->was_swapped = 0 ; /* 07 Mar 2002 - flag that bytes were swapped */ 00085 00086 #ifdef USE_MRI_LABELS 00087 newim->xlab[0] = '\0' ; /* default labels */ 00088 newim->ylab[0] = '\0' ; 00089 newim->zlab[0] = '\0' ; 00090 newim->tlab[0] = '\0' ; 00091 newim->ulab[0] = '\0' ; 00092 newim->vlab[0] = '\0' ; 00093 newim->wlab[0] = '\0' ; 00094 #endif 00095 00096 #ifdef USE_MRI_DELAY 00097 newim->fname = NULL ; 00098 newim->foffset = newim->fondisk = 0 ; 00099 #endif 00100 00101 npix = newim->nvox ; 00102 00103 switch( kind ){ 00104 00105 case MRI_byte: 00106 if( make_space ) 00107 newim->im.byte_data = (byte *)calloc( npix,sizeof(byte) ) ; 00108 else 00109 newim->im.byte_data = NULL ; 00110 newim->pixel_size = sizeof(byte) ; 00111 break ; 00112 00113 case MRI_short: 00114 if( make_space ) 00115 newim->im.short_data = (short *)calloc( npix,sizeof(short) ) ; 00116 else 00117 newim->im.short_data = NULL ; 00118 newim->pixel_size = sizeof(short) ; 00119 break ; 00120 00121 case MRI_int: 00122 if( make_space ) 00123 newim->im.int_data = (int *)calloc( npix,sizeof(int) ) ; 00124 else 00125 newim->im.int_data = NULL ; 00126 newim->pixel_size = sizeof(int) ; 00127 break ; 00128 00129 case MRI_float: 00130 if( make_space ) 00131 newim->im.float_data = (float *)calloc( npix,sizeof(float) ) ; 00132 else 00133 newim->im.float_data = NULL ; 00134 newim->pixel_size = sizeof(float) ; 00135 break ; 00136 00137 case MRI_double: 00138 if( make_space ) 00139 newim->im.double_data = (double *)calloc( npix,sizeof(double) ) ; 00140 else 00141 newim->im.double_data = NULL ; 00142 newim->pixel_size = sizeof(double) ; 00143 break ; 00144 00145 case MRI_complex: 00146 if( make_space ) 00147 newim->im.complex_data = (complex *)calloc( npix,sizeof(complex) ) ; 00148 else 00149 newim->im.complex_data = NULL ; 00150 newim->pixel_size = sizeof(complex) ; 00151 break ; 00152 00153 case MRI_rgb: 00154 if( make_space ) 00155 newim->im.rgb_data = (byte *)calloc( 3*npix,sizeof(byte) ) ; 00156 else 00157 newim->im.rgb_data = NULL ; 00158 newim->pixel_size = 3 * sizeof(byte) ; 00159 break ; 00160 00161 case MRI_rgba: 00162 if( make_space ) 00163 newim->im.rgba_data = (rgba *)calloc( npix,sizeof(rgba) ) ; 00164 else 00165 newim->im.rgb_data = NULL ; 00166 newim->pixel_size = sizeof(rgba) ; 00167 break ; 00168 00169 default: 00170 fprintf( stderr , "mri_new: unrecognized image kind %d\n",(int)kind ) ; 00171 MRI_FATAL_ERROR ; 00172 } 00173 00174 if( make_space && mri_data_pointer(newim) == NULL ){ 00175 fprintf( stderr , "malloc failure for image space: %d bytes\n",npix*newim->pixel_size ) ; 00176 MRI_FATAL_ERROR ; 00177 } 00178 00179 RETURN(newim) ; 00180 } |
|
Definition at line 32 of file mri_new.c. References mri_new_7D_generic(), and nz. Referenced by mri_cut_3D(), mri_flip3D(), mri_read3D_analyze75(), mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), mri_warp3D_quintic(), THD_rota3D(), and THD_rota3D_matvec().
00033 { 00034 MRI_IMAGE *newim ; 00035 newim = mri_new_7D_generic( nx,ny,nz , 1,1,1,1 , kind , TRUE ) ; 00036 return newim ; 00037 } |
|
Definition at line 23 of file mri_new.c. References mri_new_7D_generic(), and nz. Referenced by AFNI_make_widgets(), AIVVV_imseq_addto(), AIVVV_imseq_popup(), BFIT_compute(), BFIT_main(), CORREL_main(), dset_to_mri(), EDIT_add_bricklist(), IMREG_main(), main(), MASKAVE_main(), mri_1D_fromstring(), mri_read_3D_delay(), mri_read_ascii(), mri_zeropad_3D(), process_1ddata(), read_input_data(), RT_registration_2D_onevol(), RT_registration_2D_setup(), RT_start_dataset(), THD_autonudge(), THD_init_datablock_brick(), and XImage_to_mri().
00024 { 00025 MRI_IMAGE *newim ; 00026 newim = mri_new_7D_generic( nx,ny,nz , 1,1,1,1 , kind , FALSE ) ; 00027 return newim ; 00028 } |
|
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 } |
|
Overlay a smaller 2D image into a larger 2D image.
Definition at line 20 of file mri_overlay.c. References ENTRY, imbase, MRI_IMAGE::kind, mri_data_pointer(), mri_free(), mri_to_byte(), mri_to_rgb(), MRI_TYPE_NAME, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::pixel_size, and STATUS. Referenced by AFNI_splashup().
00021 { 00022 byte *ba , *ov ; 00023 int nxba,nyba , nxov,nyov , jj , nxxov,nyyov , psiz ; 00024 MRI_IMAGE *imov ; 00025 00026 ENTRY("mri_overlay_2D") ; 00027 00028 if( imbase == NULL || imover == NULL ){ 00029 STATUS("bad inputs") ; 00030 EXRETURN ; /* bad inputs */ 00031 } 00032 00033 /* 13 Nov 2002: possibly do type conversion on imover to match imbase */ 00034 00035 if( imbase->kind == imover->kind ){ 00036 STATUS("direct overlay possible") ; 00037 imov = imover ; 00038 } else if( imbase->kind == MRI_byte && imover->kind == MRI_rgb ){ 00039 STATUS("conversion to byte needed") ; 00040 imov = mri_to_byte( imover ) ; 00041 } else if( imbase->kind == MRI_rgb && imover->kind == MRI_byte ){ 00042 STATUS("conversion to RGB needed") ; 00043 imov = mri_to_rgb( imover ) ; 00044 } else { 00045 if(PRINT_TRACING){ 00046 char str[256] ; 00047 sprintf(str,"incompatible inputs: imbase=%s imover=%s", 00048 MRI_TYPE_NAME(imbase) , MRI_TYPE_NAME(imover) ) ; 00049 STATUS(str); 00050 } 00051 EXRETURN ; /* bad inputs */ 00052 } 00053 00054 /* get dimensions and pointers of images */ 00055 00056 nxba = imbase->nx ; nyba = imbase->ny ; ba = mri_data_pointer(imbase) ; 00057 nxov = imov ->nx ; nyov = imov ->ny ; ov = mri_data_pointer(imov ) ; 00058 psiz = imbase->pixel_size ; 00059 00060 if( ix >= nxba || jy >= nyba ){ /* bad placement */ 00061 STATUS("overlay oompossible") ; 00062 if( imov != imover ) mri_free(imov) ; 00063 EXRETURN ; 00064 } 00065 00066 /* negative offsets are from right & bottom */ 00067 00068 if( ix < 0 ){ 00069 ix = nxba + ix ; 00070 if( ix < 0 ){ /* bad */ 00071 STATUS("ix < 0"); if( imov != imover ) mri_free(imov); EXRETURN; 00072 } 00073 } 00074 if( jy < 0 ){ 00075 jy = nyba + jy ; 00076 if( jy < 0 ){ /* bad */ 00077 STATUS("jy < 0"); if( imov != imover ) mri_free(imov); EXRETURN; 00078 } 00079 } 00080 00081 nxxov = nxov ; /* length of overlay row */ 00082 if( ix+nxov > nxba ) nxxov = nxba - ix ; /* row too long for base? */ 00083 00084 nyyov = nyov ; /* number of overlay rows */ 00085 if( jy+nyov > nyba ) nyyov = nyba - jy ; /* too many rows for base? */ 00086 00087 /* actually overlay each row */ 00088 STATUS("overlaying now") ; 00089 00090 for( jj=0 ; jj < nyyov ; jj++ ) 00091 memcpy( ba + ((jy+jj)*nxba + ix)*psiz , ov + jj*nxov*psiz , nxxov*psiz ) ; 00092 00093 if( imov != imover ) mri_free(imov) ; /* throw away converted overlay? */ 00094 EXRETURN ; 00095 } |
|
Definition at line 199 of file mri_to_complex.c. References ENTRY, complex::i, MRI_IMAGE::kind, MRI_COMPLEX_PTR, MRI_FLOAT_PTR, mri_free(), mri_new_conforming, mri_to_float(), MRI_IMAGE::nvox, complex::r, and RETURN. Referenced by main(), mri_affine_bicubic(), mri_dup2D(), mri_rota(), mri_rota_bilinear(), mri_rota_shear(), mri_shift2D_bilinear(), mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), and mri_warp3D_quintic().
00200 { 00201 MRI_IMAGE * cim , * rfim , * ifim ; 00202 register complex * car ; 00203 register float * rar , * iar ; 00204 register int ii , nvox ; 00205 00206 ENTRY("mri_pair_to_complex") ; 00207 00208 if( rim == NULL || iim == NULL || rim->nvox != iim->nvox ) RETURN( NULL ); 00209 00210 cim = mri_new_conforming( rim , MRI_complex ) ; 00211 car = MRI_COMPLEX_PTR(cim) ; 00212 00213 rfim = (rim->kind == MRI_float) ? rim : mri_to_float( rim ) ; 00214 ifim = (iim->kind == MRI_float) ? iim : mri_to_float( iim ) ; 00215 00216 rar = MRI_FLOAT_PTR(rfim) ; iar = MRI_FLOAT_PTR(ifim) ; 00217 nvox = rfim->nvox ; 00218 00219 for( ii=0 ; ii < nvox ; ii++ ){ car[ii].r = rar[ii] ; car[ii].i = iar[ii] ; } 00220 00221 if( rfim != rim ) mri_free( rfim ) ; 00222 if( ifim != iim ) mri_free( ifim ) ; 00223 00224 RETURN( cim ); 00225 } |
|
Definition at line 467 of file mri_percents.c. References far, MRI_IMAGE::kind, MRI_FLOAT_PTR, mri_free(), MRI_SHORT_PTR, mri_to_float(), mri_to_short(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, qsort_float(), and qsort_short(). Referenced by THD_orient_guess().
00468 { 00469 register int pp , ii , nvox ; 00470 register float fi , frac ; 00471 00472 /*** sanity checks ***/ 00473 00474 if( im == NULL || per == NULL || nper < 2 ) return ; 00475 00476 #ifdef MRILIB_7D 00477 nvox = im->nvox ; 00478 #else 00479 nvox = im->nx * im->ny ; 00480 #endif 00481 frac = nvox / ((float) nper) ; 00482 00483 switch( im->kind ){ 00484 00485 /*** create a float image copy of the data, 00486 sort it, then interpolate the percentage points ***/ 00487 00488 default:{ 00489 MRI_IMAGE * inim ; 00490 float * far ; 00491 00492 inim = mri_to_float( im ) ; 00493 far = MRI_FLOAT_PTR(inim) ; 00494 qsort_float( nvox , far ) ; 00495 00496 per[0] = far[0] ; 00497 for( pp=1 ; pp < nper ; pp++ ){ 00498 fi = frac * pp ; ii = fi ; fi = fi - ii ; 00499 per[pp] = (1.0-fi) * far[ii] + fi * far[ii+1] ; 00500 } 00501 per[nper] = far[nvox-1] ; 00502 mri_free( inim ) ; 00503 } 00504 break ; 00505 00506 /*** create a short image copy of the data, 00507 sort it, then interpolate the percentage points ***/ 00508 00509 case MRI_short: 00510 case MRI_byte:{ 00511 MRI_IMAGE * inim ; 00512 short * sar ; 00513 00514 inim = mri_to_short( 1.0 , im ) ; 00515 sar = MRI_SHORT_PTR(inim) ; 00516 qsort_short( nvox , sar ) ; 00517 00518 per[0] = sar[0] ; 00519 for( pp=1 ; pp < nper ; pp++ ){ 00520 fi = frac * pp ; ii = fi ; fi = fi - ii ; 00521 per[pp] = (1.0-fi) * sar[ii] + fi * sar[ii+1] ; 00522 } 00523 per[nper] = sar[nvox-1] ; 00524 mri_free( inim ) ; 00525 } 00526 } 00527 00528 return ; 00529 } |
|
Test if a file is possibly a DICOM file. -- RWCox - 07 May 2003 ---------------------------------------------------------------------------- Definition at line 207 of file dimon_afni.c. Referenced by mri_imcount_dicom(), mri_read_dicom(), and r_mri_read_dicom().
00208 { 00209 #undef BSIZ 00210 #define BSIZ 4096 00211 FILE *fp ; 00212 unsigned char buf[BSIZ] , *cpt ; 00213 int nn , ii ; 00214 00215 if( fname == NULL || *fname == '\0' ) return 0 ; 00216 fp = fopen( fname , "rb" ) ; if( fp == NULL ) return 0 ; 00217 00218 /* read 1st buffer */ 00219 00220 nn = fread( buf , 1 , BSIZ , fp ) ; 00221 if( nn < 256 ){ fclose(fp) ; return 0 ; } /* too short */ 00222 00223 /* easy: check if has 'DICM' marker at offset 128..131 */ 00224 00225 if( buf[128]=='D' && buf[129]=='I' && buf[130]=='C' && buf[131]=='M' ){ 00226 fclose(fp) ; return 1 ; 00227 } 00228 00229 /* hard: scan file for sequence: E0 7F 10 00 (image data attribute) */ 00230 00231 while(1){ 00232 00233 cpt = memchr( buf, 0xe0, nn ) ; /* look for E0 */ 00234 00235 if( cpt == NULL ){ /* skip this buffer */ 00236 nn = fread( buf , 1 , BSIZ , fp ) ; /* and get another */ 00237 if( nn < 256 ){ fclose(fp) ; return 0 ; } 00238 continue ; 00239 } 00240 00241 ii = nn - (cpt-buf) ; /* num char to end of buf */ 00242 if( ii <= 4 ){ /* too close to end of buf */ 00243 memmove( buf , cpt , ii ) ; 00244 nn = fread( buf+ii , 1 , BSIZ-ii , fp ) ; nn += ii ; 00245 if( nn < 256 ){ fclose(fp) ; return 0 ; } 00246 cpt = buf ; ii = nn ; 00247 } 00248 00249 /* see if we got what we want */ 00250 00251 if( *cpt==0xe0 && *(cpt+1)==0x7f && *(cpt+2)==0x10 && *(cpt+3)==0x00 ){ 00252 fclose(fp) ; return 1 ; 00253 } 00254 00255 /* no? start again at next char in buf */ 00256 00257 memmove( buf , cpt+1 , ii-1 ) ; nn = ii-1 ; 00258 } 00259 } |
|
Definition at line 3142 of file mri_read.c. References MRI_IMAGE::fname, MRI_IMAGE::fondisk, free, mri_clear_data_pointer, and mri_data_pointer().
03143 { 03144 void * ar ; 03145 03146 /** if no delay filename, 03147 or if it is marked as already set for delay input, do nothing **/ 03148 03149 if( im->fname == NULL || 03150 (im->fondisk & INPUT_DELAY) != 0 ) return ; 03151 03152 /** get the data pointer, throw data way, clear the data pointer **/ 03153 03154 ar = mri_data_pointer( im ) ; 03155 if( ar != NULL ){ free(ar) ; mri_clear_data_pointer(im) ; } 03156 03157 /** mark as set for delay input **/ 03158 03159 im->fondisk |= INPUT_DELAY ; 03160 return ; 03161 } |
|
scan itop up until value is distinct * Definition at line 628 of file mri_percents.c. References far, MRI_IMAGE::kind, MRI_FLOAT_PTR, mri_free(), mri_max(), mri_min(), MRI_SHORT_PTR, mri_to_float(), mri_to_short(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, qsort_float(), and qsort_short(). Referenced by main().
00629 { 00630 int ii , nvox ; 00631 float fi , quan ; 00632 00633 /*** sanity checks ***/ 00634 00635 if( im == NULL ) return 0.0 ; 00636 00637 if( alpha <= 0.0 ) return (float) mri_min(im) ; 00638 if( alpha >= 1.0 ) return (float) mri_max(im) ; 00639 00640 #ifdef MRILIB_7D 00641 nvox = im->nvox ; 00642 #else 00643 nvox = im->nx * im->ny ; 00644 #endif 00645 00646 switch( im->kind ){ 00647 00648 /*** create a float image copy of the data, 00649 sort it, then interpolate the percentage points ***/ 00650 00651 default:{ 00652 MRI_IMAGE * inim ; 00653 float * far ; 00654 00655 inim = mri_to_float( im ) ; 00656 far = MRI_FLOAT_PTR(inim) ; 00657 qsort_float( nvox , far ) ; 00658 00659 fi = alpha * nvox ; 00660 ii = (int) fi ; if( ii >= nvox ) ii = nvox-1 ; 00661 fi = fi - ii ; 00662 quan = (1.0-fi) * far[ii] + fi * far[ii+1] ; 00663 mri_free( inim ) ; 00664 } 00665 break ; 00666 00667 /*** create a short image copy of the data, 00668 sort it, then interpolate the percentage points ***/ 00669 00670 case MRI_short: 00671 case MRI_byte:{ 00672 MRI_IMAGE * inim ; 00673 short * sar ; 00674 00675 inim = mri_to_short( 1.0 , im ) ; 00676 sar = MRI_SHORT_PTR(inim) ; 00677 qsort_short( nvox , sar ) ; 00678 00679 fi = alpha * nvox ; 00680 ii = (int) fi ; if( ii >= nvox ) ii = nvox-1 ; 00681 fi = fi - ii ; 00682 quan = (1.0-fi) * sar[ii] + fi * sar[ii+1] ; 00683 mri_free( inim ) ; 00684 } 00685 break ; 00686 } 00687 00688 return quan ; 00689 } |
|
Earliest image reading function in the AFNI package. Reads a single 2D image.
Definition at line 188 of file mri_read.c. References abs, MRI_IMAGE::dt, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, L, mri_add_name(), mri_data_pointer(), mri_free(), mri_new(), mri_read_ascii(), mri_read_ppm(), mri_read_stuff(), mri_try_7D(), mri_try_mri(), mri_try_pgm(), MRILIB_orients, MRILIB_slicespacing, MRILIB_tr, MRILIB_xoff, MRILIB_yoff, MRILIB_zoff, MRI_IMAGE::nvox, MRI_IMAGE::pixel_size, RETURN, SEEK_END, SEEK_SET, skip, swap, swap_4(), swap_fourbytes(), swap_twobytes(), use_MRILIB_slicespacing, use_MRILIB_xoff, use_MRILIB_yoff, use_MRILIB_zoff, MRI_IMAGE::was_swapped, and MRI_IMAGE::zo. Referenced by main(), mri_read_file(), mri_read_file_delay(), PH_loadim(), and UC_read_opts().
00189 { 00190 FILE *imfile ; 00191 MRI_IMAGE *im ; 00192 int length , skip=0 , swap=0 ; 00193 void *data ; 00194 00195 ENTRY("mri_read") ; 00196 00197 if( fname == NULL || *fname == '\0' ) RETURN(NULL) ; /* bad user */ 00198 00199 /**-- 27 Apr 2005: check here for special filenames --**/ 00200 00201 if( strstr(fname,".jpg" ) != NULL || /* various formats */ 00202 strstr(fname,".JPG" ) != NULL || /* that we convert */ 00203 strstr(fname,".jpeg") != NULL || /* to PPG/PGM using */ 00204 strstr(fname,".JPEG") != NULL || /* external filters */ 00205 strstr(fname,".gif" ) != NULL || 00206 strstr(fname,".GIF" ) != NULL || 00207 strstr(fname,".tif" ) != NULL || 00208 strstr(fname,".TIF" ) != NULL || 00209 strstr(fname,".tiff") != NULL || 00210 strstr(fname,".TIFF") != NULL || 00211 strstr(fname,".bmp" ) != NULL || 00212 strstr(fname,".BMP" ) != NULL || 00213 strstr(fname,".pbm" ) != NULL || 00214 strstr(fname,".PBM" ) != NULL || 00215 strstr(fname,".pgm" ) != NULL || 00216 strstr(fname,".PGM" ) != NULL || 00217 strstr(fname,".ppm" ) != NULL || 00218 strstr(fname,".PPM" ) != NULL || 00219 strstr(fname,".png" ) != NULL || 00220 strstr(fname,".PNG" ) != NULL ){ 00221 00222 im = mri_read_stuff(fname) ; if( im != NULL ) RETURN(im) ; 00223 } 00224 00225 /*-- check if file exists and is readable --*/ 00226 00227 imfile = fopen( fname , "r" ) ; 00228 if( imfile == NULL ){ 00229 fprintf( stderr , "couldn't open image file %s\n" , fname ) ; 00230 RETURN( NULL ); 00231 } 00232 00233 fseek( imfile , 0L , SEEK_END ) ; /* get the length of the file */ 00234 length = ftell( imfile ) ; /* (the AJ way) */ 00235 00236 /*--- 03 Dec 2001: check for GEMS format file "IMGF" ---*/ 00237 /*[[[ Information herein from Medical Image Format FAQ ]]]*/ 00238 00239 { char str[5]="AFNI" ; 00240 int nx , ny , bpp , cflag , hdroff , extraskip=0 ; 00241 rewind(imfile) ; fread(str,1,4,imfile) ; /* check for "IMGF" or "GEMS" */ 00242 00243 if( str[0]=='G' && str[1]=='E' && str[2]=='M' && str[3]=='S' ){ /* 12 Feb 2004 */ 00244 char buf[4096]; int bb,cc; /* search for IMGF in 1st 4K */ 00245 rewind(imfile); cc=fread(buf,1,4096,imfile); cc-=4 ; 00246 for( bb=4; bb < cc ; bb++ ) 00247 if( buf[bb]=='I' && buf[bb+1]=='M' && buf[bb+2]=='G' && buf[bb+3]=='F' ) break ; 00248 if( bb < cc ){ 00249 fseek( imfile , (long)bb , SEEK_SET ) ; extraskip = bb ; 00250 fread(str,1,4,imfile) ; 00251 } 00252 } 00253 00254 /* 12 Feb 2004: modified to allow for starting at extraskip */ 00255 00256 if( str[0]=='I' && str[1]=='M' && str[2]=='G' && str[3]=='F' ){ 00257 00258 fread( &skip , 4,1, imfile ) ; /* read next 5 ints */ 00259 fread( &nx , 4,1, imfile ) ; 00260 fread( &ny , 4,1, imfile ) ; 00261 fread( &bpp , 4,1, imfile ) ; 00262 fread( &cflag, 4,1, imfile ) ; 00263 00264 if( nx < 0 || nx > 8192 ){ /* maybe have to byte swap 5 ints */ 00265 swap = 1 ; /* flag that we are swapping data */ 00266 swap_4(&skip); swap_4(&nx) ; 00267 swap_4(&ny) ; swap_4(&bpp); swap_4(&cflag); 00268 } 00269 skip += extraskip ; /* location of image data in file */ 00270 if( nx < 0 || nx > 8192 || ny < 0 || ny > 8192 ) goto The_Old_Way ; 00271 if( skip < 0 || skip >= length ) goto The_Old_Way ; 00272 if( bpp != 16 || cflag != 1 ) goto The_Old_Way ; 00273 00274 /* make image space */ 00275 00276 im = mri_new( nx , ny , MRI_short ) ; 00277 00278 /* try to read image auxiliary data as well (not mandatory) */ 00279 00280 length = fseek( imfile , 148L+extraskip , SEEK_SET ) ; /* magic GEMS offset */ 00281 if( length == 0 ){ 00282 fread( &hdroff , 4,1 , imfile ) ; /* location of image header */ 00283 if( swap ) swap_4(&hdroff) ; 00284 if( hdroff > 0 ){ /* read from image header */ 00285 float dx,dy,dz, dxx,dyy,dzz, xyz[9], zz ; int itr, ii,jj,kk, qq ; 00286 static int nzoff=0 ; 00287 static float zoff ; 00288 00289 /* get voxel grid sizes */ 00290 00291 fseek( imfile , hdroff+26+extraskip , SEEK_SET ) ; 00292 fread( &dzz , 4,1 , imfile ) ; 00293 00294 fseek( imfile , hdroff+50+extraskip , SEEK_SET ) ; 00295 fread( &dxx , 4,1 , imfile ) ; 00296 fread( &dyy , 4,1 , imfile ) ; 00297 00298 if( swap ){ swap_4(&dxx); swap_4(&dyy); swap_4(&dzz); } 00299 00300 /* save into image header [dw > 0 is signal that dx,dy,dz are OK] */ 00301 00302 if( dxx > 0.01 && dyy > 0.01 && dzz > 0.01 ){ 00303 im->dx = dxx; im->dy = dyy; im->dz = dzz; im->dw = 1.0; 00304 } 00305 00306 /* grid orientation: from 3 sets of LPI corner coordinates: */ 00307 /* xyz[0..2] = top left hand corner of image (TLHC) */ 00308 /* xyz[3..5] = top right hand corner of image (TRHC) */ 00309 /* xyz[6..8] = bottom right hand corner of image (BRHC) */ 00310 /* GEMS coordinate orientation here is LPI. */ 00311 /* Orientation is saved into global string MRILIB_orients. */ 00312 /* N.B.: AFNI coordinates are RAI orientation. */ 00313 00314 fseek( imfile , hdroff+154+extraskip , SEEK_SET ) ; 00315 fread( xyz , 4,9 , imfile ) ; 00316 if( swap ) swap_fourbytes(9,xyz) ; 00317 00318 /* x-axis orientation */ 00319 /* ii determines which spatial direction is x-axis */ 00320 /* and is the direction that has the biggest change */ 00321 /* between the TLHC and TRHC */ 00322 00323 dx = fabs(xyz[3]-xyz[0]) ; ii = 1 ; 00324 dy = fabs(xyz[4]-xyz[1]) ; if( dy > dx ){ ii=2; dx=dy; } 00325 dz = fabs(xyz[5]-xyz[2]) ; if( dz > dx ){ ii=3; } 00326 dx = xyz[ii+2]-xyz[ii-1] ; if( dx < 0. ){ ii = -ii; } 00327 switch( ii ){ 00328 case 1: MRILIB_orients[0] = 'L'; MRILIB_orients[1] = 'R'; break; 00329 case -1: MRILIB_orients[0] = 'R'; MRILIB_orients[1] = 'L'; break; 00330 case 2: MRILIB_orients[0] = 'P'; MRILIB_orients[1] = 'A'; break; 00331 case -2: MRILIB_orients[0] = 'A'; MRILIB_orients[1] = 'P'; break; 00332 case 3: MRILIB_orients[0] = 'I'; MRILIB_orients[1] = 'S'; break; 00333 case -3: MRILIB_orients[0] = 'S'; MRILIB_orients[1] = 'I'; break; 00334 default: MRILIB_orients[0] ='\0'; MRILIB_orients[1] ='\0'; break; 00335 } 00336 00337 /* y-axis orientation */ 00338 /* jj determines which spatial direction is y-axis */ 00339 /* and is the direction that has the biggest change */ 00340 /* between the BRHC and TRHC */ 00341 00342 dx = fabs(xyz[6]-xyz[3]) ; jj = 1 ; 00343 dy = fabs(xyz[7]-xyz[4]) ; if( dy > dx ){ jj=2; dx=dy; } 00344 dz = fabs(xyz[8]-xyz[5]) ; if( dz > dx ){ jj=3; } 00345 dx = xyz[jj+5]-xyz[jj+2] ; if( dx < 0. ){ jj = -jj; } 00346 switch( jj ){ 00347 case 1: MRILIB_orients[2] = 'L'; MRILIB_orients[3] = 'R'; break; 00348 case -1: MRILIB_orients[2] = 'R'; MRILIB_orients[3] = 'L'; break; 00349 case 2: MRILIB_orients[2] = 'P'; MRILIB_orients[3] = 'A'; break; 00350 case -2: MRILIB_orients[2] = 'A'; MRILIB_orients[3] = 'P'; break; 00351 case 3: MRILIB_orients[2] = 'I'; MRILIB_orients[3] = 'S'; break; 00352 case -3: MRILIB_orients[2] = 'S'; MRILIB_orients[3] = 'I'; break; 00353 default: MRILIB_orients[2] ='\0'; MRILIB_orients[3] ='\0'; break; 00354 } 00355 00356 MRILIB_orients[6] = '\0' ; /* terminate orientation string */ 00357 00358 kk = 6 - abs(ii)-abs(jj) ; /* which spatial direction is z-axis */ 00359 /* where 1=L-R, 2=P-A, 3=I-S */ 00360 zz = xyz[kk-1] ; /* z-coordinate of this slice (from TLHC) */ 00361 00362 im->zo = zz ; /* 07 Aug 2002: save slice offset */ 00363 00364 /* getting orientation of z-axis requires 2 images in a row -*/ 00365 00366 if( nzoff == 0 ){ /* from 1st GEMS image */ 00367 00368 zoff = zz ; /* save this for 2nd image calculation */ 00369 switch( kk ){ /* may be changed on second image */ 00370 case 1: MRILIB_orients[4] = 'L'; MRILIB_orients[5] = 'R'; break; 00371 case 2: MRILIB_orients[4] = 'P'; MRILIB_orients[5] = 'A'; break; 00372 case 3: MRILIB_orients[4] = 'I'; MRILIB_orients[5] = 'S'; break; 00373 default: MRILIB_orients[4] ='\0'; MRILIB_orients[5] ='\0'; break; 00374 } 00375 00376 } else if( nzoff == 1 ){ /* from 2nd GEMS image */ 00377 00378 float qoff = zz - zoff ; /* vive la difference */ 00379 if( qoff < 0 ) kk = -kk ; /* kk determines z-axis orientation */ 00380 00381 if( !use_MRILIB_slicespacing && qoff != 0.0 ){ /* 10 Jan 2004 */ 00382 use_MRILIB_slicespacing = 1 ; 00383 MRILIB_slicespacing = fabs(qoff) ; 00384 } 00385 00386 switch( kk ){ 00387 case 1: MRILIB_orients[4] = 'L'; MRILIB_orients[5] = 'R'; break; 00388 case -1: MRILIB_orients[4] = 'R'; MRILIB_orients[5] = 'L'; break; 00389 case 2: MRILIB_orients[4] = 'P'; MRILIB_orients[5] = 'A'; break; 00390 case -2: MRILIB_orients[4] = 'A'; MRILIB_orients[5] = 'P'; break; 00391 case 3: MRILIB_orients[4] = 'I'; MRILIB_orients[5] = 'S'; break; 00392 case -3: MRILIB_orients[4] = 'S'; MRILIB_orients[5] = 'I'; break; 00393 default: MRILIB_orients[4] ='\0'; MRILIB_orients[5] ='\0'; break; 00394 } 00395 00396 /* save spatial offset of first slice */ 00397 /* [this needs to be positive in the direction of] */ 00398 /* [the -z axis, so may need to change its sign ] */ 00399 00400 MRILIB_zoff = zoff ; use_MRILIB_zoff = 1 ; 00401 if( kk == 1 || kk == 2 || kk == 3 ) MRILIB_zoff = -MRILIB_zoff ; 00402 00403 /* Same for x offset; [20 Dec 2001] 00404 This must be at the middle of the TLHC voxel, 00405 so we must move a little bit towards the TRHC edge; 00406 We only use the result if the x-coordinate doesn't 00407 change significantly between the TRHC and BRHC, 00408 to avoid problems with oblique slices. */ 00409 00410 qq = abs(ii) ; 00411 MRILIB_xoff = ( xyz[qq-1]*(nx-0.5) + xyz[qq+2]*0.5 ) / nx ; 00412 if( ii == 1 || ii == 2 || ii == 3 ) MRILIB_xoff = -MRILIB_xoff ; 00413 use_MRILIB_xoff = ( fabs(xyz[qq+2]-xyz[qq+5]) < 0.01*dxx ) ; 00414 00415 /* Same for y offset; 00416 This must be at the middle of the TLHC voxel, 00417 so we must move a little bit towards the BRHC edge; 00418 We only use the result if the y-coordinate doesn't 00419 change significantly between the TLHC and TRHC. */ 00420 00421 qq = abs(jj) ; 00422 MRILIB_yoff = ( xyz[qq-1]*(ny-0.5) + xyz[qq+5]*0.5 ) / ny ; 00423 if( jj == 1 || jj == 2 || jj == 3 ) MRILIB_yoff = -MRILIB_yoff ; 00424 use_MRILIB_yoff = ( fabs(xyz[qq-1]-xyz[qq+2]) < 0.01*dyy ) ; 00425 } 00426 nzoff++ ; /* 3rd and later images don't count for z-orientation */ 00427 00428 /* get TR, save into global variable */ 00429 00430 if( MRILIB_tr <= 0.0 ){ 00431 fseek( imfile , hdroff+194+extraskip , SEEK_SET ) ; 00432 fread( &itr , 4,1 , imfile ) ; 00433 if( swap ) swap_4(&itr) ; 00434 MRILIB_tr = im->dt = 1.0e-6 * itr ; 00435 } 00436 } 00437 } /* end of trying to read image header */ 00438 00439 goto Ready_To_Roll ; /* skip to the reading place */ 00440 } 00441 } /* end of GEMS */ 00442 00443 /*--- OK, do it the old way ---*/ 00444 00445 The_Old_Way: 00446 00447 #if 0 00448 MRILIB_orients[0] = '\0' ; MRILIB_zoff = MRILIB_tr = 0.0 ; /* 03 Dec 2001 */ 00449 #endif 00450 00451 switch( length ){ 00452 00453 case 512: /* raw 16x16 short -- RWCox: 06 Dec 2001 */ 00454 im = mri_new( 16 , 16 , MRI_short ) ; 00455 break ; 00456 00457 case 2048: /* raw 32x32 short -- RWCox: 19 Sep 2000 */ 00458 im = mri_new( 32 , 32 , MRI_short ) ; 00459 break ; 00460 00461 case 4096: /* raw 64x64 byte -- RWC 3/21/95 */ 00462 im = mri_new( 64 , 64 , MRI_byte ) ; 00463 break ; 00464 00465 case 8192: /* raw 64x64 short */ 00466 case 16096: /* with Signa 5.x header */ 00467 im = mri_new( 64 , 64 , MRI_short ) ; 00468 skip = length - 8192 ; 00469 break ; 00470 00471 #if 0 00472 case 18432: /* raw 96x96 short */ 00473 im = mri_new( 96 , 96 , MRI_short ) ; 00474 break ; 00475 #endif 00476 00477 case 16384: /* raw 128x128 byte -- RWC 3/21/95 */ 00478 im = mri_new( 128 , 128 , MRI_byte ) ; 00479 break ; 00480 00481 case 32768: /* raw 128x128 short */ 00482 case 40672: /* with Signa 5.x header */ 00483 im = mri_new( 128 , 128 , MRI_short ) ; 00484 skip = length - 32768 ; 00485 break ; 00486 00487 case 65536: /* raw 256x256 8-bit -- Matthew Belmonte March 1995 */ 00488 im = mri_new( 256 , 256 , MRI_byte ) ; 00489 break ; 00490 00491 case 131072: /* raw 256x256 short */ 00492 case 138976: /* Signa 5.x */ 00493 case 145408: /* Signa 4.x */ 00494 00495 im = mri_new( 256 , 256 , MRI_short ) ; 00496 skip = length - 131072 ; 00497 break ; 00498 00499 #if 0 00500 case 262144: /* raw 256x256 float */ 00501 im = mri_new( 256 , 256 , MRI_float ) ; 00502 break ; 00503 #else 00504 case 262144: /* raw 512x512 byte -- RWC 3/21/95 */ 00505 im = mri_new( 512 , 512 , MRI_byte ) ; 00506 break ; 00507 00508 case 524288: /* raw 512x512 short -- RWC 3/21/95 */ 00509 im = mri_new( 512 , 512 , MRI_short ) ; 00510 break ; 00511 00512 case 1048576: /* raw 1024x1024 byte -- RWC 3/21/95 */ 00513 im = mri_new( 1024 , 1024 , MRI_byte ) ; 00514 break ; 00515 00516 case 2097152: /* raw 1024x1024 short -- RWC 3/21/95 */ 00517 im = mri_new( 1024 , 1024 , MRI_short ) ; 00518 break ; 00519 #endif 00520 00521 /** not a canonical length: try something else **/ 00522 00523 default: 00524 im = mri_try_mri( imfile , &skip ) ; /* Cox format */ 00525 if( im == NULL ) im = mri_try_7D ( imfile , &skip ) ; /* 7D format */ 00526 if( im == NULL ) im = mri_try_pgm( imfile , &skip ) ; /* PGM format */ 00527 if( im != NULL ) break ; 00528 00529 fclose( imfile ) ; /* close it, since we failed (so far) */ 00530 00531 im = mri_read_ascii( fname ) ; /* list of ASCII numbers */ 00532 if( im != NULL ) RETURN( im ); 00533 00534 im = mri_read_ppm( fname ) ; /* 15 Apr 1999 */ 00535 if( im != NULL ) RETURN( im ); 00536 00537 im = mri_read_stuff( fname ) ; /* 22 Nov 2002 */ 00538 if( im != NULL ) RETURN( im ); 00539 00540 fprintf( stderr , "do not recognize image file %s\n" , fname ); 00541 fprintf( stderr , "length seen as %d\n" , length ) ; 00542 RETURN( NULL ); 00543 } 00544 00545 /*-- Actually read the data from disk --*/ 00546 00547 Ready_To_Roll: 00548 00549 data = mri_data_pointer( im ) ; 00550 00551 length = fseek( imfile , skip , SEEK_SET ) ; 00552 if( length != 0 ){ 00553 fprintf( stderr , "mri_read error in skipping in file %s\n" , fname ) ; 00554 mri_free( im ) ; 00555 RETURN( NULL ); 00556 } 00557 00558 length = fread( data , im->pixel_size , im->nvox , imfile ) ; 00559 fclose( imfile ) ; 00560 00561 if( length != im->nvox ){ 00562 mri_free( im ) ; 00563 fprintf( stderr , "couldn't read image data from file %s\n" , fname ) ; 00564 RETURN( NULL ); 00565 } 00566 00567 mri_add_name( fname , im ) ; 00568 00569 /*-- 03 Dec 2001: maybe need to swap bytes --*/ 00570 00571 if( swap ){ 00572 switch( im->pixel_size ){ 00573 default: break ; 00574 case 2: swap_twobytes ( im->nvox, data ) ; break ; /* short */ 00575 case 4: swap_fourbytes( im->nvox, data ) ; break ; /* int, float */ 00576 case 8: swap_fourbytes( 2*im->nvox, data ) ; break ; /* complex */ 00577 } 00578 00579 im->was_swapped = 1 ; /* 07 Mar 2002 */ 00580 } 00581 00582 RETURN( im ); 00583 } |
|
Read an ANALYZE file into an ARRAY of 3D images [26 Aug 2002].
Definition at line 2683 of file mri_read.c. References ADDTO_IMARR, AFNI_noenv(), AFNI_yesenv(), ANDT_COMPLEX, ANDT_FLOAT, ANDT_RGB, ANDT_SIGNED_INT, ANDT_SIGNED_SHORT, ANDT_string, ANDT_UNSIGNED_CHAR, image_dimension::datatype, image_dimension::dim, dsr::dime, MRI_IMAGE::dt, dt, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, image_dimension::funused1, dsr::hist, INIT_IMARR, mri_add_name(), mri_data_pointer(), mri_datum_size(), mri_free(), mri_new_vol(), mri_scale_inplace(), mri_to_float(), MRILIB_orients, nz, data_history::originator, image_dimension::pixdim, RETURN, SEEK_SET, swap, swap_2(), swap_analyze_hdr(), swap_fourbytes(), swap_twobytes(), THD_filesize(), thd_floatscan(), and MRI_IMAGE::was_swapped.
02684 { 02685 FILE * fp ; 02686 char iname[1024] , buf[1024] ; 02687 int ii , jj , doswap ; 02688 struct dsr hdr ; /* ANALYZE .hdr format */ 02689 int ngood , length , kim , koff , datum_type , datum_len , swap ; 02690 int nx,ny,nz , hglobal=0 , himage=0 ; 02691 float dx,dy,dz ; 02692 MRI_IMARR * newar ; 02693 MRI_IMAGE * newim ; 02694 void * imar ; 02695 float fac=0.0 ; /* 27 Nov 2001 */ 02696 int floatize ; /* 28 Nov 2001 */ 02697 int spmorg=0 ; /* 28 Nov 2001 */ 02698 02699 int nt , nxyz ; /* 26 Aug 2002 */ 02700 float dt ; 02701 02702 ENTRY("mri_read3D_analyze75") ; 02703 02704 /* check & prepare filenames */ 02705 02706 if( hname == NULL ) RETURN(NULL) ; 02707 jj = strlen(hname) ; 02708 if( jj < 5 ) RETURN(NULL) ; 02709 if( strcmp(hname+jj-3,"hdr") != 0 ) RETURN(NULL) ; 02710 strcpy(iname,hname) ; strcpy(iname+jj-3,"img") ; 02711 02712 /* read header file into struct */ 02713 02714 fp = fopen( hname , "rb" ) ; 02715 if( fp == NULL ) RETURN(NULL) ; 02716 hdr.dime.dim[0] = 0 ; 02717 fread( &hdr , 1 , sizeof(struct dsr) , fp ) ; 02718 fclose(fp) ; 02719 if( hdr.dime.dim[0] == 0 ) RETURN(NULL) ; 02720 02721 /* check for swap-age */ 02722 02723 doswap = (hdr.dime.dim[0] < 0 || hdr.dime.dim[0] > 15) ; 02724 if( doswap ) swap_analyze_hdr( &hdr ) ; 02725 02726 /* 28 Nov 2001: attempt to decode originator a la SPM */ 02727 02728 { short xyzuv[5] , xx,yy,zz ; 02729 memcpy( xyzuv , hdr.hist.originator , 10 ) ; 02730 if( xyzuv[3] == 0 && xyzuv[4] == 0 ){ 02731 xx = xyzuv[0] ; yy = xyzuv[1] ; zz = xyzuv[2] ; 02732 if( doswap ){ swap_2(&xx); swap_2(&yy); swap_2(&zz); } 02733 if( xx > 0 && xx < hdr.dime.dim[1] && 02734 yy > 0 && yy < hdr.dime.dim[2] && 02735 zz > 0 && zz < hdr.dime.dim[3] ) spmorg = 1 ; 02736 } 02737 } 02738 if( spmorg ) strcpy( MRILIB_orients , "LRPAIS" ) ; 02739 02740 /* 27 Nov 2001: get a scale factor for images */ 02741 02742 if( !AFNI_noenv("AFNI_ANALYZE_SCALE") ){ 02743 fac = hdr.dime.funused1 ; 02744 (void) thd_floatscan( 1 , &fac ) ; 02745 if( fac < 0.0 || fac == 1.0 ) fac = 0.0 ; 02746 } 02747 02748 floatize = (fac != 0.0 || AFNI_yesenv("AFNI_ANALYZE_FLOATIZE")) ; /* 28 Nov 2001 */ 02749 02750 /* get data type into mrilib MRI_* form */ 02751 02752 switch( hdr.dime.datatype ){ 02753 default: 02754 fprintf(stderr,"*** %s: Unknown ANALYZE datatype=%d (%s)\n", 02755 hname,hdr.dime.datatype,ANDT_string(hdr.dime.datatype) ) ; 02756 RETURN(NULL) ; 02757 02758 case ANDT_UNSIGNED_CHAR: datum_type = MRI_byte ; break; 02759 case ANDT_SIGNED_SHORT: datum_type = MRI_short ; break; 02760 case ANDT_SIGNED_INT: datum_type = MRI_int ; break; 02761 case ANDT_FLOAT: datum_type = MRI_float ; floatize = 0; break; 02762 case ANDT_COMPLEX: datum_type = MRI_complex; floatize = 0; break; 02763 case ANDT_RGB: datum_type = MRI_rgb ; floatize = 0; break; 02764 } 02765 02766 datum_len = mri_datum_size(datum_type) ; 02767 02768 /* compute dimensions of images, and number of images */ 02769 02770 nx = hdr.dime.dim[1] ; 02771 ny = hdr.dime.dim[2] ; 02772 if( nx < 2 || ny < 2 ) RETURN(NULL) ; 02773 02774 switch( hdr.dime.dim[0] ){ 02775 case 2: nz = 1 ; nt = 1 ; ; break ; 02776 case 3: nz = hdr.dime.dim[3] ; nt = 1 ; ; break ; 02777 02778 default: 02779 case 4: nz = hdr.dime.dim[3] ; nt = hdr.dime.dim[4] ; break ; 02780 } 02781 if( nz < 1 ) nz = 1 ; 02782 if( nt < 1 ) nt = 1 ; 02783 02784 dx = hdr.dime.pixdim[1] ; 02785 dy = hdr.dime.pixdim[2] ; 02786 dz = hdr.dime.pixdim[3] ; 02787 dt = hdr.dime.pixdim[4] ; if( dt <= 0.0 ) dt = 1.0 ; 02788 02789 /* open .img file and read images from it */ 02790 02791 length = THD_filesize(iname) ; 02792 if( length <= 0 ){ 02793 fprintf(stderr,"*** Can't find ANALYZE file %s\n",iname) ; 02794 RETURN(NULL) ; 02795 } 02796 02797 fp = fopen( iname , "rb" ) ; 02798 if( fp == NULL ){ 02799 fprintf(stderr,"*** Can't open ANALYZE file %s\n",iname) ; 02800 RETURN(NULL) ; 02801 } 02802 02803 ngood = datum_len*nx*ny*nz*nt ; 02804 if( length < ngood ){ 02805 fprintf( stderr, 02806 "*** ANALYZE file %s is %d bytes long but must be at least %d bytes long\n" 02807 "*** for nx=%d ny=%d nz=%d nt=%d and voxel=%d bytes\n", 02808 iname,length,ngood,nx,ny,nz,nt,datum_len ) ; 02809 fclose(fp) ; RETURN(NULL) ; 02810 } 02811 02812 /*** read images from the file ***/ 02813 02814 INIT_IMARR(newar) ; 02815 02816 for( kim=0 ; kim < nt ; kim++ ){ 02817 koff = hglobal + (kim+1)*himage + datum_len*nxyz*kim ; 02818 fseek( fp , koff , SEEK_SET ) ; 02819 02820 newim = mri_new_vol( nx,ny,nz , datum_type ) ; 02821 imar = mri_data_pointer( newim ) ; 02822 length = fread( imar , datum_len , nxyz , fp ) ; 02823 02824 if( doswap ){ 02825 switch( datum_len ){ 02826 default: break ; 02827 case 2: swap_twobytes ( nxyz , imar ) ; break ; /* short */ 02828 case 4: swap_fourbytes( nxyz , imar ) ; break ; /* int, float */ 02829 case 8: swap_fourbytes( 2*nxyz , imar ) ; break ; /* complex */ 02830 } 02831 newim->was_swapped = 1 ; /* 07 Mar 2002 */ 02832 } 02833 02834 /* 28 Nov 2001: convert to floats? */ 02835 02836 if( floatize ){ 02837 MRI_IMAGE *qim = mri_to_float(newim) ; 02838 mri_free(newim) ; newim = qim ; 02839 } 02840 02841 if( nt == 1 ) mri_add_name( iname , newim ) ; 02842 else { 02843 sprintf( buf , "%s#%d" , iname,kim ) ; 02844 mri_add_name( buf , newim ) ; 02845 } 02846 02847 newim->dx = dx ; newim->dy = dy ; newim->dz = dz ; newim->dt = dt ; newim->dw = 1.0 ; 02848 ADDTO_IMARR(newar,newim) ; 02849 02850 /* 27 Nov 2001: scale image? */ 02851 02852 if( fac != 0.0 ) mri_scale_inplace( fac , newim ) ; 02853 } 02854 02855 fclose(fp) ; RETURN(newar) ; 02856 } |
|
Read an ASCII file as columns, transpose to rows, allow column selectors.
Definition at line 2079 of file mri_read.c. References ENTRY, far, free, MCW_get_intlist(), mri_1D_fromstring(), MRI_FLOAT_PTR, mri_free(), mri_new(), mri_read_ascii(), mri_transpose(), MRI_IMAGE::nx, MRI_IMAGE::ny, and RETURN. Referenced by AFNI_finalize_read_1D_CB(), conv_set_ref(), custom_filter(), DT_read_opts(), GRA_refread_choose_CB(), IJKAR_reader(), initialize_program(), main(), MAIN_workprocess(), matrix_file_read(), NL_main(), Process_Options(), read_nodes_file(), read_one_time_series(), read_sxyz_1D(), read_table(), read_time_series(), sdata_from_1D(), SUMA_Load1DDset(), SUMA_Load_Surface_Object_eng(), SUMA_OpenDrawnROI_1D(), SUMA_Read_Color_Map_1D(), SUMA_Read_IRGB_file(), SUMA_readFScurv(), SUMA_ReadSegDO(), SUMA_VEC_Read(), THD_fetch_1D(), THD_get_all_timeseries(), THD_load_1D(), THD_open_1D(), and TS_reader().
02080 { 02081 MRI_IMAGE *inim , *outim , *flim ; 02082 char dname[512] , *cpt , *dpt ; 02083 int ii,jj,nx,ny,nts , *ivlist , *ivl , *sslist ; 02084 float *far , *oar ; 02085 02086 ENTRY("mri_read_1D") ; 02087 02088 if( fname == NULL || fname[0] == '\0' || strlen(fname) > 511 ) RETURN(NULL) ; 02089 02090 if( strncmp(fname,"1D:",3) == 0 ){ /* 28 Apr 2003 */ 02091 return mri_1D_fromstring( fname+3 ) ; 02092 } 02093 02094 /*-- split filename and subvector list --*/ 02095 02096 cpt = strstr(fname,"[") ; 02097 dpt = strstr(fname,"{") ; /* 30 Apr 2003: subsampling list */ 02098 02099 if( cpt == fname || dpt == fname ){ /* can't be at start of filename! */ 02100 fprintf(stderr,"*** Illegal filename in mri_read_1D: %s\n",fname) ; 02101 RETURN(NULL) ; 02102 } else { /* got a subvector list */ 02103 strcpy( dname , fname ) ; 02104 if( cpt != NULL ){ ii = cpt-fname; dname[ii] = '\0'; } 02105 if( dpt != NULL ){ ii = dpt-fname; dname[ii] = '\0'; } 02106 } 02107 02108 /*-- read file in --*/ 02109 02110 inim = mri_read_ascii(dname) ; 02111 if( inim == NULL ) RETURN(NULL) ; 02112 flim = mri_transpose(inim) ; mri_free(inim) ; 02113 02114 /*-- get the subvector and subsampling lists, if any --*/ 02115 02116 nx = flim->nx ; ny = flim->ny ; 02117 02118 ivlist = MCW_get_intlist( ny , cpt ) ; /* subvector list */ 02119 sslist = MCW_get_intlist( nx , dpt ) ; /* subsampling list */ 02120 02121 /* if have subvector list, extract those rows into a new image */ 02122 02123 if( ivlist != NULL && ivlist[0] > 0 ){ 02124 nts = ivlist[0] ; /* number of subvectors */ 02125 ivl = ivlist + 1 ; /* start of array of subvectors */ 02126 02127 for( ii=0 ; ii < nts ; ii++ ){ /* check them out */ 02128 if( ivl[ii] < 0 || ivl[ii] >= ny ){ 02129 fprintf(stderr,"*** Out-of-range subvector [list] in mri_read_1D: %s\n",fname) ; 02130 mri_free(flim) ; free(ivlist) ; RETURN(NULL) ; 02131 } 02132 } 02133 02134 outim = mri_new( nx , nts , MRI_float ) ; /* make output image */ 02135 far = MRI_FLOAT_PTR( flim ) ; 02136 oar = MRI_FLOAT_PTR( outim ) ; 02137 02138 for( ii=0 ; ii < nts ; ii++ ) /* copy desired rows */ 02139 memcpy( oar + ii*nx , far + ivl[ii]*nx , sizeof(float)*nx ) ; 02140 02141 mri_free(flim); free(ivlist); flim = outim; ny = nts; 02142 } 02143 02144 /* if have subsampling list, extract those columns into a new image */ 02145 02146 if( sslist != NULL && sslist[0] > 0 ){ 02147 nts = sslist[0] ; /* number of columns to get */ 02148 ivl = sslist + 1 ; /* start of array of column indexes */ 02149 02150 for( ii=0 ; ii < nts ; ii++ ){ /* check them out */ 02151 if( ivl[ii] < 0 || ivl[ii] >= nx ){ 02152 fprintf(stderr,"*** Out-of-range subsampling {list} in mri_read_1D: %s\n",fname) ; 02153 mri_free(flim) ; free(sslist) ; RETURN(NULL) ; 02154 } 02155 } 02156 02157 outim = mri_new( nts , ny , MRI_float ) ; /* make output image */ 02158 far = MRI_FLOAT_PTR( flim ) ; 02159 oar = MRI_FLOAT_PTR( outim ) ; 02160 02161 for( ii=0 ; ii < nts ; ii++ ) /* copy desired columns */ 02162 for( jj=0 ; jj < ny ; jj++ ) 02163 oar[ii+jj*nts] = far[ivl[ii]+jj*nx] ; 02164 02165 mri_free(flim); free(sslist); flim = outim; 02166 } 02167 02168 RETURN(flim) ; 02169 } |
|
read lines, convert to floats, store * Definition at line 2327 of file mri_read.c. References ADDTO_IMARR, ENTRY, free, INIT_IMARR, mri_add_name(), MRI_FLOAT_PTR, mri_free(), mri_new(), mri_to_byte_scl(), mri_to_short(), nz, read_ascii_floats(), realloc, and RETURN. Referenced by mri_read_file(), and mri_read_file_delay().
02328 { 02329 int nx , ny , nz , ii , nxyz,nxy , nff ; 02330 int ngood , length , kim , datum_type ; 02331 char fname[256]="\0" , buf[512] ; 02332 MRI_IMARR * newar ; 02333 MRI_IMAGE * newim , * flim ; 02334 float * ff ; 02335 02336 ENTRY("mri_read_3A") ; 02337 02338 /*** get info from 3A tname ***/ 02339 02340 if( tname == NULL || strlen(tname) < 10 ) RETURN(NULL) ; 02341 02342 switch( tname[2] ){ /* allow for 3As:, 3Ab:, 3Af: */ 02343 02344 default: ngood = 0 ; break ; 02345 02346 case 's': 02347 ngood = sscanf( tname, "3As:%d:%d:%d:%s", &nx, &ny, &nz, fname ) ; 02348 datum_type = MRI_short ; 02349 break ; 02350 02351 case 'b': 02352 ngood = sscanf( tname, "3Ab:%d:%d:%d:%s", &nx, &ny, &nz, fname ) ; 02353 datum_type = MRI_byte ; 02354 break ; 02355 02356 case 'f': 02357 ngood = sscanf( tname, "3Af:%d:%d:%d:%s", &nx, &ny, &nz, fname ) ; 02358 datum_type = MRI_float ; 02359 break ; 02360 } 02361 02362 if( ngood < 4 || nx <= 0 || ny <= 0 || nz <= 0 || strlen(fname) <= 0 ) RETURN(NULL) ; 02363 02364 /* read the input file */ 02365 02366 read_ascii_floats( fname , &nff , &ff ) ; 02367 02368 if( nff <= 0 || ff == NULL ) RETURN(NULL) ; 02369 02370 nxy = nx*ny ; nxyz = nxy*nz ; 02371 02372 if( nff < nxyz ){ 02373 fprintf(stderr, 02374 "\n** WARNING: %s is too short - padding with %d zeros\n", 02375 tname,nxyz-nff) ; 02376 ff = (float *) realloc( ff , sizeof(float) * nxyz ) ; 02377 for( ii=nff ; ii < nxyz ; ii++ ) ff[ii] = 0.0 ; 02378 nff = nxyz ; 02379 } else if( nff > nxyz ){ 02380 fprintf(stderr, 02381 "\n** WARNING: %s is too long - truncating off last %d values\n", 02382 tname,nff-nxyz) ; 02383 } 02384 02385 /* put the input data into MRI_IMAGEs */ 02386 02387 INIT_IMARR(newar) ; 02388 02389 for( kim=0 ; kim < nz ; kim++ ){ 02390 flim = mri_new( nx,ny , MRI_float ) ; 02391 memcpy( MRI_FLOAT_PTR(flim) , ff+nxy*kim , sizeof(float)*nxy ) ; 02392 switch( datum_type ){ 02393 case MRI_float: newim = flim ; break ; 02394 case MRI_short: newim = mri_to_short(1.0,flim) ; mri_free(flim) ; break ; 02395 case MRI_byte: newim = mri_to_byte_scl(1.0,0.0,flim) ; mri_free(flim) ; break ; 02396 } 02397 02398 if( nz == 1 ) mri_add_name( fname , newim ) ; 02399 else { 02400 sprintf( buf , "%s#%d" , fname,kim ) ; 02401 mri_add_name( buf , newim ) ; 02402 } 02403 02404 ADDTO_IMARR(newar,newim) ; 02405 } 02406 02407 free(ff) ; RETURN(newar) ; 02408 } |
|
Read one or more 2D slices from a "3D:" formatted image file. Definition at line 817 of file mri_read.c. References ADDTO_IMARR, ENTRY, INIT_IMARR, L, mri_add_name(), mri_data_pointer(), mri_new(), mri_swapbytes(), MRI_IMAGE::nvox, nz, MRI_IMAGE::pixel_size, RETURN, SEEK_END, SEEK_SET, swap, and MRI_IMAGE::was_swapped. Referenced by mri_read_file().
00818 { 00819 int hglobal , himage , nx , ny , nz ; 00820 char fname[256] , buf[512] ; 00821 int ngood , length , kim , koff , datum_type , datum_len , swap ; 00822 MRI_IMARR * newar ; 00823 MRI_IMAGE * newim ; 00824 void * imar ; 00825 FILE * imfile ; 00826 00827 ENTRY("mri_read_3D") ; 00828 00829 /*** get info from 3D tname ***/ 00830 00831 if( tname == NULL || strlen(tname) < 10 ) RETURN(NULL) ; 00832 00833 switch( tname[2] ){ /* allow for 3D: or 3Ds: or 3Db:, etc */ 00834 00835 default: 00836 case ':': 00837 ngood = sscanf( tname , "3D:%d:%d:%d:%d:%d:%s" , 00838 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00839 00840 swap = 0 ; 00841 datum_type = MRI_short ; 00842 datum_len = sizeof(short) ; /* better be 2 */ 00843 break ; 00844 00845 case 's': 00846 ngood = sscanf( tname , "3Ds:%d:%d:%d:%d:%d:%s" , 00847 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00848 00849 swap = 1 ; 00850 datum_type = MRI_short ; 00851 datum_len = sizeof(short) ; /* better be 2 */ 00852 break ; 00853 00854 case 'b': 00855 ngood = sscanf( tname , "3Db:%d:%d:%d:%d:%d:%s" , 00856 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00857 00858 swap = 0 ; 00859 datum_type = MRI_byte ; 00860 datum_len = sizeof(byte) ; /* better be 1 */ 00861 break ; 00862 00863 case 'f': 00864 ngood = sscanf( tname , "3Df:%d:%d:%d:%d:%d:%s" , 00865 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00866 00867 swap = 0 ; 00868 datum_type = MRI_float ; 00869 datum_len = sizeof(float) ; /* better be 4 */ 00870 break ; 00871 00872 case 'd': /* 06 Feb 2003 */ 00873 ngood = sscanf( tname , "3Dd:%d:%d:%d:%d:%d:%s" , 00874 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00875 00876 swap = 0 ; 00877 datum_type = MRI_double ; 00878 datum_len = sizeof(double) ; /* better be 8 */ 00879 break ; 00880 00881 case 'i': 00882 ngood = sscanf( tname , "3Di:%d:%d:%d:%d:%d:%s" , 00883 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00884 00885 swap = 0 ; 00886 datum_type = MRI_int ; 00887 datum_len = sizeof(int) ; /* better be 4 */ 00888 break ; 00889 00890 case 'c': 00891 ngood = sscanf( tname , "3Dc:%d:%d:%d:%d:%d:%s" , 00892 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00893 00894 swap = 0 ; 00895 datum_type = MRI_complex ; 00896 datum_len = sizeof(complex) ; /* better be 8 */ 00897 break ; 00898 00899 case 'r': 00900 ngood = sscanf( tname , "3Dr:%d:%d:%d:%d:%d:%s" , 00901 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 00902 00903 swap = 0 ; 00904 datum_type = MRI_rgb ; 00905 datum_len = 3*sizeof(byte) ; /* better be 3 */ 00906 break ; 00907 } 00908 00909 if( ngood < 6 || himage < 0 || 00910 nx <= 0 || ny <= 0 || nz <= 0 || 00911 strlen(fname) <= 0 ) RETURN(NULL); /* bad info */ 00912 00913 /*** 06 Mar 2001: special case of fname ***/ 00914 00915 if( strcmp(fname,"ALLZERO") == 0 ){ 00916 INIT_IMARR(newar) ; 00917 for( kim=0 ; kim < nz ; kim++ ){ 00918 newim = mri_new( nx , ny , datum_type ) ; 00919 imar = mri_data_pointer( newim ) ; 00920 memset( imar , 0 , newim->nvox * newim->pixel_size ) ; 00921 sprintf( buf , "%s#%d" , fname,kim ) ; 00922 mri_add_name( buf , newim ) ; 00923 ADDTO_IMARR(newar,newim) ; 00924 } 00925 RETURN(newar); 00926 } 00927 00928 /*** open the input file and position it ***/ 00929 00930 imfile = fopen( fname , "r" ) ; 00931 if( imfile == NULL ){ 00932 fprintf( stderr , "couldn't open image file %s\n" , fname ) ; 00933 RETURN(NULL); 00934 } 00935 00936 fseek( imfile , 0L , SEEK_END ) ; /* get the length of the file */ 00937 length = ftell( imfile ) ; 00938 00939 /** 13 Apr 1999: modified to allow actual hglobal < -1 00940 as long as hglobal+himage >= 0 **/ 00941 00942 #if 0 /* the old code */ 00943 if( hglobal < 0 ){ 00944 hglobal = length - nz*(datum_len*nx*ny+himage) ; 00945 if( hglobal < 0 ) hglobal = 0 ; 00946 } 00947 #else /* 13 Apr 1999 */ 00948 if( hglobal == -1 || hglobal+himage < 0 ){ 00949 hglobal = length - nz*(datum_len*nx*ny+himage) ; 00950 if( hglobal < 0 ) hglobal = 0 ; 00951 } 00952 #endif 00953 00954 ngood = hglobal + nz*(datum_len*nx*ny+himage) ; 00955 if( length < ngood ){ 00956 fprintf( stderr, 00957 "image file %s is %d bytes long but must be at least %d bytes long\n" 00958 "for hglobal=%d himage=%d nx=%d ny=%d nz=%d and voxel=%d bytes\n", 00959 fname,length,ngood,hglobal,himage,nx,ny,nz,datum_len ) ; 00960 fclose( imfile ) ; 00961 RETURN(NULL); 00962 } 00963 00964 /*** read images from the file ***/ 00965 00966 INIT_IMARR(newar) ; 00967 00968 for( kim=0 ; kim < nz ; kim++ ){ 00969 koff = hglobal + (kim+1)*himage + datum_len*nx*ny*kim ; 00970 fseek( imfile , koff , SEEK_SET ) ; 00971 00972 newim = mri_new( nx , ny , datum_type ) ; 00973 imar = mri_data_pointer( newim ) ; 00974 length = fread( imar , datum_len , nx * ny , imfile ) ; 00975 if( swap ){ 00976 mri_swapbytes( newim ) ; 00977 newim->was_swapped = 1 ; /* 07 Mar 2002 */ 00978 } 00979 00980 if( nz == 1 ) mri_add_name( fname , newim ) ; 00981 else { 00982 sprintf( buf , "%s#%d" , fname,kim ) ; 00983 mri_add_name( buf , newim ) ; 00984 } 00985 00986 ADDTO_IMARR(newar,newim) ; 00987 } 00988 00989 fclose(imfile) ; 00990 RETURN(newar); 00991 } |
|
Definition at line 3292 of file mri_read.c. References ADDTO_IMARR, MRI_IMAGE::foffset, MRI_IMAGE::fondisk, INIT_IMARR, L, mri_add_fname_delay(), mri_add_name(), mri_new_vol_empty(), nz, SEEK_END, and swap. Referenced by mri_read_file_delay().
03293 { 03294 int hglobal , himage , nx , ny , nz ; 03295 char fname[256] , buf[512] ; 03296 int ngood , length , kim , datum_type , datum_len , swap ; 03297 MRI_IMARR * newar ; 03298 MRI_IMAGE * newim ; 03299 FILE * imfile ; 03300 03301 /*** get info from 3D tname ***/ 03302 03303 if( tname == NULL || strlen(tname) < 10 ) return NULL ; 03304 03305 switch( tname[2] ){ /* allow for 3D: or 3Ds: or 3Db: */ 03306 03307 default: 03308 case ':': 03309 ngood = sscanf( tname , "3D:%d:%d:%d:%d:%d:%s" , 03310 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03311 03312 swap = 0 ; 03313 datum_type = MRI_short ; 03314 datum_len = sizeof(short) ; /* better be 2 */ 03315 break ; 03316 03317 case 's': 03318 ngood = sscanf( tname , "3Ds:%d:%d:%d:%d:%d:%s" , 03319 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03320 03321 swap = 1 ; 03322 datum_type = MRI_short ; 03323 datum_len = sizeof(short) ; /* better be 2 */ 03324 break ; 03325 03326 case 'b': 03327 ngood = sscanf( tname , "3Db:%d:%d:%d:%d:%d:%s" , 03328 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03329 03330 swap = 0 ; 03331 datum_type = MRI_byte ; 03332 datum_len = sizeof(byte) ; /* better be 1 */ 03333 break ; 03334 03335 case 'f': 03336 ngood = sscanf( tname , "3Df:%d:%d:%d:%d:%d:%s" , 03337 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03338 03339 swap = 0 ; 03340 datum_type = MRI_float ; 03341 datum_len = sizeof(float) ; /* better be 4 */ 03342 break ; 03343 03344 case 'd': /* 06 Feb 2003 */ 03345 ngood = sscanf( tname , "3Dd:%d:%d:%d:%d:%d:%s" , 03346 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03347 03348 swap = 0 ; 03349 datum_type = MRI_float ; 03350 datum_len = sizeof(double) ; /* better be 8 */ 03351 break ; 03352 03353 case 'i': 03354 ngood = sscanf( tname , "3Di:%d:%d:%d:%d:%d:%s" , 03355 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03356 03357 swap = 0 ; 03358 datum_type = MRI_int ; 03359 datum_len = sizeof(int) ; /* better be 4 */ 03360 break ; 03361 03362 case 'c': 03363 ngood = sscanf( tname , "3Dc:%d:%d:%d:%d:%d:%s" , 03364 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03365 03366 swap = 0 ; 03367 datum_type = MRI_complex ; 03368 datum_len = sizeof(complex) ; /* better be 8 */ 03369 break ; 03370 03371 case 'r': 03372 ngood = sscanf( tname , "3Dr:%d:%d:%d:%d:%d:%s" , 03373 &hglobal , &himage , &nx , &ny , &nz , fname ) ; 03374 03375 swap = 0 ; 03376 datum_type = MRI_rgb ; 03377 datum_len = 3*sizeof(byte) ; /* better be 3 */ 03378 break ; 03379 } 03380 03381 if( ngood < 6 || himage < 0 || 03382 nx <= 0 || ny <= 0 || nz <= 0 || 03383 strlen(fname) <= 0 ) return NULL ; /* bad info */ 03384 03385 /*** open the input file and position it [06 Mar 2001: maybe not] ***/ 03386 03387 if( strcmp(fname,"ALLZERO") != 0 ){ 03388 imfile = fopen( fname , "r" ) ; 03389 if( imfile == NULL ){ 03390 fprintf( stderr , "couldn't open delayed image file %s\n" , fname ) ; 03391 return NULL ; 03392 } 03393 } else { 03394 imfile = NULL ; 03395 } 03396 03397 if( imfile != NULL ){ 03398 fseek( imfile , 0L , SEEK_END ) ; /* get the length of the file */ 03399 length = ftell( imfile ) ; 03400 03401 /** 13 Apr 1999: modified to allow actual hglobal < -1 03402 as long as hglobal+himage >= 0 **/ 03403 03404 #if 0 /* the old code */ 03405 if( hglobal < 0 ){ 03406 hglobal = length - nz*(datum_len*nx*ny+himage) ; 03407 if( hglobal < 0 ) hglobal = 0 ; 03408 } 03409 #else /* 13 Apr 1999 */ 03410 if( hglobal == -1 || hglobal+himage < 0 ){ 03411 hglobal = length - nz*(datum_len*nx*ny+himage) ; 03412 if( hglobal < 0 ) hglobal = 0 ; 03413 } 03414 #endif 03415 03416 ngood = hglobal + nz*(datum_len*nx*ny+himage) ; 03417 if( length < ngood ){ 03418 fprintf( stderr, 03419 "file %s is %d bytes long but must be at least %d bytes long\n" 03420 "for hglobal=%d himage=%d nx=%d ny=%d nz=%d and voxel=%d bytes\n", 03421 fname,length,ngood,hglobal,himage,nx,ny,nz,datum_len ) ; 03422 fclose( imfile ) ; 03423 return NULL ; 03424 } 03425 fclose( imfile ) ; 03426 } 03427 03428 /*** put pointers to data in the file into the images ***/ 03429 03430 INIT_IMARR(newar) ; 03431 03432 for( kim=0 ; kim < nz ; kim++ ){ 03433 newim = mri_new_vol_empty( nx,ny,1 , datum_type ) ; /* empty image */ 03434 mri_add_fname_delay( fname , newim ) ; /* put filename in */ 03435 newim->fondisk = (swap) ? (INPUT_DELAY | BSWAP_DELAY) /* mark read type */ 03436 : (INPUT_DELAY) ; 03437 newim->foffset = hglobal + (kim+1)*himage + datum_len*nx*ny*kim ; 03438 03439 if( nz == 1 ) mri_add_name( fname , newim ) ; 03440 else { 03441 sprintf( buf , "%s#%d" , fname,kim ) ; 03442 mri_add_name( buf , newim ) ; 03443 } 03444 03445 ADDTO_IMARR(newar,newim) ; 03446 } 03447 03448 return newar ; 03449 } |
|
Read an ANALYZE file into an ARRAY of 2D images.
Definition at line 2502 of file mri_read.c. References ADDTO_IMARR, AFNI_noenv(), AFNI_yesenv(), ANDT_COMPLEX, ANDT_DOUBLE, ANDT_FLOAT, ANDT_RGB, ANDT_SIGNED_INT, ANDT_SIGNED_SHORT, ANDT_string, ANDT_UNSIGNED_CHAR, image_dimension::datatype, image_dimension::dim, dsr::dime, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, image_dimension::funused1, dsr::hist, INIT_IMARR, mri_add_name(), mri_data_pointer(), mri_datum_size(), mri_free(), mri_new(), mri_scale_inplace(), mri_to_float(), MRILIB_orients, nz, data_history::originator, image_dimension::pixdim, RETURN, SEEK_SET, swap, swap_2(), swap_analyze_hdr(), swap_fourbytes(), swap_twobytes(), THD_filesize(), thd_floatscan(), and MRI_IMAGE::was_swapped. Referenced by main(), mri_read_file(), and mri_read_file_delay().
02503 { 02504 FILE * fp ; 02505 char iname[1024] , buf[1024] ; 02506 int ii , jj , doswap ; 02507 struct dsr hdr ; /* ANALYZE .hdr format */ 02508 int ngood , length , kim , koff , datum_type , datum_len , swap ; 02509 int nx,ny,nz , hglobal=0 , himage=0 ; 02510 float dx,dy,dz ; 02511 MRI_IMARR * newar ; 02512 MRI_IMAGE * newim ; 02513 void * imar ; 02514 float fac=0.0 ; /* 27 Nov 2001 */ 02515 int floatize ; /* 28 Nov 2001 */ 02516 int spmorg=0 ; /* 28 Nov 2001 */ 02517 02518 ENTRY("mri_read_analyze75") ; 02519 02520 /* check & prepare filenames */ 02521 02522 if( hname == NULL ) RETURN(NULL) ; 02523 jj = strlen(hname) ; 02524 if( jj < 5 ) RETURN(NULL) ; 02525 if( strcmp(hname+jj-3,"hdr") != 0 ) RETURN(NULL) ; 02526 strcpy(iname,hname) ; strcpy(iname+jj-3,"img") ; 02527 02528 /* read header file into struct */ 02529 02530 fp = fopen( hname , "rb" ) ; 02531 if( fp == NULL ) RETURN(NULL) ; 02532 hdr.dime.dim[0] = 0 ; 02533 fread( &hdr , 1 , sizeof(struct dsr) , fp ) ; 02534 fclose(fp) ; 02535 if( hdr.dime.dim[0] == 0 ) RETURN(NULL) ; 02536 02537 /* check for swap-age */ 02538 02539 doswap = (hdr.dime.dim[0] < 0 || hdr.dime.dim[0] > 15) ; 02540 if( doswap ) swap_analyze_hdr( &hdr ) ; 02541 02542 /* 28 Nov 2001: attempt to decode originator a la SPM */ 02543 02544 { short xyzuv[5] , xx,yy,zz ; 02545 memcpy( xyzuv , hdr.hist.originator , 10 ) ; 02546 if( xyzuv[3] == 0 && xyzuv[4] == 0 ){ 02547 xx = xyzuv[0] ; yy = xyzuv[1] ; zz = xyzuv[2] ; 02548 if( doswap ){ swap_2(&xx); swap_2(&yy); swap_2(&zz); } 02549 if( xx > 0 && xx < hdr.dime.dim[1] && 02550 yy > 0 && yy < hdr.dime.dim[2] && 02551 zz > 0 && zz < hdr.dime.dim[3] ) spmorg = 1 ; 02552 } 02553 } 02554 if( spmorg ) strcpy( MRILIB_orients , "LRPAIS" ) ; 02555 02556 /* 27 Nov 2001: get a scale factor for images */ 02557 02558 if( !AFNI_noenv("AFNI_ANALYZE_SCALE") ){ 02559 fac = hdr.dime.funused1 ; 02560 (void) thd_floatscan( 1 , &fac ) ; 02561 if( fac < 0.0 || fac == 1.0 ) fac = 0.0 ; 02562 } 02563 02564 floatize = (fac != 0.0 || AFNI_yesenv("AFNI_ANALYZE_FLOATIZE")) ; /* 28 Nov 2001 */ 02565 02566 /* get data type into mrilib MRI_* form */ 02567 02568 switch( hdr.dime.datatype ){ 02569 default: 02570 fprintf(stderr,"*** %s: Unknown ANALYZE datatype=%d (%s)\n", 02571 hname,hdr.dime.datatype,ANDT_string(hdr.dime.datatype) ) ; 02572 RETURN(NULL) ; 02573 02574 case ANDT_UNSIGNED_CHAR: datum_type = MRI_byte ; break; 02575 case ANDT_SIGNED_SHORT: datum_type = MRI_short ; break; 02576 case ANDT_SIGNED_INT: datum_type = MRI_int ; break; 02577 case ANDT_FLOAT: datum_type = MRI_float ; floatize = 0; break; 02578 case ANDT_COMPLEX: datum_type = MRI_complex; floatize = 0; break; 02579 case ANDT_RGB: datum_type = MRI_rgb ; floatize = 0; break; 02580 case ANDT_DOUBLE: datum_type = MRI_double ; floatize = 0; break; 02581 } 02582 02583 datum_len = mri_datum_size(datum_type) ; 02584 02585 /* compute dimensions of images, and number of images */ 02586 02587 nx = hdr.dime.dim[1] ; 02588 ny = hdr.dime.dim[2] ; 02589 if( nx < 2 || ny < 2 ) RETURN(NULL) ; 02590 02591 switch( hdr.dime.dim[0] ){ 02592 case 2: nz = 1 ; break ; 02593 case 3: nz = hdr.dime.dim[3] ; break ; 02594 02595 default: 02596 case 4: nz = hdr.dime.dim[3] * hdr.dime.dim[4] ; break ; 02597 } 02598 if( nz < 1 ) nz = 1 ; 02599 02600 dx = hdr.dime.pixdim[1] ; 02601 dy = hdr.dime.pixdim[2] ; 02602 dz = hdr.dime.pixdim[3] ; 02603 02604 /** fprintf(stderr,"mri_read_analyze75: nx=%d ny=%d nz=%d\n",nx,ny,nz) ; **/ 02605 /** fprintf(stderr,"mri_read_analyze75: dx=%g dy=%g dz=%g\n",dx,dy,dz) ; **/ 02606 02607 /* open .img file and read images from it */ 02608 02609 length = THD_filesize(iname) ; 02610 if( length <= 0 ){ 02611 fprintf(stderr,"*** Can't find ANALYZE file %s\n",iname) ; 02612 RETURN(NULL) ; 02613 } 02614 02615 fp = fopen( iname , "rb" ) ; 02616 if( fp == NULL ){ 02617 fprintf(stderr,"*** Can't open ANALYZE file %s\n",iname) ; 02618 RETURN(NULL) ; 02619 } 02620 02621 ngood = datum_len*nx*ny*nz ; 02622 if( length < ngood ){ 02623 fprintf( stderr, 02624 "*** ANALYZE file %s is %d bytes long but must be at least %d bytes long\n" 02625 "*** for nx=%d ny=%d nz=%d and voxel=%d bytes\n", 02626 iname,length,ngood,nx,ny,nz,datum_len ) ; 02627 fclose(fp) ; RETURN(NULL) ; 02628 } 02629 02630 /*** read images from the file ***/ 02631 02632 INIT_IMARR(newar) ; 02633 02634 for( kim=0 ; kim < nz ; kim++ ){ 02635 koff = hglobal + (kim+1)*himage + datum_len*nx*ny*kim ; 02636 /** fprintf(stderr,"mri_read_analyze75: kim=%d koff=%d\n",kim,koff) ; **/ 02637 fseek( fp , koff , SEEK_SET ) ; 02638 02639 newim = mri_new( nx , ny , datum_type ) ; 02640 imar = mri_data_pointer( newim ) ; 02641 length = fread( imar , datum_len , nx * ny , fp ) ; 02642 02643 if( doswap ){ 02644 switch( datum_len ){ 02645 default: break ; 02646 case 2: swap_twobytes ( nx*ny , imar ) ; break ; /* short */ 02647 case 4: swap_fourbytes( nx*ny , imar ) ; break ; /* int, float */ 02648 case 8: swap_fourbytes( 2*nx*ny , imar ) ; break ; /* complex */ 02649 } 02650 newim->was_swapped = 1 ; /* 07 Mar 2002 */ 02651 } 02652 02653 /* 28 Nov 2001: convert to floats? */ 02654 02655 if( floatize ){ 02656 MRI_IMAGE *qim = mri_to_float(newim) ; 02657 mri_free(newim) ; newim = qim ; 02658 } 02659 02660 if( nz == 1 ) mri_add_name( iname , newim ) ; 02661 else { 02662 sprintf( buf , "%s#%d" , iname,kim ) ; 02663 mri_add_name( buf , newim ) ; 02664 } 02665 02666 newim->dx = dx ; newim->dy = dy ; newim->dz = dz ; newim->dw = 1.0 ; 02667 ADDTO_IMARR(newar,newim) ; 02668 02669 /* 27 Nov 2001: scale image? */ 02670 02671 if( fac != 0.0 ) mri_scale_inplace( fac , newim ) ; 02672 } 02673 02674 fclose(fp) ; RETURN(newar) ; 02675 } |
|
Read an array of ASCII numbers into a 1D or 2D image.
Definition at line 1965 of file mri_read.c. References AFMALL, floatvec::ar, decode_linebuf(), ENTRY, EXIT, FRB, free, INC_TSARSIZE, KILL_floatvec, lbfill, LBUF, malloc, MAX, mri_1D_fromstring(), mri_add_name(), mri_fix_data_pointer(), mri_free(), mri_new_vol_empty(), mri_transpose(), my_fgets(), floatvec::nar, ncol, realloc, and RETURN. Referenced by get_dfile_params(), main(), mri_read(), and mri_read_1D().
01966 { 01967 MRI_IMAGE * outim ; 01968 int ii,jj,val , used_tsar , alloc_tsar ; 01969 float * tsar ; 01970 float ftemp ; 01971 FILE * fts ; 01972 char * ptr ; 01973 int ncol , bpos , blen , nrow ; 01974 static char *buf=NULL ; /* 20 Jun 2002: make a ptr */ 01975 01976 floatvec *fvec ; /* 20 Jul 2004 */ 01977 int incts ; 01978 01979 ENTRY("mri_read_ascii") ; 01980 01981 if( fname == NULL || fname[0] == '\0' ) RETURN(NULL) ; 01982 01983 if( strncmp(fname,"1D:",3) == 0 ){ /* 28 Apr 2003 */ 01984 MRI_IMAGE *qim = mri_1D_fromstring( fname+3 ) ; 01985 if( qim != NULL ){ 01986 outim = mri_transpose(qim); mri_free(qim); RETURN(outim); 01987 } 01988 } 01989 01990 fts = fopen( fname , "r" ); if( fts == NULL ) RETURN(NULL); 01991 01992 if( buf == NULL ) buf = AFMALL(char, LBUF) ; /* create buffer */ 01993 01994 /** step 1: read in the first line and see how many numbers are in it 01995 (skipping lines that are comments or entirely blank) */ 01996 01997 (void) my_fgets( NULL , 0 , NULL ) ; /* reset [20 Jul 2004] */ 01998 ptr = my_fgets( buf , LBUF , fts ) ; 01999 if( ptr==NULL || *ptr=='\0' ){ FRB(buf); fclose(fts); RETURN(NULL); } /* bad read? */ 02000 02001 lbfill = 0.0f ; /* 10 Aug 2004 */ 02002 02003 fvec = decode_linebuf( buf ) ; /* 20 Jul 2004 */ 02004 if( fvec == NULL || fvec->nar == 0 ){ 02005 if( fvec != NULL ) KILL_floatvec(fvec) ; 02006 FRB(buf); fclose(fts); RETURN(NULL); 02007 } 02008 ncol = fvec->nar ; KILL_floatvec(fvec) ; 02009 02010 /** At this point, ncol is the number of floats to be read from each line **/ 02011 02012 rewind( fts ) ; /* will start over */ 02013 02014 incts = MAX(INC_TSARSIZE,ncol) ; 02015 used_tsar = 0 ; 02016 alloc_tsar = incts ; 02017 tsar = (float *) malloc( sizeof(float) * alloc_tsar ) ; 02018 if( tsar == NULL ){ 02019 fprintf(stderr,"\n*** malloc error in mri_read_ascii ***\n"); EXIT(1); 02020 } 02021 02022 /** read lines, convert to floats, store **/ 02023 02024 nrow = 0 ; 02025 while( 1 ){ 02026 ptr = my_fgets( buf , LBUF , fts ) ; /* read */ 02027 if( ptr==NULL || *ptr=='\0' ) break ; /* failure --> end of data */ 02028 02029 fvec = decode_linebuf( buf ) ; 02030 if( fvec == NULL ) break ; 02031 if( fvec->nar == 0 ){ KILL_floatvec(fvec); break; } 02032 02033 if( used_tsar + ncol >= alloc_tsar ){ 02034 alloc_tsar += incts ; 02035 tsar = (float *)realloc( (void *)tsar,sizeof(float)*alloc_tsar ); 02036 if( tsar == NULL ){ 02037 fprintf(stderr,"\n*** realloc error in mri_read_ascii ***\n"); EXIT(1); 02038 } 02039 } 02040 for( ii=0 ; ii < fvec->nar && ii < ncol ; ii++ ) 02041 tsar[used_tsar+ii] = fvec->ar[ii] ; 02042 for( ; ii < ncol ; ii++ ) 02043 tsar[used_tsar+ii] = 0.0 ; 02044 used_tsar += ncol ; 02045 KILL_floatvec(fvec) ; 02046 02047 nrow++ ; /* got one more complete row! */ 02048 } 02049 fclose( fts ) ; /* finished with this file! */ 02050 (void) my_fgets( NULL , 0 , NULL ) ; /* reset [20 Jul 2004] */ 02051 02052 if( used_tsar <= 1 ){ FRB(buf); free(tsar); RETURN(NULL); } 02053 02054 tsar = (float *) realloc( tsar , sizeof(float) * used_tsar ) ; 02055 if( tsar == NULL ){ 02056 fprintf(stderr,"\n*** final realloc error in mri_read_ascii ***\n"); EXIT(1); 02057 } 02058 02059 outim = mri_new_vol_empty( ncol , nrow , 1 , MRI_float ) ; 02060 mri_fix_data_pointer( tsar , outim ) ; 02061 mri_add_name( fname , outim ) ; 02062 02063 FRB(buf) ; RETURN(outim) ; 02064 } |
|
Definition at line 2173 of file mri_read.c. References AFMALL, floatvec::ar, decode_linebuf(), ENTRY, FRB, KILL_floatvec, lbfill, LBUF, MAX, mri_add_name(), MRI_FLOAT_PTR, mri_new(), my_fgets(), floatvec::nar, ncol, and RETURN. Referenced by get_options(), and main().
02174 { 02175 MRI_IMAGE *outim ; 02176 int ii,jj , ncol,nrow ; 02177 float *tsar ; 02178 FILE *fts ; 02179 char *ptr ; 02180 static char *buf=NULL ; 02181 floatvec *fvec ; 02182 02183 ENTRY("mri_read_ascii_ragged") ; 02184 02185 if( fname == NULL || *fname == '\0' ){ FRB(buf); RETURN(NULL); } 02186 02187 fts = fopen( fname , "r" ); if( fts == NULL ){ FRB(buf); RETURN(NULL); } 02188 02189 if( buf == NULL ) buf = AFMALL(char, LBUF) ; 02190 02191 /** step 1: read in ALL lines, see how many numbers are in each, 02192 in order to get the maximum row length and # of rows **/ 02193 02194 lbfill = filler ; /* 10 Aug 2004 */ 02195 02196 (void) my_fgets( NULL , 0 , NULL ) ; /* reset */ 02197 ncol = nrow = 0 ; 02198 while(1){ 02199 ptr = my_fgets( buf , LBUF , fts ) ; 02200 if( ptr==NULL || *ptr=='\0' ) break ; 02201 fvec = decode_linebuf( buf ) ; 02202 if( fvec != NULL && fvec->nar > 0 ){ nrow++; ncol = MAX(ncol,fvec->nar); } 02203 if( fvec != NULL ) KILL_floatvec(fvec) ; else break ; 02204 } 02205 if( nrow == 0 || ncol == 0 ){ fclose(fts); FRB(buf); lbfill=0.0f; RETURN(NULL); } 02206 02207 /** At this point, ncol is the number of floats to be read from each line **/ 02208 02209 rewind( fts ) ; /* will start over */ 02210 02211 outim = mri_new( ncol , nrow , MRI_float ) ; 02212 tsar = MRI_FLOAT_PTR(outim) ; 02213 02214 /** read lines, convert to floats, store **/ 02215 02216 nrow = 0 ; 02217 while( 1 ){ 02218 ptr = my_fgets( buf , LBUF , fts ) ; /* read */ 02219 if( ptr==NULL || *ptr=='\0' ) break ; /* failure --> end of data */ 02220 02221 fvec = decode_linebuf( buf ) ; 02222 if( fvec == NULL ) break ; 02223 if( fvec->nar == 0 ){ KILL_floatvec(fvec); break; } 02224 02225 for( ii=0 ; ii < fvec->nar && ii < ncol ; ii++ ) 02226 tsar[nrow*ncol+ii] = fvec->ar[ii] ; 02227 for( ; ii < ncol ; ii++ ) 02228 tsar[nrow*ncol+ii] = filler ; /* fill for incomplete lines */ 02229 KILL_floatvec(fvec) ; 02230 nrow++ ; /* got one more complete row! */ 02231 } 02232 fclose( fts ) ; /* finished with this file! */ 02233 (void) my_fgets( NULL , 0 , NULL ) ; /* reset */ 02234 02235 mri_add_name( fname , outim ) ; 02236 FRB(buf) ; lbfill = 0.0f ; RETURN(outim) ; 02237 } |
|
Read image(s) from a DICOM file, if possible. ------------------------------------------------------------------------------------- Definition at line 119 of file mri_read_dicom.c. References abs, ADDTO_IMARR, AFMALL, calloc, MRI_IMAGE::dt, dt, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, E_BITS_ALLOCATED, E_BITS_STORED, E_COLUMNS, E_FIELD_OF_VIEW, E_HIGH_BIT, E_ID_IMAGE_TYPE, E_ID_MANUFACTURER, E_IMAGE_ORIENTATION, E_IMAGE_POSITION, E_NUMBER_OF_FRAMES, E_PATIENT_ORIENTATION, E_PHOTOMETRIC_INTERPRETATION, E_PIXEL_REPRESENTATION, E_PIXEL_SPACING, E_REPETITION_TIME, E_RESCALE_INTERCEPT, E_RESCALE_SLOPE, E_ROWS, E_SAMPLES_PER_PIXEL, E_SIEMENS_2, E_SLICE_LOCATION, E_SLICE_SPACING, E_SLICE_THICKNESS, E_WINDOW_CENTER, E_WINDOW_WIDTH, elist, ENTRY, extract_bytes_from_file(), free, get_siemens_extra_info(), getenv(), Siemens_extra_info::good, Siemens_extra_info::have_data, IMARR_COUNT, IMARR_SUBIM, INIT_IMARR, MRI_IMAGE::kind, LITTLE_ENDIAN_ARCHITECTURE, MAX, MIN, Siemens_extra_info::mosaic_num, mri_data_pointer(), mri_dicom_header(), mri_dicom_nohex(), mri_dicom_noname(), mri_dicom_pxlarr(), mri_new(), mri_possibly_dicom(), NUM_ELIST, MRI_IMAGE::nvox, nz, MRI_IMAGE::pixel_size, RETURN, RWC_set_endianosity(), Siemens_extra_info::slice_xyz, str_sexinfo, swap, swap_fourbytes(), swap_twobytes(), THD_filesize(), TRUNCATE_IMARR, MRI_IMAGE::was_swapped, xc, xn, yc, yn, z0, and z1. Referenced by main(), mri_read_file(), and mri_read_file_delay().
00120 { 00121 char *ppp , *ddd ; 00122 off_t poff ; 00123 unsigned int plen ; 00124 char *epos[NUM_ELIST] ; 00125 int ii,jj , ee , bpp , datum ; 00126 int nx,ny,nz , swap , shift=0 ; 00127 float dx,dy,dz,dt ; 00128 MRI_IMARR *imar ; 00129 MRI_IMAGE *im ; 00130 void *iar ; 00131 FILE *fp ; 00132 short sbot,stop ; 00133 int have_orients=0 ; 00134 int ior,jor,kor ; 00135 static int nzoff=0 ; /* for determining z-axis orientation/offset from multiple calls */ 00136 00137 int mosaic=0 , mos_nx,mos_ny , mos_ix,mos_iy,mos_nz ; /* 28 Oct 2002 */ 00138 Siemens_extra_info sexinfo ; /* 31 Oct 2002 */ 00139 float xcen,ycen,zcen ; 00140 int use_xycen=0 ; 00141 float dxx,dyy,dzz ; 00142 00143 char *eee ; 00144 float rescale_slope=0.0 , rescale_inter=0.0 ; /* 23 Dec 2002 */ 00145 float window_center=0.0 , window_width =0.0 ; 00146 00147 char *sexi_start; /* KRH 25 Jul 2003 */ 00148 char *sexi_end; 00149 00150 ENTRY("mri_read_dicom") ; 00151 00152 if( str_sexinfo != NULL ){ free(str_sexinfo); str_sexinfo=NULL; } 00153 00154 if( !mri_possibly_dicom(fname) ) RETURN(NULL) ; /* 07 May 2003 */ 00155 00156 /* extract header info from file into a string 00157 - cf. mri_dicom_hdr.[ch] 00158 - run 'dicom_hdr -noname fname' to see the string format */ 00159 00160 mri_dicom_nohex(1) ; /* don't print ints in hex mode */ 00161 mri_dicom_noname(1) ; /* don't print names, just tags */ 00162 ppp = mri_dicom_header( fname ) ; /* print header to malloc()-ed string */ 00163 if( ppp == NULL ) RETURN(NULL); /* didn't work; not a DICOM file? */ 00164 00165 /* find out where the pixel array is in the file */ 00166 00167 mri_dicom_pxlarr( &poff , &plen ) ; 00168 if( plen <= 0 ){ free(ppp) ; RETURN(NULL); } 00169 00170 /* check if file is actually this big (maybe it was truncated) */ 00171 00172 { unsigned int psiz , fsiz ; 00173 fsiz = THD_filesize( fname ) ; 00174 psiz = (unsigned int)(poff) + plen ; 00175 if( fsiz < psiz ){ free(ppp) ; RETURN(NULL); } 00176 } 00177 00178 /* find positions in header of elements we care about */ 00179 00180 for( ee=0 ; ee < NUM_ELIST ; ee++ ) 00181 epos[ee] = strstr(ppp,elist[ee]) ; 00182 00183 /* see if the header has the elements we absolutely need */ 00184 00185 if( epos[E_ROWS] == NULL || 00186 epos[E_COLUMNS] == NULL || 00187 epos[E_BITS_ALLOCATED] == NULL ){ free(ppp) ; RETURN(NULL); } 00188 00189 /* check if we have 1 sample per pixel (can't deal with 3 or 4 now) */ 00190 00191 if( epos[E_SAMPLES_PER_PIXEL] != NULL ){ 00192 ddd = strstr(epos[E_SAMPLES_PER_PIXEL],"//") ; 00193 if( ddd == NULL ){ free(ppp) ; RETURN(NULL); } 00194 ii = 0 ; sscanf(ddd+2,"%d",&ii) ; 00195 if( ii != 1 ){ free(ppp) ; RETURN(NULL); } 00196 } 00197 00198 /* check if photometric interpretation is MONOCHROME (don't like PALETTE) */ 00199 00200 if( epos[E_PHOTOMETRIC_INTERPRETATION] != NULL ){ 00201 ddd = strstr(epos[E_PHOTOMETRIC_INTERPRETATION],"MONOCHROME") ; 00202 if( ddd == NULL ){ free(ppp) ; RETURN(NULL); } 00203 } 00204 00205 /* check if we have 8, 16, or 32 bits per pixel */ 00206 00207 ddd = strstr(epos[E_BITS_ALLOCATED],"//") ; 00208 if( ddd == NULL ){ free(ppp); RETURN(NULL); } 00209 bpp = 0 ; sscanf(ddd+2,"%d",&bpp) ; 00210 switch( bpp ){ 00211 default: free(ppp); RETURN(NULL); /* bad value */ 00212 case 8: datum = MRI_byte ; break ; 00213 case 16: datum = MRI_short; break ; 00214 case 32: datum = MRI_int ; break ; /* probably not present in DICOM? */ 00215 } 00216 bpp /= 8 ; /* now bytes per pixel, instead of bits */ 00217 00218 /*** Print some warnings if appropriate ***/ 00219 00220 /* check if BITS_STORED and HIGH_BIT are aligned */ 00221 00222 #define NWMAX 2 00223 if( epos[E_BITS_STORED] != NULL && epos[E_HIGH_BIT] != NULL ){ 00224 int bs=0 , hb=0 ; 00225 ddd = strstr(epos[E_BITS_STORED],"//") ; sscanf(ddd+2,"%d",&bs) ; 00226 ddd = strstr(epos[E_HIGH_BIT],"//") ; sscanf(ddd+2,"%d",&hb) ; 00227 if( bs != hb+1 ){ 00228 static int nwarn=0 ; 00229 if( nwarn < NWMAX ) 00230 fprintf(stderr, 00231 "++ DICOM WARNING: file %s has Bits_Stored=%d and High_Bit=%d\n", 00232 fname,bs,hb) ; 00233 if( nwarn == NWMAX ) 00234 fprintf(stderr,"++ DICOM WARNING: no more Bits_Stored messages will be printed\n") ; 00235 nwarn++ ; 00236 } 00237 } 00238 00239 /* check if Rescale is ordered */ 00240 /* 23 Dec 2002: actually get the rescale params, if environment says to */ 00241 00242 eee = getenv("AFNI_DICOM_RESCALE") ; 00243 if( epos[E_RESCALE_INTERCEPT] != NULL && epos[E_RESCALE_SLOPE] != NULL ){ 00244 if( eee == NULL || toupper(*eee) != 'Y' ){ 00245 static int nwarn=0 ; 00246 if( nwarn < NWMAX ) 00247 fprintf(stderr, 00248 "++ DICOM WARNING: file %s has Rescale tags; setenv AFNI_DICOM_RESCALE YES to enforce them\n", 00249 fname ) ; 00250 if( nwarn == NWMAX ) 00251 fprintf(stderr,"++ DICOM WARNING: no more Rescale tags messages will be printed\n") ; 00252 nwarn++ ; 00253 } else { 00254 ddd = strstr(epos[E_RESCALE_INTERCEPT],"//") ; sscanf(ddd+2,"%f",&rescale_inter) ; 00255 ddd = strstr(epos[E_RESCALE_SLOPE ],"//") ; sscanf(ddd+2,"%f",&rescale_slope) ; 00256 } 00257 } 00258 00259 /* check if Window is ordered */ 00260 /* 23 Dec 2002: actually get the window params, if environment says to */ 00261 00262 eee = getenv("AFNI_DICOM_WINDOW") ; 00263 if( epos[E_WINDOW_CENTER] != NULL && epos[E_WINDOW_WIDTH] != NULL ){ 00264 if( eee == NULL || toupper(*eee) != 'Y' ){ 00265 static int nwarn=0 ; 00266 if( nwarn < NWMAX ) 00267 fprintf(stderr, 00268 "++ DICOM WARNING: file %s has Window tags; setenv AFNI_DICOM_WINDOW YES to enforce them\n", 00269 fname ) ; 00270 if( nwarn == NWMAX ) 00271 fprintf(stderr,"++ DICOM WARNING: no more Window tags messages will be printed\n") ; 00272 nwarn++ ; 00273 } else { 00274 ddd = strstr(epos[E_WINDOW_CENTER],"//") ; sscanf(ddd+2,"%f",&window_center) ; 00275 ddd = strstr(epos[E_WINDOW_WIDTH ],"//") ; sscanf(ddd+2,"%f",&window_width ) ; 00276 } 00277 } 00278 00279 /*** extract attributes of the image(s) to be read in ***/ 00280 00281 /* get image nx & ny */ 00282 00283 ddd = strstr(epos[E_ROWS],"//") ; /* 31 Oct 2002: */ 00284 if( ddd == NULL ){ free(ppp) ; RETURN(NULL); } /* Oops: ROWS is ny and */ 00285 ny = 0 ; sscanf(ddd+2,"%d",&ny) ; /* COLUMNS is nx! */ 00286 if( ny < 2 ){ free(ppp) ; RETURN(NULL); } 00287 00288 ddd = strstr(epos[E_COLUMNS],"//") ; 00289 if( ddd == NULL ){ free(ppp) ; RETURN(NULL); } 00290 nx = 0 ; sscanf(ddd+2,"%d",&nx) ; 00291 if( nx < 2 ){ free(ppp) ; RETURN(NULL); } 00292 00293 /* get number of slices */ 00294 00295 nz = 0 ; 00296 if( epos[E_NUMBER_OF_FRAMES] != NULL ){ 00297 ddd = strstr(epos[E_NUMBER_OF_FRAMES],"//") ; 00298 if( ddd != NULL ) sscanf(ddd+2,"%d",&nz) ; 00299 } 00300 00301 /* if didn't get nz above, make up a value */ 00302 00303 if( nz == 0 ) nz = plen / (bpp*nx*ny) ; /* compute from image array size */ 00304 if( nz == 0 ){ free(ppp) ; RETURN(NULL); } 00305 00306 /*-- 28 Oct 2002: Check if this is a Siemens mosaic. --*/ 00307 /*-- 02 Dec 2002: Don't use Acquisition Matrix anymore; 00308 instead, use the Siemens extra info 00309 in epos[E_SIEMENS_2]. --*/ 00310 /*-- 24 Dec 2002: Extract str_sexinfo even if not a mosaic. --*/ 00311 00312 if( epos[E_ID_MANUFACTURER] != NULL && 00313 strstr(epos[E_ID_MANUFACTURER],"SIEMENS") != NULL && 00314 epos[E_SIEMENS_2] != NULL ){ 00315 00316 int len=0,loc=0 , aa,bb ; 00317 sscanf(epos[E_SIEMENS_2],"%x%x%d [%d" , &aa,&bb , &len,&loc ) ; 00318 if( len > 0 && loc > 0 ){ 00319 fp = fopen( fname , "rb" ) ; 00320 if( fp != NULL ){ 00321 str_sexinfo = extract_bytes_from_file( fp, (off_t)loc, (size_t)len, 1 ) ; 00322 fclose(fp) ; 00323 } 00324 } 00325 } 00326 00327 /*-- process str_sexinfo only if this is marked as a mosaic image --*/ 00328 00329 if( epos[E_ID_IMAGE_TYPE] != NULL && 00330 strstr(epos[E_ID_IMAGE_TYPE],"MOSAIC") != NULL && 00331 str_sexinfo != NULL ){ 00332 00333 /* 31 Oct 2002: extract extra Siemens info from str_sexinfo */ 00334 00335 /* KRH 25 Jul 2003 if start and end markers are present for 00336 * Siemens extra info, cut string down to those boundaries */ 00337 00338 sexi_start = strstr(str_sexinfo, "### ASCCONV BEGIN ###"); 00339 sexi_end = strstr(str_sexinfo, "### ASCCONV END ###"); 00340 if ((sexi_start != NULL) && (sexi_end != NULL)) { 00341 char *sexi_tmp; 00342 int sexi_size; 00343 00344 sexi_size = sexi_end - sexi_start + 19 ; 00345 sexi_tmp = AFMALL( char, sexi_size ); 00346 memcpy(sexi_tmp,sexi_start,sexi_size); 00347 free(str_sexinfo); 00348 str_sexinfo = sexi_tmp; 00349 } 00350 /* end KRH 25 Jul 2003 change */ 00351 00352 sexinfo.good = 0 ; /* start by marking it as bad */ 00353 for(ii = 0; ii < 3; ii++) sexinfo.have_data[ii] = 0; /* 25 Feb 03 Initialize new member KRH */ 00354 00355 get_siemens_extra_info( str_sexinfo , &sexinfo ) ; 00356 00357 if( sexinfo.good ){ /* if data is good */ 00358 00359 /* compute size of mosaic layout 00360 as 1st integer whose square is >= # of images in mosaic */ 00361 00362 for( mos_ix=1 ; mos_ix*mos_ix < sexinfo.mosaic_num ; mos_ix++ ) ; /* nada */ 00363 mos_iy = mos_ix ; 00364 00365 mos_nx = nx / mos_ix ; mos_ny = ny / mos_iy ; /* sub-image dimensions */ 00366 00367 if( mos_ix*mos_nx == nx && /* Sub-images must fit nicely */ 00368 mos_iy*mos_ny == ny ){ /* into super-image layout. */ 00369 00370 static int nwarn=0 ; 00371 00372 /* should be tagged as a 1 slice image thus far */ 00373 00374 if( nz > 1 ){ 00375 fprintf(stderr, 00376 "** DICOM ERROR: %dx%d Mosaic of %dx%d images in file %s, but also have nz=%d\n", 00377 mos_ix,mos_iy,mos_nx,mos_ny,fname,nz) ; 00378 free(ppp) ; RETURN(NULL) ; 00379 } 00380 00381 /* mark as a mosaic */ 00382 00383 mosaic = 1 ; 00384 mos_nz = mos_ix * mos_iy ; /* number of slices in mosaic */ 00385 if( nwarn < NWMAX ) 00386 fprintf(stderr,"++ DICOM NOTICE: %dx%d Siemens Mosaic of %d %dx%d images in file %s\n", 00387 mos_ix,mos_iy,sexinfo.mosaic_num,mos_nx,mos_ny,fname) ; 00388 if( nwarn == NWMAX ) 00389 fprintf(stderr,"++ DICOM NOTICE: no more Siemens Mosiac messages will be printed\n") ; 00390 nwarn++ ; 00391 00392 } /* end of if mosaic sizes are reasonable */ 00393 00394 else { /* warn about bad mosaic sizes */ 00395 static int nwarn=0 ; 00396 if( nwarn < NWMAX ) 00397 fprintf(stderr, 00398 "++ DICOM WARNING: bad Siemens Mosaic params: nx=%d ny=%d ix=%d iy=%d imx=%d imy=%d\n", 00399 mos_nx,mos_ny , mos_ix,mos_iy , nx,ny ) ; 00400 if( nwarn == NWMAX ) 00401 fprintf(stderr,"++ DICOM NOTICE: no more Siemens Mosaic param messages will be printed\n"); 00402 nwarn++ ; 00403 } 00404 00405 } /* end of if sexinfo was good */ 00406 00407 else { /* warn if sexinfo was bad */ 00408 static int nwarn=0 ; 00409 if( nwarn < NWMAX ) 00410 fprintf(stderr,"++ DICOM WARNING: indecipherable Siemens Mosaic info (%s) in file %s\n", 00411 elist[E_SIEMENS_2] , fname ) ; 00412 if( nwarn == NWMAX ) 00413 fprintf(stderr,"++ DICOM NOTICE: no more Siemens Mosaic info messages will be printed\n"); 00414 nwarn++ ; 00415 } 00416 00417 } /* end of if a Siemens mosaic */ 00418 00419 /*-- try to get dx, dy, dz, dt --*/ 00420 00421 dx = dy = dz = dt = 0.0 ; 00422 00423 /* dx,dy first */ 00424 00425 if( epos[E_PIXEL_SPACING] != NULL ){ 00426 ddd = strstr(epos[E_PIXEL_SPACING],"//") ; 00427 if( ddd != NULL ) sscanf( ddd+2 , "%f\\%f" , &dx , &dy ) ; 00428 if( dy == 0.0 && dx > 0.0 ) dy = dx ; 00429 } 00430 if( dx == 0.0 && epos[E_FIELD_OF_VIEW] != NULL ){ 00431 ddd = strstr(epos[E_FIELD_OF_VIEW],"//") ; 00432 if( ddd != NULL ) sscanf( ddd+2 , "%f\\%f" , &dx , &dy ) ; 00433 if( dx > 0.0 ){ 00434 if( dy == 0.0 ) dy = dx ; 00435 dx /= nx ; dy /= ny ; 00436 } 00437 } 00438 00439 /*-- 27 Nov 2002: fix stupid GE error, 00440 where the slice spacing is really the slice gap --*/ 00441 00442 { int stupid_ge_fix , no_stupidity ; 00443 float sp=0.0 , th=0.0 ; 00444 static int nwarn=0 ; 00445 00446 eee = getenv("AFNI_SLICE_SPACING_IS_GAP") ; 00447 stupid_ge_fix = (eee != NULL && (*eee=='Y' || *eee=='y') ) ; 00448 no_stupidity = (eee != NULL && (*eee=='N' || *eee=='n') ) ; /* 03 Mar 2003 */ 00449 00450 if( epos[E_SLICE_SPACING] != NULL ){ /* get reported slice spacing */ 00451 ddd = strstr(epos[E_SLICE_SPACING],"//") ; 00452 if( ddd != NULL ) sscanf( ddd+2 , "%f" , &sp ) ; 00453 } 00454 if( epos[E_SLICE_THICKNESS] != NULL ){ /* get reported slice thickness */ 00455 ddd = strstr(epos[E_SLICE_THICKNESS],"//") ; 00456 if( ddd != NULL ) sscanf( ddd+2 , "%f" , &th ) ; 00457 } 00458 00459 th = fabs(th) ; sp = fabs(sp) ; /* we don't use the sign */ 00460 00461 if( stupid_ge_fix ){ /* always be stupid */ 00462 dz = sp+th ; 00463 } else { 00464 00465 if( no_stupidity && sp > 0.0 ) /* 13 Jan 2004: if 'NO', then */ 00466 dz = sp ; /* always use spacing if present */ 00467 else 00468 dz = (sp > th) ? sp : th ; /* the correct-ish DICOM way */ 00469 00470 #define GFAC 0.99 00471 00472 if( !no_stupidity ){ /* unless stupidity is turned off */ 00473 if( sp > 0.0 && sp < GFAC*th ) dz = sp+th ; /* the stupid GE way again */ 00474 00475 if( sp > 0.0 && sp < GFAC*th && nwarn < NWMAX ){ 00476 fprintf(stderr, 00477 "++ DICOM WARNING: file %s has Slice_Spacing=%f smaller than Slice_Thickness=%f\n", 00478 fname , sp , th ) ; 00479 if( nwarn == 0 ) 00480 fprintf(stderr, 00481 "\n" 00482 "++ Setting environment variable AFNI_SLICE_SPACING_IS_GAP ++\n" 00483 "++ to YES will make the center-to-center slice distance ++\n" 00484 "++ be set to Slice_Spacing+Slice_Thickness=%6.3f. ++\n" 00485 "++ This is against the DICOM standard [attribute (0018,0088) ++\n" 00486 "++ is defined as the center-to-center spacing between slices, ++\n" 00487 "++ NOT as the edge-to-edge gap between slices], but it seems ++\n" 00488 "++ to be necessary for some GE scanners. ++\n" 00489 "++ ++\n" 00490 "++ This correction has been made on this data: dz=%6.3f. ++\n" 00491 "++ ++\n" 00492 "++ Setting AFNI_SLICE_SPACING_IS_GAP to NO means that the ++\n" 00493 "++ DICOM Slice_Spacing variable will be used for dz, replacing ++\n" 00494 "++ the Slice_Thickness variable. This usage may be required ++\n" 00495 "++ for some pulse sequences on Phillips scanners. ++\n" 00496 "\n\a" , 00497 sp+th , dz ) ; 00498 } 00499 if( sp > 0.0 && sp < th && nwarn == NWMAX ) 00500 fprintf(stderr,"++ DICOM WARNING: no more Slice_Spacing messages will be printed\n") ; 00501 nwarn++ ; 00502 } 00503 } 00504 if( dz == 0.0 && dx != 0.0 ) dz = 1.0 ; /* nominal dz */ 00505 00506 } /*-- end of dz code, with all its stupidities --*/ 00507 00508 /* get dt */ 00509 00510 if( epos[E_REPETITION_TIME] != NULL ){ 00511 ddd = strstr(epos[E_REPETITION_TIME],"//") ; 00512 if( ddd != NULL ){ 00513 sscanf( ddd+2 , "%f" , &dt ) ; 00514 dt *= 0.001 ; /* ms to s */ 00515 } 00516 } 00517 00518 /* check if we might have 16 bit unsigned data that fills all bits */ 00519 00520 #if 0 00521 if( bpp == 2 ){ 00522 if( epos[E_PIXEL_REPRESENTATION] != NULL ){ 00523 ddd = strstr(epos[E_PIXEL_REPRESENTATION],"//") ; 00524 if( ddd != NULL ){ 00525 ii = 0 ; sscanf( ddd+2 , "%d" , &ii ) ; 00526 if( ii == 1 ) shift = -1 ; 00527 } 00528 } 00529 if( shift == 0 && epos[E_HIGH_BIT] != NULL ){ 00530 ddd = strstr(epos[E_HIGH_BIT],"//") ; 00531 if( ddd != NULL ){ 00532 ii = 0 ; sscanf( ddd+2 , "%d" , &ii ) ; 00533 if( ii == 15 ) shift = 1 ; 00534 } 00535 } 00536 sbot = 32767 ; stop = -32767 ; 00537 } 00538 #endif 00539 00540 /** Finally! Read images from file. **/ 00541 00542 fp = fopen( fname , "rb" ) ; 00543 if( fp == NULL ){ free(ppp) ; RETURN(NULL); } 00544 lseek( fileno(fp) , poff , SEEK_SET ) ; 00545 00546 INIT_IMARR(imar) ; 00547 00548 /* DICOM files are stored in LSB first (little endian) mode */ 00549 00550 RWC_set_endianosity() ; swap = !LITTLE_ENDIAN_ARCHITECTURE ; 00551 00552 /* 28 Oct 2002: must allow for 2D mosaic mode */ 00553 00554 if( !mosaic ){ /*-- 28 Oct 2002: old method, not a mosaic --*/ 00555 00556 for( ii=0 ; ii < nz ; ii++ ){ 00557 im = mri_new( nx , ny , datum ) ; /* new MRI_IMAGE struct */ 00558 iar = mri_data_pointer( im ) ; /* data array in struct */ 00559 fread( iar , bpp , nx*ny , fp ) ; /* read data directly into it */ 00560 00561 if( swap ){ /* swap bytes? */ 00562 switch( im->pixel_size ){ 00563 default: break ; 00564 case 2: swap_twobytes ( im->nvox, iar ) ; break ; /* short */ 00565 case 4: swap_fourbytes( im->nvox, iar ) ; break ; /* int, float */ 00566 case 8: swap_fourbytes( 2*im->nvox, iar ) ; break ; /* complex */ 00567 } 00568 im->was_swapped = 1 ; 00569 } 00570 00571 #if 0 00572 if( shift == 1 ){ 00573 switch( datum ){ 00574 case MRI_short:{ 00575 short * sar = (short *) iar ; 00576 for( jj=0 ; jj < im->nvox ; jj++ ){ 00577 sbot = MIN( sar[jj] , sbot ) ; 00578 stop = MAX( sar[jj] , stop ) ; 00579 } 00580 } 00581 break ; 00582 } 00583 } 00584 #endif 00585 00586 /* store auxiliary data in image struct */ 00587 00588 if( dx > 0.0 && dy > 0.0 && dz > 0.0 ){ 00589 im->dx = dx; im->dy = dy; im->dz = dz; im->dw = 1.0; 00590 } 00591 if( dt > 0.0 ) im->dt = dt ; 00592 00593 ADDTO_IMARR(imar,im) ; 00594 } 00595 00596 } else { /*-- 28 Oct 2002: is a 2D mosaic --*/ 00597 00598 char *dar , *iar ; 00599 int last_ii=-1 , nvox , yy,xx,nxx ; 00600 00601 nvox = mos_nx*mos_ny*mos_nz ; /* total number of voxels */ 00602 dar = (char*)calloc(bpp,nvox) ; /* make space for super-image */ 00603 fread( dar , bpp , nvox , fp ) ; /* read data directly into it */ 00604 if( swap ){ /* swap bytes? */ 00605 switch( bpp ){ 00606 default: break ; 00607 case 2: swap_twobytes ( nvox, dar ) ; break ; /* short */ 00608 case 4: swap_fourbytes( nvox, dar ) ; break ; /* int, float */ 00609 case 8: swap_fourbytes( 2*nvox, dar ) ; break ; /* complex */ 00610 } 00611 } 00612 00613 /* load data from dar into images */ 00614 00615 nxx = mos_nx * mos_ix ; /* # pixels per mosaic line */ 00616 00617 for( yy=0 ; yy < mos_iy ; yy++ ){ /* loop over sub-images in mosaic */ 00618 for( xx=0 ; xx < mos_ix ; xx++ ){ 00619 00620 im = mri_new( mos_nx , mos_ny , datum ) ; 00621 iar = mri_data_pointer( im ) ; /* sub-image array */ 00622 00623 /* copy data rows from dar into iar */ 00624 00625 for( jj=0 ; jj < mos_ny ; jj++ ) /* loop over rows inside sub-image */ 00626 memcpy( iar + jj*mos_nx*bpp , 00627 dar + xx*mos_nx*bpp + (jj+yy*mos_ny)*nxx*bpp , 00628 mos_nx*bpp ) ; 00629 00630 if( dx > 0.0 && dy > 0.0 && dz > 0.0 ){ 00631 im->dx = dx; im->dy = dy; im->dz = dz; im->dw = 1.0; 00632 } 00633 if( dt > 0.0 ) im->dt = dt ; 00634 if( swap ) im->was_swapped = 1 ; 00635 00636 ADDTO_IMARR(imar,im) ; 00637 } 00638 } 00639 free(dar) ; /* don't need no more; copied all data out of it now */ 00640 00641 /* truncate zero images out of tail of mosaic */ 00642 00643 if( sexinfo.good ){ /* the new way: use the mosaic count from Siemens extra info */ 00644 00645 if( sexinfo.mosaic_num < IMARR_COUNT(imar) ) 00646 TRUNCATE_IMARR(imar,sexinfo.mosaic_num) ; 00647 00648 } else { /* the old way: find the last image with a nonzero value inside */ 00649 00650 for( ii=mos_nz-1 ; ii >= 0 ; ii-- ){ /* loop backwards over images */ 00651 im = IMARR_SUBIM(imar,ii) ; 00652 switch( im->kind ){ 00653 case MRI_short:{ 00654 short *ar = mri_data_pointer( im ) ; 00655 for( jj=0 ; jj < im->nvox ; jj++ ) if( ar[jj] != 0 ) break ; 00656 if( jj < im->nvox ) last_ii = ii ; 00657 } 00658 break ; 00659 00660 case MRI_byte:{ 00661 byte *ar = mri_data_pointer( im ) ; 00662 for( jj=0 ; jj < im->nvox ; jj++ ) if( ar[jj] != 0 ) break ; 00663 if( jj < im->nvox ) last_ii = ii ; 00664 } 00665 break ; 00666 00667 case MRI_int:{ 00668 int *ar = mri_data_pointer( im ) ; 00669 for( jj=0 ; jj < im->nvox ; jj++ ) if( ar[jj] != 0 ) break ; 00670 if( jj < im->nvox ) last_ii = ii ; 00671 } 00672 break ; 00673 } 00674 if( last_ii >= 0 ) break ; 00675 } 00676 00677 if( last_ii <= 0 ) last_ii = 1 ; 00678 if( last_ii+1 < IMARR_COUNT(imar) ) TRUNCATE_IMARR(imar,last_ii+1) ; 00679 00680 } /* end of truncating off all zero images at end */ 00681 00682 #if 0 00683 fprintf(stderr,"\nmri_read_dicom Mosaic: mos_nx=%d mos_ny=%d mos_ix=%d mos_iy=%d slices=%d\n", 00684 mos_nx,mos_ny,mos_ix,mos_iy,IMARR_COUNT(imar)) ; 00685 MCHECK ; 00686 #endif 00687 00688 } /* end of mosaic input mode */ 00689 00690 fclose(fp) ; /* 10 Sep 2002: oopsie - forgot to close file */ 00691 00692 /*-- 23 Dec 2002: implement Rescale, if ordered --*/ 00693 00694 if( rescale_slope > 0.0 ){ 00695 for( ii=0 ; ii < IMARR_COUNT(imar) ; ii++ ){ 00696 im = IMARR_SUBIM(imar,ii) ; 00697 switch( im->kind ){ 00698 case MRI_byte:{ 00699 byte *ar = mri_data_pointer( im ) ; 00700 for( jj=0 ; jj < im->nvox ; jj++ ) 00701 ar[jj] = rescale_slope*ar[jj] + rescale_inter ; 00702 } 00703 break ; 00704 00705 case MRI_short:{ 00706 short *ar = mri_data_pointer( im ) ; 00707 for( jj=0 ; jj < im->nvox ; jj++ ) 00708 ar[jj] = rescale_slope*ar[jj] + rescale_inter ; 00709 } 00710 break ; 00711 00712 case MRI_int:{ 00713 int *ar = mri_data_pointer( im ) ; 00714 for( jj=0 ; jj < im->nvox ; jj++ ) 00715 ar[jj] = rescale_slope*ar[jj] + rescale_inter ; 00716 } 00717 break ; 00718 } 00719 } 00720 } /* end of Rescale */ 00721 00722 /*-- 23 Dec 2002: implement Window, if ordered --*/ 00723 /* section C.11.2.1.2 (page 503) */ 00724 00725 if( window_width >= 1.0 ){ 00726 float wbot,wtop,wfac ; 00727 int ymax=0 ; 00728 00729 /* get output range */ 00730 00731 ddd = strstr(epos[E_BITS_STORED],"//") ; 00732 if( ddd != NULL ){ 00733 ymax = 0 ; sscanf(ddd+2,"%d",&ymax) ; 00734 if( ymax > 0 ) ymax = (1 << ymax) - 1 ; 00735 } 00736 if( ymax <= 0 ){ 00737 switch( IMARR_SUBIM(imar,0)->kind ){ 00738 case MRI_byte: ymax = MRI_maxbyte ; break ; 00739 case MRI_short: ymax = MRI_maxshort ; break ; 00740 case MRI_int: ymax = MRI_maxint ; break ; 00741 } 00742 } 00743 /** window_width == 1 is special **/ 00744 if( window_width == 1.0 ){ /** binary threshold case **/ 00745 00746 wbot = window_center - 0.5 ; /* the threshold */ 00747 00748 for( ii=0 ; ii < IMARR_COUNT(imar) ; ii++ ){ 00749 im = IMARR_SUBIM(imar,ii) ; 00750 switch( im->kind ){ 00751 case MRI_byte:{ 00752 byte *ar = mri_data_pointer( im ) ; 00753 for( jj=0 ; jj < im->nvox ; jj++ ) 00754 ar[jj] = (ar[jj] <= wbot) ? 0 : ymax ; 00755 } 00756 break ; 00757 00758 case MRI_short:{ 00759 short *ar = mri_data_pointer( im ) ; 00760 for( jj=0 ; jj < im->nvox ; jj++ ) 00761 ar[jj] = (ar[jj] <= wbot) ? 0 : ymax ; 00762 } 00763 break ; 00764 00765 case MRI_int:{ 00766 int *ar = mri_data_pointer( im ) ; 00767 for( jj=0 ; jj < im->nvox ; jj++ ) 00768 ar[jj] = (ar[jj] <= wbot) ? 0 : ymax ; 00769 } 00770 break ; 00771 } 00772 } 00773 00774 } else { /** linear windowing case **/ 00775 00776 wbot = (window_center - 0.5) - 0.5*(window_width-1.0) ; 00777 wtop = (window_center - 0.5) + 0.5*(window_width-1.0) ; 00778 wfac = ymax / (window_width-1.0) ; 00779 00780 for( ii=0 ; ii < IMARR_COUNT(imar) ; ii++ ){ 00781 im = IMARR_SUBIM(imar,ii) ; 00782 switch( im->kind ){ 00783 case MRI_byte:{ 00784 byte *ar = mri_data_pointer( im ) ; 00785 for( jj=0 ; jj < im->nvox ; jj++ ) 00786 ar[jj] = (ar[jj] <= wbot) ? 0 00787 :(ar[jj] > wtop) ? ymax 00788 : wfac*(ar[jj]-wbot)+0.499 ; 00789 } 00790 break ; 00791 00792 case MRI_short:{ 00793 short *ar = mri_data_pointer( im ) ; 00794 for( jj=0 ; jj < im->nvox ; jj++ ) 00795 ar[jj] = (ar[jj] <= wbot) ? 0 00796 :(ar[jj] > wtop) ? ymax 00797 : wfac*(ar[jj]-wbot)+0.499 ; 00798 } 00799 break ; 00800 00801 case MRI_int:{ 00802 int *ar = mri_data_pointer( im ) ; 00803 for( jj=0 ; jj < im->nvox ; jj++ ) 00804 ar[jj] = (ar[jj] <= wbot) ? 0 00805 :(ar[jj] > wtop) ? ymax 00806 : wfac*(ar[jj]-wbot)+0.499 ; 00807 } 00808 break ; 00809 } 00810 } 00811 } 00812 } /* end of Window */ 00813 00814 /*-- store some extra information in MRILIB globals, too? --*/ 00815 00816 if( dt > 0.0 && MRILIB_tr <= 0.0 ) MRILIB_tr = dt ; /* TR */ 00817 00818 /*-- try to get image orientation fields (also, set ior,jor,kor) --*/ 00819 00820 if( epos[E_IMAGE_ORIENTATION] != NULL ){ /* direction cosines of image plane */ 00821 00822 ddd = strstr(epos[E_IMAGE_ORIENTATION],"//") ; 00823 if( ddd != NULL ){ 00824 float xc1=0.0,xc2=0.0,xc3=0.0 , yc1=0.0,yc2=0.0,yc3=0.0 ; 00825 float xn,yn ; int qq ; 00826 qq = sscanf(ddd+2,"%f\\%f\\%f\\%f\\%f\\%f",&xc1,&xc2,&xc3,&yc1,&yc2,&yc3) ; 00827 xn = sqrt( xc1*xc1 + xc2*xc2 + xc3*xc3 ) ; /* vector norms */ 00828 yn = sqrt( yc1*yc1 + yc2*yc2 + yc3*yc3 ) ; 00829 if( qq == 6 && xn > 0.0 && yn > 0.0 ){ /* both vectors OK */ 00830 00831 xc1 /= xn ; xc2 /= xn ; xc3 /= xn ; /* normalize vectors */ 00832 yc1 /= yn ; yc2 /= yn ; yc3 /= yn ; 00833 00834 if( !use_MRILIB_xcos ){ 00835 MRILIB_xcos[0] = xc1 ; MRILIB_xcos[1] = xc2 ; /* save direction */ 00836 MRILIB_xcos[2] = xc3 ; use_MRILIB_xcos = 1 ; /* cosine vectors */ 00837 } 00838 00839 if( !use_MRILIB_ycos ){ 00840 MRILIB_ycos[0] = yc1 ; MRILIB_ycos[1] = yc2 ; 00841 MRILIB_ycos[2] = yc3 ; use_MRILIB_ycos = 1 ; 00842 } 00843 00844 /* x-axis orientation */ 00845 /* ior determines which spatial direction is x-axis */ 00846 /* and is the direction that has the biggest change */ 00847 00848 dxx = fabs(xc1) ; ior = 1 ; 00849 dyy = fabs(xc2) ; if( dyy > dxx ){ ior=2; dxx=dyy; } 00850 dzz = fabs(xc3) ; if( dzz > dxx ){ ior=3; } 00851 dxx = MRILIB_xcos[ior-1] ; if( dxx < 0. ) ior = -ior; 00852 00853 if( MRILIB_orients[0] == '\0' ){ 00854 switch( ior ){ 00855 case -1: MRILIB_orients[0] = 'L'; MRILIB_orients[1] = 'R'; break; 00856 case 1: MRILIB_orients[0] = 'R'; MRILIB_orients[1] = 'L'; break; 00857 case -2: MRILIB_orients[0] = 'P'; MRILIB_orients[1] = 'A'; break; 00858 case 2: MRILIB_orients[0] = 'A'; MRILIB_orients[1] = 'P'; break; 00859 case 3: MRILIB_orients[0] = 'I'; MRILIB_orients[1] = 'S'; break; 00860 case -3: MRILIB_orients[0] = 'S'; MRILIB_orients[1] = 'I'; break; 00861 default: MRILIB_orients[0] ='\0'; MRILIB_orients[1] ='\0'; break; 00862 } 00863 } 00864 00865 /* y-axis orientation */ 00866 /* jor determines which spatial direction is y-axis */ 00867 /* and is the direction that has the biggest change */ 00868 00869 dxx = fabs(yc1) ; jor = 1 ; 00870 dyy = fabs(yc2) ; if( dyy > dxx ){ jor=2; dxx=dyy; } 00871 dzz = fabs(yc3) ; if( dzz > dxx ){ jor=3; } 00872 dyy = MRILIB_ycos[jor-1] ; if( dyy < 0. ) jor = -jor; 00873 if( MRILIB_orients[2] == '\0' ){ 00874 switch( jor ){ 00875 case -1: MRILIB_orients[2] = 'L'; MRILIB_orients[3] = 'R'; break; 00876 case 1: MRILIB_orients[2] = 'R'; MRILIB_orients[3] = 'L'; break; 00877 case -2: MRILIB_orients[2] = 'P'; MRILIB_orients[3] = 'A'; break; 00878 case 2: MRILIB_orients[2] = 'A'; MRILIB_orients[3] = 'P'; break; 00879 case 3: MRILIB_orients[2] = 'I'; MRILIB_orients[3] = 'S'; break; 00880 case -3: MRILIB_orients[2] = 'S'; MRILIB_orients[3] = 'I'; break; 00881 default: MRILIB_orients[2] ='\0'; MRILIB_orients[3] ='\0'; break; 00882 } 00883 } 00884 00885 MRILIB_orients[6] = '\0' ; /* terminate orientation string */ 00886 00887 kor = 6 - abs(ior)-abs(jor) ; /* which spatial direction is z-axis */ 00888 /* where 1=L-R, 2=P-A, 3=I-S */ 00889 have_orients = 1 ; 00890 #if 0 00891 fprintf(stderr,"MRILIB_orients=%s (from IMAGE_ORIENTATION)\n",MRILIB_orients) ; 00892 #endif 00893 } 00894 } 00895 00896 } else if( epos[E_PATIENT_ORIENTATION] != NULL ){ /* symbolic orientation of image */ 00897 /* [not so useful, or common] */ 00898 ddd = strstr(epos[E_PATIENT_ORIENTATION],"//") ; 00899 if( ddd != NULL ){ 00900 char xc='\0' , yc='\0' ; 00901 sscanf(ddd+2,"%c\\%c",&xc,&yc) ; /* e.g., "L\P" */ 00902 switch( toupper(xc) ){ 00903 case 'L': MRILIB_orients[0] = 'L'; MRILIB_orients[1] = 'R'; ior=-1; break; 00904 case 'R': MRILIB_orients[0] = 'R'; MRILIB_orients[1] = 'L'; ior= 1; break; 00905 case 'P': MRILIB_orients[0] = 'P'; MRILIB_orients[1] = 'A'; ior=-2; break; 00906 case 'A': MRILIB_orients[0] = 'A'; MRILIB_orients[1] = 'P'; ior= 2; break; 00907 case 'F': MRILIB_orients[0] = 'I'; MRILIB_orients[1] = 'S'; ior= 3; break; /* F = foot */ 00908 case 'H': MRILIB_orients[0] = 'S'; MRILIB_orients[1] = 'I'; ior=-3; break; /* H = head */ 00909 default: MRILIB_orients[0] ='\0'; MRILIB_orients[1] ='\0'; ior= 0; break; 00910 } 00911 switch( toupper(yc) ){ 00912 case 'L': MRILIB_orients[2] = 'L'; MRILIB_orients[3] = 'R'; jor=-1; break; 00913 case 'R': MRILIB_orients[2] = 'R'; MRILIB_orients[3] = 'L'; jor= 1; break; 00914 case 'P': MRILIB_orients[2] = 'P'; MRILIB_orients[3] = 'A'; jor=-2; break; 00915 case 'A': MRILIB_orients[2] = 'A'; MRILIB_orients[3] = 'P'; jor= 2; break; 00916 case 'F': MRILIB_orients[2] = 'I'; MRILIB_orients[3] = 'S'; jor= 3; break; 00917 case 'H': MRILIB_orients[2] = 'S'; MRILIB_orients[3] = 'I'; jor=-3; break; 00918 default: MRILIB_orients[2] ='\0'; MRILIB_orients[3] ='\0'; jor= 0; break; 00919 } 00920 MRILIB_orients[6] = '\0' ; /* terminate orientation string */ 00921 kor = 6 - abs(ior)-abs(jor) ; /* which spatial direction is z-axis */ 00922 have_orients = (ior != 0 && jor != 0) ; 00923 } 00924 00925 } /* end of 2D image orientation */ 00926 00927 /*-- try to get image offset (position), if have orientation from above --*/ 00928 00929 if( nzoff == 0 && have_orients && mosaic && sexinfo.good ){ /* 01 Nov 2002: use Siemens mosaic info */ 00930 int qq ; 00931 float z0, z1 ; 00932 /* 25 Feb 2003 changing error checking for mosaics missing one or more * 00933 * dimension of slice coordinates KRH */ 00934 if (sexinfo.have_data[kor-1]) { 00935 z0 = sexinfo.slice_xyz[0][kor-1] ; /* kor from orients above */ 00936 z1 = sexinfo.slice_xyz[1][kor-1] ; /* z offsets of 1st 2 slices */ 00937 } else { /* warn if sexinfo was bad */ 00938 static int nwarn=0 ; 00939 if( nwarn < NWMAX ) 00940 fprintf(stderr,"++ DICOM WARNING: Unusable coord. in Siemens Mosaic info (%s) in file %s\n", 00941 elist[E_SIEMENS_2] , fname ) ; 00942 if( nwarn == NWMAX ) 00943 fprintf(stderr,"++ DICOM NOTICE: no more Siemens Mosaic info messages will be printed\n"); 00944 nwarn++ ; 00945 } 00946 00947 00948 #if 0 00949 /* Save x,y center of this 1st slice */ 00950 00951 xcen = sexinfo.slice_xyz[0][abs(ior)-1] ; 00952 ycen = sexinfo.slice_xyz[0][abs(jor)-1] ; use_xycen = 1 ; 00953 #endif 00954 00955 /* finish z orientation now */ 00956 00957 if( z1-z0 < 0.0 ) kor = -kor ; /* reversed orientation */ 00958 if( MRILIB_orients[4] == '\0' ){ 00959 switch( kor ){ 00960 case 1: MRILIB_orients[4] = 'R'; MRILIB_orients[5] = 'L'; break; 00961 case -1: MRILIB_orients[4] = 'L'; MRILIB_orients[5] = 'R'; break; 00962 case 2: MRILIB_orients[4] = 'A'; MRILIB_orients[5] = 'P'; break; 00963 case -2: MRILIB_orients[4] = 'P'; MRILIB_orients[5] = 'A'; break; 00964 case 3: MRILIB_orients[4] = 'I'; MRILIB_orients[5] = 'S'; break; 00965 case -3: MRILIB_orients[4] = 'S'; MRILIB_orients[5] = 'I'; break; 00966 default: MRILIB_orients[4] ='\0'; MRILIB_orients[5] ='\0'; break; 00967 } 00968 } 00969 MRILIB_orients[6] = '\0' ; 00970 00971 #if 0 00972 fprintf(stderr,"z0=%f z1=%f kor=%d MRILIB_orients=%s\n",z0,z1,kor,MRILIB_orients) ; 00973 #endif 00974 00975 MRILIB_zoff = z0 ; use_MRILIB_zoff = 1 ; 00976 if( kor > 0 ) MRILIB_zoff = -MRILIB_zoff ; 00977 } 00978 00979 /** use image position vector to set offsets, 00980 and (2cd time in) the z-axis orientation **/ 00981 00982 if( nzoff < 2 && epos[E_IMAGE_POSITION] != NULL && have_orients ){ 00983 ddd = strstr(epos[E_IMAGE_POSITION],"//") ; 00984 if( ddd != NULL ){ 00985 float xyz[3] ; int qq ; 00986 qq = sscanf(ddd+2,"%f\\%f\\%f",xyz,xyz+1,xyz+2) ; 00987 if( qq == 3 ){ 00988 static float zoff ; /* saved from nzoff=0 case */ 00989 float zz = xyz[kor-1] ; /* kor from orients above */ 00990 00991 #if 0 00992 fprintf(stderr,"IMAGE_POSITION=%f %f %f kor=%d\n",xyz[0],xyz[1],xyz[2],kor) ; 00993 #endif 00994 00995 if( nzoff == 0 ){ /* 1st DICOM image */ 00996 00997 zoff = zz ; /* save this for 2nd image calculation */ 00998 00999 /* 01 Nov 2002: in mosaic case, may have set this already */ 01000 01001 if( MRILIB_orients[4] == '\0' ){ 01002 switch( kor ){ /* may be changed on second image */ 01003 case 1: MRILIB_orients[4] = 'L'; MRILIB_orients[5] = 'R'; break; 01004 case 2: MRILIB_orients[4] = 'P'; MRILIB_orients[5] = 'A'; break; 01005 case 3: MRILIB_orients[4] = 'I'; MRILIB_orients[5] = 'S'; break; 01006 default: MRILIB_orients[4] ='\0'; MRILIB_orients[5] ='\0'; break; 01007 } 01008 MRILIB_orients[6] = '\0' ; 01009 } 01010 01011 /* Save x,y offsets of this 1st slice */ 01012 01013 qq = abs(ior) ; 01014 MRILIB_xoff = xyz[qq-1] ; use_MRILIB_xoff = 1 ; 01015 if( ior > 0 ) MRILIB_xoff = -MRILIB_xoff ; 01016 01017 qq = abs(jor) ; 01018 MRILIB_yoff = xyz[qq-1] ; use_MRILIB_yoff = 1 ; 01019 if( jor > 0 ) MRILIB_yoff = -MRILIB_yoff ; 01020 01021 /* 01 Nov 2002: adjust x,y offsets for mosaic */ 01022 01023 if( mosaic ){ 01024 if( MRILIB_xoff < 0.0 ) MRILIB_xoff += 0.5*dx*mos_nx*(mos_ix-1) ; 01025 else MRILIB_xoff -= 0.5*dx*mos_nx*(mos_ix-1) ; 01026 if( MRILIB_yoff < 0.0 ) MRILIB_yoff += 0.5*dy*mos_ny*(mos_iy-1) ; 01027 else MRILIB_yoff -= 0.5*dy*mos_ny*(mos_iy-1) ; 01028 } 01029 01030 } else if( nzoff == 1 && !use_MRILIB_zoff ){ /* 2nd DICOM image */ 01031 01032 float qoff = zz - zoff ; /* vive la difference */ 01033 if( qoff < 0 ) kor = -kor ; /* kor determines z-axis orientation */ 01034 #if 0 01035 fprintf(stderr," nzoff=1 kor=%d qoff=%f\n",kor,qoff) ; 01036 #endif 01037 switch( kor ){ 01038 case 1: MRILIB_orients[4] = 'R'; MRILIB_orients[5] = 'L'; break; 01039 case -1: MRILIB_orients[4] = 'L'; MRILIB_orients[5] = 'R'; break; 01040 case 2: MRILIB_orients[4] = 'A'; MRILIB_orients[5] = 'P'; break; 01041 case -2: MRILIB_orients[4] = 'P'; MRILIB_orients[5] = 'A'; break; 01042 case 3: MRILIB_orients[4] = 'I'; MRILIB_orients[5] = 'S'; break; 01043 case -3: MRILIB_orients[4] = 'S'; MRILIB_orients[5] = 'I'; break; 01044 default: MRILIB_orients[4] ='\0'; MRILIB_orients[5] ='\0'; break; 01045 } 01046 MRILIB_orients[6] = '\0' ; 01047 01048 /* save spatial offset of first slice */ 01049 /* [this needs to be positive in the direction of] */ 01050 /* [the -z axis, so may need to change its sign ] */ 01051 01052 MRILIB_zoff = zoff ; use_MRILIB_zoff = 1 ; 01053 if( kor > 0 ) MRILIB_zoff = -MRILIB_zoff ; 01054 } 01055 nzoff++ ; /* 3rd and later images don't count for z-orientation */ 01056 } 01057 } 01058 } /* end of using image position */ 01059 01060 /** 23 Dec 2002: 01061 use slice location value to set z-offset, 01062 and (2cd time in) the z-axis orientation 01063 -- only try this if image position vector (code above) isn't present 01064 AND if we don't have a mosaic image (which already did this stuff) 01065 -- shouldn't be necessary, since slice location is deprecated **/ 01066 01067 else if( nzoff < 2 && epos[E_SLICE_LOCATION] != NULL && have_orients && !mosaic ){ 01068 ddd = strstr(epos[E_SLICE_LOCATION],"//") ; 01069 if( ddd != NULL ){ 01070 float zz ; int qq ; 01071 qq = sscanf(ddd+2,"%f",&zz) ; 01072 if( qq == 1 ){ 01073 static float zoff ; /* saved from nzoff=0 case */ 01074 01075 #if 0 01076 fprintf(stderr,"SLICE_LOCATION = %f\n",zz) ; 01077 #endif 01078 01079 if( nzoff == 0 ){ /* 1st DICOM image */ 01080 01081 zoff = zz ; /* save this for 2nd image calculation */ 01082 01083 if( MRILIB_orients[4] == '\0' ){ 01084 switch( kor ){ /* may be changed on second image */ 01085 case 1: MRILIB_orients[4] = 'L'; MRILIB_orients[5] = 'R'; break; 01086 case 2: MRILIB_orients[4] = 'P'; MRILIB_orients[5] = 'A'; break; 01087 case 3: MRILIB_orients[4] = 'I'; MRILIB_orients[5] = 'S'; break; 01088 default: MRILIB_orients[4] ='\0'; MRILIB_orients[5] ='\0'; break; 01089 } 01090 MRILIB_orients[6] = '\0' ; 01091 } 01092 01093 } else if( nzoff == 1 && !use_MRILIB_zoff ){ /* 2nd DICOM image */ 01094 01095 float qoff = zz - zoff ; /* vive la difference */ 01096 if( qoff < 0 ) kor = -kor ; /* kor determines z-axis orientation */ 01097 switch( kor ){ 01098 case 1: MRILIB_orients[4] = 'R'; MRILIB_orients[5] = 'L'; break; 01099 case -1: MRILIB_orients[4] = 'L'; MRILIB_orients[5] = 'R'; break; 01100 case 2: MRILIB_orients[4] = 'A'; MRILIB_orients[5] = 'P'; break; 01101 case -2: MRILIB_orients[4] = 'P'; MRILIB_orients[5] = 'A'; break; 01102 case 3: MRILIB_orients[4] = 'I'; MRILIB_orients[5] = 'S'; break; 01103 case -3: MRILIB_orients[4] = 'S'; MRILIB_orients[5] = 'I'; break; 01104 default: MRILIB_orients[4] ='\0'; MRILIB_orients[5] ='\0'; break; 01105 } 01106 MRILIB_orients[6] = '\0' ; 01107 01108 /* save spatial offset of first slice */ 01109 /* [this needs to be positive in the direction of] */ 01110 /* [the -z axis, so may need to change its sign ] */ 01111 01112 MRILIB_zoff = zoff ; use_MRILIB_zoff = 1 ; 01113 if( kor > 0 ) MRILIB_zoff = -MRILIB_zoff ; 01114 } 01115 nzoff++ ; /* 3rd and later images don't count for z-orientation */ 01116 } 01117 } 01118 } /* end of using slice location */ 01119 01120 /* perhaps shift data shorts */ 01121 01122 #if 0 01123 if( shift == 1 ){ 01124 switch( datum ){ 01125 case MRI_short:{ 01126 if( sbot < 0 ){ 01127 unsigned short *sar ; int nvox = IMARR_SUBIM(imar,0)->nvox ; 01128 for( ii=0 ; ii < nz ; ii++ ){ 01129 sar = mri_data_pointer( IMARR_SUBIM(imar,ii) ) ; 01130 for( jj=0 ; jj < nvox ; jj++ ) sar[jj] >>= 1 ; 01131 } 01132 } 01133 } 01134 break ; 01135 } 01136 } 01137 #endif 01138 01139 RETURN( imar ); 01140 } |
|
Read one or more 2D images from a file. This function is the main point of input for to3d.c.
Definition at line 1016 of file mri_read.c. References ADDTO_IMARR, AFNI_yesenv(), check_dicom_magic_num(), ENTRY, MRI_IMAGE::fname, free, IMARR_SUBIM, imsized_fname(), INIT_IMARR, mri_read(), mri_read_3A(), mri_read_3D(), mri_read_analyze75(), mri_read_dicom(), mri_read_ge4(), mri_read_mpeg(), mri_read_siemens(), mri_read_stuff(), MRI_IMARR::num, and RETURN. Referenced by AFNI_read_images(), main(), mri_read_just_one(), mri_read_many_files(), mri_read_nsize(), REG_command_line(), and T3D_read_images().
01017 { 01018 MRI_IMARR * newar=NULL ; 01019 MRI_IMAGE * newim ; 01020 char * new_fname ; 01021 01022 ENTRY("mri_read_file") ; 01023 01024 /* convert fname to new_fname, based on environment */ 01025 01026 new_fname = imsized_fname( fname ) ; 01027 if( new_fname == NULL ) RETURN( NULL ); 01028 01029 /* input method is based on filename */ 01030 01031 if( strlen(new_fname) > 9 && 01032 new_fname[0] == '3' && 01033 new_fname[1] == 'D' && 01034 (new_fname[2] == ':' || new_fname[3] == ':') ){ 01035 01036 newar = mri_read_3D( new_fname ) ; /* read from a 3D: file */ 01037 01038 } else if( strlen(new_fname) > 9 && 01039 new_fname[0] == '3' && new_fname[1] == 'A' && new_fname[3] == ':' ){ 01040 01041 newar = mri_read_3A( new_fname ) ; /* from a 3A: file */ 01042 01043 } else if( check_dicom_magic_num( new_fname ) ) { /* 10 Aug 2004 */ 01044 01045 newar = mri_read_dicom( new_fname ); 01046 01047 } else if( strstr(new_fname,".hdr") != NULL || 01048 strstr(new_fname,".HDR") != NULL ){ /* 05 Feb 2001 */ 01049 01050 newar = mri_read_analyze75( new_fname ) ; /* ANALYZE .hdr/.img filepair */ 01051 01052 } else if( strstr(new_fname,".ima") != NULL || 01053 strstr(new_fname,".IMA") != NULL ){ /* 12 Mar 2001 */ 01054 01055 newar = mri_read_siemens( new_fname ) ; /* Siemens file */ 01056 01057 } else if( strncmp(new_fname,"I.",2) == 0 || /* GE I.* files */ 01058 strstr(new_fname,"/I.") != NULL || 01059 strstr(new_fname,".ppm") != NULL || /* raw PPM or PGM files */ 01060 strstr(new_fname,".pgm") != NULL || 01061 strstr(new_fname,".pnm") != NULL || 01062 strstr(new_fname,".PPM") != NULL || 01063 strstr(new_fname,".PNM") != NULL || 01064 strstr(new_fname,".PGM") != NULL ){ /* 05 Nov 2002 */ 01065 01066 newim = mri_read( new_fname ) ; /* read from a 2D file with 1 slice */ 01067 01068 if ( newim == NULL ) /* GEMS 4.x - 03 Jun 2003 [rickr] */ 01069 newim = mri_read_ge4( new_fname ) ; 01070 01071 if( newim != NULL ){ 01072 INIT_IMARR(newar) ; 01073 ADDTO_IMARR(newar,newim) ; 01074 } 01075 01076 } else if( strncmp(new_fname,"i.",2) == 0 || /* GEMS 4.x i.* files */ 01077 strstr(new_fname,"/i.") != NULL ){ /* 03 Jun 2003 [rickr] */ 01078 01079 newim = mri_read_ge4( new_fname ) ; /* 2D file with 1 slice */ 01080 01081 if( newim != NULL ){ 01082 INIT_IMARR(newar) ; 01083 ADDTO_IMARR(newar,newim) ; 01084 } 01085 01086 } else if( strstr(new_fname,".jpg" ) != NULL || /* various formats */ 01087 strstr(new_fname,".JPG" ) != NULL || /* that we convert */ 01088 strstr(new_fname,".jpeg") != NULL || /* to PPG/PGM using */ 01089 strstr(new_fname,".JPEG") != NULL || /* external filters */ 01090 strstr(new_fname,".gif" ) != NULL || 01091 strstr(new_fname,".GIF" ) != NULL || 01092 strstr(new_fname,".tif" ) != NULL || 01093 strstr(new_fname,".TIF" ) != NULL || 01094 strstr(new_fname,".tiff") != NULL || 01095 strstr(new_fname,".TIFF") != NULL || 01096 strstr(new_fname,".bmp" ) != NULL || 01097 strstr(new_fname,".BMP" ) != NULL || 01098 strstr(new_fname,".pbm" ) != NULL || 01099 strstr(new_fname,".PBM" ) != NULL || 01100 strstr(new_fname,".png" ) != NULL || 01101 strstr(new_fname,".PNG" ) != NULL ){ /* 22 Nov 2002 */ 01102 01103 newim = mri_read_stuff( new_fname ) ; 01104 if( newim != NULL ){ 01105 INIT_IMARR(newar) ; 01106 ADDTO_IMARR(newar,newim) ; 01107 } 01108 01109 } else if( strstr(new_fname,".mpg" ) != NULL || /* 03 Dec 2003 */ 01110 strstr(new_fname,".MPG" ) != NULL || /* read MPEGs */ 01111 strstr(new_fname,".mpeg") != NULL || 01112 strstr(new_fname,".MPEG") != NULL ){ 01113 01114 newar = mri_read_mpeg( new_fname ) ; /* cf. mri_read_mpeg.c */ 01115 } 01116 01117 /** failed to read anything? try DICOM format (doesn't have a fixed suffix) **/ 01118 /* 05 May 2003 added option to try DICOM last KRH */ 01119 01120 if( newar == NULL ){ 01121 01122 if ( !AFNI_yesenv("AFNI_TRY_DICOM_LAST")) { 01123 newar = mri_read_dicom( new_fname ) ; /* cf. mri_read_dicom.c */ 01124 } 01125 01126 /** if DICOM failed, try a 2D slice file, hope for the best **/ 01127 01128 if( newar == NULL ){ 01129 newim = mri_read( new_fname ) ; 01130 if( newim == NULL ){ free(new_fname); RETURN( NULL ); } /* give up */ 01131 INIT_IMARR(newar) ; 01132 ADDTO_IMARR(newar,newim) ; 01133 } 01134 01135 if ( (newar == NULL) && AFNI_yesenv("AFNI_TRY_DICOM_LAST")) { 01136 newar = mri_read_dicom( new_fname ) ; /* cf. mri_read_dicom.c */ 01137 } 01138 } 01139 01140 free(new_fname) ; /* done with the mangled filename */ 01141 01142 /* 07 Mar 2002: add fname to the images, if needed */ 01143 01144 if( newar != NULL && newar->num > 0 ){ 01145 int ii ; 01146 for( ii=0 ; ii < newar->num ; ii++ ){ 01147 newim = IMARR_SUBIM(newar,ii) ; 01148 if( newim != NULL && newim->fname == NULL ) 01149 newim->fname = strdup(fname) ; 01150 } 01151 } 01152 01153 RETURN( newar ); 01154 } |
|
mark as already read from disk * Definition at line 3228 of file mri_read.c. References ADDTO_IMARR, AFNI_yesenv(), free, imsized_fname(), INIT_IMARR, mri_read(), mri_read_3A(), mri_read_3D_delay(), mri_read_analyze75(), mri_read_dicom(), mri_read_mpeg(), and mri_read_siemens(). Referenced by T3D_read_images().
03229 { 03230 MRI_IMARR * newar=NULL ; 03231 MRI_IMAGE * newim ; 03232 char * new_fname ; 03233 03234 new_fname = imsized_fname( fname ) ; 03235 if( new_fname == NULL ) return NULL ; 03236 03237 if( strlen(new_fname) > 9 && new_fname[0] == '3' && new_fname[1] == 'D' && 03238 (new_fname[2] == ':' || new_fname[3] == ':') ){ 03239 /* check for ':', too 3 Jan 2005 [rickr] */ 03240 03241 newar = mri_read_3D_delay( new_fname ) ; /* read from a 3D file, later */ 03242 03243 } else if( strlen(new_fname) > 9 && 03244 new_fname[0] == '3' && new_fname[1] == 'A' && new_fname[3] == ':' ){ 03245 03246 newar = mri_read_3A( new_fname ) ; 03247 03248 } else if( strstr(new_fname,".hdr") != NULL || 03249 strstr(new_fname,".HDR") != NULL ){ /* 05 Feb 2001 - ANALYZE header */ 03250 03251 newar = mri_read_analyze75( new_fname ) ; 03252 03253 } else if( strstr(new_fname,".ima") != NULL || 03254 strstr(new_fname,".IMA") != NULL ){ /* 12 Mar 2001 - Siemens */ 03255 03256 newar = mri_read_siemens( new_fname ) ; 03257 03258 } else if( strstr(new_fname,".mpg" ) != NULL || /* 03 Dec 2003 */ 03259 strstr(new_fname,".MPG" ) != NULL || /* read MPEGs */ 03260 strstr(new_fname,".mpeg") != NULL || 03261 strstr(new_fname,".MPEG") != NULL ){ 03262 03263 newar = mri_read_mpeg( new_fname ) ; /* cf. mri_read_mpeg.c */ 03264 } 03265 03266 /* failed thus far? try DICOM, unless user has requested DICOM last */ 03267 /* 05 May 2003 added option to try DICOM last KRH */ 03268 03269 if ((newar == NULL) && !AFNI_yesenv("AFNI_TRY_DICOM_LAST")) { 03270 newar = mri_read_dicom( new_fname ) ; /* cf. mri_read_dicom.c */ 03271 } 03272 03273 /* failed again? try mri_read() for 1 image */ 03274 03275 if( newar == NULL ){ 03276 newim = mri_read( new_fname ) ; /* read from a 2D file */ 03277 if( newim == NULL ){ free(new_fname) ; return NULL ; } 03278 INIT_IMARR(newar) ; 03279 ADDTO_IMARR(newar,newim) ; 03280 } 03281 03282 if ( (newar == NULL) && AFNI_yesenv("AFNI_TRY_DICOM_LAST")) { 03283 newar = mri_read_dicom( new_fname ) ; /* cf. mri_read_dicom.c */ 03284 } 03285 03286 free(new_fname) ; 03287 return newar ; 03288 } |
|
Read a single 2D GEMS 4.x image.
Definition at line 597 of file mri_read.c. References MRI_IMAGE::dt, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, ge4_series_t::fov, free, ge4_read_header(), ge4_header::im_bytes, ge4_header::im_h, ge4_image_t::im_loc, ge4_header::image, mri_add_name(), mri_data_pointer(), mri_new(), RETURN, ge4_series_t::scan_mat_x, ge4_series_t::scan_mat_y, ge4_header::ser_h, ge4_header::swap, ge4_image_t::tr, MRI_IMAGE::was_swapped, and MRI_IMAGE::zo. Referenced by mri_read_file().
00598 { 00599 MRI_IMAGE * im; 00600 ge4_header H; 00601 00602 ENTRY( "mri_read_ge4" ); 00603 00604 if ( filename == NULL ) 00605 { 00606 fprintf( stderr, "** mri_read_ge4 - missing filename\n" ); 00607 RETURN( NULL ); 00608 } 00609 00610 /* try to read image file - return with image */ 00611 if ( ge4_read_header( &H, filename, True ) != 0 ) 00612 RETURN( NULL ); 00613 00614 /* these dimensions are fixed */ 00615 if ( (im = mri_new(256, 256, MRI_short)) == NULL ) 00616 { 00617 free(H.image); 00618 RETURN( NULL ); 00619 } 00620 00621 /* fill im struct with data from H */ 00622 im->zo = H.im_h.im_loc; /* this may well be incorrect */ 00623 im->dt = H.im_h.tr; 00624 im->was_swapped = H.swap; 00625 00626 if ( ( H.ser_h.fov > 1.0 ) && 00627 ( H.ser_h.fov < 1000.0 ) && 00628 ( H.ser_h.scan_mat_x > 0 ) && 00629 ( H.ser_h.scan_mat_x < 1000 ) && 00630 ( H.ser_h.scan_mat_y > 0 ) && 00631 ( H.ser_h.scan_mat_y < 1000 ) ) 00632 { 00633 /* attempt to set dx, dy and dz from these */ 00634 00635 im->dx = 2 * H.ser_h.fov / H.ser_h.scan_mat_x; 00636 im->dy = im->dx; 00637 im->dz = 2 * H.ser_h.fov / H.ser_h.scan_mat_y; 00638 im->dw = 1; 00639 } 00640 00641 memcpy( mri_data_pointer(im), H.image, H.im_bytes ); 00642 00643 mri_add_name( filename, im ); 00644 00645 free(H.image); /* your services are no longer required */ 00646 00647 RETURN( im ); 00648 } |
|
Like mri_read_file(), but will only return 1 2D image. If the input file has more than 1 slice, or cannot be read, then NULL is returned. Definition at line 1164 of file mri_read.c. References DESTROY_IMARR, ENTRY, free, FREE_IMARR, IMAGE_IN_IMARR, imsized_fname(), mri_read_file(), MRI_IMARR::num, and RETURN. Referenced by AFNI_make_widgets(), CALC_read_opts(), get_line_opt(), main(), and REG_command_line().
01165 { 01166 MRI_IMARR * imar ; 01167 MRI_IMAGE * im ; 01168 char * new_fname ; 01169 01170 ENTRY("mri_read_just_one") ; 01171 01172 new_fname = imsized_fname( fname ) ; 01173 if( new_fname == NULL ) RETURN( NULL ); 01174 01175 imar = mri_read_file( new_fname ) ; free(new_fname) ; 01176 if( imar == NULL ) RETURN( NULL ); 01177 if( imar->num != 1 ){ DESTROY_IMARR(imar) ; RETURN( NULL ); } 01178 im = IMAGE_IN_IMARR(imar,0) ; 01179 FREE_IMARR(imar) ; 01180 RETURN( im ); 01181 } |
|
Like mri_read_file(), but returns images from many files.
Definition at line 1341 of file mri_read.c. References ADDTO_IMARR, ENTRY, FREE_IMARR, MRI_IMARR::imarr, INIT_IMARR, mri_free(), mri_read_file(), MRI_IMARR::num, and RETURN. Referenced by FTOSH_getopts(), get_line_opt(), main(), mri_read_many_nsize(), SFIM_getopts(), and TFIM_getopts().
01342 { 01343 MRI_IMARR * newar , * outar ; 01344 int kf , ii ; 01345 01346 ENTRY("mri_read_many_files") ; 01347 01348 if( nf <= 0 ) RETURN( NULL ); /* no inputs! */ 01349 INIT_IMARR(outar) ; /* initialize output array */ 01350 01351 for( kf=0 ; kf < nf ; kf++ ){ 01352 newar = mri_read_file( fn[kf] ) ; /* read all images in this file */ 01353 01354 if( newar == NULL ){ /* none? flush the output array! */ 01355 fprintf(stderr,"cannot read images from file %s\n",fn[kf]) ; 01356 for( ii=0 ; ii < outar->num ; ii++ ) mri_free(outar->imarr[ii]) ; 01357 FREE_IMARR(outar) ; 01358 RETURN( NULL ); 01359 } 01360 01361 for( ii=0 ; ii < newar->num ; ii++ ) /* move images to output array */ 01362 ADDTO_IMARR( outar , newar->imarr[ii] ) ; 01363 01364 FREE_IMARR(newar) ; /* don't need this no more */ 01365 } 01366 RETURN( outar ); 01367 } |
|
Read many 2D images from many files. Definition at line 1483 of file mri_read.c. References ADDTO_IMARR, FREE_IMARR, IMAGE_IN_IMARR, INIT_IMARR, mri_add_name(), mri_free(), mri_nsize(), mri_read_many_files(), name, and MRI_IMARR::num.
01484 { 01485 MRI_IMARR * newar , * outar ; 01486 MRI_IMAGE * im ; 01487 int ii ; 01488 01489 newar = mri_read_many_files( nf , fn ) ; 01490 if( newar == NULL ) return NULL ; 01491 01492 INIT_IMARR(outar) ; 01493 for( ii=0 ; ii < newar->num ; ii++ ){ 01494 im = mri_nsize( IMAGE_IN_IMARR(newar,ii) ) ; 01495 mri_add_name( IMAGE_IN_IMARR(newar,ii)->name , im ) ; 01496 ADDTO_IMARR(outar,im) ; 01497 mri_free( IMAGE_IN_IMARR(newar,ii) ) ; 01498 } 01499 FREE_IMARR(newar) ; 01500 return outar ; 01501 } |
|
Convert an MPEG file into a set of images. Must have program mpegtoppm in the path. [03 Dec 2003] Definition at line 45 of file mri_read_mpeg.c. References ADDTO_IMARR, AFMALL, AFNI_yesenv(), DESTROY_IMARR, ENTRY, free, FREE_IMARR, IMARR_COUNT, IMARR_SUBIM, INIT_IMARR, mpeg_filter, mpeg_setup(), mri_filesize(), mri_free(), mri_isgray(), mri_read_ppm(), mri_to_byte(), RETURN, THD_is_directory(), THD_mkdir(), tmpdir, and TSIZ. Referenced by mri_read_file(), mri_read_file_delay(), THD_load_mpeg(), and THD_open_mpeg().
00046 { 00047 char *pg ; 00048 int ii , allgray=1 ; 00049 FILE *fp ; 00050 MRI_IMAGE *im ; 00051 MRI_IMARR *imar ; 00052 00053 ENTRY("mri_read_mpeg") ; 00054 00055 /*--- check input for OK-ness ---*/ 00056 00057 if( fname == NULL || *fname == '\0' ) RETURN( NULL ); 00058 ii = mri_filesize(fname) ; 00059 if( ii <= 0 ) RETURN( NULL ); 00060 00061 mpeg_setup() ; 00062 00063 if( mpeg_filter == NULL ) RETURN( NULL ); /* can't filter? */ 00064 00065 /*--- create the filter for this file and run it to create .ppm files ---*/ 00066 00067 pg = AFMALL(char, strlen(fname)+strlen(mpeg_filter)+32) ; /* string to hold filter */ 00068 sprintf( pg , mpeg_filter , fname ) ; 00069 THD_mkdir( tmpdir ) ; /* create the temp directory */ 00070 if( !THD_is_directory(tmpdir) ){ free(pg); RETURN(NULL); } /* can't? */ 00071 00072 if( ii > TSIZ ) fprintf(stderr,"++ Decoding file %s",fname) ; 00073 system( pg ) ; /* run the command */ 00074 if( ii > TSIZ ) fprintf(stderr,".\n") ; 00075 00076 /*--- read files from the temp directory ---*/ 00077 00078 INIT_IMARR(imar) ; 00079 for( ii=0 ; ; ii++ ){ /* loop until we fail to read */ 00080 sprintf( pg , "%s%06d.ppm" , tmpdir,ii ) ; 00081 im = mri_read_ppm( pg ) ; 00082 if( im == NULL ) break ; 00083 allgray = allgray && mri_isgray(im) ; 00084 remove( pg ) ; 00085 ADDTO_IMARR(imar,im) ; 00086 } 00087 remove( tmpdir ) ; free(pg) ; 00088 00089 /* if all images are grayscale, convert to byte-valued images */ 00090 00091 if( IMARR_COUNT(imar) == 0 ){ 00092 DESTROY_IMARR(imar); 00093 imar = NULL; 00094 } else if( AFNI_yesenv("AFNI_MPEG_GRAYIZE") ){ 00095 MRI_IMARR *qmar ; 00096 INIT_IMARR(qmar) ; 00097 for( ii=0 ; ii < IMARR_COUNT(imar) ; ii++ ){ 00098 im = mri_to_byte( IMARR_SUBIM(imar,ii) ) ; 00099 ADDTO_IMARR(qmar,im) ; 00100 mri_free( IMARR_SUBIM(imar,ii) ) ; 00101 } 00102 FREE_IMARR(imar) ; imar = qmar ; 00103 } 00104 00105 RETURN( imar ); 00106 } |
|
Read 1 2D image, then "nsize" it - make it a power of 2 in sizes. This was developed in the days when FD/FD2/fim ruled the world, and those programs (AJ's legacy) only deal with square images that are a power of 2 in size.
Definition at line 1465 of file mri_read.c. References DESTROY_IMARR, IMAGE_IN_IMARR, mri_add_name(), mri_nsize(), mri_read_file(), name, and MRI_IMARR::num.
01466 { 01467 MRI_IMARR *imar ; 01468 MRI_IMAGE *imout ; 01469 01470 imar = mri_read_file( fname ) ; 01471 if( imar == NULL ) return NULL ; 01472 if( imar->num != 1 ){ DESTROY_IMARR(imar) ; return NULL ; } 01473 01474 imout = mri_nsize( IMAGE_IN_IMARR(imar,0) ) ; 01475 mri_add_name( IMAGE_IN_IMARR(imar,0)->name , imout ) ; 01476 01477 DESTROY_IMARR(imar) ; 01478 return imout ; 01479 } |
|
Reads a raw PPM file into 1 2D MRI_rgb-valued image.
Definition at line 1722 of file mri_read.c. References ENTRY, maxval, mri_add_name(), mri_free(), mri_new(), MRI_RGB_PTR, NUMSCAN, and RETURN. Referenced by IM_main(), main(), mri_read(), mri_read_mpeg(), and SUMA_read_ppm().
01723 { 01724 int ch , nch , nx,ny,maxval , length ; 01725 MRI_IMAGE * rgbim ; 01726 FILE * imfile ; 01727 byte * rgby ; 01728 char buf[256] ; 01729 01730 ENTRY("mri_read_ppm") ; 01731 01732 /*** open input file ***/ 01733 01734 imfile = fopen( fname , "r" ) ; 01735 if( imfile == NULL ) RETURN(NULL); 01736 01737 /*** check if a raw PPM file ***/ 01738 01739 ch = getc( imfile ) ; if( ch != 'P' ) { fclose(imfile) ; RETURN(NULL); } 01740 ch = getc( imfile ) ; if( ch != '6' ) { fclose(imfile) ; RETURN(NULL); } 01741 01742 /* magic P6 found, so read numbers in header */ 01743 01744 ch = getc(imfile) ; 01745 01746 NUMSCAN(nx) ; if( nx <= 0 ) { fclose(imfile); RETURN(NULL); } 01747 NUMSCAN(ny) ; if( ny <= 0 ) { fclose(imfile); RETURN(NULL); } 01748 NUMSCAN(maxval); if( maxval <= 0 || 01749 maxval > 255 ){ fclose(imfile); RETURN(NULL); } 01750 01751 /*** create output image ***/ 01752 01753 rgbim = mri_new( nx , ny , MRI_rgb ) ; mri_add_name( fname , rgbim ) ; 01754 rgby = MRI_RGB_PTR(rgbim) ; 01755 01756 /*** read all data into image array */ 01757 01758 length = fread( rgby , sizeof(byte) , 3*nx*ny , imfile ) ; 01759 fclose( imfile ) ; 01760 01761 if( length != 3*nx*ny ){ mri_free(rgbim) ; RETURN(NULL) ; } 01762 01763 /* 17 Sep 2001: scale to maxval=255, if needed */ 01764 01765 if( maxval < 255 ){ 01766 int ii ; float fac = 255.4/maxval ; 01767 for( ii=0 ; ii < 3*nx*ny ; ii++ ) rgby[ii] = (byte)( rgby[ii]*fac ) ; 01768 } 01769 01770 RETURN(rgbim) ; 01771 } |
|
Read a raw PPM file into 3 byte-valued MRI_IMAGEs.
Definition at line 1376 of file mri_read.c. References ADDTO_IMARR, ENTRY, EXIT, free, INIT_IMARR, malloc, maxval, mri_add_name(), mri_data_pointer(), mri_free(), mri_new(), NUMSCAN, and RETURN. Referenced by main().
01377 { 01378 int ch , nch , nx,ny,maxval , length , npix,ii ; 01379 char buf[512] ; 01380 MRI_IMAGE *rim , *gim , *bim ; 01381 MRI_IMARR * outar ; 01382 FILE * imfile ; 01383 byte * rby , * gby , * bby , * rgby ; 01384 01385 ENTRY("mri_read_ppm3") ; 01386 01387 /*** open input file ***/ 01388 01389 imfile = fopen( fname , "r" ) ; 01390 if( imfile == NULL ){ 01391 fprintf(stderr,"couldn't open file %s in mri_read_ppm3\n",fname); RETURN(NULL) ; 01392 } 01393 01394 /*** check if a raw PPM file ***/ 01395 01396 ch = getc( imfile ) ; if( ch != 'P' ) { fclose(imfile) ; RETURN(NULL); } 01397 ch = getc( imfile ) ; if( ch != '6' ) { fclose(imfile) ; RETURN(NULL); } 01398 01399 /* magic P6 found, so read numbers in header */ 01400 01401 ch = getc(imfile) ; 01402 01403 NUMSCAN(nx) ; if( nx <= 0 ) { fclose(imfile) ; RETURN(NULL); } 01404 NUMSCAN(ny) ; if( ny <= 0 ) { fclose(imfile) ; RETURN(NULL); } 01405 NUMSCAN(maxval) ; if( maxval <= 0 || 01406 maxval > 255 ) { fclose(imfile) ; RETURN(NULL); } 01407 01408 /*** create output images and workspace array ***/ 01409 01410 rim = mri_new( nx , ny , MRI_byte ) ; rby = mri_data_pointer( rim ) ; 01411 gim = mri_new( nx , ny , MRI_byte ) ; gby = mri_data_pointer( gim ) ; 01412 bim = mri_new( nx , ny , MRI_byte ) ; bby = mri_data_pointer( bim ) ; 01413 01414 sprintf(buf,"%s#R",fname) ; mri_add_name( buf , rim ) ; 01415 sprintf(buf,"%s#G",fname) ; mri_add_name( buf , gim ) ; 01416 sprintf(buf,"%s#B",fname) ; mri_add_name( buf , bim ) ; 01417 01418 rgby = (byte *) malloc( sizeof(byte) * 3*nx*ny ) ; 01419 if( rgby == NULL ){ 01420 fprintf(stderr,"couldn't malloc workspace in mri_read_ppm3!\n") ; EXIT(1) ; 01421 } 01422 01423 /*** read all data into workspace array ***/ 01424 01425 length = fread( rgby , sizeof(byte) , 3*nx*ny , imfile ) ; 01426 fclose( imfile ) ; 01427 01428 if( length != 3*nx*ny ){ 01429 free(rgby) ; mri_free(rim) ; mri_free(gim) ; mri_free(bim) ; 01430 fprintf(stderr,"couldn't read data from file %s in mri_read_ppm3\n",fname) ; 01431 RETURN(NULL); 01432 } 01433 01434 /*** put data from workspace array into output images ***/ 01435 01436 npix = nx*ny ; 01437 for( ii=0 ; ii < npix ; ii++ ){ 01438 rby[ii] = rgby[3*ii ] ; 01439 gby[ii] = rgby[3*ii+1] ; 01440 bby[ii] = rgby[3*ii+2] ; 01441 } 01442 free( rgby ) ; 01443 01444 /*** create output image array ***/ 01445 01446 INIT_IMARR(outar) ; 01447 ADDTO_IMARR( outar , rim ) ; 01448 ADDTO_IMARR( outar , gim ) ; 01449 ADDTO_IMARR( outar , bim ) ; 01450 RETURN(outar); 01451 } |
|
Read the header from PPM file and return its info.
Definition at line 1680 of file mri_read.c. References ENTRY, and NUMSCAN.
01681 { 01682 FILE *imfile ; 01683 int ch , nch , nxx,nyy ; 01684 char buf[256] ; 01685 01686 ENTRY("mri_read_ppm_header") ; 01687 01688 if( fname == NULL || nx == NULL || ny == NULL ) EXRETURN ; 01689 01690 *nx = *ny = 0 ; /* default returns */ 01691 01692 /*** open input file ***/ 01693 01694 imfile = fopen( fname , "r" ) ; if( imfile == NULL ) EXRETURN ; 01695 01696 /*** check if a raw PPM file ***/ 01697 01698 ch = getc( imfile ) ; if( ch != 'P' ) { fclose(imfile) ; EXRETURN ; } 01699 ch = getc( imfile ) ; if( ch != '6' ) { fclose(imfile) ; EXRETURN ; } 01700 01701 /* magic P6 found, so read numbers in header */ 01702 01703 ch = getc(imfile) ; 01704 01705 NUMSCAN(nxx) ; if( nxx <= 0 ){ fclose(imfile) ; EXRETURN ; } 01706 NUMSCAN(nyy) ; if( nyy <= 0 ){ fclose(imfile) ; EXRETURN ; } 01707 01708 /* return dimensions */ 01709 01710 fclose(imfile) ; *nx = nxx ; *ny = nyy ; EXRETURN ; 01711 } |
|
Read an array of 2D images from Siemens Vision .ima file. The images are stored in a 2D array, which requires untangling the data rows to put them into separate MRI_IMAGE structs. Definition at line 2955 of file mri_read.c. References ADDTO_IMARR, calloc, Siemens_vision_header::DisplayMatrixSize, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, Siemens_vision_header::FOVColumn, Siemens_vision_header::FOVRow, free, FREE_IMARR, getenv(), i, IMARR_COUNT, IMARR_SUBIM, INIT_IMARR, mri_add_name(), mri_new(), MRI_SHORT_PTR, MRILIB_orients, MRILIB_zoff, nz, Siemens_vision_header::OrientationSet1Back, Siemens_vision_header::OrientationSet1Left, Siemens_vision_header::OrientationSet1Top, Siemens_vision_header::OrientationSet2Down, Siemens_vision_header::OrientationSet2Front, Siemens_vision_header::OrientationSet2Right, RETURN, SEEK_SET, SIEMENS_HEADERSIZE, Siemens_vision_header::SiemensStudyDateMM, Siemens_vision_header::SliceThickness, strtod(), swap, swap_4(), swap_8(), swap_twobytes(), Siemens_vision_header::TextSlicePosition, use_MRILIB_zoff, and MRI_IMAGE::was_swapped. Referenced by mri_read_file(), and mri_read_file_delay().
02956 { 02957 struct Siemens_vision_header head ; 02958 FILE * fp ; 02959 int i,j,xx,yy , matrix , swap , imagesize,nxx,blank , slices,nz ; 02960 struct stat file_stat ; 02961 short *imar ; 02962 MRI_IMARR * newar ; 02963 MRI_IMAGE * newim ; 02964 short * nar ; 02965 char buf[256] ; 02966 float dx,dy,dz ; 02967 char *eee ; int ileave=0 ; /* 25 Sep 2001 */ 02968 02969 ENTRY("mri_read_siemens") ; 02970 02971 /*--- check file size ---*/ 02972 02973 if( hname == NULL ) RETURN(NULL) ; 02974 02975 i = stat( hname , &file_stat ) ; 02976 if( i < 0 ) RETURN(NULL) ; 02977 02978 /*--- read header data ---*/ 02979 02980 fp = fopen( hname , "rb" ) ; 02981 if( fp == NULL ) RETURN(NULL) ; 02982 fread( &head , sizeof(struct Siemens_vision_header) , 1 , fp ) ; 02983 02984 /*-- check some integer in header to determine if we need to byteswap --*/ 02985 02986 swap = ( head.SiemensStudyDateMM < 0 || head.SiemensStudyDateMM > 13 ) ; 02987 if( swap ){ 02988 swap_4( &(head.SiemensStudyDateMM) ) ; 02989 if( head.SiemensStudyDateMM < 0 || head.SiemensStudyDateMM > 13 ){ 02990 swap = 0 ; 02991 } 02992 } 02993 02994 /*-- find image size from header --*/ 02995 02996 if( swap ) swap_4( &(head.DisplayMatrixSize) ) ; 02997 imagesize = head.DisplayMatrixSize ; 02998 02999 /*-- determine number of sub-images in file --*/ 03000 03001 #undef MATRIX_MAX 03002 #define MATRIX_MAX 16 03003 03004 i = 2*imagesize*imagesize ; 03005 for( matrix=1 ; matrix < MATRIX_MAX ; matrix++ ) 03006 if( file_stat.st_size == i*matrix*matrix + SIEMENS_HEADERSIZE ) break ; 03007 03008 if( matrix == MATRIX_MAX ){ 03009 fclose(fp) ; RETURN(NULL) ; /* didn't recognize file format */ 03010 } 03011 #undef MATRIX_MAX 03012 03013 /*-- read image data from file and byteswap it, if needed --*/ 03014 03015 imar = (short *) calloc(sizeof(short),matrix*matrix*imagesize*imagesize) ; 03016 fseek( fp , SIEMENS_HEADERSIZE , SEEK_SET ) ; 03017 fread( imar , sizeof(short) , matrix*matrix*imagesize*imagesize , fp ) ; 03018 fclose(fp) ; 03019 03020 if( swap ) swap_twobytes( matrix*matrix*imagesize*imagesize , imar ) ; 03021 03022 /*-- count slices - all zero (blank) slices at end are skipped --*/ 03023 03024 slices = 0 ; nxx = matrix*imagesize ; 03025 03026 for( yy=0 ; yy < matrix ; yy++ ){ /* rows in array of sub-images */ 03027 for( xx=0 ; xx < matrix ; xx++ ){ /* cols in array of sub-images */ 03028 blank = 1 ; 03029 for( j=0 ; j < imagesize ; j++ ){ /* row in sub-image */ 03030 for( i=0 ; i < imagesize ; i++ ){ /* col in sub-image */ 03031 if( imar[i+xx*imagesize+(j+yy*imagesize)*nxx] ) blank = 0 ; 03032 } 03033 } 03034 if( !blank ) slices = 1 + xx + yy*matrix ; 03035 } 03036 } 03037 03038 if( slices == 0 ){ free(imar) ; RETURN(NULL) ; } /* bad news */ 03039 03040 /*-- get image dimensions, etc --*/ 03041 03042 if( swap ){ 03043 swap_8(&(head.FOVRow)); 03044 swap_8(&(head.FOVColumn)); 03045 swap_8(&(head.SliceThickness)); 03046 } 03047 dx = head.FOVRow / imagesize ; 03048 dy = head.FOVColumn / imagesize ; 03049 dz = head.SliceThickness ; 03050 03051 /*-- save orientation and offset in global variables --*/ 03052 03053 MRILIB_orients[0] = head.OrientationSet1Left[0] ; 03054 MRILIB_orients[1] = head.OrientationSet2Right[0]; 03055 MRILIB_orients[2] = head.OrientationSet1Top[0] ; 03056 MRILIB_orients[3] = head.OrientationSet2Down[0] ; 03057 MRILIB_orients[4] = head.OrientationSet1Back[0] ; 03058 MRILIB_orients[5] = head.OrientationSet2Front[0]; 03059 for (i=0; i<6; i++) { 03060 if (MRILIB_orients[i]=='H') MRILIB_orients[i]='S'; 03061 if (MRILIB_orients[i]=='F') MRILIB_orients[i]='I'; 03062 } 03063 MRILIB_orients[6] = '\0' ; 03064 MRILIB_zoff = fabs(strtod(head.TextSlicePosition,NULL)) ; use_MRILIB_zoff = 1 ; 03065 03066 /*-- create output --*/ 03067 03068 INIT_IMARR(newar) ; 03069 03070 for( yy=0 ; yy < matrix ; yy++ ){ /* rows in array of sub-images */ 03071 for( xx=0 ; xx < matrix ; xx++ ){ /* cols in array of sub-images */ 03072 03073 newim = mri_new( imagesize , imagesize , MRI_short ) ; 03074 nar = MRI_SHORT_PTR( newim ) ; 03075 03076 if( swap ) newim->was_swapped = 1 ; /* 07 Mar 2002 */ 03077 03078 for( j=0 ; j < imagesize ; j++ ) /* row in sub-image */ 03079 memcpy( nar+j*imagesize , 03080 imar+xx*imagesize+(j+yy*imagesize)*nxx , 2*imagesize ) ; 03081 03082 sprintf( buf , "%s#%d:%d" , hname,xx,yy ) ; 03083 mri_add_name( buf , newim ) ; 03084 03085 newim->dx = dx ; newim->dy = dy ; newim->dz = dz ; newim->dw = 1.0 ; 03086 ADDTO_IMARR(newar,newim) ; 03087 if( IMARR_COUNT(newar) == slices ) goto Done ; /* Aauugghh!!! */ 03088 } 03089 } 03090 03091 Done: 03092 03093 /*-- 25 Sep 2001: possibly interleave the images --*/ 03094 03095 eee = getenv("AFNI_SIEMENS_INTERLEAVE") ; 03096 ileave = ( (eee != NULL) && (*eee=='Y' || *eee=='y') ) ; 03097 if( ileave && slices > 2 ){ 03098 int mid = (slices-1)/2 ; /* midpoint */ 03099 MRI_IMARR *qar ; /* new image array */ 03100 INIT_IMARR(qar) ; 03101 for( i=0 ; i < slices ; i++ ){ 03102 if( i%2 == 0 ) j = i/2 ; /* slice #i is in newar #j */ 03103 else j = mid + (i+1)/2 ; 03104 ADDTO_IMARR(qar,IMARR_SUBIM(newar,j)) ; /* move image to new array */ 03105 } 03106 FREE_IMARR(newar) ; newar = qar ; 03107 } 03108 03109 free(imar) ; RETURN(newar) ; 03110 } |
|
Definition at line 7 of file mri_read_stuff.c. References AFMALL, ENTRY, free, maxval, mri_add_name(), MRI_BYTE_PTR, mri_inflate_pbm(), mri_new(), MRI_RGB_PTR, NUMSCAN, pclose, popen, QBUF, RETURN, and THD_find_executable(). Referenced by AFNI_faceup(), AFNI_splashup(), mri_read(), and mri_read_file().
00008 { 00009 static int first=1 ; 00010 static char *jpeg_filter = NULL ; /* djpeg */ 00011 static char *gif_filter = NULL ; /* giftopnm */ 00012 static char *tiff_filter = NULL ; /* tifftopnm */ 00013 static char *bmp_filter = NULL ; /* bmptoppm */ 00014 static char *png_filter = NULL ; /* pngtopnm */ 00015 static char *pnm_filter = NULL ; /* cat */ 00016 00017 char *pg , *pg2 , *filt=NULL ; 00018 int nf , nbuf , ipos , nx,ny,maxval=255 , bper,nbim, pbm=0 ; 00019 FILE *fp ; 00020 MRI_IMAGE *im ; 00021 byte *imar , *buf ; 00022 00023 ENTRY("mri_read_stuff") ; 00024 00025 /*--- check input for OK-ness ---*/ 00026 00027 if( fname == NULL || *fname == '\0' ) RETURN(NULL) ; 00028 00029 /*--- first time in, setup up filters to PNM format ---*/ 00030 00031 if( first ){ 00032 first = 0 ; 00033 00034 pg = THD_find_executable( "cat" ) ; /* cheap, but works */ 00035 if( pg != NULL ){ 00036 pnm_filter = AFMALL(char, strlen(pg)+32) ; 00037 sprintf( pnm_filter , "%s %%s" , pg ) ; 00038 } 00039 00040 pg = THD_find_executable( "djpeg" ) ; 00041 if( pg != NULL ){ 00042 jpeg_filter = AFMALL(char, strlen(pg)+32) ; 00043 sprintf( jpeg_filter , "%s %%s" , pg ) ; 00044 } 00045 00046 pg = THD_find_executable( "giftopnm" ) ; 00047 if( pg != NULL ){ 00048 gif_filter = AFMALL(char, strlen(pg)+32) ; 00049 sprintf( gif_filter , "%s %%s" , pg ) ; 00050 } 00051 00052 pg = THD_find_executable( "tifftopnm" ) ; 00053 if( pg != NULL ){ 00054 tiff_filter = AFMALL(char, strlen(pg)+32) ; 00055 sprintf( tiff_filter , "%s %%s" , pg ) ; 00056 } 00057 00058 pg = THD_find_executable( "bmptoppm" ) ; 00059 if( pg != NULL ){ 00060 bmp_filter = AFMALL(char, strlen(pg)+32) ; 00061 sprintf( bmp_filter , "%s %%s" , pg ) ; 00062 } 00063 00064 pg = THD_find_executable( "pngtopnm" ) ; 00065 if( pg != NULL ){ 00066 png_filter = AFMALL(char, strlen(pg)+32) ; 00067 sprintf( png_filter , "%s %%s" , pg ) ; 00068 } 00069 } 00070 00071 /*--- determine filter based on file suffix ---*/ 00072 00073 nf = strlen(fname) ; 00074 if( nf < 5 ) RETURN(NULL); /* filename too short! */ 00075 00076 pg = fname + (nf-4); /* points to last 4 chars */ 00077 pg2 = pg - 1; /* points to last 5 chars */ 00078 00079 if( strcmp(pg ,".jpg" ) == 0 || 00080 strcmp(pg ,".JPG" ) == 0 || 00081 strcmp(pg2,".jpeg") == 0 || 00082 strcmp(pg2,".JPEG") == 0 ) filt = jpeg_filter ; 00083 00084 else if( strcmp(pg ,".gif" ) == 0 || 00085 strcmp(pg ,".GIF" ) == 0 ) filt = gif_filter ; 00086 00087 else if( strcmp(pg ,".pbm" ) == 0 || 00088 strcmp(pg ,".PBM" ) == 0 || 00089 strcmp(pg ,".pgm" ) == 0 || 00090 strcmp(pg ,".PGM" ) == 0 || 00091 strcmp(pg ,".ppm" ) == 0 || 00092 strcmp(pg ,".PPM" ) == 0 ) filt = pnm_filter ; 00093 00094 else if( strcmp(pg ,".tif" ) == 0 || 00095 strcmp(pg ,".TIF" ) == 0 || 00096 strcmp(pg2,".tiff") == 0 || 00097 strcmp(pg2,".TIFF") == 0 ) filt = tiff_filter ; 00098 00099 else if( strcmp(pg ,".bmp" ) == 0 || 00100 strcmp(pg ,".BMP" ) == 0 ) filt = bmp_filter ; 00101 00102 else if( strcmp(pg ,".png" ) == 0 || 00103 strcmp(pg ,".PNG" ) == 0 ) filt = png_filter ; 00104 00105 if( filt == NULL ) RETURN(NULL); /* didn't match, or no filter */ 00106 00107 /*--- create the filter for this file and open the pipe ---*/ 00108 00109 pg = AFMALL(char, nf+strlen(filt)+32) ; /* string to hold filter */ 00110 sprintf( pg , filt , fname ) ; 00111 00112 signal( SIGPIPE , SIG_IGN ) ; /* ignore this signal */ 00113 fp = popen( pg , "r" ) ; 00114 if( fp == NULL ){ free(pg); RETURN(NULL); } /* bad pipe */ 00115 00116 buf = AFMALL(byte, QBUF) ; /* read buffer for initial data from pipe */ 00117 00118 /*--- read 1st block from pipe ---*/ 00119 00120 nbuf = fread( buf , 1 , QBUF , fp ) ; 00121 00122 if( nbuf < 16 ){ /* bad read */ 00123 free(buf); free(pg); pclose(fp); RETURN(NULL); 00124 } 00125 00126 if( buf[0] != 'P' ){ /* not a P?M file */ 00127 free(buf); free(pg); pclose(fp); RETURN(NULL); 00128 } 00129 00130 if( buf[1] == '6' ) bper = 3 ; /* PPM from pipe */ 00131 else if( buf[1] == '5' ) bper = 1 ; /* PGM from pipe */ 00132 else if( buf[1] == '4' ){bper = 1 ; pbm=1; } /* PBM from pipe */ 00133 else { 00134 free(buf); free(pg); pclose(fp); RETURN(NULL); /* bad bad bad!! */ 00135 } 00136 00137 ipos = 2 ; /* start scanning for PNM header stuff at position 2 in buf */ 00138 00139 /* skip comment lines in the buffer */ 00140 00141 #undef SKIPCOM 00142 #define SKIPCOM \ 00143 { if(buf[ipos]=='#') \ 00144 do{ ipos++; } while( ipos<nbuf && buf[ipos]!='\n' ) ; } 00145 00146 /* find an ASCII number in the buffer */ 00147 00148 #undef NUMSCAN 00149 #define NUMSCAN(var) \ 00150 { SKIPCOM ; \ 00151 while( ipos<nbuf && !isdigit(buf[ipos]) ){ipos++; SKIPCOM;} \ 00152 if( ipos >= nbuf ){ var = -1; } \ 00153 else { \ 00154 int nch; char chb[32]; \ 00155 for( nch=0 ; ipos<nbuf && isdigit(buf[ipos]) ; nch++,ipos++ ){ \ 00156 chb[nch] = buf[ipos]; } \ 00157 chb[nch]='\0'; var = strtol(chb,NULL,10); \ 00158 } } 00159 00160 /* scan for the nx variable */ 00161 00162 NUMSCAN(nx) ; 00163 if( nx < 2 || ipos >= nbuf ){ /* bad */ 00164 free(buf); free(pg); pclose(fp); RETURN(NULL); 00165 } 00166 00167 /* scan for the ny variable */ 00168 00169 NUMSCAN(ny) ; 00170 if( ny < 2 || ipos >= nbuf ){ /* bad */ 00171 free(buf); free(pg); pclose(fp); RETURN(NULL); 00172 } 00173 00174 /* scan for the maxval variable */ 00175 00176 if( !pbm ){ 00177 NUMSCAN(maxval) ; 00178 if( maxval <= 0 || maxval > 255 || ipos >= nbuf ){ /* bad */ 00179 free(buf); free(pg); pclose(fp); RETURN(NULL); 00180 } 00181 } 00182 00183 ipos++ ; /* skip byte after maxval; */ 00184 /* ipos now points at 1st byte of image data */ 00185 00186 /*--- create output image struct ---*/ 00187 00188 if( bper == 3 ){ /* PPM */ 00189 im = mri_new( nx , ny , MRI_rgb ) ; 00190 imar = MRI_RGB_PTR(im) ; 00191 } else { /* PGM or PBM */ 00192 im = mri_new( nx , ny , MRI_byte ) ; 00193 imar = MRI_BYTE_PTR(im) ; 00194 } 00195 mri_add_name( fname , im ) ; 00196 nbim = bper * nx * ny ; /* num bytes in image array imar */ 00197 00198 /*--- copy remaining data in buf (if any) to image array ---*/ 00199 00200 nbuf = nbuf - ipos ; /* num bytes left in buf */ 00201 if( nbuf > nbim ) nbuf = nbim ; /* but don't want too much */ 00202 if( nbuf > 0 ) 00203 memcpy( imar , buf+ipos , nbuf ) ; 00204 00205 free(buf) ; /* have used this up now */ 00206 00207 /*--- read rest of image array directly from pipe ---*/ 00208 00209 if( nbuf < nbim ) 00210 fread( imar+nbuf , 1 , nbim-nbuf , fp ) ; 00211 00212 free(pg) ; pclose(fp) ; /* toss out the trash */ 00213 00214 /*--- if was really a PBM image, inflate to PGM now ---*/ 00215 00216 if( pbm ) mri_inflate_pbm( im ) ; /* 02 Jan 2003 */ 00217 00218 /*--- if maxval < 255, scale byte data up to that level ---*/ 00219 00220 if( maxval < 255 ){ 00221 int ii ; float fac = 255.4/maxval ; 00222 for( ii=0 ; ii < nbim ; ii++ ) imar[ii] = (byte)( imar[ii]*fac ) ; 00223 } 00224 00225 /*--- vamoose the ranch ---*/ 00226 00227 RETURN(im); 00228 } |
|
Definition at line 115 of file mri_warp.c. References MRI_BICUBIC, MRI_BILINEAR, MRI_FATAL_ERROR, mri_warp(), mri_warp_bicubic(), MRI_IMAGE::nx, MRI_IMAGE::ny, sx_scale, sy_scale, and xxMRI_scaler(). Referenced by AFNI_read_images(), AFNI_splashup(), and PH_loadim().
00116 { 00117 int nx,ny , nnx,nny , wtype ; 00118 00119 nx = im->nx ; ny = im->ny ; 00120 nnx = nxnew ; nny = nynew ; 00121 00122 if( nnx <= 0 && nny <= 0 ){ 00123 fprintf( stderr , "mri_resize: nxnew,nynew = %d %d\n",nxnew,nynew ) ; 00124 MRI_FATAL_ERROR ; 00125 } 00126 00127 sx_scale = (nnx > 0) ? ((float)nx)/nnx : 0.0 ; 00128 sy_scale = (nny > 0) ? ((float)ny)/nny : 0.0 ; 00129 00130 if( nnx <= 0 ){ 00131 sx_scale = sy_scale ; 00132 nnx = sx_scale * nx ; 00133 } else if( nny <= 0 ){ 00134 sy_scale = sx_scale ; 00135 nny = sy_scale * ny ; 00136 } 00137 00138 00139 #if 0 00140 wtype = MRI_BICUBIC ; 00141 00142 if( ( ((nnx>=nx) && (nnx%nx==0)) || ((nnx<nx) && (nx%nnx==0)) ) && 00143 ( ((nny>=ny) && (nny%ny==0)) || ((nny<ny) && (ny%nny==0)) ) ){ 00144 00145 wtype = MRI_BILINEAR ; 00146 } else { 00147 wtype = MRI_BICUBIC ; 00148 } 00149 00150 return mri_warp( im , nnx,nny , wtype , xxMRI_scaler ) ; 00151 #else 00152 return mri_warp_bicubic( im , nnx,nny , xxMRI_scaler ) ; 00153 #endif 00154 } |
|
Definition at line 54 of file mri_warp.c. References MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::kind, MRI_COPY_AUX, mri_data_pointer(), mri_new(), MRI_IMAGE::nx, MRI_IMAGE::ny, and MRI_IMAGE::pixel_size. Referenced by mri_squareaspect().
00055 { 00056 int nx,ny , nnx,nny , ii,jj , pp,qq , bb ; 00057 float fx,fy ; 00058 MRI_IMAGE *nim ; 00059 char *nar , *ar ; 00060 00061 if( im == NULL ) return NULL ; 00062 00063 nx = im->nx ; ny = im->ny ; 00064 nnx = nxnew ; nny = nynew ; 00065 fx = ((float)nx) / (float)nnx ; 00066 fy = ((float)ny) / (float)nny ; 00067 00068 nim = mri_new( nnx , nny , im->kind ) ; 00069 nar = mri_data_pointer( nim ) ; 00070 ar = mri_data_pointer( im ) ; 00071 bb = im->pixel_size ; 00072 00073 for( jj=0 ; jj < nny ; jj++ ){ 00074 qq = (int)( fy*jj ) ; 00075 for( ii=0 ; ii < nnx ; ii++ ){ 00076 pp = (int)( fx*ii ) ; 00077 memcpy( nar + (ii+jj*nnx)*bb , ar + (pp+qq*nx)*bb , bb ) ; 00078 } 00079 } 00080 00081 MRI_COPY_AUX(nim,im) ; 00082 nim->dx *= fx ; 00083 nim->dy *= fy ; 00084 return nim ; 00085 } |
|
Definition at line 144 of file mri_to_rgb.c. References ADDTO_IMARR, ENTRY, INIT_IMARR, MRI_IMAGE::kind, MRI_BYTE_PTR, mri_new_conforming, MRI_IMAGE::nvox, and RETURN. Referenced by mri_dup2D().
00145 { 00146 MRI_IMARR * imar ; 00147 MRI_IMAGE * rim , * gim , * bim ; 00148 byte * rr , * gg , * bb , * rgb ; 00149 int ii , npix ; 00150 00151 ENTRY("mri_rgb_to_3byte") ; 00152 if( oldim == NULL || oldim->kind != MRI_rgb ) RETURN( NULL ); 00153 00154 rim = mri_new_conforming( oldim , MRI_byte ) ; rr = MRI_BYTE_PTR(rim) ; 00155 gim = mri_new_conforming( oldim , MRI_byte ) ; gg = MRI_BYTE_PTR(gim) ; 00156 bim = mri_new_conforming( oldim , MRI_byte ) ; bb = MRI_BYTE_PTR(bim) ; 00157 rgb= MRI_BYTE_PTR(oldim) ; 00158 npix = oldim->nvox ; 00159 00160 for( ii=0 ; ii < npix ; ii++ ){ 00161 rr[ii] = rgb[3*ii ] ; 00162 gg[ii] = rgb[3*ii+1] ; 00163 bb[ii] = rgb[3*ii+2] ; 00164 } 00165 00166 INIT_IMARR(imar) ; 00167 ADDTO_IMARR(imar,rim) ; ADDTO_IMARR(imar,gim) ; ADDTO_IMARR(imar,bim) ; 00168 00169 RETURN( imar ); 00170 } |
|
Definition at line 112 of file mri_to_rgb.c. References ADDTO_IMARR, ENTRY, INIT_IMARR, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_FLOAT_PTR, mri_new_conforming, MRI_IMAGE::nvox, and RETURN. Referenced by mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), mri_warp3D_quintic(), mri_warp_bicubic(), and NUD_rotate().
00113 { 00114 MRI_IMARR * imar ; 00115 MRI_IMAGE * rim , * gim , * bim ; 00116 float * rr , * gg , * bb ; 00117 byte * rgb ; 00118 int ii , npix ; 00119 00120 ENTRY("mri_rgb_to_3float") ; 00121 00122 if( oldim == NULL || oldim->kind != MRI_rgb ) RETURN( NULL ); 00123 00124 rim = mri_new_conforming( oldim , MRI_float ) ; rr = MRI_FLOAT_PTR(rim) ; 00125 gim = mri_new_conforming( oldim , MRI_float ) ; gg = MRI_FLOAT_PTR(gim) ; 00126 bim = mri_new_conforming( oldim , MRI_float ) ; bb = MRI_FLOAT_PTR(bim) ; 00127 rgb= MRI_BYTE_PTR(oldim) ; 00128 npix = oldim->nvox ; 00129 00130 for( ii=0 ; ii < npix ; ii++ ){ 00131 rr[ii] = rgb[3*ii ] ; 00132 gg[ii] = rgb[3*ii+1] ; 00133 bb[ii] = rgb[3*ii+2] ; 00134 } 00135 00136 INIT_IMARR(imar) ; 00137 ADDTO_IMARR(imar,rim) ; ADDTO_IMARR(imar,gim) ; ADDTO_IMARR(imar,bim) ; 00138 00139 RETURN( imar ); 00140 } |
|
------------------------------------------------------------------- Rotate and shift an image, using bicubic interpolation: aa = shift in x bb = shift in y phi = angle in radians Sort of a replacement for mri_rotate in mri_warp.c; supposed to be faster. If the input image is MRI_complex, the output will be also; otherwise, the output will be MRI_float. ----------------------------------------------------------------------* Definition at line 42 of file mri_rota.c. References EXIT, far, FINS, FREE_IMARR, IMAGE_IN_IMARR, MRI_IMAGE::kind, mri_complex_to_pair(), MRI_COPY_AUX, MRI_FLOAT_PTR, mri_free(), MRI_IS_2D, mri_new(), mri_pair_to_complex(), mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, P_00, P_M1, P_P1, P_P2, and top. Referenced by main(), and mri_rota_variable().
00043 { 00044 float rot_dx , rot_dy , rot_cph , rot_sph , top,bot,val ; 00045 MRI_IMAGE *imfl , *newImg ; 00046 MRI_IMARR *impair ; 00047 float *far , *nar ; 00048 float xx,yy , fx,fy ; 00049 int ii,jj, nx,ny , ix,jy , ifx,jfy ; 00050 float f_jm1,f_j00,f_jp1,f_jp2 , wt_m1,wt_00,wt_p1,wt_p2 ; 00051 00052 #ifdef USE_CGRID 00053 if( p_first ){ 00054 p_first = 0 ; 00055 xx = 1.0 / CGRID ; 00056 for( ii=0 ; ii <= CGRID ; ii++ ){ 00057 yy = ii * xx ; 00058 p_m1[ii] = P_M1(yy) ; 00059 p_00[ii] = P_00(yy) ; 00060 p_p1[ii] = P_P1(yy) ; 00061 p_p2[ii] = P_P2(yy) ; 00062 } 00063 } 00064 #endif 00065 00066 if( im == NULL || ! MRI_IS_2D(im) ){ 00067 fprintf(stderr,"*** mri_rota only works on 2D images!\n") ; EXIT(1) ; 00068 } 00069 00070 /** if complex image, break into pairs, do each separately, put back together **/ 00071 00072 if( im->kind == MRI_complex ){ 00073 MRI_IMARR *impair ; 00074 MRI_IMAGE * rim , * iim , * tim ; 00075 impair = mri_complex_to_pair( im ) ; 00076 if( impair == NULL ){ 00077 fprintf(stderr,"*** mri_complex_to_pair fails in mri_rota!\n") ; EXIT(1) ; 00078 } 00079 rim = IMAGE_IN_IMARR(impair,0) ; 00080 iim = IMAGE_IN_IMARR(impair,1) ; FREE_IMARR(impair) ; 00081 tim = mri_rota( rim , aa,bb,phi ) ; mri_free( rim ) ; rim = tim ; 00082 tim = mri_rota( iim , aa,bb,phi ) ; mri_free( iim ) ; iim = tim ; 00083 newImg = mri_pair_to_complex( rim , iim ) ; 00084 mri_free( rim ) ; mri_free( iim ) ; 00085 MRI_COPY_AUX(newImg,im) ; 00086 return newImg ; 00087 } 00088 00089 /** rotation params **/ 00090 00091 rot_cph = cos(phi) ; rot_sph = sin(phi) ; 00092 00093 rot_dx = (0.5 * im->nx) * (1.0-rot_cph) - aa*rot_cph - bb*rot_sph 00094 -(0.5 * im->ny) * rot_sph ; 00095 00096 rot_dy = (0.5 * im->nx) * rot_sph + aa*rot_sph - bb*rot_cph 00097 +(0.5 * im->ny) * (1.0-rot_cph) ; 00098 00099 /** other initialization **/ 00100 00101 nx = im->nx ; /* image dimensions */ 00102 ny = im->ny ; 00103 00104 if( im->kind == MRI_float ) imfl = im ; 00105 else imfl = mri_to_float( im ) ; 00106 00107 far = MRI_FLOAT_PTR(imfl) ; /* access to float data */ 00108 newImg = mri_new( nx , nx , MRI_float ) ; /* output image */ 00109 nar = MRI_FLOAT_PTR(newImg) ; /* output image data */ 00110 00111 bot = top = far[0] ; 00112 for( ii=0 ; ii < nx*ny ; ii++ ) 00113 if( far[ii] < bot ) bot = far[ii] ; 00114 else if( far[ii] > top ) top = far[ii] ; 00115 00116 /*** loop over output points and warp to them ***/ 00117 00118 for( jj=0 ; jj < nx ; jj++ ){ 00119 xx = rot_sph * jj + rot_dx - rot_cph ; 00120 yy = rot_cph * jj + rot_dy + rot_sph ; 00121 for( ii=0 ; ii < nx ; ii++ ){ 00122 00123 xx += rot_cph ; /* get x,y in original image */ 00124 yy -= rot_sph ; 00125 00126 ix = (xx >= 0.0) ? ((int) xx) : ((int) xx)-1 ; /* floor */ 00127 jy = (yy >= 0.0) ? ((int) yy) : ((int) yy)-1 ; 00128 00129 #ifdef USE_CGRID 00130 ifx = (xx-ix)*CGRID + 0.499 ; 00131 wt_m1 = p_m1[ifx] ; wt_00 = p_00[ifx] ; 00132 wt_p1 = p_p1[ifx] ; wt_p2 = p_p2[ifx] ; 00133 #else 00134 fx = xx-ix ; 00135 wt_m1 = P_M1(fx) ; wt_00 = P_00(fx) ; 00136 wt_p1 = P_P1(fx) ; wt_p2 = P_P2(fx) ; 00137 #endif 00138 00139 if( ix > 0 && ix < nx-2 && jy > 0 && jy < ny-2 ){ 00140 float * fym1, *fy00 , *fyp1 , *fyp2 ; 00141 00142 fym1 = far + (ix-1 + (jy-1)*nx) ; 00143 fy00 = fym1 + nx ; 00144 fyp1 = fy00 + nx ; 00145 fyp2 = fyp1 + nx ; 00146 00147 f_jm1 = wt_m1 * fym1[0] + wt_00 * fym1[1] 00148 + wt_p1 * fym1[2] + wt_p2 * fym1[3] ; 00149 00150 f_j00 = wt_m1 * fy00[0] + wt_00 * fy00[1] 00151 + wt_p1 * fy00[2] + wt_p2 * fy00[3] ; 00152 00153 f_jp1 = wt_m1 * fyp1[0] + wt_00 * fyp1[1] 00154 + wt_p1 * fyp1[2] + wt_p2 * fyp1[3] ; 00155 00156 f_jp2 = wt_m1 * fyp2[0] + wt_00 * fyp2[1] 00157 + wt_p1 * fyp2[2] + wt_p2 * fyp2[3] ; 00158 00159 } else { 00160 00161 f_jm1 = wt_m1 * FINS(ix-1,jy-1) 00162 + wt_00 * FINS(ix ,jy-1) 00163 + wt_p1 * FINS(ix+1,jy-1) 00164 + wt_p2 * FINS(ix+2,jy-1) ; 00165 00166 f_j00 = wt_m1 * FINS(ix-1,jy) 00167 + wt_00 * FINS(ix ,jy) 00168 + wt_p1 * FINS(ix+1,jy) 00169 + wt_p2 * FINS(ix+2,jy) ; 00170 00171 f_jp1 = wt_m1 * FINS(ix-1,jy+1) 00172 + wt_00 * FINS(ix ,jy+1) 00173 + wt_p1 * FINS(ix+1,jy+1) 00174 + wt_p2 * FINS(ix+2,jy+1) ; 00175 00176 f_jp2 = wt_m1 * FINS(ix-1,jy+2) 00177 + wt_00 * FINS(ix ,jy+2) 00178 + wt_p1 * FINS(ix+1,jy+2) 00179 + wt_p2 * FINS(ix+2,jy+2) ; 00180 } 00181 00182 #define THIRTYSIX 2.7777778e-2 /* 1./36.0, actually */ 00183 00184 #ifdef USE_CGRID 00185 jfy = (yy-jy)*CGRID + 0.499 ; 00186 val = ( p_m1[jfy] * f_jm1 + p_00[jfy] * f_j00 00187 + p_p1[jfy] * f_jp1 + p_p2[jfy] * f_jp2 ) * THIRTYSIX ; 00188 #else 00189 fy = yy-jy ; 00190 val = ( P_M1(fy) * f_jm1 + P_00(fy) * f_j00 00191 + P_P1(fy) * f_jp1 + P_P2(fy) * f_jp2 ) * THIRTYSIX ; 00192 #endif 00193 00194 if( val < bot ) nar[ii+jj*nx] = bot ; /* too small! */ 00195 else if( val > top ) nar[ii+jj*nx] = top ; /* too big! */ 00196 else nar[ii+jj*nx] = val ; /* just right */ 00197 00198 } 00199 } 00200 00201 /*** cleanup and return ***/ 00202 00203 if( im != imfl ) mri_free(imfl) ; /* throw away unneeded workspace */ 00204 MRI_COPY_AUX(newImg,im) ; 00205 return newImg ; 00206 } |
|
------------------------------------------------------------------- Rotate and shift an image, using bilinear interpolation: aa = shift in x bb = shift in y phi = angle in radians Sort of a replacement for mri_rotate in mri_warp.c; supposed to be faster. If the input image is MRI_complex, the output will be also; otherwise, the output will be MRI_float. ----------------------------------------------------------------------* Definition at line 195 of file mri_affine.c. References ENTRY, EXIT, far, FINS, FREE_IMARR, IMAGE_IN_IMARR, MRI_IMAGE::kind, mri_complex_to_pair(), MRI_COPY_AUX, MRI_FLOAT_PTR, mri_free(), MRI_IS_2D, mri_new(), mri_pair_to_complex(), mri_rota_bilinear(), mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, and RETURN. Referenced by mri_rota_bilinear(), and mri_rota_variable().
00196 { 00197 float rot_dx , rot_dy , rot_cph , rot_sph ; 00198 MRI_IMAGE *imfl , *newImg ; 00199 MRI_IMARR *impair ; 00200 float *far , *nar ; 00201 float xx,yy , fx,fy ; 00202 int ii,jj, nx,ny , ix,jy ; 00203 float f_j00,f_jp1 , wt_00,wt_p1 ; 00204 00205 ENTRY("mri_rota_bilinear") ; 00206 00207 if( im == NULL || ! MRI_IS_2D(im) ){ 00208 fprintf(stderr,"*** mri_rota_bilinear only works on 2D images!\n"); RETURN(NULL); 00209 } 00210 00211 /** if complex image, break into pairs, do each separately, put back together **/ 00212 00213 if( im->kind == MRI_complex ){ 00214 MRI_IMARR *impair ; 00215 MRI_IMAGE * rim , * iim , * tim ; 00216 impair = mri_complex_to_pair( im ) ; 00217 if( impair == NULL ){ 00218 fprintf(stderr,"*** mri_complex_to_pair fails in mri_rota!\n") ; EXIT(1) ; 00219 } 00220 rim = IMAGE_IN_IMARR(impair,0) ; 00221 iim = IMAGE_IN_IMARR(impair,1) ; FREE_IMARR(impair) ; 00222 tim = mri_rota_bilinear( rim , aa,bb,phi ) ; mri_free( rim ) ; rim = tim ; 00223 tim = mri_rota_bilinear( iim , aa,bb,phi ) ; mri_free( iim ) ; iim = tim ; 00224 newImg = mri_pair_to_complex( rim , iim ) ; 00225 mri_free( rim ) ; mri_free( iim ) ; 00226 MRI_COPY_AUX(newImg,im) ; 00227 RETURN( newImg ); 00228 } 00229 00230 /** rotation params **/ 00231 00232 rot_cph = cos(phi) ; rot_sph = sin(phi) ; 00233 00234 rot_dx = (0.5 * im->nx) * (1.0-rot_cph) - aa*rot_cph - bb*rot_sph 00235 -(0.5 * im->ny) * rot_sph ; 00236 00237 rot_dy = (0.5 * im->nx) * rot_sph + aa*rot_sph - bb*rot_cph 00238 +(0.5 * im->ny) * (1.0-rot_cph) ; 00239 00240 /** other initialization **/ 00241 00242 nx = im->nx ; /* image dimensions */ 00243 ny = im->ny ; 00244 00245 if( im->kind == MRI_float ) imfl = im ; 00246 else imfl = mri_to_float( im ) ; 00247 00248 far = MRI_FLOAT_PTR(imfl) ; /* access to float data */ 00249 newImg = mri_new( nx , nx , MRI_float ) ; /* output image */ 00250 nar = MRI_FLOAT_PTR(newImg) ; /* output image data */ 00251 00252 /*** loop over output points and warp to them ***/ 00253 00254 for( jj=0 ; jj < nx ; jj++ ){ 00255 xx = rot_sph * jj + rot_dx - rot_cph ; 00256 yy = rot_cph * jj + rot_dy + rot_sph ; 00257 for( ii=0 ; ii < nx ; ii++ ){ 00258 00259 xx += rot_cph ; /* get x,y in original image */ 00260 yy -= rot_sph ; 00261 00262 ix = (xx >= 0.0) ? ((int) xx) : ((int) xx)-1 ; /* floor */ 00263 jy = (yy >= 0.0) ? ((int) yy) : ((int) yy)-1 ; 00264 00265 fx = xx-ix ; wt_00 = 1.0 - fx ; wt_p1 = fx ; 00266 00267 if( ix >= 0 && ix < nx-1 && jy >= 0 && jy < ny-1 ){ 00268 float *fy00 , *fyp1 ; 00269 00270 fy00 = far + (ix + jy*nx) ; fyp1 = fy00 + nx ; 00271 00272 f_j00 = wt_00 * fy00[0] + wt_p1 * fy00[1] ; 00273 f_jp1 = wt_00 * fyp1[0] + wt_p1 * fyp1[1] ; 00274 00275 } else { 00276 f_j00 = wt_00 * FINS(ix,jy ) + wt_p1 * FINS(ix+1,jy ) ; 00277 f_jp1 = wt_00 * FINS(ix,jy+1) + wt_p1 * FINS(ix+1,jy+1) ; 00278 } 00279 00280 fy = yy-jy ; nar[ii+jj*nx] = (1.0-fy) * f_j00 + fy * f_jp1 ; 00281 00282 } 00283 } 00284 00285 /*** cleanup and return ***/ 00286 00287 if( im != imfl ) mri_free(imfl) ; /* throw away unneeded workspace */ 00288 MRI_COPY_AUX(newImg,im) ; 00289 RETURN( newImg ); 00290 } |
|
Definition at line 446 of file mri_affine.c. References a, ENTRY, EXIT, FREE_IMARR, ft_xshear(), ft_yshear(), IMAGE_IN_IMARR, MRI_IMAGE::kind, mri_complex_to_pair(), MRI_COPY_AUX, MRI_FLOAT_PTR, mri_free(), MRI_IS_2D, mri_pair_to_complex(), mri_rota_shear(), mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, and top. Referenced by mri_rota_shear(), and mri_rota_variable().
00447 { 00448 double cph , sph ; 00449 float a , b , bot,top ; 00450 MRI_IMAGE *flim ; 00451 float *flar ; 00452 int ii , nxy ; 00453 00454 ENTRY("mri_rota_shear") ; 00455 00456 if( im == NULL || ! MRI_IS_2D(im) ){ 00457 fprintf(stderr,"*** mri_rota_shear only works on 2D images!\n"); RETURN(NULL); 00458 } 00459 00460 /** if complex image, break into pairs, do each separately, put back together **/ 00461 00462 if( im->kind == MRI_complex ){ 00463 MRI_IMARR *impair ; 00464 MRI_IMAGE * rim , * iim , * tim ; 00465 impair = mri_complex_to_pair( im ) ; 00466 if( impair == NULL ){ 00467 fprintf(stderr,"*** mri_complex_to_pair fails in mri_rota!\n") ; EXIT(1) ; 00468 } 00469 rim = IMAGE_IN_IMARR(impair,0) ; 00470 iim = IMAGE_IN_IMARR(impair,1) ; FREE_IMARR(impair) ; 00471 tim = mri_rota_shear( rim , aa,bb,phi ) ; mri_free( rim ) ; rim = tim ; 00472 tim = mri_rota_shear( iim , aa,bb,phi ) ; mri_free( iim ) ; iim = tim ; 00473 flim = mri_pair_to_complex( rim , iim ) ; 00474 mri_free( rim ) ; mri_free( iim ) ; 00475 MRI_COPY_AUX(flim,im) ; 00476 RETURN( flim ); 00477 } 00478 00479 /** copy input to output **/ 00480 00481 flim = mri_to_float( im ) ; 00482 flar = MRI_FLOAT_PTR( flim ) ; 00483 00484 /* find range of image data */ 00485 00486 bot = top = flar[0] ; nxy = im->nx * im->ny ; 00487 for( ii=1 ; ii < nxy ; ii++ ) 00488 if( flar[ii] < bot ) bot = flar[ii] ; 00489 else if( flar[ii] > top ) top = flar[ii] ; 00490 00491 /** rotation params **/ 00492 00493 cph = cos(phi) ; sph = sin(phi) ; 00494 00495 /* More than 90 degrees? 00496 Must be reduced to less than 90 degrees by a 180 degree flip. */ 00497 00498 if( cph < 0.0 ){ 00499 int ii , jj , top , nx=flim->nx , ny=flim->ny ; 00500 float val ; 00501 00502 top = (nx+1)/2 ; 00503 for( jj=0 ; jj < ny ; jj++ ){ 00504 for( ii=1 ; ii < top ; ii++ ){ 00505 val = flar[jj*nx+ii] ; 00506 flar[jj*nx+ii] = flar[jj*nx+nx-ii] ; 00507 flar[jj*nx+nx-ii] = val ; 00508 } 00509 } 00510 00511 top = (ny+1)/2 ; 00512 for( ii=0 ; ii < nx ; ii++ ){ 00513 for( jj=1 ; jj < top ; jj++ ){ 00514 val = flar[ii+jj*nx] ; 00515 flar[ii+jj*nx] = flar[ii+(ny-jj)*nx] ; 00516 flar[ii+(ny-jj)*nx] = val ; 00517 } 00518 } 00519 00520 cph = -cph ; sph = -sph ; 00521 } 00522 00523 /* compute shear factors for each direction */ 00524 00525 b = sph ; 00526 a = (b != 0.0 ) ? ((cph - 1.0) / b) : (0.0) ; 00527 00528 /* shear thrice */ 00529 00530 ft_xshear( a , 0.0 , im->nx , im->ny , flar ) ; 00531 ft_yshear( b , bb , im->nx , im->ny , flar ) ; 00532 ft_xshear( a , aa - a*bb , im->nx , im->ny , flar ) ; 00533 00534 /* make sure data does not go out of original range */ 00535 00536 for( ii=0 ; ii < nxy ; ii++ ) 00537 if( flar[ii] < bot ) flar[ii] = bot ; 00538 else if( flar[ii] > top ) flar[ii] = top ; 00539 00540 RETURN( flim ); 00541 } |
|
rotation params * Definition at line 543 of file mri_affine.c. References MRI_BICUBIC, MRI_BILINEAR, MRI_FOURIER, mri_rota(), mri_rota_bilinear(), and mri_rota_shear(). Referenced by main().
00544 { 00545 switch(mode){ 00546 00547 default: 00548 case MRI_BICUBIC: return mri_rota( im,aa,bb,phi ) ; 00549 00550 case MRI_BILINEAR: return mri_rota_bilinear( im,aa,bb,phi ) ; 00551 00552 case MRI_FOURIER: return mri_rota_shear( im,aa,bb,phi ) ; 00553 } 00554 } |
|
-------------------------------------------------------------------------------- Rotate and shift an image, using bicubic interpolation: aa = shift in x bb = shift in y phi = angle in radians scl = size scale factor (0.0 --> leave the same size) -----------------------------------------------------------------------------------* Definition at line 356 of file mri_warp.c. References mri_warp_bicubic(), MRI_IMAGE::nx, MRI_IMAGE::ny, rot_cph, rot_dx, rot_dy, rot_sph, and xxMRI_rotfunc().
00357 { 00358 MRI_IMAGE *imwarp ; 00359 int nxnew , nynew ; 00360 00361 rot_cph = cos(phi) ; 00362 rot_sph = sin(phi) ; 00363 00364 rot_dx = (0.5 * im->nx) * (1.0-rot_cph) - aa*rot_cph - bb*rot_sph 00365 -(0.5 * im->ny) * rot_sph ; 00366 00367 rot_dy = (0.5 * im->nx) * rot_sph + aa*rot_sph - bb*rot_cph 00368 +(0.5 * im->ny) * (1.0-rot_cph) ; 00369 00370 if( scl <= 0.0 ){ 00371 nxnew = nynew = 0 ; 00372 } else { 00373 nxnew = scl * im->nx + 0.49 ; 00374 nynew = scl * im->ny + 0.49 ; 00375 rot_cph /= scl ; 00376 rot_sph /= scl ; 00377 } 00378 00379 return mri_warp_bicubic( im , nxnew,nynew , xxMRI_rotfunc ) ; 00380 } |
|
Definition at line 382 of file mri_warp.c. References mri_warp_bilinear(), MRI_IMAGE::nx, MRI_IMAGE::ny, rot_cph, rot_dx, rot_dy, rot_sph, and xxMRI_rotfunc().
00383 { 00384 MRI_IMAGE *imwarp ; 00385 int nxnew , nynew ; 00386 00387 rot_cph = cos(phi) ; 00388 rot_sph = sin(phi) ; 00389 00390 rot_dx = (0.5 * im->nx) * (1.0-rot_cph) - aa*rot_cph - bb*rot_sph 00391 -(0.5 * im->ny) * rot_sph ; 00392 00393 rot_dy = (0.5 * im->nx) * rot_sph + aa*rot_sph - bb*rot_cph 00394 +(0.5 * im->ny) * (1.0-rot_cph) ; 00395 00396 if( scl <= 0.0 ){ 00397 nxnew = nynew = 0 ; 00398 } else { 00399 nxnew = scl * im->nx + 0.49 ; 00400 nynew = scl * im->ny + 0.49 ; 00401 rot_cph /= scl ; 00402 rot_sph /= scl ; 00403 } 00404 00405 return mri_warp_bilinear( im , nxnew,nynew , xxMRI_rotfunc ) ; 00406 } |
|
27 Nov 2001: mri_scale.c * Definition at line 7 of file mri_scale.c. References ENTRY, complex::i, MRI_IMAGE::kind, mri_data_pointer(), MRI_IMAGE::nvox, and complex::r. Referenced by mri_read3D_analyze75(), and mri_read_analyze75().
00008 { 00009 register int ii , nvox ; 00010 void *vp ; 00011 00012 ENTRY("mri_scale_inplace") ; 00013 00014 if( im == NULL || fac == 1.0 || fac == 0.0 ) EXRETURN ; 00015 vp = mri_data_pointer( im ) ; if( vp == NULL ) EXRETURN ; 00016 nvox = im->nvox ; 00017 00018 switch( im->kind ){ 00019 00020 case MRI_byte:{ 00021 byte *pp = (byte *) vp ; 00022 for( ii=0 ; ii < nvox ; ii++ ) pp[ii] *= fac ; 00023 } 00024 break ; 00025 00026 case MRI_short:{ 00027 short *pp = (short *) vp ; 00028 for( ii=0 ; ii < nvox ; ii++ ) pp[ii] *= fac ; 00029 } 00030 break ; 00031 00032 case MRI_float:{ 00033 float *pp = (float *) vp ; 00034 for( ii=0 ; ii < nvox ; ii++ ) pp[ii] *= fac ; 00035 } 00036 break ; 00037 00038 case MRI_int:{ 00039 int *pp = (int *) vp ; 00040 for( ii=0 ; ii < nvox ; ii++ ) pp[ii] *= fac ; 00041 } 00042 break ; 00043 00044 case MRI_double:{ 00045 double *pp = (double *) vp ; 00046 for( ii=0 ; ii < nvox ; ii++ ) pp[ii] *= fac ; 00047 } 00048 break ; 00049 00050 case MRI_complex:{ 00051 complex *pp = (complex *) vp ; 00052 for( ii=0 ; ii < nvox ; ii++ ){ 00053 pp[ii].r *= fac; pp[ii].i *= fac; 00054 } 00055 } 00056 break ; 00057 00058 case MRI_rgb:{ 00059 byte *pp = (byte *) vp ; 00060 nvox *= 3 ; 00061 for( ii=0 ; ii < nvox ; ii++ ) pp[ii] *= fac ; 00062 } 00063 break ; 00064 } 00065 00066 EXRETURN ; 00067 } |
|
Definition at line 84 of file mri_to_float.c. References MRI_DATA::byte_data, CABS, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, far, MRI_DATA::float_data, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FATAL_ERROR, MRI_FLOAT_PTR, mri_new_conforming, MRI_RGB_PTR, MRI_RGBA_PTR, MRI_IMAGE::nvox, RETURN, and MRI_DATA::short_data. Referenced by AFNI_dataset_slice(), FD_brick_to_mri(), main(), mri_to_mri_scl(), PH_loadim(), plot_image_surface(), THD_mean_brick(), THD_median_brick(), THD_rms_brick(), and THD_warp3D().
00085 { 00086 MRI_IMAGE *newim ; 00087 register int ii , npix ; 00088 register float fac ; 00089 00090 ENTRY("mri_scale_to_float") ; 00091 00092 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 00093 00094 fac = scl ; if( fac == 0.0 ) fac = 1.0 ; 00095 newim = mri_new_conforming( oldim , MRI_float ) ; 00096 npix = oldim->nvox ; 00097 00098 switch( oldim->kind ){ 00099 00100 case MRI_byte: 00101 for( ii=0 ; ii < npix ; ii++ ) 00102 newim->im.float_data[ii] = fac * oldim->im.byte_data[ii] ; 00103 break ; 00104 00105 case MRI_short: 00106 for( ii=0 ; ii < npix ; ii++ ) 00107 newim->im.float_data[ii] = fac * oldim->im.short_data[ii] ; 00108 break ; 00109 00110 case MRI_int: 00111 for( ii=0 ; ii < npix ; ii++ ) 00112 newim->im.float_data[ii] = fac * oldim->im.int_data[ii] ; 00113 break ; 00114 00115 case MRI_float: 00116 for( ii=0 ; ii < npix ; ii++ ) 00117 newim->im.float_data[ii] = fac * oldim->im.float_data[ii] ; 00118 break ; 00119 00120 case MRI_double: 00121 for( ii=0 ; ii < npix ; ii++ ) 00122 newim->im.float_data[ii] = fac * oldim->im.double_data[ii] ; 00123 break ; 00124 00125 case MRI_complex: 00126 for( ii=0 ; ii < npix ; ii++ ) 00127 newim->im.float_data[ii] = fac * CABS(oldim->im.complex_data[ii]) ; 00128 break ; 00129 00130 case MRI_rgb:{ 00131 byte * rgb = MRI_RGB_PTR(oldim) ; 00132 float * far = MRI_FLOAT_PTR(newim) ; 00133 for( ii=0 ; ii < npix ; ii++ ) 00134 far[ii] = fac*( 0.299 * rgb[3*ii] 00135 + 0.587 * rgb[3*ii+1] 00136 + 0.114 * rgb[3*ii+2] ) ; 00137 } 00138 break ; 00139 00140 case MRI_rgba:{ 00141 byte * rgb = (byte *) MRI_RGBA_PTR(oldim) ; 00142 float * far = MRI_FLOAT_PTR(newim) ; 00143 for( ii=0 ; ii < npix ; ii++ ) 00144 far[ii] = fac *( 0.299 * rgb[4*ii] 00145 + 0.587 * rgb[4*ii+1] 00146 + 0.114 * rgb[4*ii+2] ) ; 00147 } 00148 break ; 00149 00150 default: 00151 fprintf( stderr , "mri_to_float: unrecognized image kind %d\n",oldim->kind ) ; 00152 MRI_FATAL_ERROR ; 00153 } 00154 00155 MRI_COPY_AUX(newim,oldim) ; 00156 RETURN( newim ); 00157 } |
|
Scale a float image to an integer type [20 Oct 2003]:
Definition at line 10 of file mri_scalize.c. References EDIT_coerce_scale_type(), ENTRY, MRI_IMAGE::kind, MCW_vol_amax(), MRI_IS_INT_TYPE, mri_new_conforming, MRI_IMAGE::nvox, and RETURN. Referenced by THD_warp3D().
00011 { 00012 float gtop , fac , fimfac ; 00013 MRI_IMAGE *outim ; 00014 00015 ENTRY("mri_scalize") ; 00016 00017 if( inim == NULL || 00018 inim->kind != MRI_float || 00019 sfac == NULL || 00020 !MRI_IS_INT_TYPE(kind) ) RETURN(NULL) ; 00021 00022 fac = *sfac ; if( fac < 0.0 ) fac = 0.0 ; 00023 00024 gtop = MCW_vol_amax( inim->nvox,1,1,MRI_float,MRI_FLOAT_PTR(inim) ) ; 00025 if( gtop == 0.0 ){ 00026 fimfac = fac ; 00027 } else { 00028 fimfac = gtop / MRI_TYPE_maxval[kind] ; 00029 if( fimfac < fac ) fimfac = fac ; 00030 } 00031 outim = mri_new_conforming( inim , kind ) ; 00032 if( fimfac > 0.0 ) 00033 EDIT_coerce_scale_type( inim->nvox , 1.0/fimfac , 00034 MRI_float , MRI_FLOAT_PTR(inim) , 00035 outim->kind , mri_data_pointer(outim) ) ; 00036 *sfac = fimfac ; RETURN(outim) ; 00037 } |
|
Definition at line 91 of file mri_fft_complex.c. References malloc. Referenced by main(), mri_fft_complex(), and ts_to_ftime().
00092 { 00093 register int ii ; 00094 int ntap ; 00095 float *tap ; 00096 float phi ; 00097 00098 tap = (float *)malloc( sizeof(float) * nx ) ; /* make array */ 00099 00100 for( ii=0 ; ii < nx ; ii++ ) tap[ii] = 1.0 ; /* default 1's */ 00101 00102 ntap = (int) (nx * 0.5 * taper ) ; /* # pts on each end */ 00103 00104 if( ntap == 0 ){ /* special case of no points: taper is tiny */ 00105 tap[0] = tap[nx-1] = 0.5 ; 00106 return tap ; 00107 } 00108 00109 phi = PI / ntap ; 00110 for( ii=0 ; ii < ntap ; ii++ ){ 00111 tap[ii] = 0.5 - 0.5 * cos( ii*phi ) ; 00112 tap[nx-1-ii] = tap[ii] ; 00113 } 00114 00115 return tap ; 00116 } |
|
Definition at line 277 of file mri_sobel.c. References MRI_IMAGE::kind, mri_data_pointer(), mri_free(), mri_max(), mri_min(), mri_new(), mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, and top. Referenced by ISQ_process_mri(), and mri_sharpen_rgb().
00278 { 00279 int ii,jj , nx , ny , joff,ijoff , npix ; 00280 MRI_IMAGE * flim , * outim ; 00281 float * flar , * outar ; 00282 float nphi , omphi , sum , bot,top ; 00283 00284 #ifdef DEBUG 00285 printf("Entry: mri_sharpen\n") ; 00286 #endif 00287 00288 if( phi <= 0.0 || phi >= 1.0 ){ 00289 fprintf(stderr,"*** mri_sharpen: illegal phi=%g\n",phi) ; 00290 return NULL ; 00291 } 00292 00293 if( im->kind == MRI_float && !logify ){ 00294 flim = im ; 00295 } else { 00296 flim = mri_to_float( im ) ; 00297 } 00298 flar = mri_data_pointer( flim ) ; 00299 00300 nx = flim->nx ; ny = flim->ny ; npix = nx*ny ; 00301 outim = mri_new( nx , ny , MRI_float ) ; 00302 outar = mri_data_pointer( outim ) ; 00303 00304 if( logify ){ 00305 for( ii=0 ; ii < npix ; ii++ ) flar[ii] = log( fabs(flar[ii])+1.0 ) ; 00306 } 00307 00308 for( ii=0 ; ii < nx ; ii++ ) outar[ii] = flar[ii] ; /* copy 1st row */ 00309 00310 nphi = phi / 9.0 ; 00311 omphi = 1.0/(1.0-phi) ; 00312 bot = mri_min(flim) ; 00313 top = mri_max(flim) ; 00314 00315 for( jj=1 ; jj < ny-1 ; jj++ ){ 00316 joff = jj * nx ; 00317 00318 outar[joff] = flar[joff] ; /* copy 1st and last columns */ 00319 outar[joff+nx-1] = flar[joff+nx-1] ; 00320 00321 for( ii=1 ; ii < nx-1 ; ii++ ){ /* filter all intermediate points */ 00322 ijoff = joff + ii ; 00323 00324 sum = flar[ijoff-nx-1] + flar[ijoff-nx] + flar[ijoff-nx+1] 00325 +flar[ijoff-1] + flar[ijoff] + flar[ijoff+1] 00326 +flar[ijoff+nx-1] + flar[ijoff+nx] + flar[ijoff+nx+1] ; 00327 00328 outar[ijoff] = (flar[ijoff] - nphi*sum) * omphi ; 00329 00330 if( outar[ijoff] < bot ) outar[ijoff] = bot ; 00331 else if( outar[ijoff] > top ) outar[ijoff] = top ; 00332 } 00333 } 00334 00335 joff = (ny-1) * nx ; 00336 for( ii=0 ; ii < nx ; ii++ ) outar[joff+ii] = flar[joff+ii] ; /* copy last row */ 00337 00338 if( logify ){ 00339 for( ii=0 ; ii < npix ; ii++ ) outar[ii] = exp(outar[ii]) ; 00340 } 00341 00342 00343 if( flim != im ) mri_free( flim ) ; 00344 return outim ; 00345 } |
|
Definition at line 174 of file mri_to_rgb.c. References ENTRY, far, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COPY_AUX, MRI_FLOAT_PTR, mri_free(), mri_new_conforming, mri_sharpen(), mri_to_float(), MRI_IMAGE::nvox, and RETURN. Referenced by ISQ_process_mri().
00175 { 00176 MRI_IMAGE * flim , * shim , * newim ; 00177 byte * iar , * nar ; 00178 float * sar , * far ; 00179 int ii , nvox , rr,gg,bb ; 00180 float fac ; 00181 00182 ENTRY("mri_sharpen_rgb") ; 00183 00184 if( im == NULL ) RETURN( NULL ); 00185 00186 if( im->kind != MRI_rgb ) RETURN( mri_sharpen(phi,0,im) ); 00187 00188 flim = mri_to_float( im ) ; /* intensity of input */ 00189 shim = mri_sharpen( phi , 0 , flim ) ; /* sharpen intensity */ 00190 newim = mri_new_conforming( im , MRI_rgb ) ; /* will be output */ 00191 00192 nar = MRI_BYTE_PTR(newim) ; iar = MRI_BYTE_PTR(im) ; 00193 far = MRI_FLOAT_PTR(flim) ; sar = MRI_FLOAT_PTR(shim) ; 00194 00195 nvox = newim->nvox ; 00196 for( ii=0 ; ii < nvox ; ii++ ){ 00197 if( far[ii] <= 0.0 || sar[ii] <= 0.0 ){ 00198 nar[3*ii] = nar[3*ii+1] = nar[3*ii+2] = 0 ; 00199 } else { 00200 fac = sar[ii] / far[ii] ; /* will be positive */ 00201 rr = fac * iar[3*ii] ; 00202 gg = fac * iar[3*ii+1] ; 00203 bb = fac * iar[3*ii+2] ; 00204 nar[3*ii ] = (rr > 255) ? 255 : rr ; 00205 nar[3*ii+1] = (gg > 255) ? 255 : gg ; 00206 nar[3*ii+2] = (bb > 255) ? 255 : bb ; 00207 } 00208 } 00209 00210 mri_free(flim) ; mri_free(shim) ; 00211 00212 MRI_COPY_AUX(newim,im) ; 00213 RETURN( newim ); 00214 } |
|
Definition at line 110 of file mri_shifter.c. References free, MRI_IMAGE::kind, MRI_FLOAT_PTR, mri_free(), mri_new(), mri_to_float(), MRI_IMAGE::nx, and shifter(). Referenced by GRA_doshift().
00111 { 00112 MRI_IMAGE * newim , * flim ; 00113 float * newar , * flar , * shar ; 00114 int ii , ibot,itop , nx ; 00115 00116 /*-- sanity check --*/ 00117 00118 if( im == NULL ) return NULL ; 00119 00120 /*-- create output image --*/ 00121 00122 if( im->kind != MRI_float ) flim = mri_to_float( im ) ; 00123 else flim = im ; 00124 flar = MRI_FLOAT_PTR(flim) ; 00125 00126 nx = flim->nx ; 00127 newim = mri_new( nx , 1 , MRI_float ) ; 00128 newar = MRI_FLOAT_PTR(newim) ; 00129 00130 /*-- scan for unbroken blocks to shift --*/ 00131 00132 ibot = 0 ; 00133 while( ibot < nx ){ 00134 00135 if( flar[ibot] >= WAY_BIG ){ /* just copy values */ 00136 newar[ibot] = flar[ibot] ; /* that are WAY_BIG */ 00137 ibot++ ; 00138 continue ; 00139 } 00140 00141 for( ii=ibot+1 ; ii < nx ; ii++ ) /* scan for next WAY_BIG */ 00142 if( flar[ii] >= WAY_BIG ) break ; 00143 00144 itop = ii ; /* values from ibot to itop-1 are OK to shift */ 00145 00146 /* shift and copy output into new image */ 00147 00148 shar = shifter( itop-ibot , flar+ibot , shift ) ; 00149 for( ii=ibot ; ii < itop ; ii++ ) newar[ii] = shar[ii-ibot] ; 00150 free(shar) ; shar = NULL ; 00151 00152 ibot = itop ; /* start here next loop */ 00153 } 00154 00155 /*-- cleanup and exit --*/ 00156 00157 if( flim != im ) mri_free(flim) ; 00158 return newim ; 00159 } |
|
Definition at line 13 of file mri_order.c. Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), main(), r_fill_resampled_data_brick(), THD_copy_dset_subs(), THD_dataset_info(), THD_fetch_dataset(), THD_force_malloc_type(), THD_get_write_order(), THD_init_one_datablock(), THD_load_analyze(), THD_load_ctfmri(), THD_load_ctfsam(), THD_load_datablock(), THD_open_analyze(), THD_open_ctfmri(), THD_open_ctfsam(), and THD_write_datablock().
00014 { 00015 union { unsigned char bb[2] ; 00016 short ss ; } fred ; 00017 00018 fred.bb[0] = 1 ; fred.bb[1] = 0 ; 00019 00020 return (fred.ss == 1) ? LSB_FIRST : MSB_FIRST ; 00021 } |
|
Definition at line 23 of file mri_sobel.c. References EXIT, MRI_IMAGE::kind, MAX, MIN, MRI_COPY_AUX, mri_data_pointer(), mri_free(), MRI_IS_2D, mri_new(), mri_to_float(), nonmax_kill(), MRI_IMAGE::nx, and MRI_IMAGE::ny. Referenced by ISQ_process_mri().
00024 { 00025 MRI_IMAGE * imfl , * imout ; 00026 float * flin , * flout , * fjj,*fjp,*fjm ; 00027 int ii , jj , joff , nx,ny , ij , nij , nloc ; 00028 register float sxx,syy,sdd,see ; 00029 00030 MRI_IMAGE * imxx , * imyy , * imdd , * imee ; 00031 float * flxx , * flyy , * fldd , * flee ; 00032 00033 #ifdef DEBUG 00034 printf("Entry: mri_sobel\n") ; 00035 #endif 00036 00037 /*** setup input and output images ***/ 00038 00039 if( imin == NULL || ! MRI_IS_2D(imin) ){ 00040 fprintf(stderr,"\n*** mri_sobel only works on 2D images!\n") ; 00041 EXIT(1) ; 00042 } 00043 00044 nx = imin->nx ; 00045 ny = imin->ny ; 00046 if( imin->kind == MRI_float ) imfl = imin ; 00047 else imfl = mri_to_float( imin ) ; 00048 00049 imout = mri_new( nx , ny , MRI_float ) ; 00050 flout = mri_data_pointer( imout ) ; 00051 flin = mri_data_pointer( imfl ) ; 00052 00053 /*** setup arrays for each direction ***/ 00054 00055 imxx = mri_new( nx , ny , MRI_float ) ; flxx = mri_data_pointer( imxx ) ; 00056 imyy = mri_new( nx , ny , MRI_float ) ; flyy = mri_data_pointer( imyy ) ; 00057 imdd = mri_new( nx , ny , MRI_float ) ; fldd = mri_data_pointer( imdd ) ; 00058 imee = mri_new( nx , ny , MRI_float ) ; flee = mri_data_pointer( imee ) ; 00059 00060 /*** initialize edges to be zeros ***/ 00061 00062 for( jj=0 ; jj < ny ; jj++ ){ 00063 joff = nx * jj ; 00064 flxx[joff] = flyy[joff] = fldd[joff] = flee[joff] = 0; 00065 flxx[joff+nx-1] = flyy[joff+nx-1] = fldd[joff+nx-1] = flee[joff+nx-1]= 0; 00066 } 00067 for( ii=0 ; ii < nx ; ii++ ){ 00068 flxx[ii] = flyy[ii] = fldd[ii] = flee[ii] = 0; 00069 flxx[joff+ii] = flyy[joff+ii] = fldd[joff+ii] = flee[joff+ii] = 0; 00070 } 00071 00072 /*** do scan over interior points to produce images for each direction ***/ 00073 00074 for( jj=1 ; jj < ny-1 ; jj++ ){ 00075 00076 joff = nx * jj ; 00077 fjj = &flin[joff] ; 00078 fjm = &flin[joff-nx] ; 00079 fjp = &flin[joff+nx] ; 00080 00081 for( ii=1 ; ii < nx-1 ; ii++ ){ 00082 00083 sxx = 2.0 * ( fjj[ii+1] - fjj[ii-1] ) 00084 + ( fjp[ii+1] + fjm[ii+1] - fjp[ii-1] - fjm[ii-1] ) ; 00085 00086 syy = 2.0 * ( fjp[ii] - fjm[ii] ) 00087 + ( fjp[ii+1] + fjp[ii-1] - fjm[ii+1] - fjm[ii-1] ) ; 00088 00089 sdd = 2.0 * ( fjp[ii+1] - fjm[ii-1] ) 00090 + ( fjj[ii+1] + fjp[ii] - fjj[ii-1] - fjm[ii] ) ; 00091 00092 see = 2.0 * ( fjp[ii-1] - fjm[ii+1] ) 00093 + ( fjp[ii] + fjj[ii-1] - fjm[ii] - fjj[ii+1] ) ; 00094 00095 flxx[ii+joff] = fabs(sxx) ; flyy[ii+joff] = fabs(syy) ; 00096 fldd[ii+joff] = fabs(sdd) ; flee[ii+joff] = fabs(see) ; 00097 } 00098 } 00099 00100 if( imfl != imin ) mri_free( imfl ) ; /* don't need anymore */ 00101 00102 /*.......................................................................*/ 00103 /*** if nloc > 0, scan over +/- nloc points and kill non maxima points ***/ 00104 00105 nloc = nloc_individual ; 00106 if( nloc > 0 ){ 00107 00108 /*** do xx ***/ 00109 00110 for( jj=1 ; jj < ny-1 ; jj++ ){ 00111 joff = jj * nx ; 00112 nonmax_kill( nloc , nx , &flxx[joff] ) ; 00113 } 00114 00115 /*** do yy ***/ 00116 00117 for( ii=1 ; ii < nx-1 ; ii++ ){ 00118 for( jj=0 ; jj < ny ; jj++ ) flout[jj] = flyy[jj*nx+ii] ; 00119 nonmax_kill( nloc , ny , flout ) ; 00120 for( jj=0 ; jj < ny ; jj++ ) flyy[jj*nx+ii] = flout[jj] ; 00121 } 00122 00123 /*** do dd: here, ij = ii-jj ***/ 00124 00125 for( ij = -(ny-3) ; ij < nx-2 ; ij++ ){ 00126 00127 ii = MAX( 0 , ij ) ; jj = ii - ij ; 00128 00129 for( nij=0 ; (ii<nx) && (jj<ny) ; nij++ , ii++ , jj++ ){ 00130 flout[nij] = fldd[ii+nx*jj] ; 00131 } 00132 00133 nonmax_kill( nloc , nij , flout ) ; 00134 00135 ii = MAX( 0 , ij ) ; jj = ii - ij ; 00136 00137 for( nij=0 ; (ii<nx) && (jj<ny) ; nij++ , ii++ , jj++ ){ 00138 fldd[ii+nx*jj] = flout[nij] ; 00139 } 00140 } 00141 00142 /*** do ee: here, ij = ii+jj ***/ 00143 00144 for( ij = 2 ; ij < (nx+ny-4) ; ij++ ){ 00145 00146 jj = MIN( ij , ny-1 ) ; ii = ij - jj ; 00147 00148 for( nij=0 ; (ii<nx) && (jj>=0) ; nij++ , ii++ , jj-- ){ 00149 flout[nij] = flee[ii+nx*jj] ; 00150 } 00151 00152 nonmax_kill( nloc , nij , flout ) ; 00153 00154 jj = MIN( ij , ny-1 ) ; ii = ij - jj ; 00155 00156 for( nij=0 ; (ii<nx) && (jj>=0) ; nij++ , ii++ , jj-- ){ 00157 flee[ii+nx*jj] = flout[nij] ; 00158 } 00159 } 00160 00161 } /* end if( nloc > 0 ) */ 00162 00163 /*.......................................................................*/ 00164 /*** assign maximum of outputs at a given location to the final result ***/ 00165 00166 for( jj=0 ; jj < ny ; jj++ ){ /* clear edges */ 00167 joff = nx * jj ; 00168 flout[joff] = flout[joff+nx-1] = 0.0 ; 00169 } 00170 for( ii=0 ; ii < nx ; ii++ ){ 00171 flout[ii] = flout[joff+ii] = 0.0 ; 00172 } 00173 00174 for( jj=1 ; jj < ny-1 ; jj++ ){ 00175 joff = nx * jj ; 00176 for( ii=1 ; ii < nx-1 ; ii++ ){ 00177 sxx = MAX( flxx[ii+joff] , flyy[ii+joff] ) ; 00178 sdd = MAX( fldd[ii+joff] , flee[ii+joff] ) ; 00179 flout[ii+joff] = MAX( sxx , sdd ) ; 00180 } 00181 } 00182 00183 /*.......................................................................*/ 00184 00185 nloc = nloc_collective ; 00186 if( nloc > 0 ){ 00187 int xx,yy , xbot,xtop , ybot,ytop , dx,dy ; 00188 float val ; 00189 00190 for( jj=1 ; jj < ny-1 ; jj++ ){ 00191 joff = nx * jj ; 00192 ybot = MAX(0 ,jj-nloc) ; 00193 ytop = MIN(ny-1,jj+nloc) ; 00194 00195 for( ii=1 ; ii < nx-1 ; ii++ ){ 00196 xbot = MAX(0 ,ii-nloc) ; 00197 xtop = MIN(nx-1,ii+nloc) ; 00198 00199 sxx = flxx[ii+joff] ; syy = flyy[ii+joff] ; 00200 sdd = fldd[ii+joff] ; see = flee[ii+joff] ; val = flout[ii+joff] ; 00201 00202 if( val == sxx ){ dx = 1 ; dy = 0 ; } 00203 else if( val == syy ){ dx = 0 ; dy = 1 ; } 00204 else if( val == sdd ){ dx = 1 ; dy = 1 ; } 00205 else { dx = 1 ; dy = -1 ; } 00206 00207 for( xx=ii+dx , yy=jj+dy ; 00208 (xx <= xtop) && (yy >= ybot) && (yy <= ytop) ; 00209 xx += dx , yy+= dy ) val = MAX(val,flout[xx+nx*yy]) ; 00210 00211 for( xx=ii-dx , yy=jj-dy ; 00212 (xx >= xbot) && (yy >= ybot) && (yy <= ytop) ; 00213 xx -= dx , yy-= dy ) val = MAX(val,flout[xx+nx*yy]) ; 00214 00215 if( flout[ii+joff] < val ) flout[ii+joff] = 0.0 ; 00216 00217 } /* end for ii */ 00218 } /* end for jj */ 00219 00220 /*** now, destroy points in flout with no neighbors ***/ 00221 00222 for( ii=0 ; ii < nx*ny ; ii++ ) flee[ii] = 0.0 ; 00223 00224 for( jj=1 ; jj < ny-1 ; jj++ ){ 00225 joff = nx * jj ; 00226 for( ii=1 ; ii < nx-1 ; ii++ ){ 00227 xx = ii+joff ; 00228 if( flout[xx] == 0.0 ) continue ; 00229 00230 if( flout[xx-1] != 0.0 || flout[xx+1] != 0.0 || 00231 flout[xx+nx] != 0.0 || flout[xx-nx] != 0.0 || 00232 flout[xx+nx+1] != 0.0 || flout[xx+nx-1] != 0.0 || 00233 flout[xx-nx+1] != 0.0 || flout[xx-nx-1] != 0.0 ) flee[xx] = flout[xx] ; 00234 } 00235 } 00236 00237 for( ii=0 ; ii < nx*ny ; ii++ ) flout[ii] = flee[ii] ; 00238 00239 } /* end if nloc */ 00240 00241 /*........................................................................*/ 00242 00243 mri_free(imxx) ; mri_free(imyy) ; mri_free(imdd) ; mri_free(imee) ; 00244 00245 MRI_COPY_AUX(imout,imin) ; 00246 return imout ; 00247 } |
|
Definition at line 89 of file mri_warp.c. References MRI_IMAGE::dx, MRI_IMAGE::dy, mri_resize_NN(), MRI_IMAGE::nx, and MRI_IMAGE::ny. Referenced by ISQ_save_jpeg(), and ISQ_saver_CB().
00090 { 00091 int nx,ny , nxnew,nynew ; 00092 float dx,dy , rr ; 00093 00094 if( im == NULL ) return NULL ; 00095 00096 dx = fabs(im->dx) ; dy = fabs(im->dy) ; 00097 if( dx == 0.0 || dy == 0.0 ) return NULL ; 00098 rr = dy / dx ; if( rr == 1.0 ) return NULL ; 00099 00100 nx = im->nx ; ny = im->ny ; 00101 00102 if( rr < 1.0 ){ 00103 nxnew = rint( nx/rr ) ; if( nxnew <= nx ) return NULL ; 00104 nynew = ny ; 00105 } else { 00106 nynew = rint( ny*rr ) ; if( nynew <= ny ) return NULL ; 00107 nxnew = nx ; 00108 } 00109 00110 return mri_resize_NN( im , nxnew , nynew ) ; 00111 } |
|
Definition at line 367 of file mri_lsqfit.c. References ENTRY, free, MRI_IMARR::imarr, MRI_IMAGE::kind, malloc, MRI_FLOAT_PTR, MRI_IMARR::num, MRI_IMAGE::nvox, RETURN, and startup_lsqfit(). Referenced by mri_2dalign_setup(), mri_3dalign_setup(), and mri_align_dfspace().
00368 { 00369 double *cc = NULL ; /* will be the output */ 00370 int ii , npix,nref ; 00371 float * wtar , ** refar ; 00372 00373 ENTRY("mri_startup_lsqfit") ; 00374 00375 /****---- check inputs ----****/ 00376 00377 if( wtim != NULL && wtim->kind != MRI_float ){ 00378 fprintf(stderr,"mri_startup_lsqfit: non-float wtim!\a\n") ; RETURN(NULL); 00379 } 00380 wtar = (wtim == NULL) ? (NULL) : (MRI_FLOAT_PTR(wtim)) ; 00381 00382 if( refim == NULL || refim->num < 1 ){ 00383 fprintf(stderr,"mri_startup_lsqfit: NULL refim!\a\n") ; RETURN(NULL); 00384 } 00385 00386 nref = refim->num ; 00387 npix = refim->imarr[0]->nvox ; 00388 refar = (float **) malloc( sizeof(float *) * nref ) ; 00389 if( refar == NULL ){ 00390 fprintf(stderr,"mri_startup_lsqfit: malloc failure for refar!\a\n") ; RETURN(NULL); 00391 } 00392 00393 for( ii=0 ; ii < nref ; ii++ ){ 00394 if( refim->imarr[ii] == NULL ){ 00395 fprintf(stderr,"mri_startup_lsqfit: NULL refim[%d]!\a\n",ii) ; RETURN(NULL); 00396 } 00397 if( refim->imarr[ii]->nvox != npix ){ 00398 fprintf(stderr,"mri_startup_lsqfit: MISMATCH refim[%d]!\a\n",ii) ; RETURN(NULL); 00399 } 00400 if( refim->imarr[ii]->kind != MRI_float ){ 00401 fprintf(stderr,"mri_startup_lsqfit: non-float refim[%d]!\a\n",ii) ; RETURN(NULL); 00402 } 00403 refar[ii] = MRI_FLOAT_PTR(refim->imarr[ii]) ; 00404 } 00405 00406 /****---- get Choleski, send it out ----****/ 00407 00408 cc = startup_lsqfit( npix , wtar , nref , refar ) ; 00409 if( cc == NULL ){ 00410 fprintf(stderr,"mri_startup_lsqfit: bad call to startup_lsqfit!\a\n") ; RETURN(NULL); 00411 } 00412 free(refar) ; 00413 RETURN(cc) ; 00414 } |
|
Definition at line 18 of file mri_stat_seq.c. References EXIT, MRI_IMAGE::kind, malloc, MRI_COPY_AUX, mri_data_pointer(), mri_free(), MRI_IS_2D, mri_new(), mri_to_float(), MRI_IMAGE::nx, MRI_IMAGE::ny, and retval(). Referenced by main(), and mri_align_crao().
00019 { 00020 00021 /* static variables (exist between calls) */ 00022 00023 static MRI_IMAGE * imsum , * imsumq ; 00024 static int nim = 0 , npix , nx , ny ; 00025 static double * dbsum , * dbsumq ; 00026 00027 /* local variables */ 00028 00029 register int ii ; 00030 MRI_IMAGE * imfl , * imsd , ** retval ; 00031 float * flar , * sdar ; 00032 double scl , vscl , vvv ; 00033 00034 /*** case: set up new problem ***/ 00035 00036 if( nim == 0 ){ 00037 00038 if( imin == NULL ){ 00039 fprintf(stderr,"mri_stat_seq: NULL argument for initial call!\n") ; 00040 EXIT(1) ; 00041 } 00042 00043 if( ! MRI_IS_2D(imin) ){ 00044 fprintf(stderr,"\n*** mri_stat_seq: only works on 2D images!\n") ; 00045 EXIT(1) ; 00046 } 00047 00048 nx = imin->nx ; 00049 ny = imin->ny ; 00050 npix = nx * ny ; 00051 00052 imsum = mri_new( nx , ny , MRI_double ) ; 00053 imsumq = mri_new( nx , ny , MRI_double ) ; 00054 dbsum = mri_data_pointer( imsum ) ; 00055 dbsumq = mri_data_pointer( imsumq ) ; 00056 00057 MRI_COPY_AUX(imsum,imin) ; 00058 00059 for( ii=0 ; ii < npix ; ii++ ) dbsum[ii] = dbsumq[ii] = 0.0 ; 00060 00061 } 00062 00063 /*** case: add new image into problem ***/ 00064 00065 if( imin != NULL ){ 00066 00067 if( imin->nx != nx || imin->ny != ny ){ 00068 fprintf(stderr,"mri_stat_seq: input image size mismatch!\n") ; 00069 EXIT(1) ; 00070 } 00071 00072 if( ! MRI_IS_2D(imin) ){ 00073 fprintf(stderr,"\n*** mri_stat_seq: only works on 2D images!\n") ; 00074 EXIT(1) ; 00075 } 00076 00077 if( imin->kind == MRI_float ){ 00078 imfl = imin ; 00079 } else { 00080 imfl = mri_to_float( imin ) ; 00081 } 00082 flar = mri_data_pointer( imfl ) ; 00083 00084 for( ii=0 ; ii < npix ; ii++ ){ 00085 dbsum[ii] += flar[ii] ; 00086 dbsumq[ii] += flar[ii] * flar[ii] ; 00087 } 00088 00089 if( imin != imfl ) mri_free( imfl ) ; 00090 nim++ ; 00091 return NULL ; 00092 } 00093 00094 /*** case: make report on results, and reset static data ***/ 00095 00096 if( nim < 1 ){ 00097 fprintf(stderr,"mri_stat_seq: # images input=%d; too small!\n",nim) ; 00098 EXIT(1) ; 00099 } 00100 00101 imfl = mri_new( nx , ny , MRI_float ) ; 00102 imsd = mri_new( nx , ny , MRI_float ) ; 00103 flar = mri_data_pointer( imfl ) ; 00104 sdar = mri_data_pointer( imsd ) ; 00105 00106 MRI_COPY_AUX(imfl,imsum) ; 00107 00108 scl = 1.0 / nim ; 00109 vscl = (nim==1) ? 1.0 : sqrt( ((double)(nim))/(nim-1.0) ) ; 00110 00111 for( ii=0 ; ii < npix ; ii++ ){ 00112 flar[ii] = scl * dbsum[ii] ; 00113 vvv = scl * dbsumq[ii] - flar[ii] * flar[ii] ; 00114 sdar[ii] = (vvv > 0.0) ? (sqrt(vvv)*vscl) : 0.0 ; 00115 } 00116 00117 mri_free( imsum ) ; mri_free( imsumq ) ; 00118 nim = 0 ; 00119 00120 retval = (MRI_IMAGE **) malloc( 2 * sizeof(MRI_IMAGE *) ) ; 00121 if( retval == NULL ){ 00122 fprintf(stderr,"mri_stat_seq: malloc error for retval!\n") ; 00123 EXIT(1) ; 00124 } 00125 00126 retval[0] = imfl ; 00127 retval[1] = imsd ; 00128 00129 return retval ; 00130 } |
|
Definition at line 39 of file mri_order.c. References twobytes::a, twobytes::b, and tt. Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), main(), RT_read_image(), THD_fetch_dataset(), THD_load_analyze(), THD_load_ctfmri(), THD_load_datablock(), and THD_write_datablock().
|
|
Definition at line 57 of file mri_order.c. References fourbytes::a, fourbytes::b, fourbytes::c, fourbytes::d, and tt. Referenced by adwarp_refashion_dataset(), AFNI_refashion_dataset(), main(), RT_read_image(), THD_fetch_dataset(), THD_load_analyze(), THD_load_datablock(), and THD_write_datablock().
00058 { 00059 register int ii ; 00060 register fourbytes * tb = (fourbytes *) ar ; 00061 register unsigned char tt , uu ; 00062 00063 for( ii=0 ; ii < n ; ii++ ){ 00064 tt = tb[ii].a ; 00065 tb[ii].a = tb[ii].d ; 00066 tb[ii].d = tt ; 00067 00068 uu = tb[ii].b ; 00069 tb[ii].b = tb[ii].c ; 00070 tb[ii].c = uu ; 00071 } 00072 return ; 00073 } |
|
Definition at line 13 of file mri_swapbytes.c. References ENTRY, MRI_IMAGE::im, MRI_IMAGE::kind, MRI_IMAGE::nvox, MRI_DATA::short_data, and SWAB16. Referenced by main(), mri_input_delay(), and mri_read_3D().
00014 { 00015 register int ii , npix ; 00016 00017 ENTRY("mri_swapbytes") ; 00018 00019 if( im->kind != MRI_short ){ 00020 fprintf( stderr , "mri_swapbytes called with non-short image kind\n" ) ; 00021 EXRETURN ; 00022 } 00023 00024 npix = im->nvox ; 00025 00026 for( ii=0 ; ii < npix ; ii++ ) 00027 im->im.short_data[ii] = SWAB16( im->im.short_data[ii] ) ; 00028 00029 EXRETURN ; 00030 } |
|
Definition at line 16 of file mri_thresh.c. References ENTRY, complex::i, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COMPLEX_PTR, MRI_DOUBLE_PTR, MRI_FLOAT_PTR, mri_free(), MRI_INT_PTR, MRI_RGB_PTR, MRI_SHORT_PTR, mri_to_short(), MRI_IMAGE::nvox, complex::r, and SHORTIZE. Referenced by AFNI_func_overlay().
00017 { 00018 register int ii , npix ; 00019 00020 ENTRY("mri_threshold") ; 00021 00022 if( thrim == NULL || im == NULL || 00023 thrim->nvox != im->nvox || thbot >= thtop ) EXRETURN ; 00024 00025 npix = im->nvox ; 00026 00027 switch( thrim->kind ){ 00028 00029 default: EXRETURN ; /* don't know how to use this type of threshold image */ 00030 00031 case MRI_byte:{ /* 20 Dec 2004: very stupid way to do bytes */ 00032 MRI_IMAGE *qim = mri_to_short(1.0,thrim) ; 00033 mri_threshold( thbot,thtop , qim , im ) ; 00034 mri_free(qim) ; 00035 EXRETURN ; 00036 } 00037 00038 case MRI_short:{ /* threshold image is shorts */ 00039 register short th1 , th2 ; 00040 register short *thar = MRI_SHORT_PTR(thrim) ; 00041 th1 = SHORTIZE(thbot) ; th2 = SHORTIZE(thtop) ; 00042 00043 switch( im->kind ){ 00044 00045 default: EXRETURN ; /* unknown type of data image */ 00046 00047 case MRI_byte:{ 00048 register byte *ar = MRI_BYTE_PTR(im) ; 00049 for( ii=0 ; ii < npix ; ii++ ) 00050 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ; 00051 EXRETURN ; 00052 } 00053 00054 case MRI_rgb:{ /* 20 Dec 2004 */ 00055 register byte *ar = MRI_RGB_PTR(im) ; 00056 for( ii=0 ; ii < npix ; ii++ ) 00057 if( thar[ii] > th1 && thar[ii] < th2 ){ 00058 ar[3*ii] = ar[3*ii+1] = ar[3*ii+2] = 0 ; 00059 } 00060 EXRETURN ; 00061 } 00062 00063 case MRI_short:{ 00064 register short *ar = MRI_SHORT_PTR(im) ; 00065 for( ii=0 ; ii < npix ; ii++ ) 00066 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ; 00067 EXRETURN ; 00068 } 00069 00070 case MRI_int:{ 00071 register int *ar = MRI_INT_PTR(im) ; 00072 for( ii=0 ; ii < npix ; ii++ ) 00073 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ; 00074 EXRETURN ; 00075 } 00076 00077 case MRI_float:{ 00078 register float *ar = MRI_FLOAT_PTR(im) ; 00079 for( ii=0 ; ii < npix ; ii++ ) 00080 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0f ; 00081 EXRETURN ; 00082 } 00083 00084 case MRI_double:{ 00085 register double *ar = MRI_DOUBLE_PTR(im) ; 00086 for( ii=0 ; ii < npix ; ii++ ) 00087 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0 ; 00088 EXRETURN ; 00089 } 00090 00091 case MRI_complex:{ 00092 register complex *ar = MRI_COMPLEX_PTR(im) ; 00093 for( ii=0 ; ii < npix ; ii++ ) 00094 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii].r = ar[ii].i = 0.0f ; 00095 EXRETURN ; 00096 } 00097 } 00098 } /* end of short thrim */ 00099 00100 case MRI_float:{ /* threshold image is floats */ 00101 register float th1 , th2 ; 00102 register float *thar = MRI_FLOAT_PTR(thrim) ; 00103 th1 = thbot ; th2 = thtop ; 00104 00105 switch( im->kind ){ 00106 00107 default: EXRETURN ; 00108 00109 case MRI_byte:{ 00110 register byte *ar = MRI_BYTE_PTR(im) ; 00111 for( ii=0 ; ii < npix ; ii++ ) 00112 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ; 00113 EXRETURN ; 00114 } 00115 00116 case MRI_rgb:{ /* 20 Dec 2004 */ 00117 register byte *ar = MRI_RGB_PTR(im) ; 00118 for( ii=0 ; ii < npix ; ii++ ) 00119 if( thar[ii] > th1 && thar[ii] < th2 ){ 00120 ar[3*ii] = ar[3*ii+1] = ar[3*ii+2] = 0 ; 00121 } 00122 EXRETURN ; 00123 } 00124 00125 case MRI_short:{ 00126 register short *ar = MRI_SHORT_PTR(im) ; 00127 for( ii=0 ; ii < npix ; ii++ ) 00128 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ; 00129 EXRETURN ; 00130 } 00131 00132 case MRI_int:{ 00133 register int *ar = MRI_INT_PTR(im) ; 00134 for( ii=0 ; ii < npix ; ii++ ) 00135 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0 ; 00136 EXRETURN ; 00137 } 00138 00139 case MRI_float:{ 00140 register float *ar = MRI_FLOAT_PTR(im) ; 00141 for( ii=0 ; ii < npix ; ii++ ) 00142 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0f ; 00143 EXRETURN ; 00144 } 00145 00146 case MRI_double:{ 00147 register double *ar = MRI_DOUBLE_PTR(im) ; 00148 for( ii=0 ; ii < npix ; ii++ ) 00149 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii] = 0.0 ; 00150 EXRETURN ; 00151 } 00152 00153 case MRI_complex:{ 00154 register complex *ar = MRI_COMPLEX_PTR(im) ; 00155 for( ii=0 ; ii < npix ; ii++ ) 00156 if( thar[ii] > th1 && thar[ii] < th2 ) ar[ii].r = ar[ii].i = 0.0f ; 00157 EXRETURN ; 00158 } 00159 } 00160 } /* end of float thrim */ 00161 00162 } 00163 00164 EXRETURN ; /* should not be reached! */ 00165 } |
|
Definition at line 11 of file mri_to_byte.c. References MRI_DATA::byte_data, BYTEIZE, CABS, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, MRI_DATA::float_data, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_max(), mri_min(), mri_new_conforming, MRI_IMAGE::nvox, RETURN, MRI_DATA::rgb_data, scale, and MRI_DATA::short_data. Referenced by main(), mri_overlay_2D(), mri_read_mpeg(), mri_to_mri(), REND_reload_dataset(), RT_registration_2D_onevol(), RT_registration_3D_onevol(), and VOLREG_main().
00012 { 00013 MRI_IMAGE *newim ; 00014 register int ii , npix ; 00015 double imin,imax ; 00016 register double scale ; 00017 short shbot ; 00018 int inbot ; 00019 float flbot ; 00020 double dbbot ; 00021 byte *ar ; 00022 00023 ENTRY("mri_to_byte") ; 00024 00025 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 00026 00027 newim = mri_new_conforming( oldim , MRI_byte ) ; 00028 npix = oldim->nvox ; 00029 00030 switch( oldim->kind ){ 00031 case MRI_short: 00032 case MRI_int: 00033 case MRI_float: 00034 case MRI_double: 00035 imin = mri_min( oldim ) ; 00036 imax = mri_max( oldim ) ; 00037 imax = (imax <= imin) ? imin+1 : imax ; 00038 scale = 255.9 / (imax-imin) ; 00039 switch( oldim->kind ){ 00040 case MRI_short: shbot = imin ; break ; 00041 case MRI_int: inbot = imin ; break ; 00042 case MRI_float: flbot = imin ; break ; 00043 case MRI_double: dbbot = imin ; break ; 00044 } 00045 break ; 00046 00047 case MRI_complex: 00048 scale = 255.9 / mri_max( oldim ) ; 00049 break ; 00050 } 00051 00052 ar = MRI_BYTE_PTR( newim ) ; /* fast access to data */ 00053 00054 switch( oldim->kind ){ 00055 00056 case MRI_byte: 00057 #ifdef DONT_USE_MEMCPY 00058 for( ii=0 ; ii < npix ; ii++ ) 00059 ar[ii] = oldim->im.byte_data[ii] ; 00060 #else 00061 (void) memcpy( ar , oldim->im.byte_data , sizeof(byte)*npix ) ; 00062 #endif 00063 break ; 00064 00065 case MRI_rgb:{ /* 13 Nov 2002 */ 00066 byte *rgb = oldim->im.rgb_data ; 00067 float rfac=0.299*scale , gfac=0.587*scale , bfac=0.114*scale , val ; 00068 for( ii=0 ; ii < npix ; ii++ ){ 00069 val = rfac * rgb[3*ii] + gfac * rgb[3*ii+1] + bfac * rgb[3*ii+2] ; 00070 ar[ii] = BYTEIZE(val) ; 00071 } 00072 } 00073 break ; 00074 00075 case MRI_short: 00076 for( ii=0 ; ii < npix ; ii++ ) 00077 ar[ii] = scale * (oldim->im.short_data[ii]-shbot) ; 00078 break ; 00079 00080 case MRI_int: 00081 for( ii=0 ; ii < npix ; ii++ ) 00082 ar[ii] = scale * (oldim->im.int_data[ii]-inbot) ; 00083 break ; 00084 00085 case MRI_float: 00086 for( ii=0 ; ii < npix ; ii++ ) 00087 ar[ii] = scale * (oldim->im.float_data[ii]-flbot) ; 00088 break ; 00089 00090 case MRI_double: 00091 for( ii=0 ; ii < npix ; ii++ ) 00092 ar[ii] = scale * (oldim->im.double_data[ii]-dbbot) ; 00093 break ; 00094 00095 case MRI_complex: 00096 for( ii=0 ; ii < npix ; ii++ ) 00097 ar[ii] = scale * CABS(oldim->im.complex_data[ii]) ; 00098 break ; 00099 00100 default: 00101 fprintf( stderr , "mri_to_byte: unrecognized image kind\n" ) ; 00102 MRI_FATAL_ERROR ; 00103 } 00104 00105 MRI_COPY_AUX(newim,oldim) ; 00106 RETURN( newim ); 00107 } |
|
Definition at line 111 of file mri_to_byte.c. References MRI_DATA::byte_data, BYTEIZE, CABS, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, MRI_DATA::float_data, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_max(), mri_min(), mri_new_conforming, MRI_IMAGE::nvox, RETURN, scale, and MRI_DATA::short_data. Referenced by main(), mri_read_3A(), mri_to_mri(), mri_to_mri_scl(), and T3D_read_images().
00112 { 00113 MRI_IMAGE *newim ; 00114 register int ii , npix ; 00115 double imin,imax ; 00116 register double dscale , dbbot ; 00117 register float scale , flbot , val ; 00118 register byte *ar ; 00119 00120 ENTRY("mri_to_byte_scl") ; 00121 00122 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 00123 00124 newim = mri_new_conforming( oldim , MRI_byte ) ; 00125 npix = oldim->nvox ; 00126 00127 if( scl == 0 ){ /* compute scaling to make (min..max) -> (0..lev) */ 00128 00129 imin = (oldim->kind == MRI_complex) ? (0) : mri_min( oldim ) ; 00130 imax = mri_max( oldim ) ; 00131 imax = (imax <= imin) ? imin+1 : imax ; 00132 00133 scale = dscale = (lev+0.99) / (imax-imin) ; 00134 flbot = dbbot = imin ; 00135 00136 } else { /* user controlled scaling, with lev -> 0 */ 00137 scale = dscale = scl ; 00138 flbot = dbbot = lev ; 00139 } 00140 00141 ar = MRI_BYTE_PTR( newim ) ; /* fast access to data */ 00142 00143 switch( oldim->kind ){ 00144 00145 case MRI_byte: 00146 for( ii=0 ; ii < npix ; ii++ ){ 00147 val = scale * (oldim->im.byte_data[ii]-flbot) ; 00148 ar[ii] = BYTEIZE(val) ; 00149 } 00150 break ; 00151 00152 case MRI_short: 00153 for( ii=0 ; ii < npix ; ii++ ){ 00154 val = scale * (oldim->im.short_data[ii]-flbot) ; 00155 ar[ii] = BYTEIZE(val) ; 00156 } 00157 break ; 00158 00159 case MRI_int: 00160 for( ii=0 ; ii < npix ; ii++ ){ 00161 val = scale * (oldim->im.int_data[ii]-flbot) ; 00162 ar[ii] = BYTEIZE(val) ; 00163 } 00164 break ; 00165 00166 case MRI_float: 00167 for( ii=0 ; ii < npix ; ii++ ){ 00168 val = scale * (oldim->im.float_data[ii]-flbot) ; 00169 ar[ii] = BYTEIZE(val) ; 00170 } 00171 break ; 00172 00173 case MRI_double: 00174 for( ii=0 ; ii < npix ; ii++ ) 00175 ar[ii] = dscale * (oldim->im.double_data[ii]-dbbot) ; 00176 break ; 00177 00178 case MRI_complex: 00179 for( ii=0 ; ii < npix ; ii++ ) 00180 ar[ii] = scale * CABS(oldim->im.complex_data[ii]) ; 00181 break ; 00182 00183 default: 00184 fprintf( stderr , "mri_to_byte_scl: unrecognized image kind\n" ) ; 00185 MRI_FATAL_ERROR ; 00186 } 00187 00188 MRI_COPY_AUX(newim,oldim) ; 00189 RETURN( newim ); 00190 } |
|
Definition at line 18 of file mri_to_complex.c. References MRI_DATA::byte_data, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, MRI_DATA::float_data, complex::i, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_COMPLEX_PTR, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_new_conforming, MRI_RGB_PTR, MRI_IMAGE::nvox, complex::r, RETURN, and MRI_DATA::short_data. Referenced by mri_fft2D(), mri_to_mri(), mri_to_mri_scl(), and T3D_read_images().
00019 { 00020 MRI_IMAGE *newim ; 00021 register int ii , npix ; 00022 00023 ENTRY("mri_to_complex") ; 00024 00025 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 00026 00027 newim = mri_new_conforming( oldim , MRI_complex ) ; 00028 npix = oldim->nvox ; 00029 00030 switch( oldim->kind ){ 00031 00032 case MRI_byte: 00033 for( ii=0 ; ii < npix ; ii++ ) 00034 newim->im.complex_data[ii].r = oldim->im.byte_data[ii] ; 00035 break ; 00036 00037 case MRI_short: 00038 for( ii=0 ; ii < npix ; ii++ ) 00039 newim->im.complex_data[ii].r = oldim->im.short_data[ii] ; 00040 break ; 00041 00042 case MRI_int: 00043 for( ii=0 ; ii < npix ; ii++ ) 00044 newim->im.complex_data[ii].r = oldim->im.int_data[ii] ; 00045 break ; 00046 00047 case MRI_float: 00048 for( ii=0 ; ii < npix ; ii++ ) 00049 newim->im.complex_data[ii].r = oldim->im.float_data[ii] ; 00050 break ; 00051 00052 case MRI_double: 00053 for( ii=0 ; ii < npix ; ii++ ) 00054 newim->im.complex_data[ii].r = oldim->im.double_data[ii] ; 00055 break ; 00056 00057 case MRI_complex: 00058 #ifdef DONT_USE_MEMCPY 00059 for( ii=0 ; ii < npix ; ii++ ) 00060 newim->im.complex_data[ii] = oldim->im.complex_data[ii] ; 00061 #else 00062 (void) memcpy( newim->im.complex_data , 00063 oldim->im.complex_data , sizeof(complex)*npix ) ; 00064 #endif 00065 break ; 00066 00067 case MRI_rgb:{ /* 16 Jun 2000 */ 00068 byte * rgb = MRI_RGB_PTR(oldim) ; 00069 complex * car = MRI_COMPLEX_PTR(newim) ; 00070 for( ii=0 ; ii < npix ; ii++ ){ /* scale to brightness */ 00071 car[ii].r = 0.299 * rgb[3*ii] /* between 0 and 255 */ 00072 + 0.587 * rgb[3*ii+1] 00073 + 0.114 * rgb[3*ii+2] ; 00074 car[ii].i = 0.0 ; 00075 } 00076 } 00077 break ; 00078 00079 default: 00080 fprintf( stderr , "mri_to_complex: unrecognized image kind\n" ) ; 00081 MRI_FATAL_ERROR ; 00082 } 00083 00084 if( oldim->kind != MRI_complex ){ 00085 for( ii=0 ; ii < npix ; ii++ ) 00086 newim->im.complex_data[ii].i = 0.0 ; 00087 } 00088 00089 MRI_COPY_AUX(newim,oldim) ; 00090 RETURN( newim ); 00091 } |
|
Definition at line 100 of file mri_to_complex.c. References MRI_DATA::byte_data, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, MRI_DATA::float_data, complex::i, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_IS_2D, mri_new(), MRI_IMAGE::nx, MRI_IMAGE::ny, complex::r, RETURN, and MRI_DATA::short_data.
00101 { 00102 MRI_IMAGE *newim ; 00103 int oldx,oldy , itop,jtop , ii,jj , jbold,jbnew ; 00104 00105 ENTRY("mri_to_complex_ext") ; 00106 00107 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 00108 00109 if( ! MRI_IS_2D(oldim) ){ 00110 fprintf(stderr,"\n*** mri_to_complex_ext only works on 2D images\n") ; 00111 RETURN( NULL ); 00112 } 00113 00114 oldx = oldim->nx ; 00115 oldy = oldim->ny ; 00116 00117 itop = (xnew<oldx) ? xnew : oldx ; /* smallest x dimension */ 00118 jtop = (ynew<oldy) ? ynew : oldy ; /* smallest y dimension */ 00119 00120 newim = mri_new( xnew , ynew , MRI_complex ) ; 00121 00122 /*** copy 0..itop by 0..jtop from old into new ***/ 00123 00124 for( jj=0 ; jj < jtop ; jj++ ){ 00125 jbold = oldx * jj ; 00126 jbnew = xnew * jj ; 00127 for( ii=0 ; ii < itop ; ii++ ){ 00128 newim->im.complex_data[ii+jbnew].i = 0.0 ; 00129 00130 switch( oldim->kind ){ 00131 case MRI_byte: 00132 newim->im.complex_data[ii+jbnew].r = 00133 oldim->im.byte_data[ii+jbold] ; 00134 break ; 00135 case MRI_short: 00136 newim->im.complex_data[ii+jbnew].r = 00137 oldim->im.short_data[ii+jbold] ; 00138 break ; 00139 case MRI_int: 00140 newim->im.complex_data[ii+jbnew].r = 00141 oldim->im.int_data[ii+jbold] ; 00142 break ; 00143 case MRI_float: 00144 newim->im.complex_data[ii+jbnew].r = 00145 oldim->im.float_data[ii+jbold] ; 00146 break ; 00147 case MRI_double: 00148 newim->im.complex_data[ii+jbnew].r = 00149 oldim->im.double_data[ii+jbold] ; 00150 break ; 00151 case MRI_complex: 00152 newim->im.complex_data[ii+jbnew] = 00153 oldim->im.complex_data[ii+jbold] ; 00154 break ; 00155 } 00156 } 00157 } 00158 00159 /*** if old image is smaller in x, extend all x rows with zeros ***/ 00160 00161 if( oldx < xnew ){ 00162 for( jj=0 ; jj < jtop ; jj++ ){ 00163 jbnew = jj * xnew ; 00164 for( ii=oldx ; ii < xnew ; ii++ ){ 00165 newim->im.complex_data[ii+jbnew].r = 0.0 ; 00166 newim->im.complex_data[ii+jbnew].i = 0.0 ; 00167 } 00168 } 00169 } 00170 00171 /*** if old image is smaller in y, fill out last rows with zeros ***/ 00172 00173 for( jj=oldy ; jj < ynew ; jj++ ){ 00174 jbnew = jj * xnew ; 00175 for( ii=0 ; ii < xnew ; ii++ ){ 00176 newim->im.complex_data[ii+jbnew].r = 0.0 ; 00177 newim->im.complex_data[ii+jbnew].i = 0.0 ; 00178 } 00179 } 00180 00181 if( altern ){ 00182 for( jj=0 ; jj < ynew ; jj++ ){ 00183 jbnew = jj * xnew ; 00184 for( ii=0 ; ii < xnew ; ii++ ){ 00185 if( (ii+jj)%2 ){ 00186 newim->im.complex_data[ii+jbnew].r = - newim->im.complex_data[ii+jbnew].r ; 00187 newim->im.complex_data[ii+jbnew].i = - newim->im.complex_data[ii+jbnew].i ; 00188 } 00189 } 00190 } 00191 } 00192 00193 MRI_COPY_AUX(newim,oldim) ; 00194 RETURN( newim ); 00195 } |
|
Definition at line 11 of file mri_to_float.c. References MRI_DATA::byte_data, CABS, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, far, MRI_DATA::float_data, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FATAL_ERROR, MRI_FLOAT_PTR, mri_new_conforming, MRI_RGB_PTR, MRI_RGBA_PTR, MRI_IMAGE::nvox, RETURN, and MRI_DATA::short_data. Referenced by AFNI_func_overlay(), AFNI_gra_send_CB(), avg_epochs(), CORREL_main(), FTOSH_getopts(), get_line_opt(), GRA_opt_CB(), GRA_pick_xaxis_CB(), ISQ_getimage(), ISQ_process_mri(), main(), mri_2dalign_one(), mri_2dalign_setup(), mri_3dalign_one(), mri_3dalign_setup(), mri_affine_bicubic(), mri_align_dfspace(), MRI_autobbox(), mri_automask_image(), mri_automask_imarr(), mri_dup2D(), mri_edit_image(), mri_filt_fft(), mri_flatten(), mri_flatten_rgb(), mri_get_cmass_2D(), mri_get_cmass_3D(), mri_histogram(), mri_lsqfit(), mri_medianfilter(), mri_pair_to_complex(), mri_percents(), mri_quantile(), mri_read3D_analyze75(), mri_read_analyze75(), mri_rgb_transform_nD(), mri_rota(), mri_rota_bilinear(), mri_rota_shear(), mri_sharpen(), mri_sharpen_rgb(), mri_shift2D_bilinear(), mri_shift_1D(), mri_sobel(), mri_stat_seq(), mri_to_mri(), mri_warp3d_align_one(), mri_warp3D_align_setup(), mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), mri_warp3D_quintic(), mri_warp_bicubic(), mri_warp_bilinear(), plot_graphs(), plot_image_surface(), PLUTO_register_timeseries(), process_NIML_MRI_IMAGE(), REG_command_line(), T3D_read_images(), text_graphs(), TFIM_getopts(), THD_cmass(), THD_extract_many_series(), UC_read_opts(), VL_command_line(), and VOLREG_main().
00012 { 00013 MRI_IMAGE *newim ; 00014 register int ii , npix ; 00015 00016 ENTRY("mri_to_float") ; 00017 00018 if( oldim == NULL ) RETURN( NULL ) ; /* 09 Feb 1999 */ 00019 00020 newim = mri_new_conforming( oldim , MRI_float ) ; 00021 npix = oldim->nvox ; 00022 00023 switch( oldim->kind ){ 00024 00025 case MRI_byte: 00026 for( ii=0 ; ii < npix ; ii++ ) 00027 newim->im.float_data[ii] = oldim->im.byte_data[ii] ; 00028 break ; 00029 00030 case MRI_short: 00031 for( ii=0 ; ii < npix ; ii++ ) 00032 newim->im.float_data[ii] = oldim->im.short_data[ii] ; 00033 break ; 00034 00035 case MRI_int: 00036 for( ii=0 ; ii < npix ; ii++ ) 00037 newim->im.float_data[ii] = oldim->im.int_data[ii] ; 00038 break ; 00039 00040 case MRI_float: 00041 (void) memcpy( newim->im.float_data , 00042 oldim->im.float_data , sizeof(float) * npix ) ; 00043 break ; 00044 00045 case MRI_double: 00046 for( ii=0 ; ii < npix ; ii++ ) 00047 newim->im.float_data[ii] = oldim->im.double_data[ii] ; 00048 break ; 00049 00050 case MRI_complex: 00051 for( ii=0 ; ii < npix ; ii++ ) 00052 newim->im.float_data[ii] = CABS(oldim->im.complex_data[ii]) ; 00053 break ; 00054 00055 case MRI_rgb:{ /* 11 Feb 1999 */ 00056 byte * rgb = MRI_RGB_PTR(oldim) ; 00057 float * far = MRI_FLOAT_PTR(newim) ; 00058 for( ii=0 ; ii < npix ; ii++ ) /* scale to brightness */ 00059 far[ii] = 0.299 * rgb[3*ii] /* between 0 and 255 */ 00060 + 0.587 * rgb[3*ii+1] 00061 + 0.114 * rgb[3*ii+2] ; 00062 } 00063 break ; 00064 00065 case MRI_rgba:{ /* 15 Apr 2002 */ 00066 byte * rgb = (byte *) MRI_RGBA_PTR(oldim) ; 00067 float * far = MRI_FLOAT_PTR(newim) ; 00068 for( ii=0 ; ii < npix ; ii++ ) /* scale to brightness */ 00069 far[ii] = 0.299 * rgb[4*ii] /* between 0 and 255 */ 00070 + 0.587 * rgb[4*ii+1] 00071 + 0.114 * rgb[4*ii+2] ; 00072 } 00073 break ; 00074 00075 default: 00076 fprintf( stderr , "mri_to_float: unrecognized image kind %d\n",oldim->kind ) ; 00077 MRI_FATAL_ERROR ; 00078 } 00079 00080 MRI_COPY_AUX(newim,oldim) ; 00081 RETURN( newim ); 00082 } |
|
Definition at line 15 of file mri_to_mri.c. References ENTRY, MRI_IMAGE::kind, mri_max(), mri_maxabs(), mri_min(), mri_to_byte(), mri_to_byte_scl(), mri_to_complex(), mri_to_float(), mri_to_rgb(), mri_to_rgba(), mri_to_short(), mri_to_short_scl(), and RETURN. Referenced by AFNI_read_images(), IMREG_main(), ISQ_getimage(), main(), mri_cat2D(), mri_dup2D(), mri_scramble(), mri_warp3D_cubic(), mri_warp3D_linear(), mri_warp3D_NN(), mri_warp3D_quintic(), mri_warp_bicubic(), PH_popup_image(), PLUGIN_imseq_getim(), RCREND_imseq_getim(), and REND_imseq_getim().
00016 { 00017 MRI_IMAGE * newim ; 00018 00019 ENTRY("mri_to_mri") ; 00020 00021 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 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 ) ; /* 11 Feb 1999 */ 00066 break ; 00067 00068 case MRI_rgba: 00069 newim = mri_to_rgba( oldim ) ; /* 20 Mar 2002 */ 00070 break ; 00071 00072 } 00073 RETURN( newim ); 00074 } |
|
Definition at line 81 of file mri_to_mri.c. References ENTRY, complex::i, MRI_COMPLEX_PTR, mri_scale_to_float(), mri_to_byte_scl(), mri_to_complex(), mri_to_short(), MRI_IMAGE::nvox, complex::r, and RETURN. Referenced by main().
00082 { 00083 MRI_IMAGE * newim ; 00084 00085 ENTRY("mri_to_mri_scl") ; 00086 00087 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 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 } |
|
Definition at line 11 of file mri_to_rgb.c. References rgba::b, MRI_DATA::byte_data, ENTRY, MRI_DATA::float_data, rgba::g, MRI_IMAGE::im, MRI_IMAGE::kind, MRI_COPY_AUX, mri_new_conforming, MRI_RGB_PTR, MRI_IMAGE::nvox, rgba::r, RETURN, MRI_DATA::rgba_data, and MRI_DATA::short_data. Referenced by AIVVV_imseq_getim(), ISQ_make_image(), ISQ_make_montage(), ISQ_record_getim(), main(), mri_overlay_2D(), mri_to_mri(), mri_write_angif(), PLUTO_imseq_getim(), RCREND_imseq_getim(), REND_imseq_getim(), and T3D_read_images().
00012 { 00013 MRI_IMAGE *newim ; 00014 register int ii , npix ; 00015 register byte * rgb ; 00016 00017 ENTRY("mri_to_rgb") ; 00018 00019 if( oldim == NULL ) RETURN( NULL ); 00020 00021 newim = mri_new_conforming( oldim , MRI_rgb ) ; rgb = MRI_RGB_PTR(newim) ; 00022 npix = oldim->nvox ; 00023 00024 switch( oldim->kind ){ 00025 00026 case MRI_byte: 00027 for( ii=0 ; ii < npix ; ii++ ) 00028 rgb[3*ii] = rgb[3*ii+1] = rgb[3*ii+2] = oldim->im.byte_data[ii] ; 00029 break ; 00030 00031 case MRI_float: 00032 for( ii=0 ; ii < npix ; ii++ ) 00033 rgb[3*ii] = rgb[3*ii+1] = rgb[3*ii+2] = oldim->im.float_data[ii] ; 00034 break ; 00035 00036 case MRI_short: 00037 for( ii=0 ; ii < npix ; ii++ ) 00038 rgb[3*ii] = rgb[3*ii+1] = rgb[3*ii+2] = oldim->im.short_data[ii] ; 00039 break ; 00040 00041 case MRI_rgb: 00042 memcpy( rgb , MRI_RGB_PTR(oldim) , 3*npix ) ; 00043 break ; 00044 00045 case MRI_rgba: 00046 for( ii=0 ; ii < npix ; ii++ ){ 00047 rgb[3*ii] = oldim->im.rgba_data[ii].r ; 00048 rgb[3*ii+1] = oldim->im.rgba_data[ii].g ; 00049 rgb[3*ii+2] = oldim->im.rgba_data[ii].b ; 00050 } 00051 break ; 00052 00053 default: 00054 fprintf(stderr,"mri_to_rgb: unrecognized image conversion %d\n",oldim->kind) ; 00055 RETURN( NULL ); 00056 } 00057 00058 MRI_COPY_AUX(newim,oldim) ; 00059 RETURN( newim ); 00060 } |
|
Definition at line 5 of file mri_to_rgba.c. References rgba::a, rgba::b, MRI_DATA::byte_data, ENTRY, MRI_DATA::float_data, rgba::g, MRI_IMAGE::im, MRI_IMAGE::kind, MRI_COPY_AUX, mri_new_conforming, MRI_RGBA_PTR, MRI_IMAGE::nvox, rgba::r, RETURN, MRI_DATA::rgb_data, MRI_DATA::rgba_data, and MRI_DATA::short_data. Referenced by mri_to_mri().
00006 { 00007 MRI_IMAGE *newim ; 00008 register int ii , npix ; 00009 register rgba * oar ; 00010 00011 ENTRY("mri_to_rgba") ; 00012 00013 if( oldim == NULL ) RETURN( NULL ); 00014 00015 newim = mri_new_conforming( oldim , MRI_rgba ) ; oar = MRI_RGBA_PTR(newim) ; 00016 npix = oldim->nvox ; 00017 00018 switch( oldim->kind ){ 00019 00020 case MRI_byte: 00021 for( ii=0 ; ii < npix ; ii++ ){ 00022 oar[ii].r = oar[ii].g = oar[ii].b = oldim->im.byte_data[ii] ; 00023 oar[ii].a = 255 ; 00024 } 00025 break ; 00026 00027 case MRI_float: 00028 for( ii=0 ; ii < npix ; ii++ ){ 00029 oar[ii].r = oar[ii].g = oar[ii].b = oldim->im.float_data[ii] ; 00030 oar[ii].a = 255 ; 00031 } 00032 break ; 00033 00034 case MRI_short: 00035 for( ii=0 ; ii < npix ; ii++ ){ 00036 oar[ii].r = oar[ii].g = oar[ii].b = oldim->im.short_data[ii] ; 00037 oar[ii].a = 255 ; 00038 } 00039 break ; 00040 00041 case MRI_rgb: 00042 for( ii=0 ; ii < npix ; ii++ ){ 00043 oar[ii].r = oldim->im.rgb_data[3*ii] ; 00044 oar[ii].g = oldim->im.rgb_data[3*ii+1] ; 00045 oar[ii].b = oldim->im.rgb_data[3*ii+2] ; 00046 oar[ii].a = 255 ; 00047 } 00048 break ; 00049 00050 case MRI_rgba: 00051 memcpy( oar , oldim->im.rgba_data , sizeof(rgba)*npix ) ; 00052 break ; 00053 00054 default: 00055 fprintf(stderr,"mri_to_rgb: unrecognized image conversion %d\n",oldim->kind) ; 00056 RETURN( NULL ); 00057 } 00058 00059 MRI_COPY_AUX(newim,oldim) ; 00060 RETURN( newim ); 00061 } |
|
Definition at line 11 of file mri_to_short.c. References MRI_DATA::byte_data, CABS, MRI_DATA::complex_data, MRI_DATA::double_data, ENTRY, MRI_DATA::float_data, MRI_IMAGE::im, MRI_DATA::int_data, MRI_IMAGE::kind, MRI_COPY_AUX, MRI_FATAL_ERROR, mri_maxabs(), mri_new_conforming, MRI_IMAGE::nvox, RETURN, MRI_DATA::rgb_data, scale, MRI_DATA::short_data, and SHORTIZE. Referenced by main(), mri_brainormalize(), mri_histogram(), mri_percents(), mri_quantile(), mri_read_3A(), mri_threshold(), mri_to_mri(), mri_to_mri_scl(), RT_registration_2D_onevol(), RT_registration_3D_onevol(), T3D_read_images(), THD_cliplevel(), VOLREG_main(), and write_images().
00012 { 00013 MRI_IMAGE *newim ; 00014 register int ii , npix ; 00015 register double scale , val ; 00016 00017 ENTRY("mri_to_short") ; 00018 00019 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 00020 00021 newim = mri_new_conforming( oldim , MRI_short ) ; 00022 npix = oldim->nvox ; 00023 00024 if( scl == 0.0 ){ 00025 switch( oldim->kind ){ 00026 case MRI_int: 00027 case MRI_float: 00028 case MRI_double: 00029 case MRI_complex: 00030 scale = mri_maxabs( oldim ) ; 00031 if( scale != 0.0 ) scale = 10000.0 / scale ; 00032 #ifdef MRI_DEBUG 00033 fprintf( stderr , "mri_to_short: scale factor = %e\n" , scale ) ; 00034 #endif 00035 break ; 00036 00037 default: 00038 scale = 1.0 ; 00039 break ; 00040 } 00041 } else { 00042 scale = scl ; 00043 } 00044 00045 switch( oldim->kind ){ 00046 00047 case MRI_rgb:{ 00048 byte *rgb = oldim->im.rgb_data ; 00049 float rfac=0.299*scale , gfac=0.587*scale , bfac=0.114*scale ; 00050 00051 for( ii=0 ; ii < npix ; ii++ ) 00052 newim->im.short_data[ii] = (short)( rfac * rgb[3*ii] 00053 + gfac * rgb[3*ii+1] 00054 + bfac * rgb[3*ii+2] ) ; 00055 } 00056 break ; 00057 00058 case MRI_byte: 00059 if( scale != 1.0 ) 00060 for( ii=0 ; ii < npix ; ii++ ){ 00061 val = scale * oldim->im.byte_data[ii] ; 00062 newim->im.short_data[ii] = SHORTIZE(val) ; 00063 } 00064 else 00065 for( ii=0 ; ii < npix ; ii++ ) 00066 newim->im.short_data[ii] = (short) oldim->im.byte_data[ii] ; 00067 break ; 00068 00069 case MRI_short: 00070 #ifndef DONT_USE_MEMCPY /* this is a double negative! */ 00071 if( scale != 1.0 ) 00072 #endif 00073 for( ii=0 ; ii < npix ; ii++ ){ 00074 val = scale * oldim->im.short_data[ii] ; 00075 newim->im.short_data[ii] = SHORTIZE(val) ; 00076 } 00077 #ifndef DONT_USE_MEMCPY 00078 else 00079 (void) memcpy( newim->im.short_data , 00080 oldim->im.short_data , sizeof(short)*npix ) ; 00081 #endif 00082 break ; 00083 00084 case MRI_int: 00085 if( scale != 1.0 ) 00086 for( ii=0 ; ii < npix ; ii++ ){ 00087 val = scale * oldim->im.int_data[ii] ; 00088 newim->im.short_data[ii] = SHORTIZE(val) ; 00089 } 00090 else 00091 for( ii=0 ; ii < npix ; ii++ ) 00092 newim->im.short_data[ii] = SHORTIZE(oldim->im.int_data[ii]) ; 00093 break ; 00094 00095 case MRI_float: 00096 if( scale != 1.0 ) 00097 for( ii=0 ; ii < npix ; ii++ ){ 00098 val = scale * oldim->im.float_data[ii] ; 00099 newim->im.short_data[ii] = SHORTIZE(val) ; 00100 } 00101 else 00102 for( ii=0 ; ii < npix ; ii++ ) 00103 newim->im.short_data[ii] = SHORTIZE(oldim->im.float_data[ii]) ; 00104 break ; 00105 00106 case MRI_double: 00107 for( ii=0 ; ii < npix ; ii++ ) 00108 newim->im.short_data[ii] = scale * oldim->im.double_data[ii] ; 00109 break ; 00110 00111 case MRI_complex: 00112 for( ii=0 ; ii < npix ; ii++ ) 00113 newim->im.short_data[ii] = scale * CABS(oldim->im.complex_data[ii]) ; 00114 break ; 00115 00116 default: 00117 fprintf( stderr , "mri_to_short: unrecognized image kind\n" ) ; 00118 MRI_FATAL_ERROR ; 00119 } 00120 00121 MRI_COPY_AUX(newim,oldim) ; 00122 RETURN( newim ); 00123 } |
|
Definition at line 127 of file mri_to_short.c. References mri_to_short_sclip(). Referenced by main(), mri_to_mri(), and T3D_read_images().
00128 { 00129 MRI_IMAGE * im ; 00130 im = mri_to_short_sclip( scl , lev , 0,0 , oldim ) ; 00131 return im ; 00132 } |
|
Definition at line 137 of file mri_to_short.c. References BYTEIZE, CABS, ENTRY, MRI_IMAGE::kind, MRI_COPY_AUX, mri_data_pointer(), MRI_FATAL_ERROR, mri_max(), mri_min(), mri_new_conforming, MRI_IMAGE::nvox, RETURN, scale, SHORTIZE, top, and tt. Referenced by ISQ_process_mri(), and mri_to_short_scl().
00139 { 00140 MRI_IMAGE *newim ; 00141 register int ii , npix ; 00142 double imin,imax ; 00143 register double dscale , dbbot ; 00144 register float scale , flbot , val ; 00145 register short * ar ; 00146 00147 ENTRY("mri_to_short_sclip") ; 00148 00149 if( oldim == NULL ) RETURN( NULL ); /* 09 Feb 1999 */ 00150 00151 newim = mri_new_conforming( oldim , MRI_short ) ; 00152 npix = oldim->nvox ; 00153 00154 if( scl == 0 ){ /* compute scaling to make [min..max] -> [0..lev] */ 00155 00156 imin = (oldim->kind==MRI_complex || oldim->kind==MRI_rgb) ? (0) : mri_min(oldim) ; 00157 imax = mri_max( oldim ) ; 00158 imax = (imax <= imin) ? imin+1 : imax ; 00159 00160 scale = dscale = (lev+0.99) / (imax-imin) ; 00161 flbot = dbbot = imin ; 00162 00163 } else { /* user controlled scaling, with lev -> 0 */ 00164 scale = dscale = scl ; 00165 flbot = dbbot = lev ; 00166 } 00167 00168 ar = mri_data_pointer( newim ) ; /* fast access to data */ 00169 00170 switch( oldim->kind ){ 00171 00172 case MRI_rgb:{ 00173 register byte * rgb = mri_data_pointer(oldim) ; 00174 float rfac=0.299*scale , gfac=0.587*scale , bfac=0.114*scale ; 00175 for( ii=0 ; ii < npix ; ii++ ) 00176 ar[ii] = (short) ( rfac * rgb[3*ii] 00177 + gfac * rgb[3*ii+1] 00178 + bfac * rgb[3*ii+2] ) ; 00179 } 00180 break ; 00181 00182 case MRI_byte:{ 00183 register byte * oar = mri_data_pointer(oldim) ; 00184 for( ii=0 ; ii < npix ; ii++ ){ 00185 val = scale * (oar[ii]-flbot) ; 00186 ar[ii] = BYTEIZE(val) ; 00187 } 00188 break ; 00189 } 00190 00191 case MRI_short:{ 00192 register short * oar = mri_data_pointer(oldim) ; 00193 for( ii=0 ; ii < npix ; ii++ ){ 00194 val = scale * (oar[ii]-flbot) ; 00195 ar[ii] = SHORTIZE(val) ; 00196 } 00197 break ; 00198 } 00199 00200 case MRI_int:{ 00201 register int * oar = mri_data_pointer(oldim) ; 00202 for( ii=0 ; ii < npix ; ii++ ) 00203 ar[ii] = scale * (oar[ii]-flbot) ; 00204 break ; 00205 } 00206 00207 case MRI_float:{ 00208 register float * oar = mri_data_pointer(oldim) ; 00209 for( ii=0 ; ii < npix ; ii++ ) 00210 ar[ii] = scale * (oar[ii]-flbot) ; 00211 break ; 00212 } 00213 00214 case MRI_double:{ 00215 register double * oar = mri_data_pointer(oldim) ; 00216 for( ii=0 ; ii < npix ; ii++ ) 00217 ar[ii] = dscale * (oar[ii]-dbbot) ; 00218 break ; 00219 } 00220 00221 case MRI_complex:{ 00222 register complex * oar = mri_data_pointer(oldim) ; 00223 for( ii=0 ; ii < npix ; ii++ ) 00224 ar[ii] = scale * CABS(oar[ii]) ; 00225 break ; 00226 } 00227 00228 default: 00229 fprintf( stderr , "mri_to_short_scl: unrecognized image kind\n" ) ; 00230 MRI_FATAL_ERROR ; 00231 } 00232 00233 /* clip, if desired */ 00234 00235 if( bot < top ){ 00236 register short bb = bot , tt = top ; 00237 for( ii=0 ; ii < npix ; ii++ ){ 00238 if( ar[ii] < bb ) ar[ii] = bb ; 00239 else if( ar[ii] > tt ) ar[ii] = tt ; 00240 } 00241 } 00242 00243 MRI_COPY_AUX(newim,oldim) ; 00244 RETURN( newim ); 00245 } |
|
Definition at line 150 of file mri_transpose.c. References MRI_IMAGE::kind, mri_transpose_byte(), mri_transpose_complex(), mri_transpose_float(), mri_transpose_int(), mri_transpose_rgbyte(), and mri_transpose_short(). Referenced by GRA_refwrite_choose_CB(), main(), mri_read_1D(), mri_read_ascii(), mri_write_1D(), read_sxyz_1D(), sdata_from_1D(), THD_load_1D(), THD_open_1D(), and UC_read_opts().
00151 { 00152 if( im == NULL ) return NULL ; 00153 00154 switch( im->kind ){ 00155 case MRI_float : return mri_transpose_float (im) ; 00156 case MRI_short : return mri_transpose_short (im) ; 00157 case MRI_byte : return mri_transpose_byte (im) ; 00158 case MRI_int : return mri_transpose_int (im) ; 00159 case MRI_complex: return mri_transpose_complex(im) ; 00160 case MRI_rgb: return mri_transpose_rgbyte (im) ; 00161 } 00162 return NULL ; 00163 } |
|
Definition at line 15 of file mri_uncat2D.c. References ADDTO_IMARR, ENTRY, INIT_IMARR, MRI_IMAGE::kind, mri_cut_2D(), MRI_IMAGE::nx, nxim, MRI_IMAGE::ny, nyim, and RETURN. Referenced by main().
00016 { 00017 MRI_IMARR * imar ; 00018 MRI_IMAGE * qim ; 00019 int nxim , nyim , ii,jj,kk , kind ; 00020 00021 ENTRY("mri_uncat2D") ; 00022 00023 if( nx < 1 || ny < 1 || im == NULL ) RETURN(NULL) ; 00024 00025 kind = im->kind ; 00026 00027 nxim = im->nx / nx ; 00028 nyim = im->ny / ny ; 00029 if( nxim < 1 || nyim < 1 ) RETURN(NULL) ; 00030 00031 INIT_IMARR(imar) ; 00032 00033 for( jj=0 ; jj < nyim ; jj++ ){ 00034 for( ii=0 ; ii < nxim ; ii++ ){ 00035 qim = mri_cut_2D( im , ii*nx , (ii+1)*nx-1 , jj*ny , (jj+1)*ny-1 ) ; 00036 if( qim != NULL ) ADDTO_IMARR(imar,qim) ; 00037 else fprintf(stderr,"mri_uncat2D: NULL image error!\n") ; 00038 } 00039 } 00040 00041 RETURN(imar) ; 00042 } |
|
Definition at line 35 of file mri_warp.c. References MRI_BICUBIC, MRI_BILINEAR, MRI_FATAL_ERROR, mri_warp_bicubic(), and mri_warp_bilinear(). Referenced by mri_resize().
00037 { 00038 switch( wtype ){ 00039 case MRI_BILINEAR: 00040 return mri_warp_bilinear( im , nxnew , nynew , wfunc ) ; 00041 00042 case MRI_BICUBIC: 00043 return mri_warp_bicubic( im , nxnew , nynew , wfunc ) ; 00044 00045 default: 00046 fprintf( stderr , "mri_warp: illegal wtype %d\n" , wtype ) ; 00047 MRI_FATAL_ERROR ; 00048 } 00049 return NULL ; 00050 } |
|
Referenced by mri_brainormalize(), mri_warp3D_affine(), mri_warp3D_align_fitim(), mri_warp3d_align_one(), mri_warp3D_resize(), and THD_warp3D(). |
|
Special image warp for affine transformation of indices. ---------------------------------------------------------------------------- Definition at line 855 of file mri_warp3D.c. References a11_aff, a12_aff, a13_aff, a14_aff, a21_aff, a22_aff, a23_aff, a24_aff, a31_aff, a32_aff, a33_aff, a34_aff, THD_mat33::mat, THD_vecmat::mm, mri_warp3D(), THD_vecmat::vv, w3dMRI_scaler(), and THD_fvec3::xyz.
00856 { 00857 if( im == NULL ) return NULL ; 00858 00859 a11_aff = aff.mm.mat[0][0] ; a12_aff = aff.mm.mat[0][1] ; 00860 a13_aff = aff.mm.mat[0][2] ; a14_aff = aff.vv.xyz[0] ; 00861 00862 a21_aff = aff.mm.mat[1][0] ; a22_aff = aff.mm.mat[1][1] ; 00863 a23_aff = aff.mm.mat[1][2] ; a24_aff = aff.vv.xyz[1] ; 00864 00865 a31_aff = aff.mm.mat[2][0] ; a32_aff = aff.mm.mat[2][1] ; 00866 a33_aff = aff.mm.mat[2][2] ; a34_aff = aff.vv.xyz[2] ; 00867 00868 return mri_warp3D( im , 0,0,0 , w3dMRI_scaler ) ; 00869 } |
|
mri_warp3D.c functions: 14 Apr 2003 Referenced by mri_warp3D(), and mri_warp3D_cubic(). |
|
Referenced by mri_warp3D(), and mri_warp3D_linear(). |
|
Definition at line 12 of file mri_warp3D.c. References wtype. Referenced by main(), mri_brainormalize(), mri_warp3D_align_fitim(), and mri_warp3d_align_one().
00012 { wtype = mode ; } /** set interpolation **/ |
|
Referenced by mri_warp3D(), and mri_warp3D_NN(). |
|
Referenced by mri_warp3D(), and mri_warp3D_quintic(). |
|
Special image warp just for resizing. ---------------------------------------------------------------------------- Definition at line 805 of file mri_warp3D.c. References MAX, mri_warp3D(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, nz, sx_scale, sy_scale, sz_scale, and w3dMRI_scaler().
00806 { 00807 int nx,ny,nz , nnx,nny,nnz ; 00808 00809 if( im == NULL ) return NULL ; 00810 nx = im->nx ; ny = im->ny ; nz = im->nz ; 00811 nnx = nxnew ; nny = nynew ; nnz = nznew ; 00812 00813 if( nnx <= 0 && nny <= 0 && nnz <= 0 ) return NULL ; 00814 00815 sx_scale = (nnx > 0) ? ((float)nx)/nnx : 0.0 ; /* global variables */ 00816 sy_scale = (nny > 0) ? ((float)ny)/nny : 0.0 ; 00817 sz_scale = (nnz > 0) ? ((float)nz)/nnz : 0.0 ; 00818 00819 if( nnx <= 0 ){ 00820 sx_scale = MAX(sy_scale,sz_scale) ; 00821 nnx = rint(sx_scale*nx) ; 00822 } 00823 if( nny <= 0 ){ 00824 sy_scale = MAX(sx_scale,sz_scale) ; 00825 nny = rint(sy_scale*ny) ; 00826 } 00827 if( nnz <= 0 ){ 00828 sz_scale = MAX(sx_scale,sy_scale) ; 00829 nnz = rint(sz_scale*nz) ; 00830 } 00831 00832 return mri_warp3D( im , nnx,nny,nnz , w3dMRI_scaler ) ; 00833 } |
|
Definition at line 18 of file mri_warp3D.c. References MRI_IMAGE::kind, MRI_BYTE_PTR, and womask. Referenced by mri_warp3D_align_fitim(), and mri_warp3d_align_one().
00019 { 00020 womask = (wim == NULL || wim->kind != MRI_byte) ? NULL 00021 : MRI_BYTE_PTR(wim) ; 00022 } |
|
Definition at line 29 of file mri_warp3D.c. References zout.
|
|
Definition at line 158 of file mri_warp.c. References DESTROY_IMARR, far, FINS, IMARR_SUBIM, MRI_IMAGE::kind, mri_3to_rgb(), mri_data_pointer(), mri_free(), mri_new(), mri_rgb_to_3float(), mri_to_float(), mri_to_mri(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, P_00, P_M1, P_P1, P_P2, and top. Referenced by mri_resize(), mri_rotate(), and mri_warp().
00160 { 00161 MRI_IMAGE *imfl , *newImg ; 00162 float *far , *nar ; 00163 float xpr,ypr , xx,yy , fx,fy ; 00164 int ii,jj, nx,ny , ix,jy ; 00165 float f_jm1,f_j00,f_jp1,f_jp2 , wt_m1,wt_00,wt_p1,wt_p2 ; 00166 float bot,top,val ; /* 29 Mar 2003 */ 00167 00168 nx = im->nx ; /* input image dimensions, for convenience */ 00169 ny = im->ny ; 00170 00171 nxnew = (nxnew > 0) ? nxnew : nx ; /* default output image sizes */ 00172 nynew = (nynew > 0) ? nynew : ny ; 00173 00174 switch( im->kind ){ /* 29 Mar 2003: allow for different input types */ 00175 /* by doing components 1 at a time */ 00176 case MRI_float: 00177 imfl = im ; break ; 00178 00179 default: 00180 imfl = mri_to_float(im) ; break ; 00181 00182 case MRI_short:{ 00183 imfl = mri_to_float(im) ; 00184 newImg = mri_warp_bicubic( imfl , nxnew,nynew , wf ) ; 00185 mri_free(imfl) ; 00186 imfl = mri_to_mri(MRI_short,newImg) ; 00187 mri_free(newImg) ; return imfl ; 00188 } 00189 00190 case MRI_byte:{ 00191 imfl = mri_to_float(im) ; 00192 newImg = mri_warp_bicubic( imfl , nxnew,nynew , wf ) ; 00193 mri_free(imfl) ; 00194 imfl = mri_to_mri(MRI_byte,newImg) ; 00195 mri_free(newImg) ; return imfl ; 00196 } 00197 00198 case MRI_rgb:{ 00199 MRI_IMARR *imar = mri_rgb_to_3float(im) ; 00200 MRI_IMAGE *rim,*gim,*bim ; 00201 rim = mri_warp_bicubic( IMARR_SUBIM(imar,0), nxnew,nynew, wf ) ; 00202 gim = mri_warp_bicubic( IMARR_SUBIM(imar,1), nxnew,nynew, wf ) ; 00203 bim = mri_warp_bicubic( IMARR_SUBIM(imar,2), nxnew,nynew, wf ) ; 00204 DESTROY_IMARR(imar) ; 00205 newImg = mri_3to_rgb( rim,gim,bim ) ; 00206 mri_free(rim); mri_free(gim); mri_free(bim); return newImg; 00207 } 00208 00209 } 00210 00211 /* at this point, imfl is in MRI_float format */ 00212 00213 far = mri_data_pointer( imfl ) ; /* easy access to float data */ 00214 00215 newImg = mri_new( nxnew , nynew , MRI_float ) ; /* output image */ 00216 nar = mri_data_pointer( newImg ) ; /* output image data */ 00217 00218 bot = top = far[0] ; /* 29 Mar 2003: */ 00219 for( ii=1 ; ii < imfl->nvox ; ii++ ){ /* clip output data range */ 00220 if( far[ii] > top ) top = far[ii] ; 00221 else if( far[ii] < bot ) bot = far[ii] ; 00222 } 00223 00224 /*** loop over output points and warp to them ***/ 00225 00226 for( jj=0 ; jj < nynew ; jj++ ){ 00227 ypr = jj ; 00228 for( ii=0 ; ii < nxnew ; ii++ ){ 00229 xpr = ii ; 00230 wf( xpr,ypr , &xx,&yy ) ; /* get xx,yy in original image */ 00231 00232 ix = floor( xx ) ; fx = xx - ix ; /* integer and */ 00233 jy = floor( yy ) ; fy = yy - jy ; /* fractional coords */ 00234 00235 /* define cubic interpolation polynomials and data from original grid */ 00236 00237 #define P_M1(x) (-(x)*((x)-1)*((x)-2)) 00238 #define P_00(x) (3*((x)+1)*((x)-1)*((x)-2)) 00239 #define P_P1(x) (-3*(x)*((x)+1)*((x)-2)) 00240 #define P_P2(x) ((x)*((x)+1)*((x)-1)) 00241 00242 wt_m1 = P_M1(fx) ; wt_00 = P_00(fx) ; /* weights for interpolating */ 00243 wt_p1 = P_P1(fx) ; wt_p2 = P_P2(fx) ; /* in the x-direction */ 00244 00245 f_jm1 = wt_m1 * FINS(ix-1,jy-1) /* interpolate to ix + fx */ 00246 + wt_00 * FINS(ix ,jy-1) /* at levels jy-1 .. jy+2 */ 00247 + wt_p1 * FINS(ix+1,jy-1) 00248 + wt_p2 * FINS(ix+2,jy-1) ; 00249 00250 f_j00 = wt_m1 * FINS(ix-1,jy) 00251 + wt_00 * FINS(ix ,jy) 00252 + wt_p1 * FINS(ix+1,jy) 00253 + wt_p2 * FINS(ix+2,jy) ; 00254 00255 f_jp1 = wt_m1 * FINS(ix-1,jy+1) 00256 + wt_00 * FINS(ix ,jy+1) 00257 + wt_p1 * FINS(ix+1,jy+1) 00258 + wt_p2 * FINS(ix+2,jy+1) ; 00259 00260 f_jp2 = wt_m1 * FINS(ix-1,jy+2) 00261 + wt_00 * FINS(ix ,jy+2) 00262 + wt_p1 * FINS(ix+1,jy+2) 00263 + wt_p2 * FINS(ix+2,jy+2) ; 00264 00265 /* interpolate between y-levels to jy+fy */ 00266 00267 val = ( P_M1(fy) * f_jm1 + P_00(fy) * f_j00 00268 + P_P1(fy) * f_jp1 + P_P2(fy) * f_jp2 ) / 36.0 ; 00269 00270 if( val > top ) val = top ; /* 29 Mar 2003 */ 00271 else if( val < bot ) val = bot ; 00272 00273 nar[ii+jj*nxnew] = val ; 00274 } 00275 } 00276 00277 /*** cleanup and return ***/ 00278 00279 if( im != imfl ) mri_free(imfl) ; /* throw away unneeded workspace */ 00280 return newImg ; 00281 } |
|
Definition at line 285 of file mri_warp.c. References far, FINS, MRI_IMAGE::kind, mri_data_pointer(), mri_free(), mri_new(), mri_to_float(), MRI_IMAGE::nx, and MRI_IMAGE::ny. Referenced by mri_rotate_bilinear(), and mri_warp().
00287 { 00288 MRI_IMAGE *imfl , *newImg ; 00289 float *far , *nar ; 00290 float xpr,ypr , xx,yy , fx,fx1,fy,fy1 , f00,f10,f01,f11 ; 00291 int ii,jj, nx,ny , ix,jy ; 00292 00293 nx = im->nx ; /* dimensions, for convenience */ 00294 ny = im->ny ; 00295 00296 nxnew = (nxnew > 0) ? nxnew : nx ; /* default output image sizes */ 00297 nynew = (nynew > 0) ? nynew : ny ; 00298 00299 if( im->kind == MRI_float ){ /* convert input to float, if needed */ 00300 imfl = im ; 00301 } else { 00302 imfl = mri_to_float( im ) ; 00303 } 00304 far = mri_data_pointer( imfl ) ; /* easy access to float data */ 00305 00306 newImg = mri_new( nxnew , nynew , MRI_float ) ; /* output image */ 00307 nar = mri_data_pointer( newImg ) ; /* output image data */ 00308 00309 /*** loop over output points and warp to them ***/ 00310 00311 for( jj=0 ; jj < nynew ; jj++ ){ 00312 ypr = jj ; 00313 for( ii=0 ; ii < nxnew ; ii++ ){ 00314 xpr = ii ; 00315 wf( xpr,ypr , &xx,&yy ) ; /* get xx,yy in original image */ 00316 00317 ix = floor( xx ) ; fx = xx - ix ; fx1 = 1.0 - fx ; 00318 jy = floor( yy ) ; fy = yy - jy ; fy1 = 1.0 - fy ; 00319 00320 f00 = FINS(ix ,jy ) ; 00321 f01 = FINS(ix+1,jy ) ; 00322 f10 = FINS(ix ,jy+1) ; 00323 f11 = FINS(ix+1,jy+1) ; 00324 00325 nar[ii+jj*nxnew] = fx1 * ( fy1 * f00 + fy * f01 ) 00326 +fx * ( fy1 * f10 + fy * f11 ) ; 00327 00328 } 00329 } 00330 00331 /*** cleanup and return ***/ 00332 00333 if( im != imfl ) mri_free(imfl) ; /* throw away unneeded workspace */ 00334 return newImg ; 00335 } |
|
Definition at line 15 of file mri_write.c. References ENTRY, free, MRI_IMAGE::kind, malloc, mri_data_pointer(), MRI_IS_2D, mri_write_7D(), mri_write_pnm(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::pixel_size, and RETURN. Referenced by AB_interp(), get_line_opt(), ISQ_saver_CB(), main(), SFIM_write_avs(), and write_images().
00016 { 00017 FILE *imfile ; 00018 void *data ; 00019 int dsize , noheader = FALSE ; 00020 00021 ENTRY("mri_write") ; 00022 00023 /* bad inputs? */ 00024 00025 if( im == NULL || fname == NULL || *fname == '\0' ) RETURN(0) ; 00026 00027 /* special cases */ 00028 00029 if( ! MRI_IS_2D(im) ){ RETURN(mri_write_7D ( fname , im )) ; } 00030 if( im->kind == MRI_rgb ){ RETURN(mri_write_pnm( fname , im )) ; } 00031 if( im->kind == MRI_byte ){ RETURN(mri_write_pnm( fname , im )) ; } 00032 00033 /* open the file for output */ 00034 00035 if( strcmp(fname,"-") != 0 ){ 00036 imfile = fopen( fname , "r" ) ; 00037 if( imfile != NULL ){ 00038 fclose( imfile ) ; 00039 fprintf(stderr,"(FAILED) attempt to overwrite file %s\n",fname) ; 00040 RETURN(0) ; 00041 } 00042 } 00043 00044 if( strcmp(fname,"-") != 0 ) 00045 imfile = fopen( fname , "w" ) ; 00046 else 00047 imfile = stdout ; /* 18 Apr 2005: write to stdout instead */ 00048 00049 if( imfile == NULL ){ 00050 fprintf( stderr , "couldn't open for output file %s\n" , fname ) ; 00051 RETURN(0) ; 00052 } 00053 00054 /*** possibly write MRI header, unless a standard image type ***/ 00055 00056 dsize = im->pixel_size * im->nx * im->ny ; 00057 00058 if( im->kind == MRI_short ){ 00059 switch( dsize ){ 00060 default: noheader = FALSE ; break ; 00061 00062 case 8192: /* raw 64x64 short */ 00063 case 32768: /* raw 128x128 short */ 00064 case 131072: /* raw 256x256 short */ 00065 case 524288: /* raw 512x512 short -- RWC 3/21/95 */ 00066 case 2097152: /* raw 1024x1024 short -- RWC 3/21/95 */ 00067 noheader = TRUE ; 00068 break ; 00069 } 00070 } else if( im->kind == MRI_byte ){ 00071 switch( dsize ){ 00072 default: noheader = FALSE ; break ; 00073 00074 case 4096: /* raw 64x64 byte -- RWC 3/21/95 */ 00075 case 16384: /* raw 128x128 byte -- RWC 3/21/95 */ 00076 case 65536: /* raw 256x256 8-bit -- Matthew Belmonte March 1995 */ 00077 case 262144: /* raw 512x512 byte -- RWC 3/21/95 */ 00078 case 1048576: /* raw 1024x1024 byte -- RWC 3/21/95 */ 00079 noheader = TRUE ; 00080 break ; 00081 } 00082 } 00083 00084 if( !noheader ) fprintf( imfile , "MRI %d %d %d\n" , 00085 im->kind , im->nx , im->ny ) ; 00086 00087 /*** special case: add Signa 4.x header (of all zeros) ***/ 00088 00089 if( noheader && dsize == 131072 && im->kind == MRI_short ){ 00090 #define HEADER (28*256) 00091 int ii ; 00092 short * qq ; 00093 qq = (short *) malloc(sizeof(short)*HEADER) ; /* header 256 x 256 */ 00094 for( ii=0 ; ii < HEADER ; ii++ ) qq[ii] = 0 ; 00095 fwrite( qq , sizeof(short) , HEADER , imfile ) ; 00096 free(qq) ; 00097 } 00098 00099 /*** write rest of data now ***/ 00100 00101 data = mri_data_pointer( im ) ; 00102 fwrite( data , im->pixel_size , im->nx * im->ny , imfile ) ; 00103 00104 if( imfile != stdout ) fclose( imfile ) ; 00105 RETURN(1) ; 00106 } |
|
Definition at line 239 of file mri_write.c. References ENTRY, fim, mri_free(), mri_transpose(), mri_write_ascii(), MRI_IMAGE::nz, and RETURN. Referenced by GRA_handle_keypress(), GRA_refwrite_choose_CB(), main(), MASKAVE_main(), and process_1ddata().
00240 { 00241 MRI_IMAGE *fim ; 00242 int jj ; 00243 00244 ENTRY("mri_write_1D") ; 00245 00246 if( fname == NULL || strlen(fname) == 0 || 00247 im == NULL || im->nz > 1 ) RETURN( 0 ); 00248 00249 fim = mri_transpose( im ) ; 00250 jj = mri_write_ascii( fname , fim ) ; 00251 mri_free(fim) ; 00252 RETURN( jj ); 00253 } |
|
Definition at line 110 of file mri_write.c. References ENTRY, MRI_IMAGE::kind, mri_data_pointer(), MRI_DIMENSIONALITY, MRI_IMAGE::nt, MRI_IMAGE::nu, MRI_IMAGE::nv, MRI_IMAGE::nvox, MRI_IMAGE::nw, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, MRI_IMAGE::pixel_size, and RETURN. Referenced by mri_write().
00111 { 00112 FILE *imfile ; 00113 void *data ; 00114 00115 ENTRY("mri_write_7D") ; 00116 00117 if( im == NULL ) RETURN( 0 ); 00118 00119 imfile = fopen( fname , "r" ) ; 00120 if( imfile != NULL ){ 00121 fclose( imfile ) ; 00122 fprintf(stderr,"(FAILED) attempt to overwrite file %s\n",fname) ; 00123 RETURN( 0 ); 00124 } 00125 00126 imfile = fopen( fname , "w" ) ; 00127 00128 if( imfile == NULL ){ 00129 fprintf( stderr , "couldn't open for output file %s\n" , fname ) ; 00130 RETURN( 0 ); 00131 } 00132 00133 /*** write MR7 header ***/ 00134 00135 switch( MRI_DIMENSIONALITY(im) ){ 00136 default: 00137 case 1: 00138 fprintf( imfile , "MR1 %d %d\n" , 00139 im->kind , im->nx ) ; 00140 break ; 00141 00142 case 2: 00143 fprintf( imfile , "MR2 %d %d %d\n" , 00144 im->kind , im->nx,im->ny ) ; 00145 break ; 00146 00147 case 3: 00148 fprintf( imfile , "MR2 %d %d %d %d\n" , 00149 im->kind , im->nx,im->ny,im->nz ) ; 00150 break ; 00151 00152 case 4: 00153 fprintf( imfile , "MR2 %d %d %d %d %d\n" , 00154 im->kind , im->nx,im->ny,im->nz,im->nt ) ; 00155 break ; 00156 00157 case 5: 00158 fprintf( imfile , "MR2 %d %d %d %d %d %d\n" , 00159 im->kind , im->nx,im->ny,im->nz,im->nt,im->nu ) ; 00160 break ; 00161 00162 case 6: 00163 fprintf( imfile , "MR2 %d %d %d %d %d %d %d\n" , 00164 im->kind , im->nx,im->ny,im->nz,im->nt,im->nu,im->nv ) ; 00165 break ; 00166 00167 case 7: 00168 fprintf( imfile , "MR2 %d %d %d %d %d %d %d %d\n" , 00169 im->kind , im->nx,im->ny,im->nz,im->nt,im->nu,im->nv,im->nw ) ; 00170 break ; 00171 } 00172 00173 /*** write rest of data now ***/ 00174 00175 data = mri_data_pointer( im ) ; 00176 fwrite( data , im->pixel_size , im->nvox , imfile ) ; 00177 fclose( imfile ) ; 00178 00179 RETURN( 1 ); 00180 } |
|
Definition at line 90 of file mri_write_analyze.c. References AFMALL, AFNI_yesenv(), ANDT_COMPLEX, ANDT_DOUBLE, ANDT_FLOAT, ANDT_RGB, ANDT_SIGNED_INT, ANDT_SIGNED_SHORT, ANDT_UNSIGNED_CHAR, image_dimension::bitpix, image_dimension::datatype, header_key::db_name, data_history::descrip, image_dimension::dim, dsr::dime, MRI_IMAGE::dt, MRI_IMAGE::du, MRI_IMAGE::dv, MRI_IMAGE::dw, MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, free, image_dimension::funused1, image_dimension::glmax, image_dimension::glmin, dsr::hist, dsr::hk, MRI_IMAGE::kind, mri_data_pointer(), MRI_DIMENSIONALITY, mri_max(), mri_min(), MRI_IMAGE::nt, MRI_IMAGE::nu, MRI_IMAGE::nv, MRI_IMAGE::nvox, MRI_IMAGE::nw, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, data_history::originator, image_dimension::pixdim, MRI_IMAGE::pixel_size, header_key::regular, header_key::sizeof_hdr, MRI_IMAGE::xo, MRI_IMAGE::yo, and MRI_IMAGE::zo. Referenced by main().
00091 { 00092 struct dsr hdr ; /* ANALYZE .hdr */ 00093 void *ip ; 00094 FILE *fp ; 00095 char *fff ; 00096 00097 ENTRY("mri_write_analyze") ; 00098 00099 /*-- check inputs for sanity --*/ 00100 00101 if( fname == NULL || fname[0] == '\0' || im == NULL ) EXRETURN ; 00102 ip = mri_data_pointer(im) ; 00103 00104 /*-- clear header --*/ 00105 00106 memset( &hdr , 0 , sizeof(struct dsr) ) ; 00107 00108 /*-- set random header stuff --*/ 00109 00110 hdr.hk.sizeof_hdr = sizeof(struct dsr) ; 00111 hdr.hk.regular = 'r' ; 00112 00113 sprintf( hdr.hk.db_name , "%.17s" , fname ) ; 00114 #if 0 00115 sprintf( hdr.hist.descrip , "via AFNI: %.68s" , fname ) ; 00116 #endif 00117 00118 /*-- set data dimensions --*/ 00119 00120 hdr.dime.dim[0] = MRI_DIMENSIONALITY(im) ; 00121 hdr.dime.dim[1] = im->nx ; hdr.dime.pixdim[1] = im->dx ; 00122 hdr.dime.dim[2] = im->ny ; hdr.dime.pixdim[2] = im->dy ; 00123 hdr.dime.dim[3] = im->nz ; hdr.dime.pixdim[3] = im->dz ; 00124 hdr.dime.dim[4] = im->nt ; hdr.dime.pixdim[4] = im->dt ; 00125 hdr.dime.dim[5] = im->nu ; hdr.dime.pixdim[5] = im->du ; 00126 hdr.dime.dim[6] = im->nv ; hdr.dime.pixdim[6] = im->dv ; 00127 hdr.dime.dim[7] = im->nw ; hdr.dime.pixdim[7] = im->dw ; 00128 00129 hdr.dime.funused1 = 1.0 ; /* SPM scale factor */ 00130 00131 /*-- set data type --*/ 00132 00133 switch( im->kind ){ 00134 00135 default: EXRETURN ; /* bad */ 00136 00137 case MRI_byte: hdr.dime.datatype = ANDT_UNSIGNED_CHAR; break; 00138 case MRI_short: hdr.dime.datatype = ANDT_SIGNED_SHORT ; break; 00139 case MRI_int: hdr.dime.datatype = ANDT_SIGNED_INT ; break; 00140 case MRI_float: hdr.dime.datatype = ANDT_FLOAT ; break; 00141 case MRI_complex: hdr.dime.datatype = ANDT_COMPLEX ; break; 00142 case MRI_double: hdr.dime.datatype = ANDT_DOUBLE ; break; 00143 case MRI_rgb: hdr.dime.datatype = ANDT_RGB ; break; 00144 } 00145 00146 hdr.dime.bitpix = 8*im->pixel_size ; 00147 00148 if( ip != NULL ){ 00149 hdr.dime.glmin = mri_min( im ) ; 00150 hdr.dime.glmax = mri_max( im ) ; 00151 } else { 00152 hdr.dime.glmin = 0.0 ; 00153 hdr.dime.glmax = 0.0 ; 00154 } 00155 00156 /*--KRH 03/11/04 writing out originator field from AFNI origin--*/ 00157 /*- adding 1.5 to value for rounding (+0.5) and conversion */ 00158 /* to 1-based matlab arrays (+1.0) - */ 00159 /*--change abs() to -() 25 Mar 2004 [rickr] */ 00160 00161 if( AFNI_yesenv("AFNI_ANALYZE_ORIGINATOR") ){ 00162 short xyzuv[5] = {0}; 00163 xyzuv[0] = -im->xo/im->dx + 1.5; 00164 xyzuv[1] = -im->yo/im->dy + 1.5; 00165 xyzuv[2] = -im->zo/im->dz + 1.5; 00166 memcpy( hdr.hist.originator, xyzuv, 10 ); 00167 } 00168 00169 /*-- write header --*/ 00170 00171 fff = AFMALL(char, strlen(fname)+16 ) ; 00172 00173 sprintf(fff,"%s.hdr",fname) ; 00174 fp = fopen( fff , "wb" ) ; 00175 if( fp == NULL ){ 00176 fprintf(stderr,"** Can't open file %s for output!\n",fff) ; 00177 free(fff) ; EXRETURN ; 00178 } 00179 fwrite( &hdr , sizeof(struct dsr) , 1 , fp ) ; 00180 fclose(fp) ; 00181 00182 if( ip == NULL ){ /* 30 Sep 2002: skip .img if data not present */ 00183 free(fff); EXRETURN; 00184 } 00185 00186 /*-- write image --*/ 00187 00188 sprintf(fff,"%s.img",fname) ; 00189 fp = fopen( fff , "wb" ) ; 00190 if( fp == NULL ){ 00191 fprintf(stderr,"** Can't open file %s for output!\n",fff) ; 00192 free(fff) ; EXRETURN ; 00193 } 00194 fwrite( ip , im->nvox , im->pixel_size , fp ) ; 00195 fclose(fp) ; 00196 00197 free(fff) ; EXRETURN ; 00198 } |
|
Definition at line 50 of file mri_write_angif.c. References ganim, gfilt, IMARR_COUNT, IMARR_SUBIMAGE, MRI_IMAGE::kind, mri_free(), MRI_RGB_PTR, mri_to_rgb(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, pclose, popen, setup, and setup_mri_write_angif().
00051 { 00052 char gnam[32] , gt[16] , filt[512] ; 00053 MRI_IMAGE *tim , *qim ; 00054 int ii , nim ; 00055 FILE *fp ; 00056 00057 /*-- sanity check --*/ 00058 00059 if( fname == NULL || fname[0] == '\0' || 00060 imar == NULL || IMARR_COUNT(imar) < 2 ) return 0 ; 00061 00062 if( setup < 0 ) setup_mri_write_angif() ; 00063 if( setup == 0 ) return 0 ; 00064 00065 /*-- make individual gifs from each file --*/ 00066 00067 nim = IMARR_COUNT(imar) ; 00068 00069 sprintf(gt,"%x",(unsigned int)imar) ; gt[5] = '\0' ; 00070 00071 for( ii=0 ; ii < nim ; ii++ ){ 00072 sprintf(gnam,"Elvis%s.%05d.gif",gt,ii) ; 00073 00074 tim = IMARR_SUBIMAGE(imar,ii) ; if( tim == NULL ) continue ; 00075 qim = tim ; 00076 if( tim->kind != MRI_rgb ) qim = mri_to_rgb( tim ) ; 00077 00078 sprintf( filt , gfilt , gnam ) ; 00079 fp = popen( filt , "w" ) ; 00080 if( fp == NULL ){ 00081 fprintf(stderr,"** Can't open output filter %s\n",filt) ; 00082 return 0 ; 00083 } 00084 00085 fprintf(fp,"P6\n%d %d\n255\n" , qim->nx,qim->ny ) ; 00086 fwrite( MRI_RGB_PTR(qim), sizeof(byte), 3*qim->nvox, fp ) ; 00087 pclose(fp) ; 00088 00089 if( qim != tim ) mri_free(qim) ; 00090 } 00091 00092 /*-- make the animated gif output --*/ 00093 00094 sprintf( filt , "%s Elvis.%s.*.gif > %s" , ganim , gt , fname ) ; 00095 system( filt ) ; 00096 00097 /*-- remove individual gif files --*/ 00098 00099 for( ii=0 ; ii < nim ; ii++ ){ 00100 sprintf(gnam,"Elvis%s.%05d.gif",gt,ii) ; 00101 remove(gnam) ; 00102 } 00103 00104 return 1 ; /* indicate success */ 00105 } |
|
------------------------ Only good for 1D and 2D images ---------------------------* Definition at line 257 of file mri_write.c. References ENTRY, i, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COMPLEX_PTR, MRI_DOUBLE_PTR, MRI_FLOAT_PTR, MRI_INT_PTR, MRI_RGB_PTR, MRI_SHORT_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, r, and RETURN. Referenced by GRA_refwrite_choose_CB(), main(), and mri_write_1D().
00258 { 00259 int ii , jj , nx , ny ; 00260 FILE *imfile ; 00261 00262 ENTRY("mri_write_ascii") ; 00263 00264 if( fname == NULL || strlen(fname) == 0 || 00265 im == NULL || im->nz > 1 ) RETURN( 0 ); 00266 00267 if( strcmp(fname,"-") == 0 ){ 00268 imfile = stdout ; 00269 } else { 00270 imfile = fopen( fname , "r" ) ; 00271 if( imfile != NULL ){ 00272 fclose( imfile ) ; 00273 fprintf(stderr,"(FAILED) attempt to overwrite file %s\n",fname) ; 00274 RETURN( 0 ); 00275 } 00276 imfile = fopen( fname , "w" ) ; 00277 if( imfile == NULL ){ 00278 fprintf( stderr , "couldn't open for output file %s\n" , fname ) ; 00279 RETURN( 0 ); 00280 } 00281 } 00282 00283 nx = im->nx ; ny = im->ny ; 00284 00285 for( jj=0 ; jj < ny ; jj++ ){ 00286 00287 switch( im->kind ){ 00288 00289 case MRI_float:{ 00290 float *iar = MRI_FLOAT_PTR(im) + (jj*nx) ; 00291 for( ii=0 ; ii < nx ; ii++ ) 00292 fprintf(imfile," %14.7g",iar[ii]) ; 00293 } 00294 break ; 00295 00296 case MRI_short:{ 00297 short *iar = MRI_SHORT_PTR(im) + (jj*nx) ; 00298 for( ii=0 ; ii < nx ; ii++ ) 00299 fprintf(imfile," %6d",iar[ii]) ; 00300 } 00301 break ; 00302 00303 case MRI_byte:{ 00304 byte *iar = MRI_BYTE_PTR(im) + (jj*nx) ; 00305 for( ii=0 ; ii < nx ; ii++ ) 00306 fprintf(imfile," %3d",iar[ii]) ; 00307 } 00308 break ; 00309 00310 case MRI_int:{ 00311 int *iar = MRI_INT_PTR(im) + (jj*nx) ; 00312 for( ii=0 ; ii < nx ; ii++ ) 00313 fprintf(imfile," %6d",iar[ii]) ; 00314 } 00315 break ; 00316 00317 case MRI_double:{ 00318 double *iar = MRI_DOUBLE_PTR(im) + (jj*nx) ; 00319 for( ii=0 ; ii < nx ; ii++ ) 00320 fprintf(imfile," %14.7g",iar[ii]) ; 00321 } 00322 break ; 00323 00324 case MRI_complex:{ 00325 complex *iar = MRI_COMPLEX_PTR(im) + (jj*nx) ; 00326 for( ii=0 ; ii < nx ; ii++ ) 00327 fprintf(imfile," %14.7g %14.7g",iar[ii].r,iar[ii].i) ; 00328 } 00329 break ; 00330 00331 case MRI_rgb:{ 00332 byte *iar = MRI_RGB_PTR(im) + (3*jj*nx) ; 00333 for( ii=0 ; ii < nx ; ii++ ) 00334 fprintf(imfile," %3d %3d %3d",iar[3*ii],iar[3*ii+1],iar[3*ii+2]) ; 00335 } 00336 break ; 00337 } 00338 00339 fprintf(imfile,"\n") ; 00340 } 00341 00342 if( imfile != stdout ) fclose(imfile) ; 00343 RETURN( 1 ); 00344 } |
|
Definition at line 380 of file mri_write.c. References free, MRI_IMAGE::kind, malloc, MRI_BYTE_PTR, MRI_RGB_PTR, MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, pclose, popen, and THD_find_executable(). Referenced by mri_write_pnm().
00381 { 00382 char *pg , *jpfilt ; 00383 FILE *fp ; 00384 00385 if( fname == NULL || *fname == '\0' || im == NULL ) return 0 ; 00386 if( im->kind != MRI_rgb && im->kind != MRI_byte ) return 0 ; 00387 00388 pg = THD_find_executable( "cjpeg" ) ; 00389 if( pg == NULL ) return 0 ; 00390 00391 jpfilt = (char *)malloc( sizeof(char)*(strlen(pg)+strlen(fname)+32) ) ; 00392 sprintf( jpfilt , "%s -quality 95 > %s" , pg , fname ) ; 00393 #ifndef CYGWIN 00394 signal( SIGPIPE , SIG_IGN ) ; 00395 #endif 00396 fp = popen( jpfilt , "w" ) ; 00397 if( fp == NULL ){ free((void *)jpfilt); return 0 ;} 00398 00399 if( im->kind == MRI_rgb ){ 00400 fprintf(fp,"P6\n%d %d\n255\n" , im->nx,im->ny ) ; 00401 fwrite( MRI_RGB_PTR(im), sizeof(byte), 3*im->nvox, fp ) ; 00402 } else if( im->kind == MRI_byte ){ 00403 fprintf(fp,"P5\n%d %d\n255\n" , im->nx,im->ny ) ; 00404 fwrite( MRI_BYTE_PTR(im), sizeof(byte), im->nvox, fp ) ; 00405 } 00406 (void) pclose(fp) ; 00407 free((void *)jpfilt) ; return 1 ; 00408 } |
|
Definition at line 184 of file mri_write.c. References ENTRY, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_RGB_PTR, mri_write_jpg(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, RETURN, and STRING_HAS_SUFFIX. Referenced by AFNI_finalize_saveim_CB(), GRA_file_pixmap(), ISQ_saver_CB(), ISQ_snapfile(), main(), mri_write(), RCREND_finalize_saveim_CB(), and REND_finalize_saveim_CB().
00185 { 00186 FILE *imfile ; 00187 void *data ; 00188 int dsize , noheader = FALSE ; 00189 00190 ENTRY("mri_write_pnm") ; 00191 00192 if( im == NULL ) RETURN( 0 ); 00193 if( im->nz > 1 ) RETURN( 0 ); 00194 if( im->kind != MRI_byte && im->kind != MRI_rgb ) RETURN( 0 ); 00195 00196 if( STRING_HAS_SUFFIX(fname,".jpg") ){ /* 15 Apr 2005 */ 00197 RETURN( mri_write_jpg(fname,im) ) ; 00198 } 00199 00200 if( strcmp(fname,"-") != 0 ){ 00201 imfile = fopen( fname , "r" ) ; 00202 if( imfile != NULL ){ 00203 fclose( imfile ) ; 00204 fprintf(stderr,"(FAILED) attempt to overwrite file %s\n",fname) ; 00205 RETURN( 0 ); 00206 } 00207 } 00208 00209 if( strcmp(fname,"-") != 0 ) 00210 imfile = fopen( fname , "w" ) ; 00211 else 00212 imfile = stdout ; /* 18 Apr 2005: write to stdout */ 00213 00214 if( imfile == NULL ){ 00215 fprintf( stderr , "couldn't open for output file %s\n" , fname ) ; 00216 RETURN( 0 ); 00217 } 00218 00219 switch( im->kind ){ 00220 00221 case MRI_byte: 00222 fprintf( imfile , "P5\n%d %d\n255\n" , im->nx,im->ny ) ; /* header */ 00223 fwrite( MRI_BYTE_PTR(im), sizeof(byte), im->nvox, imfile ) ; /* bytes */ 00224 break ; 00225 00226 case MRI_rgb: 00227 fprintf( imfile , "P6\n%d %d\n255\n" , im->nx,im->ny ) ; /* header */ 00228 fwrite( MRI_RGB_PTR(im), sizeof(byte), 3*im->nvox, imfile ) ; /* bytes */ 00229 break ; 00230 00231 } 00232 00233 if( imfile != stdout ) fclose( imfile ) ; 00234 RETURN( 1 ); 00235 } |
|
Definition at line 350 of file mri_write.c. References ENTRY, mri_data_pointer(), MRI_IMAGE::nvox, MRI_IMAGE::pixel_size, and RETURN. Referenced by main().
00351 { 00352 FILE *imfile ; 00353 void *data ; 00354 int dsize ; 00355 00356 ENTRY("mri_write_raw") ; 00357 00358 if( im == NULL || fname == NULL || fname[0] == '\0' ) RETURN( 0 ); 00359 00360 dsize = im->pixel_size * im->nvox ; 00361 data = mri_data_pointer( im ) ; 00362 00363 if( dsize <= 0 || data == NULL ) RETURN( 0 ); 00364 00365 imfile = fopen( fname , "w" ) ; 00366 00367 if( imfile == NULL ){ 00368 fprintf(stderr,"** Can't open for output: %s\n",fname) ; RETURN( 0 ); 00369 } 00370 00371 fwrite( data , 1 , dsize , imfile ) ; 00372 fclose( imfile ) ; 00373 RETURN( 1 ); 00374 } |
|
Definition at line 14 of file mri_zeropad.c. References ENTRY, fim, MRI_IMAGE::kind, MAX, MIN, MRI_BYTE_PTR, MRI_COMPLEX_PTR, mri_copy(), MRI_COPY_AUX, mri_data_pointer(), mri_datum_size(), MRI_DOUBLE_PTR, MRI_FLOAT_PTR, mri_free(), MRI_INT_PTR, mri_new(), MRI_RGB_PTR, MRI_SHORT_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, and RETURN. Referenced by AFNI_faceup(), and SPLASH_imseq_getim().
00016 { 00017 int nxold,nyold , nxnew,nynew , nx,ny ; 00018 int ii,jj , iibot,iitop , jjbot,jjtop ; 00019 MRI_IMAGE * vim ; 00020 00021 ENTRY("mri_zeropad_2D") ; 00022 00023 /*- check for user stupidity -*/ 00024 00025 if( fim == NULL ) RETURN(NULL) ; 00026 00027 nx = fim->nx ; ny = fim->ny ; 00028 00029 /*- special case: just copy input -*/ 00030 00031 if( nxbot == 0 && nybot == 0 && 00032 nxtop == 0 && nytop == 0 ){ 00033 00034 vim = mri_copy( fim ) ; 00035 RETURN(vim) ; 00036 } 00037 00038 nxold = nx ; nxnew = nxold + nxbot + nxtop ; /* dimensions */ 00039 nyold = ny ; nynew = nyold + nybot + nytop ; 00040 00041 iibot = MAX(0,-nxbot) ; iitop = MIN(nxold,nxold+nxtop) ; /* range of data */ 00042 jjbot = MAX(0,-nybot) ; jjtop = MIN(nyold,nyold+nytop) ; /* in old dataset */ 00043 00044 if( nxnew < 1 || iibot >= iitop || /* check for reasonable sizes */ 00045 nynew < 1 || jjbot >= jjtop ){ /* and ranges of dataset */ 00046 00047 fprintf(stderr,"*** mri_zeropad: can't cut image down to nothing!\n") ; 00048 RETURN(NULL) ; 00049 } 00050 00051 vim = mri_new( nxnew , nynew , fim->kind ) ; 00052 MRI_COPY_AUX(vim,fim) ; 00053 memset( mri_data_pointer(vim) , 0 , 00054 nxnew*nynew*mri_datum_size(vim->kind) ) ; 00055 00056 /* macros for computing 1D subscripts from 2D indices */ 00057 00058 #undef SNEW /* in case was defined in some stupid .h file */ 00059 #undef SOLD 00060 #define SNEW(i,j) ((i+nxbot)+(j+nybot)*nxnew) 00061 #define SOLD(i,j) (i+j*nxold) 00062 00063 switch( fim->kind ){ /* copy rows of old into new */ 00064 00065 default: 00066 fprintf(stderr,"*** mri_zeropad: unknown input datum=%d\n",fim->kind) ; 00067 mri_free(vim) ; 00068 RETURN(NULL) ; 00069 00070 case MRI_byte:{ 00071 byte * bnew = MRI_BYTE_PTR(vim), * bold = MRI_BYTE_PTR(fim) ; 00072 for( jj=jjbot ; jj < jjtop ; jj++ ) 00073 for( ii=iibot ; ii < iitop ; ii++ ) 00074 bnew[SNEW(ii,jj)] = bold[SOLD(ii,jj)] ; 00075 } 00076 break ; 00077 00078 case MRI_rgb:{ 00079 byte * bnew = MRI_RGB_PTR(vim), * bold = MRI_RGB_PTR(fim) ; 00080 for( jj=jjbot ; jj < jjtop ; jj++ ) 00081 for( ii=iibot ; ii < iitop ; ii++ ){ 00082 bnew[3*SNEW(ii,jj) ] = bold[3*SOLD(ii,jj) ] ; 00083 bnew[3*SNEW(ii,jj)+1] = bold[3*SOLD(ii,jj)+1] ; 00084 bnew[3*SNEW(ii,jj)+2] = bold[3*SOLD(ii,jj)+2] ; 00085 } 00086 } 00087 break ; 00088 00089 case MRI_short:{ 00090 short * bnew = MRI_SHORT_PTR(vim), * bold = MRI_SHORT_PTR(fim) ; 00091 for( jj=jjbot ; jj < jjtop ; jj++ ) 00092 for( ii=iibot ; ii < iitop ; ii++ ) 00093 bnew[SNEW(ii,jj)] = bold[SOLD(ii,jj)] ; 00094 } 00095 break ; 00096 00097 case MRI_int:{ 00098 int * bnew = MRI_INT_PTR(vim), * bold = MRI_INT_PTR(fim) ; 00099 for( jj=jjbot ; jj < jjtop ; jj++ ) 00100 for( ii=iibot ; ii < iitop ; ii++ ) 00101 bnew[SNEW(ii,jj)] = bold[SOLD(ii,jj)] ; 00102 } 00103 break ; 00104 00105 case MRI_float:{ 00106 float * bnew = MRI_FLOAT_PTR(vim), * bold = MRI_FLOAT_PTR(fim) ; 00107 for( jj=jjbot ; jj < jjtop ; jj++ ) 00108 for( ii=iibot ; ii < iitop ; ii++ ) 00109 bnew[SNEW(ii,jj)] = bold[SOLD(ii,jj)] ; 00110 } 00111 break ; 00112 00113 case MRI_double:{ 00114 double * bnew = MRI_DOUBLE_PTR(vim), * bold = MRI_DOUBLE_PTR(fim) ; 00115 for( jj=jjbot ; jj < jjtop ; jj++ ) 00116 for( ii=iibot ; ii < iitop ; ii++ ) 00117 bnew[SNEW(ii,jj)] = bold[SOLD(ii,jj)] ; 00118 } 00119 break ; 00120 00121 case MRI_complex:{ 00122 complex * bnew = MRI_COMPLEX_PTR(vim), * bold = MRI_COMPLEX_PTR(fim) ; 00123 for( jj=jjbot ; jj < jjtop ; jj++ ) 00124 for( ii=iibot ; ii < iitop ; ii++ ) 00125 bnew[SNEW(ii,jj)] = bold[SOLD(ii,jj)] ; 00126 } 00127 break ; 00128 00129 } /* end of switch on datum type */ 00130 00131 RETURN(vim) ; 00132 } |
|
Definition at line 152 of file edt_volpad.c. References EDIT_volpad(), ENTRY, MRI_IMAGE::kind, MRI_COPY_AUX, mri_fix_data_pointer(), MRI_IS_3D, mri_new_vol_empty(), MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::nz, RETURN, and var.
00155 { 00156 MRI_IMAGE * jm ; 00157 void * var ; 00158 00159 ENTRY("mri_zeropad_3D") ; 00160 00161 if( im == NULL || !MRI_IS_3D(im) ) RETURN(NULL) ; /* bad */ 00162 00163 /* do the padding work */ 00164 00165 var = EDIT_volpad( nxbot,nxtop,nybot,nytop,nzbot,nztop , 00166 im->nx , im->ny , im->nz , 00167 im->kind , mri_data_pointer(im) ) ; 00168 00169 if( var == NULL ) RETURN(NULL) ; /* bad */ 00170 00171 /* put padded data into new image */ 00172 00173 jm = mri_new_vol_empty( im->nx+nxbot+nybot , 00174 im->ny+nybot+nytop , 00175 im->nz+nzbot+nztop , im->kind ) ; 00176 MRI_COPY_AUX(jm,im) ; 00177 mri_fix_data_pointer( var , jm ) ; 00178 RETURN( jm ); 00179 } |
|
My version of strdup(), which won't fail if the input is NULL. Definition at line 1578 of file mri_read.c. References malloc. Referenced by imsized_fname().
01579 { 01580 char * new_str ; 01581 if( str == NULL ) return NULL ; 01582 new_str = (char *) malloc( sizeof(char) * (strlen(str)+1) ) ; 01583 if( new_str != NULL ) strcpy( new_str , str ) ; 01584 return new_str ; 01585 } |
|
Definition at line 511 of file mri_stats.c. References cdfnor(), p, and q. Referenced by process_volume(), and THD_pval_to_stat().
00512 { 00513 int which , status ; 00514 double p , q , x , mean,sd,bound ; 00515 00516 if( qq <= 0.0 ) return 9.99 ; 00517 if( qq >= 0.999999 ) return 0.0 ; 00518 00519 which = 2 ; 00520 p = 1.0 - 0.5 * qq ; 00521 q = 0.5 * qq ; /* single sided prob = 1/2 of double sided */ 00522 x = 0.0 ; 00523 mean = 0.0 ; 00524 sd = 1.0 ; 00525 00526 cdfnor( &which , &p , &q , &x , &mean , &sd , &status , &bound ) ; 00527 return x ; 00528 } |
|
Step 2: do 3 Newton steps to improve this (uses the math library erfc function) * Definition at line 488 of file mri_stats.c. References cdfnor(), p, and q. Referenced by THD_stat_to_pval().
00489 { 00490 int which , status ; 00491 double p , q , x , mean,sd,bound ; 00492 00493 if( zz <= 0.0 ) return 1.0 ; 00494 00495 which = 1 ; 00496 p = 0.0 ; 00497 q = 0.0 ; 00498 x = zz ; 00499 mean = 0.0 ; 00500 sd = 1.0 ; 00501 00502 cdfnor( &which , &p , &q , &x , &mean , &sd , &status , &bound ) ; 00503 00504 if( status == 0 ) return 2.0*q ; /* double sided prob = 2 times single sided */ 00505 else return 1.0 ; 00506 } |
|
Definition at line 774 of file mri_stats.c. References cdfpoi(), p, and q. Referenced by THD_pval_to_stat().
00775 { 00776 int which , status ; 00777 double p,q, s,xlam,bound ; 00778 00779 if( qq <= 0.0 ) return 999.9 ; 00780 if( qq >= 0.999999 ) return 0.0 ; 00781 00782 which = 2 ; 00783 p = 1.0 - qq ; 00784 q = qq ; 00785 s = 0.0 ; 00786 xlam = lambda ; 00787 00788 cdfpoi( &which , &p , &q , &s , &xlam , &status , &bound ) ; 00789 00790 return s ; 00791 } |
|
Definition at line 747 of file mri_stats.c. References cdfpoi(), p, and q. Referenced by poisson_t2z(), and THD_stat_to_pval().
00748 { 00749 int which , status ; 00750 double p,q, s,xlam,bound ; 00751 00752 which = 1 ; 00753 p = 0.0 ; 00754 q = 0.0 ; 00755 s = xx ; 00756 xlam = lambda ; 00757 00758 cdfpoi( &which , &p , &q , &s , &xlam , &status , &bound ) ; 00759 00760 if( status == 0 ) return q ; 00761 else return 1.0 ; 00762 } |
|
Definition at line 767 of file mri_stats.c. References poisson_t2p(), and qginv(). Referenced by THD_stat_to_zscore().
00768 { 00769 double pp ; 00770 pp = 0.5 * poisson_t2p( xx , lambda ) ; 00771 return qginv(pp) ; 00772 } |
|
solve for x by a modified newton-raphson method * Definition at line 443 of file mri_stats.c. References erfc(). Referenced by log10qg(), and main().
00443 { return 0.5*erfc(x/1.414213562373095); } |
|
solve for x by a modified newton-raphson method * Definition at line 438 of file p2t.c.
00439 { 00440 double dp , dx , dt , ddq , dq ; 00441 int newt ; 00442 00443 dp = (p <= 0.5) ? (p) : (1.0-p) ; /* make between 0 and 0.5 */ 00444 00445 if( dp <= 0.0 ){ 00446 dx = 13.0 ; 00447 return ( (p <= 0.5) ? (dx) : (-dx) ) ; 00448 } 00449 00450 /** Step 1: use 26.2.23 from Abramowitz and Stegun **/ 00451 00452 dt = sqrt( -2.0 * log(dp) ) ; 00453 dx = dt 00454 - ((.010328e+0*dt + .802853e+0)*dt + 2.525517e+0) 00455 /(((.001308e+0*dt + .189269e+0)*dt + 1.432788e+0)*dt + 1.e+0) ; 00456 00457 /** Step 2: do 3 Newton steps to improve this **/ 00458 00459 for( newt=0 ; newt < 3 ; newt++ ){ 00460 dq = 0.5e+0 * erfc( dx / 1.414213562373095e+0 ) - dp ; 00461 ddq = exp( -0.5e+0 * dx * dx ) / 2.506628274631000e+0 ; 00462 dx = dx + dq / ddq ; 00463 } 00464 00465 return ( (p <= 0.5) ? (dx) : (-dx) ) ; /* return with correct sign */ 00466 } |
|
Definition at line 340 of file mri_percents.c. References a, isort_float(), QS_CUTOFF, and qsrec_float(). Referenced by BFIT_bootstrap_sample(), BFIT_prepare_dataset(), CORREL_main(), EDIT_filter_volume(), find_unusual_correlations(), main(), mri_percents(), mri_quantile(), and unusuality().
00341 { 00342 qsrec_float( n , a , QS_CUTOFF ) ; 00343 isort_float( n , a ) ; 00344 return ; 00345 } |
|
Definition at line 240 of file mri_percents.c. References a, isort_int(), QS_CUTOFF, and qsrec_int(). Referenced by DRAW_collapsar(), main(), and mri_quantize().
|
|
Definition at line 451 of file mri_percents.c. References a, isort_pair(), QS_CUTOFF, and qsrec_pair(). Referenced by mri_flatten().
00452 { 00453 qsrec_pair( n , a , ia , QS_CUTOFF ) ; 00454 isort_pair( n , a , ia ) ; 00455 return ; 00456 } |
|
Definition at line 140 of file mri_percents.c. References a, isort_short(), QS_CUTOFF, and qsrec_short(). Referenced by mri_percents(), and mri_quantile().
00141 { 00142 qsrec_short( n , a , QS_CUTOFF ) ; 00143 isort_short( n , a ) ; 00144 return ; 00145 } |
|
Definition at line 20 of file mri_coxplot.c. References box_xbot, box_xtop, box_ybot, and box_ytop. Referenced by memplot_to_RGB_sef().
|
|
Definition at line 13 of file mri_write_angif.c. References AFMALL, ganim, gfilt, setup, and THD_find_executable(). Referenced by mri_write_angif().
00014 { 00015 char *pq,*pg,*pgs,*pwg ; 00016 00017 if( setup >= 0 ) return setup ; 00018 00019 /*-- make the commands: gfilt to produce 1 gif 00020 ganim to animate a bunch of them --*/ 00021 00022 pg = THD_find_executable( "ppmtogif" ) ; 00023 if( pg == NULL ){ setup = 0; return setup; } 00024 pq = THD_find_executable( "ppmquant" ) ; 00025 if( pq == NULL ){ setup = 0; return setup; } 00026 pgs = THD_find_executable( "gifsicle" ) ; 00027 if( pgs == NULL ){ 00028 pwg = THD_find_executable( "whirlgif" ) ; 00029 if( pwg == NULL ){ setup = 0; return setup; } 00030 } 00031 00032 gfilt = AFMALL(char, strlen(pg)+strlen(pq)+32) ; 00033 sprintf( gfilt , "%s 127 | %s > %%s" , pq,pg ) ; 00034 00035 if( pgs != NULL ){ 00036 ganim = AFMALL(char, strlen(pgs)+64) ; 00037 sprintf(ganim,"%s -d 10 -l -O1 -k 127 --method median-cut",pgs) ; 00038 } else { 00039 ganim = AFMALL(char, strlen(pwg)+64) ; 00040 sprintf(ganim,"%s -loop -time 10",pwg) ; 00041 } 00042 00043 setup = 1; return setup; 00044 } |
|
macros will be used in routines below, as well! * Definition at line 243 of file mri_lsqfit.c. Referenced by LSQ_worker(), main(), and mri_startup_lsqfit().
00245 { 00246 int ii , jj , kk ; 00247 double *cc = NULL ; 00248 double sum ; 00249 00250 if( nref < 1 || veclen < nref || ref == NULL ){ 00251 fprintf(stderr,"*** Illegal inputs to startup_lsqfit\n") ; 00252 return NULL ; 00253 } 00254 00255 /*** form coefficient matrix into cc */ 00256 00257 cc = DBLEVEC(nref*nref) ; 00258 if( cc == NULL ){ 00259 fprintf(stderr,"Can't malloc workspace in startup_lsqfit\n") ; 00260 return NULL ; 00261 } 00262 00263 if( wt != NULL ){ 00264 for( jj=0 ; jj < nref ; jj++ ){ 00265 for( ii=0 ; ii <= jj ; ii++ ){ 00266 sum = 0.0 ; 00267 for( kk=0 ; kk < veclen ; kk++ ) sum += ref[ii][kk] * ref[jj][kk] * wt[kk] ; 00268 CC(ii,jj) = CC(jj,ii) = sum ; 00269 } 00270 } 00271 } else { 00272 for( jj=0 ; jj < nref ; jj++ ){ 00273 for( ii=0 ; ii <= jj ; ii++ ){ 00274 sum = 0.0 ; 00275 for( kk=0 ; kk < veclen ; kk++ ) sum += ref[ii][kk] * ref[jj][kk] ; 00276 CC(ii,jj) = CC(jj,ii) = sum ; 00277 } 00278 } 00279 } 00280 00281 /*** Choleski decompose cc ***/ 00282 00283 for( ii=0 ; ii < nref ; ii++ ){ 00284 for( jj=0 ; jj < ii ; jj++ ){ 00285 sum = CC(ii,jj) ; 00286 for( kk=0 ; kk < jj ; kk++ ) sum -= CC(ii,kk) * CC(jj,kk) ; 00287 CC(ii,jj) = sum / CC(jj,jj) ; 00288 } 00289 sum = CC(ii,ii) ; 00290 for( kk=0 ; kk < ii ; kk++ ) sum -= CC(ii,kk) * CC(ii,kk) ; 00291 if( sum <= 0.0 ){ 00292 free(cc) ; 00293 fprintf(stderr,"Choleski factorization failure in startup_lsqfit\n") ; 00294 return NULL ; 00295 } 00296 CC(ii,ii) = sqrt(sum) ; 00297 } 00298 00299 /*** scale ref by wt, if desired ***/ 00300 00301 if( wt != NULL ){ 00302 for( ii=0 ; ii < nref ; ii++ ) 00303 for( jj=0 ; jj < veclen ; jj++ ) ref[ii][jj] *= wt[jj] ; 00304 } 00305 00306 return cc ; 00307 } |
|
Definition at line 116 of file mri_stats.c.
00117 { 00118 double ww , xx , gam2,gam4 , tt ; 00119 00120 if( pp <= 0.0 ) return 99.99 ; 00121 if( pp >= 0.999999 ) return 0.0 ; 00122 00123 if( dof < 6.01 || nn < 1.0 ) return 0.0 ; 00124 00125 /* 4th and 6th order moments (or scaled cumulants) */ 00126 00127 gam2 = 6.0 / ( (dof-4.0) * nn ) ; 00128 gam4 = 240.0 / ( (dof-6.0) * (dof-4.0) * nn * nn ) ; 00129 00130 /* Cornish-Fisher expansion */ 00131 00132 xx = qginv( 0.5 * pp ) ; /* Gaussian approx */ 00133 00134 ww = xx + gam2 * xx * ( xx*xx - 3.0) / 24.0 00135 + gam4 * xx * ( xx*xx*xx*xx - 10.0*xx*xx + 15.0) / 720.0 00136 - gam2 * gam2 * xx * (3.0*xx*xx*xx*xx - 24.0*xx*xx + 29.0) / 384.0 ; 00137 00138 tt = sqrt( dof/(dof-2.0)/nn ) * ww ; 00139 return tt ; 00140 } |
|
Definition at line 142 of file mri_stats.c.
|
|
Definition at line 151 of file mri_stats.c.
|
|
Definition at line 18 of file mri_stats.c. References incbeta_inverse(), lnbeta(), and tt. Referenced by main(), and THD_pval_to_stat().
00019 { 00020 double bb , binv , tt ; 00021 00022 if( pp <= 0.0 ) return 99.99 ; 00023 if( pp >= 0.999999 ) return 0.0 ; 00024 if( dof < 1.0 ) return 0.0 ; 00025 00026 bb = lnbeta( 0.5*dof , 0.5 ) ; 00027 binv = incbeta_inverse( pp, 0.5*dof , 0.5 , bb ) ; 00028 tt = sqrt( dof*(1.0/binv-1.0) ) ; 00029 return tt ; 00030 } |
|
Definition at line 32 of file mri_stats.c. References incbeta(), lnbeta(), and tt. Referenced by THD_stat_to_pval().
|
|
Definition at line 44 of file mri_stats.c. References incbeta(), lnbeta(), qginv(), and tt. Referenced by THD_stat_to_zscore().
00045 { 00046 static double bb , dof_old = -666.666 ; 00047 double xx , pp ; 00048 00049 if( dof != dof_old ){ 00050 bb = lnbeta( 0.5*dof , 0.5 ) ; 00051 dof_old = dof ; 00052 } 00053 00054 xx = dof/(dof + tt*tt) ; 00055 pp = incbeta( xx , 0.5*dof , 0.5 , bb ) ; 00056 00057 if( tt > 0.0 ) pp = 1.0 - 0.5 * pp ; 00058 else pp = 0.5 * pp ; 00059 00060 xx = qginv(pp) ; 00061 return -xx ; 00062 } |
|
Definition at line 71 of file mri_swapbytes.c. References eightbytes::A, eightbytes::a, eightbytes::B, eightbytes::b, eightbytes::C, eightbytes::c, eightbytes::D, eightbytes::d, and tt. Referenced by T3D_read_images(), and T3D_swap_CB().
00072 { 00073 register int ii ; 00074 register eightbytes * tb = (eightbytes *) ar ; 00075 register unsigned char tt ; 00076 00077 for( ii=0 ; ii < n ; ii++ ){ 00078 tt = tb[ii].a ; tb[ii].a = tb[ii].A ; tb[ii].A = tt ; 00079 tt = tb[ii].b ; tb[ii].b = tb[ii].B ; tb[ii].B = tt ; 00080 tt = tb[ii].c ; tb[ii].c = tb[ii].C ; tb[ii].C = tt ; 00081 tt = tb[ii].d ; tb[ii].d = tb[ii].D ; tb[ii].D = tt ; 00082 } 00083 } |
|
Definition at line 85 of file dimon_afni.c. References c. Referenced by main(), mri_read(), mri_read3D_analyze75(), mri_read_analyze75(), mri_read_dicom(), r_mri_read_dicom(), T3D_read_images(), and T3D_swap_CB().
00086 { 00087 char * dp0 = (char *)data; 00088 char * dp1 = dp0 + 1; 00089 char * dp2 = dp0 + 2; 00090 char * dp3 = dp0 + 3; 00091 int c; 00092 00093 for( c = 0; c < nvals; c++, dp0 += 4, dp1 += 4, dp2 += 4, dp3 += 4 ) 00094 { 00095 *dp0 ^= *dp3; *dp3 ^= *dp0; *dp0 ^= *dp3; 00096 *dp1 ^= *dp2; *dp2 ^= *dp1; *dp1 ^= *dp2; 00097 } 00098 } |
|
Definition at line 71 of file dimon_afni.c. References c. Referenced by main(), mri_read(), mri_read3D_analyze75(), mri_read_analyze75(), mri_read_dicom(), mri_read_siemens(), r_mri_read_dicom(), T3D_read_images(), and T3D_swap_CB().
|
|
Expand a string like "Fred 2*Jed -Ned[1..3]" into a float vector. Each SYM_irange struct has 4 fields
Definition at line 15 of file mri_symbolize.c. References floatvec::ar, calloc, ENTRY, free, floatvecvec::fvar, SYM_irange::gbot, KILL_floatvec, malloc, MCW_get_intlist(), MCW_intlist_allow_negative(), name, floatvec::nar, SYM_irange::nbot, NI_decode_string_list(), NI_delete_str_array, SYM_irange::ntop, NI_str_array::num, floatvecvec::nvec, RETURN, NI_str_array::str, and strtod(). Referenced by read_glt_matrix().
00016 { 00017 floatvec *fv ; 00018 floatvecvec *fvv=NULL ; 00019 int rr , ii , ss , gg, *qlist , nvec=0 , iv ; 00020 NI_str_array *sar ; 00021 char qname[64] , *qstr , *qpt , *qls ; 00022 float fac ; 00023 00024 ENTRY("SYM_expand_ranges") ; 00025 00026 if( nlast < 0 ) RETURN(NULL) ; /* bad input */ 00027 00028 /* check if have anything to scan for */ 00029 00030 if( nrang < 1 || rang == NULL || str == NULL || *str == '\0' ) RETURN(NULL) ; 00031 00032 /* check if input line is a comment */ 00033 00034 for( ii=0 ; str[ii] != '\0' && isspace(str[ii]) ; ii++ ) ; /*nada*/ 00035 00036 if( str[ii] == '\0' || /* all blank */ 00037 str[ii] == '#' || /* starts with "#" */ 00038 (str[ii] == '/' && str[ii+1] == '/') /* starts with "//" */ 00039 ) RETURN(NULL) ; 00040 00041 fv = (floatvec *)malloc(sizeof(floatvec)) ; /* create empty output */ 00042 fv->nar = nlast+1 ; 00043 fv->ar = (float *)calloc(sizeof(float),nlast+1) ; 00044 00045 /* break input string into separate chunks */ 00046 00047 sar = NI_decode_string_list( str , "~" ) ; 00048 if( sar == NULL ){ 00049 fvv = (floatvecvec *)malloc(sizeof(floatvecvec)) ; 00050 fvv->nvec = 1 ; 00051 fvv->fvar = fv ; 00052 RETURN(fvv) ; 00053 } 00054 00055 /* scan each chunk */ 00056 00057 for( ss=0 ; ss < sar->num ; ss++ ){ 00058 qstr = sar->str[ss] ; 00059 if( qstr == NULL || *qstr == '\0' ) continue ; /* bad entry? */ 00060 if( *qstr == '#' || /* comment ends line */ 00061 (*qstr == '/' && *(qstr+1) == '/') ) break ; 00062 00063 qstr = strdup(sar->str[ss]) ; /* duplicate for surgery */ 00064 qls = strchr(qstr,'[') ; /* find and decode "[...]" subscripts */ 00065 qlist = NULL ; /* if they are present, that is */ 00066 if( qls != NULL ){ 00067 *qls = '\0' ; /* cut string off at '[' subscripts */ 00068 qls++ ; /* will scan for intlist starting here */ 00069 } 00070 00071 qpt = strchr(qstr,'*') ; /* find and decode factor in front */ 00072 if( qpt != NULL ){ /* if it is present, that is */ 00073 fac = (float)strtod(qstr,NULL) ; 00074 if( fac == 0.0 && *qstr != '0' ) fac = 1.0 ; 00075 qpt++ ; 00076 } else if( *qstr == '+' ){ /* "+" is same as "+1.0*" */ 00077 qpt = qstr+1 ; fac = 1.0 ; 00078 } else if( *qstr == '-' ){ /* "-" is same as "-1.0*" */ 00079 qpt = qstr+1 ; fac = -1.0 ; 00080 } else { /* default is "+" */ 00081 qpt = qstr ; fac = 1.0 ; 00082 } 00083 00084 for( rr=0 ; rr < nrang ; rr++ ) /* match name in list */ 00085 if( strcmp(qpt,rang[rr].name) == 0 ) break ; 00086 if( rr == nrang ){ /* no match!? */ 00087 fprintf(stderr,"** ERROR: can't match symbolic name '%s'\n",qpt) ; 00088 free((void *)qstr) ; continue ; 00089 } 00090 /* now scan for intlist, if present */ 00091 if( qls != NULL ){ 00092 MCW_intlist_allow_negative( (rang[rr].nbot < 0) ) ; 00093 qlist = MCW_get_intlist( rang[rr].ntop+1 , qls ) ; 00094 00095 if( qlist != NULL && *qls == '[' ){ /** [[...]] type of subscript **/ 00096 if( nvec == 0 ){ 00097 nvec = qlist[0] ; 00098 fvv = (floatvecvec *)malloc(sizeof(floatvecvec)) ; 00099 fvv->nvec = nvec ; 00100 fvv->fvar = (floatvec *)calloc(sizeof(floatvec),nvec) ; 00101 for( iv=0 ; iv < nvec ; iv++ ){ 00102 fvv->fvar[iv].nar = nlast+1 ; 00103 fvv->fvar[iv].ar = (float *)calloc(sizeof(float),nlast+1) ; 00104 } 00105 } else if( qlist[0] != nvec ){ 00106 fprintf(stderr,"** ERROR: mismatch in use of -gltsym [[...]]: '%s'\n", 00107 sar->str[ss] ) ; 00108 free((void *)qlist) ; free((void *)qstr) ; 00109 continue ; 00110 } 00111 for( iv=0 ; iv < nvec ; iv++ ){ 00112 gg = qlist[iv+1] - rang[rr].nbot + rang[rr].gbot ; 00113 if( gg >= 0 && gg <= nlast ) fvv->fvar[iv].ar[gg] = fac ; 00114 } 00115 free((void *)qlist) ; free((void *)qstr) ; 00116 continue ; /** skip to next one, since this was special **/ 00117 } 00118 } 00119 /* make up a fake list, if needed */ 00120 if( qlist == NULL ){ 00121 qlist = (int *)malloc(sizeof(int)*(rang[rr].ntop-rang[rr].nbot+2)) ; 00122 qlist[0] = rang[rr].ntop-rang[rr].nbot+1 ; 00123 for( ii=0 ; ii < qlist[0] ; ii++ ) qlist[ii+1] = rang[rr].nbot+ii ; 00124 } 00125 /* insert values into output list */ 00126 00127 for( ii=0 ; ii < qlist[0] ; ii++ ){ 00128 if( qlist[ii+1] < rang[rr].nbot || qlist[ii+1] > rang[rr].ntop ){ 00129 fprintf(stderr,"** ERROR: subscript %s[%d] out of range %d..%d\n", 00130 rang[rr].name , qlist[ii+1] , rang[rr].nbot,rang[rr].ntop ) ; 00131 continue ; 00132 } 00133 gg = qlist[ii+1] - rang[rr].nbot + rang[rr].gbot ; 00134 if( gg >= 0 && gg <= nlast ) fv->ar[gg] = fac ; 00135 } 00136 00137 free((void *)qlist) ; free((void *)qstr) ; 00138 } 00139 MCW_intlist_allow_negative(0) ; 00140 00141 NI_delete_str_array(sar); 00142 00143 /* if had no [[...]] subscripts, only have 1 vector for output */ 00144 00145 if( nvec == 0 ){ 00146 fvv = (floatvecvec *)malloc(sizeof(floatvecvec)) ; 00147 fvv->nvec = 1 ; 00148 fvv->fvar = fv ; 00149 } else { /* have multiple outputs */ 00150 for( iv=0 ; iv < nvec ; iv++ ){ 00151 for( gg=0 ; gg <= nlast ; gg++ ){ 00152 if( fvv->fvar[iv].ar[gg] == 0.0f ) fvv->fvar[iv].ar[gg] = fv->ar[gg] ; 00153 } 00154 } 00155 KILL_floatvec(fv) ; 00156 } 00157 00158 RETURN(fvv) ; 00159 } |
|
Extract a single average time series. -------------------------------------------------------------------------- Definition at line 57 of file thd_avts.c. References ADDTO_CLARR, MCW_cluster_array::clar, DESTROY_CLARR, ENTRY, INIT_CLARR, ISVALID_DSET, RETURN, and THD_average_timeseries().
00059 { 00060 MRI_IMAGE *im ; 00061 MCW_cluster_array *clustar ; 00062 00063 ENTRY("THD_average_one_timeseries") ; 00064 00065 if( clust == NULL || !ISVALID_DSET(dset) ) RETURN(NULL) ; 00066 00067 INIT_CLARR(clustar) ; 00068 ADDTO_CLARR(clustar,clust) ; 00069 00070 im = THD_average_timeseries( clustar , dset ) ; 00071 00072 clustar->clar[0] = NULL ; DESTROY_CLARR(clustar) ; 00073 RETURN(im) ; 00074 } |
|
For each cluster of points in clustar, extract the average time series from dataset dset. Put the results into an nt X nc float image, where nt = number of dataset bricks, nc = number of clusters. ------------------------------------------------------------------------- Definition at line 9 of file thd_avts.c. References MCW_cluster_array::clar, DSET_NVALS, DSET_NX, DSET_NY, ENTRY, free, MCW_cluster::i, ISVALID_DSET, MCW_cluster::j, MCW_cluster::k, malloc, MRI_FLOAT_PTR, mri_new(), nc, MCW_cluster_array::num_clu, MCW_cluster::num_pt, RETURN, THD_extract_array(), and THREE_TO_IJK. Referenced by ROIPLOT_main(), and THD_average_one_timeseries().
00011 { 00012 int nt,nc , ii,jj , npt,kk , nx,ny,nxy , ijk,nav ; 00013 MRI_IMAGE *flim ; 00014 float *flar , *tsar , *avar , fac ; 00015 MCW_cluster *clust ; 00016 00017 ENTRY("THD_average_timeseries") ; 00018 00019 if( clustar == NULL || clustar->num_clu == 0 || !ISVALID_DSET(dset) ) 00020 RETURN(NULL) ; 00021 00022 nt = DSET_NVALS(dset) ; 00023 nc = clustar->num_clu ; 00024 tsar = (float *) malloc(nt*sizeof(float)) ; 00025 avar = (float *) malloc(nt*sizeof(float)) ; 00026 00027 flim = mri_new( nt,nc , MRI_float ) ; 00028 flar = MRI_FLOAT_PTR(flim) ; 00029 00030 nx = DSET_NX(dset) ; ny = DSET_NY(dset) ; nxy = nx*ny ; 00031 00032 for( jj=0 ; jj < nc ; jj++ ){ 00033 clust = clustar->clar[jj] ; 00034 if( clust == NULL || clust->num_pt == 0 ) continue ; 00035 npt = clust->num_pt ; 00036 for( ii=0 ; ii < nt ; ii++ ) avar[ii] = 0.0 ; 00037 for( nav=kk=0 ; kk < npt ; kk++ ){ 00038 ijk = THREE_TO_IJK(clust->i[kk],clust->j[kk],clust->k[kk],nx,nxy) ; 00039 ii = THD_extract_array( ijk , dset , 0 , tsar ) ; 00040 if( ii < 0 ) continue ; 00041 for( ii=0 ; ii < nt ; ii++ ) avar[ii] += tsar[ii] ; 00042 nav++ ; 00043 } 00044 if( nav > 0 ){ 00045 fac = 1.0 / nav ; 00046 for( ii=0 ; ii < nt ; ii++ ) flar[ii+jj*nt] = fac*avar[ii] ; 00047 } 00048 } 00049 00050 free(avar) ; free(tsar) ; RETURN(flim) ; 00051 } |
|
Definition at line 335 of file mri_dup.c. References far, FINT1, fout, INT1, and MAX_NUP. Referenced by mri_dup2D_mode().
00336 { 00337 int kk,ii , ibot,itop ; 00338 static int nupold=-1 ; 00339 static float f00[MAX_NUP], fp1[MAX_NUP] ; 00340 00341 /*-- sanity checks --*/ 00342 00343 if( nup < 1 || nup > MAX_NUP || nar < 2 || far == NULL || fout == NULL ) return ; 00344 00345 if( nup == 1 ){ memcpy( fout, far, sizeof(float)*nar ); return; } 00346 00347 /*-- initialize interpolation coefficient, if nup has changed --*/ 00348 00349 if( nup != nupold ){ 00350 float val ; 00351 for( kk=0 ; kk < nup ; kk++ ){ 00352 val = ((float)kk) / ((float)nup) ; 00353 f00[kk] = 1.0 - val ; fp1[kk] = val ; 00354 } 00355 nupold = nup ; 00356 } 00357 00358 /*-- interpolate the intermediate places --*/ 00359 00360 ibot = 0 ; itop = nar-2 ; 00361 00362 switch( nup ){ 00363 default: 00364 for( ii=ibot ; ii <= itop ; ii++ ) 00365 for( kk=0 ; kk < nup ; kk++ ) fout[kk+ii*nup] = INT1(kk,ii) ; 00366 break ; 00367 00368 case 2: 00369 for( ii=ibot ; ii <= itop ; ii++ ){ 00370 fout[ii*nup] = INT1(0,ii) ; fout[ii*nup+1] = INT1(1,ii) ; 00371 } 00372 break ; 00373 00374 case 3: 00375 for( ii=ibot ; ii <= itop ; ii++ ){ 00376 fout[ii*nup] = INT1(0,ii) ; fout[ii*nup+1] = INT1(1,ii) ; 00377 fout[ii*nup+2] = INT1(2,ii) ; 00378 } 00379 break ; 00380 00381 case 4: 00382 for( ii=ibot ; ii <= itop ; ii++ ){ 00383 fout[ii*nup] = INT1(0,ii) ; fout[ii*nup+1] = INT1(1,ii) ; 00384 fout[ii*nup+2] = INT1(2,ii) ; fout[ii*nup+3] = INT1(3,ii) ; 00385 } 00386 break ; 00387 } 00388 00389 /*-- interpolate the outside edges --*/ 00390 00391 #if 0 /* nugatory */ 00392 for( ii=0 ; ii < ibot ; ii++ ) 00393 for( kk=0 ; kk < nup ; kk++ ) fout[kk+ii*nup] = FINT1(kk,ii) ; 00394 #endif 00395 00396 for( ii=itop+1 ; ii < nar ; ii++ ) 00397 for( kk=0 ; kk < nup ; kk++ ) fout[kk+ii*nup] = FINT1(kk,ii) ; 00398 00399 return ; 00400 } |
|
15 Apr 1999 * Definition at line 256 of file mri_dup.c. References far, FINT7, fout, INT7, MAX_NUP, S_00, S_M1, S_M2, S_M3, S_P1, S_P2, S_P3, and S_P4. Referenced by mri_dup2D_mode().
00257 { 00258 int kk,ii , ibot,itop ; 00259 static int nupold = -1 ; 00260 static float fm3[MAX_NUP], fm2[MAX_NUP], fm1[MAX_NUP], f00[MAX_NUP], 00261 fp1[MAX_NUP], fp2[MAX_NUP], fp3[MAX_NUP], fp4[MAX_NUP] ; 00262 00263 /*-- sanity checks --*/ 00264 00265 if( nup < 1 || nup > MAX_NUP || nar < 2 || far == NULL || fout == NULL ) return ; 00266 00267 if( nup == 1 ){ memcpy( fout, far, sizeof(float)*nar ); return; } 00268 00269 /*-- initialize interpolation coefficient, if nup has changed --*/ 00270 00271 if( nup != nupold ){ 00272 float val ; 00273 for( kk=0 ; kk < nup ; kk++ ){ 00274 val = ((float)kk) / ((float)nup) ; 00275 fm3[kk] = S_M3(val); fm2[kk] = S_M2(val); fm1[kk] = S_M1(val); 00276 f00[kk] = S_00(val); fp1[kk] = S_P1(val); fp2[kk] = S_P2(val); 00277 fp3[kk] = S_P3(val); fp4[kk] = S_P4(val); 00278 } 00279 nupold = nup ; 00280 } 00281 00282 /*-- interpolate the intermediate places --*/ 00283 00284 ibot = 3 ; itop = nar-5 ; 00285 00286 switch( nup ){ 00287 default: 00288 for( ii=ibot ; ii <= itop ; ii++ ) 00289 for( kk=0 ; kk < nup ; kk++ ) fout[kk+ii*nup] = INT7(kk,ii) ; 00290 break ; 00291 00292 case 2: 00293 for( ii=ibot ; ii <= itop ; ii++ ){ 00294 fout[ii*nup] = INT7(0,ii) ; fout[ii*nup+1] = INT7(1,ii) ; 00295 } 00296 break ; 00297 00298 case 3: 00299 for( ii=ibot ; ii <= itop ; ii++ ){ 00300 fout[ii*nup] = INT7(0,ii) ; fout[ii*nup+1] = INT7(1,ii) ; 00301 fout[ii*nup+2] = INT7(2,ii) ; 00302 } 00303 break ; 00304 00305 case 4: 00306 for( ii=ibot ; ii <= itop ; ii++ ){ 00307 fout[ii*nup] = INT7(0,ii) ; fout[ii*nup+1] = INT7(1,ii) ; 00308 fout[ii*nup+2] = INT7(2,ii) ; fout[ii*nup+3] = INT7(3,ii) ; 00309 } 00310 break ; 00311 } 00312 00313 /*-- interpolate the outside edges --*/ 00314 00315 for( ii=0 ; ii < ibot ; ii++ ) 00316 for( kk=0 ; kk < nup ; kk++ ) fout[kk+ii*nup] = FINT7(kk,ii) ; 00317 00318 for( ii=itop+1 ; ii < nar ; ii++ ) 00319 for( kk=0 ; kk < nup ; kk++ ) fout[kk+ii*nup] = FINT7(kk,ii) ; 00320 00321 return ; 00322 } |
Variable Documentation
|
|
|
|
|
|
|
|
|
|
|
Initial value: { 255.0 , 32767.0 , 2147483647.0 , 0.0,0.0,0.0 , 255.0 } |
|
Initial value: { "byte", "short", "int", "float", "double", "complex", "rgb", "RGBA" } |
|
Global variable to signal image orientation, if possible. |
|
Global variable giving the spacing between slice centers. |
|
Global variable to signal image TR, if possible. |
|
Global vector pointing in direction of x-axis. |
|
Global variable to signal image x offset, if possible. |
|
Global vector pointing in direction of y-axis. |
|
Global variable to signal image y offset, if possible. |
|
Global vector pointing in direction of y-axis. |
|
Global variable to signal image slice offset, if possible. |
|
|
|
Global variable saying whether to use MRILIB_slicespacing. |
|
Global variable saying whether to use MRILIB_xcos. |
|
Global variable saying whether to use MRILIB_xoff. |
|
Global variable saying whether to use MRILIB_ycos. |
|
Global variable saying whether to use MRILIB_yoff. |
|
Global variable saying whether to use MRILIB_zcos. |
|
Global variable saying whether to use MRILIB_zoff. |