~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/file/fileMipl_io.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/file/fileMipl_io.c,v $
 37  * Date    :  $Date: 2005/01/09 17:49:25 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: fileMipl_io.c,v 1.4 2005/01/09 17:49:25 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes   :
 44  * 
 45  *  Functions to read/write RAW image files
 46  *
 47  *********
 48 */
 49 
 50 #include "fileMipl_io.h"
 51 
 52 #if HAVE_CONFIG_H
 53 #include <config.h>
 54 #endif
 55 
 56 #include <stdio.h>
 57 #include <stdlib.h>
 58 #include <string.h>
 59 #include <tina/sys/sysPro.h>
 60 #include <tina/sys/sysDef.h>
 61 #include <tina/image/imgPro.h>
 62 #include <tina/image/imgDef.h>
 63 #include <tina/file/fileUtil_io.h>
 64 
 65 #define VOXELS    450
 66 #define DYNSTIME  451
 67 #define TE_DATA   453
 68 
 69 /* Create an imrect and read an image file called 'pathname' into it.
 70  * Open file, read data and close file. On failure, give error message
 71  * and return NULL. */
 72 
 73 
 74 void
 75 checkMiplHeader (FILE * fp_img, int row[], int col[], int nslc[],
 76                  double pixl[], double thck[])
 77 {
 78   int i;
 79   char mipl_header[80];
 80   char thickness[80];
 81   char no_row[80];
 82   char no_col[80];
 83   char pixelsize[80];
 84   char noslices[80];
 85 
 86 
 87   for (i = 0; i < 31; i++)
 88     {
 89       fgets (mipl_header, 64, fp_img);
 90       /*          printf("mipl_header(%d):  %s \n", i, mipl_header);      
 91        */
 92 
 93     }
 94 
 95 
 96   fgets (mipl_header, 64, fp_img);
 97   strcpy (thickness, mipl_header);
 98   printf ("thickness : %s \n", thickness);
 99 
100 
101   for (i = 32; i < 122; i++)
102     {
103       fgets (mipl_header, 64, fp_img);
104     }
105 
106   fgets (mipl_header, 64, fp_img);
107   strcpy (no_row, mipl_header);
108   printf ("no_row : %s \n", no_row);
109 
110 
111   fgets (mipl_header, 64, fp_img);
112   strcpy (no_col, mipl_header);
113   printf ("no_col : %s \n", no_col);
114 
115   fgets (mipl_header, 64, fp_img);
116   strcpy (pixelsize, mipl_header);
117   printf ("pixelsize : %s \n", pixelsize);
118 
119   for (i = 1; i < 27; i++)
120     {
121       fgets (mipl_header, 64, fp_img);
122       /*
123          printf("mipl_header(%d):  %s \n", i, mipl_header);       
124        */
125 
126     }
127 
128   fgets (mipl_header, 64, fp_img);
129   strcpy (noslices, mipl_header);
130   printf ("noslices : %s \n", noslices);
131 
132   *row = atoi (no_row);
133   *col = atoi (no_col);
134   *nslc = atoi (noslices);
135 
136   *thck = atof (thickness);
137 
138   *pixl = atof (pixelsize);
139 
140 }
141 
142 
143 
144 
145 Imrect *
146 mip_read_image (const char *pathname, int i)
147 {
148   Imrect *imrect = NULL;
149   FILE *fp_img = fopen_2 (pathname, "rb");
150   Vartype new_vtype;
151   int rowlo, rowhi, collo, colhi;
152 
153   int nslc;
154   double pixl, thck;
155 
156   rowlo = 0;
157   collo = 0;
158 
159   if (fp_img == NULL)
160     return (NULL);
161 
162   checkMiplHeader (fp_img, &rowhi, &colhi, &nslc, &pixl, &thck);
163 
164   /*
165      format("image_row : %d \n", rowhi);
166      format("image_col : %d \n", colhi);
167      format("no_slices : %d \n", nslc);
168 
169      format("pixel_size : %lf \n", pixl);
170      format("slice_thck : %lf \n", thck);
171    */
172 
173   new_vtype = short_v;
174 
175   if (fseek (fp_img, (long) i * 2 * rowhi * colhi, SEEK_CUR) == 0)
176     {
177       Imregion imregion;
178       imregion.lx = collo;
179       imregion.ux = colhi;
180       imregion.ly = rowlo;
181       imregion.uy = rowhi;
182 
183       imrect = im_alloc (rowhi - rowlo, colhi - collo,
184                          &imregion, (Vartype) new_vtype);
185       if (!fread_imrect_data (imrect, fp_img, pathname))
186         {
187           im_free (imrect);
188           imrect = NULL;
189         }
190       fclose_2 (fp_img, pathname);
191     }
192   return imrect;
193 }
194 
195 
196 Bool
197 mip_hdr_TE_extract (FILE * fp, Imrect * im)
198 {
199   float *TE;
200   int i;
201   char temp[128];
202 
203   TE = (float *) ralloc (sizeof (float));
204 
205   for (i = 0; i < 33; i++)
206     fgets (temp, 64, fp);
207   fgets (temp, 64, fp);         /*i=33 is te */
208   if (sscanf (temp, "%f", TE) == EOF)
209     return (false);
210 
211   im->props = proplist_rm (im->props, TE_DATA);
212   im->props =
213     proplist_addifnp (im->props, (void *) TE, TE_DATA, rfree, false);
214 
215   return (true);
216 }
217 
218 
219 Bool
220 mip_hdr_dynstimes_extract (FILE * fp, Imrect * im)
221 {
222   float *times;
223   int i, total;
224   char temp[128];
225 
226   for (i = 0; i < 151; i++)
227     fgets (temp, 64, fp);
228 
229   fgets (temp, 64, fp);         /* i=151 is noslices */
230   if (sscanf (temp, "%d", &total) == EOF)
231     return (false);
232 
233   rewind (fp);
234   times = fvector_alloc (0, total);
235 
236   for (i = 0; i < 57; i++)
237     fgets (temp, 64, fp);
238 
239   for (i = 0; i < total; i++)
240     fscanf (fp, "%f\\", &(times[i]));
241 
242   im->props = proplist_rm (im->props, DYNSTIME);
243   im->props =
244     proplist_addifnp (im->props, (void *) times, DYNSTIME, rfree, false);
245 
246   return (true);
247 }
248 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.