Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

compute_tps.c

Go to the documentation of this file.
00001 00002 /* ---------------------------------------------------------------------------- 00003 @COPYRIGHT : 00004 Copyright 1993,1994,1995 David MacDonald, 00005 McConnell Brain Imaging Centre, 00006 Montreal Neurological Institute, McGill University. 00007 Permission to use, copy, modify, and distribute this 00008 software and its documentation for any purpose and without 00009 fee is hereby granted, provided that the above copyright 00010 notice appear in all copies. The author and McGill University 00011 make no representations about the suitability of this 00012 software for any purpose. It is provided "as is" without 00013 express or implied warranty. 00014 ---------------------------------------------------------------------------- */ 00015 00016 /* ----------------------------- MNI Header ----------------------------------- 00017 @NAME : compute_tps.c 00018 @INPUT : 00019 @OUTPUT : 00020 @RETURNS : 00021 @DESCRIPTION: library of routines for warping/mapping transformations. 00022 @METHOD : The original source code for these routines are taken from 00023 program VOI, written by Weiqian Dai. 00024 @GLOBALS : 00025 @CALLS : 00026 @CREATED : Dec 2, 1991 LC 00027 @MODIFIED : Mon Apr 5 09:00:54 EST 1993 louis 00028 - building new library routines, with prototypes 00029 @MODIFIED : Jul 6 1995, David MacDonald removed recipes type code, rewrote 00030 ---------------------------------------------------------------------------- */ 00031 00032 #include <volume_io/internal_volume_io.h> 00033 #include <bicpl/trans.h> 00034 00035 #ifndef lint 00036 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Transforms/compute_tps.c,v 1.12 2000/02/06 15:30:49 stever Exp $"; 00037 #endif 00038 00039 /* prototype definitions: */ 00040 00041 private void calculate_weights( 00042 Real **values, 00043 Real **INVML, 00044 Real **INVMLY, 00045 int n_points, 00046 int n_dims, 00047 int n_values ); 00048 00049 private void makeL( 00050 Real **positions, 00051 Real **ML, 00052 int n_points, 00053 int n_dims ); 00054 00055 /* This function will get coefficients of the warping function. */ 00056 00057 /* ----------------------------- MNI Header ----------------------------------- 00058 @NAME : get_nonlinear_warp 00059 @INPUT : positions 00060 values 00061 n_points 00062 n_dims 00063 n_values 00064 @OUTPUT : INVMLY 00065 @RETURNS : 00066 @DESCRIPTION: Computes the thin plate splines weights required to interpolate 00067 the given values at the positions. 00068 @METHOD : 00069 @GLOBALS : 00070 @CALLS : 00071 @CREATED : 1993 David MacDonald 00072 @MODIFIED : 00073 ---------------------------------------------------------------------------- */ 00074 00075 public void get_nonlinear_warp( 00076 Real **positions, /* n_points x n_dims */ 00077 Real **values, /* n_points x n_values */ 00078 Real **INVMLY, /* n_points+1+n_dims x n_values */ 00079 int n_points, 00080 int n_dims, 00081 int n_values ) 00082 { 00083 Real **ML,**INVML; 00084 00085 ALLOC2D( ML, n_points+n_dims+1, n_points+n_dims+1 ); 00086 ALLOC2D( INVML, n_points+n_dims+1, n_points+n_dims+1 ); 00087 00088 /* This function will build the L matrix */ 00089 00090 makeL( positions, ML, n_points, n_dims ); 00091 00092 (void) invert_square_matrix( n_points+n_dims+1, ML, INVML ); 00093 00094 /* build the array of deformation vectors */ 00095 00096 calculate_weights( values, INVML, INVMLY, n_points, n_dims, n_values ); 00097 00098 FREE2D( ML ); 00099 FREE2D( INVML ); 00100 } 00101 00102 /* ----------------------------- MNI Header ----------------------------------- 00103 @NAME : makeL 00104 @INPUT : positions 00105 n_points 00106 n_dims 00107 @OUTPUT : 00108 ML 00109 @RETURNS : 00110 @DESCRIPTION: Creates the L matrix full of distance weights for the positions, 00111 used for computing the weights. 00112 @METHOD : 00113 @GLOBALS : 00114 @CALLS : 00115 @CREATED : 1993 David MacDonald 00116 @MODIFIED : 00117 ---------------------------------------------------------------------------- */ 00118 00119 private void makeL( 00120 Real **positions, 00121 Real **ML, 00122 int n_points, 00123 int n_dims ) 00124 { 00125 int i,j; 00126 Real fu; 00127 00128 /* initialize matrix to zero */ 00129 00130 for_less( i, 0, n_points+n_dims+1 ) 00131 { 00132 for_less( j, 0, n_points+n_dims+1 ) 00133 ML[i][j] = 0.0; 00134 } 00135 00136 /* set rest of the K matrix as follows */ 00137 00138 for_less( i, 0, n_points ) 00139 { 00140 for_less( j, i+1, n_points ) 00141 { 00142 fu = thin_plate_spline_U( positions[i], positions[j], n_dims ); 00143 ML[j][i] = fu; 00144 ML[i][j] = fu; 00145 } 00146 } 00147 00148 /* set the rest of the L matrix */ 00149 00150 for_less( i, 0, n_points ) 00151 { 00152 ML[n_points][i] = 1.0; 00153 ML[i][n_points] = 1.0; 00154 for_less( j, 0, n_dims ) 00155 { 00156 ML[n_points+1+j][i] = positions[i][j]; 00157 ML[i][n_points+1+j] = positions[i][j]; 00158 } 00159 } 00160 } 00161 00162 /* ----------------------------- MNI Header ----------------------------------- 00163 @NAME : calculate_weights 00164 @INPUT : YM 00165 INVML 00166 n_points 00167 n_dims 00168 n_values 00169 @OUTPUT : INVMLY 00170 @RETURNS : 00171 @DESCRIPTION: Computes the weights by multiplying the Y matrix by the 00172 inverse of the L matrix. 00173 @METHOD : 00174 @GLOBALS : 00175 @CALLS : 00176 @CREATED : 1993 David MacDonald 00177 @MODIFIED : 00178 ---------------------------------------------------------------------------- */ 00179 00180 private void calculate_weights( 00181 Real **YM, 00182 Real **INVML, 00183 Real **INVMLY, 00184 int n_points, 00185 int n_dims, 00186 int n_values ) 00187 { 00188 /* L_{-1} Y = (W|a_{1}, a_{x}, a_{y})^T. */ 00189 00190 matrix_multiply( n_points + n_dims + 1, n_points, n_values, 00191 INVML, YM, INVMLY ); 00192 }

Generated on Wed Jul 28 09:10:56 2004 for BICPL by doxygen 1.3.7