My Project
img.c
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Copyright (c) 2002-2009 by Turku PET Centre
4 
5  Library: img
6  Description: Basic tools for working with IMG data struct.
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  See the GNU Lesser General Public License for more details:
17  http://www.gnu.org/copyleft/lesser.html
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with this library/program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  Turku PET Centre, Turku, Finland, http://www.turkupetcentre.fi/
24 
25  Modification history:
26  2002-01-20 Vesa Oikonen
27  First created.
28  2002-03-28 VO
29  sampleDistance included in IMG structure.
30  Included function imgDecayCorrection().
31  2002-07-30 VO
32  memset() added to imgInit().
33  2002-08-23 VO
34  _dataType included in IMG structure in img.h.
35  2002-12-01 VO
36  imgDecayCorrection() can be used also to remove decay correction.
37  2002-12-03 VO
38  Included function imgCopyhdr().
39  2002-12-23 VO
40  patientName included in IMG structure.
41  imgIsotope() included.
42  Decay correction factors are saved and used in imgDecayCorrection().
43  2003-09-04 VO
44  _fileFormat included in IMG structure in img.h.
45  2003-11-04 VO
46  Added unit nCi/mL.
47  2003-12-14 VO
48  Memory for all pixels is allocated in one chunk, because:
49  -faster when disk swapping is necessary
50  -pixel data can be easily saved in tmpfile
51  -whole data set can be easily processed with one pointer.
52  Unnecessary includes were removed.
53  (Patient) orientation included in IMG structure in img.h.
54  Scanner (type) included in IMG structure in img.h.
55  2003-12-18 VO
56  Included function imgExtractRange().
57  2004-05-23 VO
58  Added unit MBq/ml in img_unit().
59  Added a few comments.
60  2004-06-21 VO
61  Previous addition should now work.
62  2004-08-23 VO
63  New library function studynr_from_fname() is applied.
64  MAX_STUDYNR_LEN applied where appropriate.
65  2004-09-20 VO
66  Doxygen style comments are corrected.
67  2004-09-24 VO
68  Added units Bq/cc and uCi/cc in img_unit().
69  2006-10-30 VO
70  imgUnit() moved into imgunit.c.
71  2007-01-28 VO
72  Applies new definitions and IMG struct members.
73  imgInfo() prints part of information in interfile-type format.
74  Functions imgDecayCorrection() and imgIsotope() moved to new imgdecay.c.
75  2007-02-11 VO
76  Status (error) message array imgmsg moved back here, with corresponding
77  enums in img.h.
78  Added functions imgStatus() and imgSetStatus().
79  2007-02-27 VO
80  Correction in imgInfo().
81  Added error messages 24 and 25.
82  2007-03-13 VO
83  Added error messages 26 and 27.
84  2007-03-26 VO
85  Polar map variables were added in IMG struct.
86  Added error messages 28 and 29 for polar maps.
87  2007-07-17 Harri Merisaari
88  Modified for optional ANSi compatibility
89  2007-09-06 VO
90  Bug correction in imgSetStatus().
91  2007-09-10 VO
92  Return value of localtime() is checked.
93  2008-07-14 VO
94  Added function imgAllocateWithHeader() from libtpcmodext.
95  2009-02-16 VO
96  Added comments for Doxygen
97 
98 
99 ******************************************************************************/
100 #include <stdio.h>
101 #include <stdlib.h>
102 #include <math.h>
103 #include <string.h>
104 #include <time.h>
105 /*****************************************************************************/
106 #include "studynr.h"
107 #include "halflife.h"
108 /*****************************************************************************/
109 #include "include/imgunit.h"
110 #include "include/img.h"
111 /*****************************************************************************/
113 static const char *imgmsg[] = {
114  /* 0, STATUS_OK */ "ok",
115  /* 1, STATUS_FAULT */ "fault in calling routine",
116  /* 2, STATUS_NOMEMORY */ "out of memory",
117  /* 3, STATUS_NOFILE */ "cannot open file",
118  /* 4, STATUS_UNKNOWNFORMAT */ "unknown file format",
119  /* 5, STATUS_UNSUPPORTED */ "unsupported file type",
120  /* 6, STATUS_MISSINGMATRIX */ "missing matrix/matrices",
121  /* 7, STATUS_NOWRITEPERM */ "no permission to write",
122  /* 8, STATUS_DISKFULL */ "disk full?",
123  /* 9, STATUS_NOMATLIST */ "cannot read matrix list",
124  /* 10, STATUS_INVALIDMATLIST */ "invalid matrix list",
125  /* 11, STATUS_VARMATSIZE */ "variable matrix size",
126  /* 12, STATUS_NOMAINHEADER */ "cannot read mainheader",
127  /* 13, STATUS_NOSUBHEADER */ "cannot read subheader",
128  /* 14, STATUS_NOMATRIX */ "cannot read matrix",
129  /* 15, STATUS_UNSUPPORTEDAXIALCOMP */ "axial compression is not supported",
130  /* 16, STATUS_NOIMGDATAFILE */ "image datafile does not exist",
131  /* 17, STATUS_NOHEADERFILE */ "header file does not exist",
132  /* 18, STATUS_INVALIDHEADER */ "invalid header contents",
133  /* 19, STATUS_NOIMGDATA */ "cannot read image data",
134  /* 20, STATUS_NOSIFDATA */ "cannot read sif data",
135  /* 21, STATUS_WRONGSIFDATA */ "wrong sif data",
136  /* 22, STATUS_CANTWRITEIMGFILE */ "cannot write image datafile",
137  /* 23, STATUS_CANTWRITEHEADERFILE */ "cannot write header file",
138  /* 24, STATUS_WRONGFILETYPE */ "wrong file type",
139  /* 25, STATUS_CANNOTERASE */ "cannot erase file",
140  /* 26, STATUS_CANNOTREAD */ "cannot read data",
141  /* 27, STATUS_CANNOTWRITE */ "cannot write data",
142  /* 28, STATUS_UNSUPPORTEDPOLARMAP */ "polar map is not supported",
143  /* 29, STATUS_INVALIDPOLARMAP */ "invalid polar map",
144  0
145 };
146 #if 0
147 
148 static const char *_imgStatusMessage[] =
149 {
150  /* 0, IMG_ERR_OK */ "ok",
151  /* 1, IMG_ERR_CALLING */ "fault in calling routine",
152  /* 2, IMG_ERR_OOM */ "out of memory"
153 };
154 #endif
155 /*****************************************************************************/
156 
157 /*****************************************************************************/
163 void imgInit(IMG *image) {
164  int i = 0;
165  if(IMG_TEST) printf("imgInit()\n");
166  memset(image, 0, sizeof(IMG));
167  /*if(image->status!=IMG_STATUS_UNINITIALIZED) return;*/
169  imgSetStatus(image, STATUS_OK);
170  image->type=0;
171  image->unit=0;
172  image->zoom=0.0;
173  image->radiopharmaceutical[0]=(char)0;
174  image->isotopeHalflife=0.0;
175  image->decayCorrected=(char)0;
176  image->unit=0;
177  image->scanStart=0;
178  image->orientation=0;
179  image->axialFOV=image->transaxialFOV=image->sampleDistance=0.0;
180  image->studyNr[0]=image->patientName[0]=(char)0;
181  image->sizex=image->sizey=image->sizez=0;
182  image->_dataType=0;
183  image->_fileFormat=0;
184  image->scanner=0;
185  image->polarmap_num_rings=0;
186  for(i=0; i<MAX_POLARMAP_NUM_RINGS; i++) {
187  image->polarmap_sectors_per_ring[i]=0;
188  image->polarmap_ring_position[i]=0.0;
189  image->polarmap_ring_angle[i]=0;
190  }
191  image->polarmap_start_angle=0;
192  image->dimt=image->dimx=image->dimy=image->dimz=0;
193  image->gapx=image->gapy=image->gapz=0.0;
194  image->resolutionx=image->resolutiony=image->resolutionz=0.0;
195  image->m=(float****)NULL;
196  image->_header=(float*)NULL;
197  image->pixel=(float*)NULL;
198  image->column=(float**)NULL;
199  image->row=(float***)NULL;
200  image->plane=(float****)NULL;
201  image->planeNumber=(int*)NULL;
202  image->start=image->end=image->mid=(float*)NULL;
203  image->isWeight=0;
204  image->weight=image->sd=image->prompts=image->randoms=(float*)NULL;
205  image->decayCorrFactor=(float*)NULL;
206  image->errstatus=STATUS_OK;
207 }
208 /*****************************************************************************/
209 
210 /*****************************************************************************/
216 void imgEmpty(IMG *image) {
217  int i = 0;
218  if(IMG_TEST) printf("imgEmpty()\n");
219  if(image->status<IMG_STATUS_OCCUPIED) return;
220  /* Free up memory */
221  if(image->_pxl!=NULL) free(image->_pxl);
222  if(image->_col!=NULL) free(image->_col);
223  if(image->_row!=NULL) free(image->_row);
224  if(image->_pln!=NULL) free(image->_pln);
225  if(image->dimz>0) free(image->planeNumber);
226  if(image->dimt>0) free(image->_header);
227  /* Set variables */
228  imgSetStatus(image, STATUS_OK);
229  image->type=0;
230  image->unit=0;
231  image->zoom=0.0;
232  image->radiopharmaceutical[0]=(char)0;
233  image->isotopeHalflife=0.0;
234  image->decayCorrected=(char)0;
235  image->unit=0;
236  image->scanStart=0;
237  image->orientation=0;
238  image->axialFOV=image->transaxialFOV=image->sampleDistance=0.0;
239  image->studyNr[0]=image->patientName[0]=image->patientID[0]=(char)0;
240  image->userProcessCode[0]=image->studyDescription[0]=(char)0;
241  image->sizex=image->sizey=image->sizez=0;
242  image->gapx=image->gapy=image->gapz=0.0;
243  image->resolutionx=image->resolutiony=image->resolutionz=0.0;
244  image->_dataType=0;
245  image->_fileFormat=0;
246  image->scanner=0;
247  image->polarmap_num_rings=0;
248  for(i=0; i<MAX_POLARMAP_NUM_RINGS; i++) {
249  image->polarmap_sectors_per_ring[i]=0;
250  image->polarmap_ring_position[i]=0.0;
251  image->polarmap_ring_angle[i]=0;
252  }
253  image->polarmap_start_angle=0;
254  image->dimt=image->dimx=image->dimy=image->dimz=0;
255  image->m=(float****)NULL;
256  image->_header=(float*)NULL;
257  image->pixel=(float*)NULL;
258  image->column=(float**)NULL;
259  image->row=(float***)NULL;
260  image->plane=(float****)NULL;
261  image->planeNumber=(int*)NULL;
262  image->start=image->end=image->mid=(float*)NULL;
263  image->isWeight=0;
264  image->weight=image->sd=(float*)NULL;
265  image->decayCorrFactor=(float*)NULL;
266  /* Set status */
268  image->errstatus=STATUS_OK;
269 }
270 /*****************************************************************************/
271 
272 /*****************************************************************************/
285 int imgAllocate(IMG *image, int planes, int rows, int columns, int frames) {
286  unsigned short int zi, ri, ci;
287  float ***rptr, **cptr, *pptr;
288 
289  if(IMG_TEST) printf("imgAllocate(*image, %d, %d, %d, %d)\n", planes, rows, columns, frames);
290  /* Check arguments */
291  imgSetStatus(image, STATUS_FAULT);
292  if(image->status==IMG_STATUS_UNINITIALIZED) return(1);
293  if(planes<1 || rows<1 || columns<1 || frames<1) return(2);
294  if(image->status>=IMG_STATUS_OCCUPIED) imgEmpty(image);
295  /* Allocate memory for header data */
297  image->_header=(float*)calloc(8*frames, sizeof(float));
298  if(image->_header==NULL)
299  return(3);
300  image->planeNumber=(int*)calloc(planes, sizeof(int));
301  if(image->planeNumber==NULL) {
302  free(image->_header); return(4);}
303  /* Allocate memory for image data */
304  image->_pln=(float****)malloc(planes*sizeof(float***));
305  if(image->_pln==NULL) {
306  free(image->_header); free(image->planeNumber); return(5);}
307  image->_row=(float***)malloc(planes*rows*sizeof(float**));
308  if(image->_row==NULL) {
309  free(image->_header); free(image->planeNumber); free(image->_pln); return(6);}
310  image->_col=(float**)malloc(planes*rows*columns*sizeof(float*));
311  if(image->_col==NULL) {
312  free(image->_header); free(image->planeNumber);
313  free(image->_pln); free(image->_row); return(7);
314  }
315  image->_pxl=(float*)calloc(planes*rows*columns*frames, sizeof(float));
316  if(image->_pxl==NULL) {
317  free(image->_header); free(image->planeNumber);
318  free(image->_pln); free(image->_row); free(image->_col); return(8);
319  }
320  /* Set data pointers */
321  rptr=image->_row; cptr=image->_col; pptr=image->_pxl;
322  for(zi=0; zi<planes; zi++) {
323  image->_pln[zi]=rptr;
324  for(ri=0; ri<rows; ri++) {
325  *rptr++=cptr;
326  for(ci=0; ci<columns; ci++) {
327  *cptr++=pptr; pptr+=frames;
328  }
329  }
330  }
331  image->m=image->_pln;
332  image->plane=image->_pln;
333  image->column=image->_col;
334  image->row=image->_row;
335  image->pixel=image->_pxl;
336  /* Set header pointers */
337  image->start= image->_header+0*frames;
338  image->end= image->_header+1*frames;
339  image->mid= image->_header+2*frames;
340  image->weight= image->_header+3*frames;
341  image->sd= image->_header+4*frames;
342  image->prompts= image->_header+5*frames;
343  image->randoms= image->_header+6*frames;
344  image->decayCorrFactor=image->_header+7*frames;
345  /* Ok */
346  image->dimz=planes; image->dimy=rows; image->dimx=columns; image->dimt=frames;
347  imgSetStatus(image, STATUS_OK);
349  return(0);
350 }
351 /*****************************************************************************/
352 
353 /*****************************************************************************/
359  IMG *image,
361  int planes,
363  int rows,
365  int columns,
367  int frames,
369  IMG *image_from
370 ) {
371  int ret;
372  ret=imgAllocate(image, planes, rows, columns, frames); if(ret) return ret;
373  ret=imgCopyhdr(image_from, image); return ret;
374 }
375 /*****************************************************************************/
376 
377 /*****************************************************************************/
384 char *imgStatus(int status_index) {
385  int n=0;
386  while(imgmsg[n]!=0) n++;
387  if(status_index<0 || status_index>n-1) return((char*)imgmsg[STATUS_FAULT]);
388  else return((char*)imgmsg[status_index]);
389 }
390 /*****************************************************************************/
391 
392 /*****************************************************************************/
399 void imgSetStatus(IMG *img, int status_index) {
400  int n=0;
401  while(imgmsg[n]!=0) n++;
402  if(status_index<0 || status_index>n-1) img->errstatus=STATUS_FAULT;
403  else img->errstatus=status_index;
404  img->statmsg=imgmsg[img->errstatus];
405 }
406 /*****************************************************************************/
407 
408 /*****************************************************************************/
414 void imgInfo(IMG *image) {
415  int i;
416  char buf[64];
417  struct tm *st;
418 
419  if(IMG_TEST) printf("imgInfo()\n");
420  if(image->status<=IMG_STATUS_UNINITIALIZED) {
421  fprintf(stdout, "image_status := not initialized\n"); return;
422  } else if(image->status==IMG_STATUS_INITIALIZED) {
423  fprintf(stdout, "image_status := initialized but empty\n"); /* return; */
424  } else if(image->status==IMG_STATUS_ERROR) {
425  fprintf(stdout, "image_status := error\n");
426  }
427  fprintf(stdout, "image_error_status := %s\n", image->statmsg);
428  fprintf(stdout, "image_type := %d\n", image->type);
429  fprintf(stdout, "saved_data_type := %d\n", image->_dataType);
430  fprintf(stdout, "file_format := %d\n", image->_fileFormat);
431  fprintf(stdout, "scanner := %d\n", image->scanner);
432  fprintf(stdout, "identification_code := %.*s\n", MAX_STUDYNR_LEN, image->studyNr);
433  fprintf(stdout, "data_unit := %s\n", imgUnit((int)image->unit));
434  fprintf(stdout, "image_zoom := %g\n", image->zoom);
435  fprintf(stdout, "radiopharmaceutical := %.32s\n", image->radiopharmaceutical);
436  fprintf(stdout, "isotope_halflife := %e [sec]\n", image->isotopeHalflife);
437  st=localtime(&image->scanStart);
438  if(st!=NULL) strftime(buf, 64, "%Y-%m-%d %H:%M:%S", st); else strcpy(buf, "1900-01-01 00:00:00");
439  fprintf(stdout, "scan_start_time := %s\n", buf);
440  fprintf(stdout, "patient_orientation := %d\n", image->orientation);
441  fprintf(stdout, "FOV_axial := %g [mm]\n", image->axialFOV);
442  fprintf(stdout, "FOV_transaxial := %g [mm]\n", image->transaxialFOV);
443  fprintf(stdout, "sample_distance := %g [mm]\n", image->sampleDistance);
444  fprintf(stdout, "pixel_size_x := %g [mm]\n", image->sizex);
445  fprintf(stdout, "pixel_size_y := %g [mm]\n", image->sizey);
446  fprintf(stdout, "pixel_size_z := %g [mm]\n", image->sizez);
447  fprintf(stdout, "dimension_x := %d\n", image->dimx);
448  fprintf(stdout, "dimension_y := %d\n", image->dimy);
449  fprintf(stdout, "dimension_z := %d\n", image->dimz);
450  fprintf(stdout, "dimension_t := %d\n", image->dimt);
451  /* Polar map */
452  fprintf(stdout, "polarmap_num_rings := %d\n", image->polarmap_num_rings);
453  if(image->polarmap_num_rings>0) {
454  fprintf(stdout, "polarmap_sectors_per_ring :=");
455  for(i=0; i<image->polarmap_num_rings; i++)
456  fprintf(stdout, " %d", image->polarmap_sectors_per_ring[i]);
457  fprintf(stdout, "\n");
458  fprintf(stdout, "polarmap_ring_position :=");
459  for(i=0; i<image->polarmap_num_rings; i++)
460  fprintf(stdout, " %g", image->polarmap_ring_position[i]);
461  fprintf(stdout, "\n");
462  fprintf(stdout, "polarmap_ring_angle :=");
463  for(i=0; i<image->polarmap_num_rings; i++)
464  fprintf(stdout, " %d", image->polarmap_ring_angle[i]);
465  fprintf(stdout, "\n");
466  fprintf(stdout, "polarmap_start_angle := %d\n", image->polarmap_start_angle);
467  }
468  /* Check if the rest is available */
469  if(image->status==IMG_STATUS_INITIALIZED) return;
470 
471  fprintf(stdout, "actual_plane_numbers := %d", image->planeNumber[0]);
472  for(i=1; i<image->dimz; i++) fprintf(stdout, " %d", image->planeNumber[i]);
473  fprintf(stdout, "\n");
474  fprintf(stdout, "Frame times (sec):\n");
475  for(i=0; i<image->dimt; i++) fprintf(stdout, " %e %e %e\n",
476  image->start[i], image->end[i], image->mid[i]);
477  if(image->isWeight) fprintf(stdout, "Frames are weighted.\n");
478  else fprintf(stdout, "Frames are not weighted.\n");
479  if(image->decayCorrected==1) {
480  fprintf(stdout, "Decay correction factors for each frame:\n");
481  for(i=0; i<image->dimt; i++)
482  fprintf(stdout, "%03i %e\n", i+1, image->decayCorrFactor[i]);
483  } else
484  fprintf(stdout, "Image is not decay corrected.\n");
485  return;
486 }
487 /*****************************************************************************/
488 
489 /*****************************************************************************/
501 int imgCopyhdr(IMG *image1, IMG *image2) {
502  int i;
503 
504  if(IMG_TEST) printf("imgCopyhdr()\n");
505  /* check */
506  if(image1==NULL || image2==NULL) return(1);
507  if(image1==image2) return(2);
508  /* copy */
509  image2->type=image1->type;
510  image2->unit=image1->unit;
511  strcpy(image2->studyNr, image1->studyNr);
512  strcpy(image2->patientName, image1->patientName);
513  strcpy(image2->patientID, image1->patientID);
514  strcpy(image2->userProcessCode, image1->userProcessCode);
515  strcpy(image2->studyDescription, image1->studyDescription);
516  image2->zoom=image1->zoom;
517  strcpy(image2->radiopharmaceutical, image1->radiopharmaceutical);
518  image2->isotopeHalflife=image1->isotopeHalflife;
519  image2->decayCorrected=image1->decayCorrected;
520  image2->scanStart=image1->scanStart;
521  image2->axialFOV=image1->axialFOV;
522  image2->transaxialFOV=image1->transaxialFOV;
523  image2->sampleDistance=image1->sampleDistance;
524  image2->sizex=image1->sizex;
525  image2->sizey=image1->sizey;
526  image2->sizez=image1->sizez;
527  image2->gapx=image1->gapx;
528  image2->gapy=image1->gapy;
529  image2->gapz=image1->gapz;
530  image2->resolutionx=image1->resolutionx;
531  image2->resolutiony=image1->resolutiony;
532  image2->resolutionz=image1->resolutionz;
533  image2->_dataType=image1->_dataType;
534  image2->_fileFormat=image1->_fileFormat;
535  image2->orientation=image1->orientation;
536  image2->scanner=image1->scanner;
537  image2->polarmap_num_rings=image1->polarmap_num_rings;
538  for(i=0; i<MAX_POLARMAP_NUM_RINGS; i++) {
540  image2->polarmap_ring_position[i]=image1->polarmap_ring_position[i];
541  image2->polarmap_ring_angle[i]=image1->polarmap_ring_angle[i];
542  }
544  if(image1->dimz==image2->dimz) for(i=0; i<image1->dimz; i++)
545  image2->planeNumber[i]=image1->planeNumber[i];
546  if(image1->dimt==image2->dimt) for(i=0; i<image1->dimt; i++) {
547  image2->start[i]=image1->start[i]; image2->end[i]=image1->end[i];
548  image2->mid[i]=image1->mid[i];
549  image2->weight[i]=image1->weight[i]; image2->sd[i]=image1->sd[i];
550  image2->prompts[i]=image1->prompts[i];
551  image2->randoms[i]=image1->randoms[i];
552  image2->decayCorrFactor[i]=image1->decayCorrFactor[i];
553  }
554  image2->isWeight=image1->isWeight;
555  return(0);
556 }
557 /*****************************************************************************/
558 
559 /*****************************************************************************/
570 int imgExtractRange(IMG *img1, IMG_RANGE r, IMG *img2) {
571  int zi, yi, xi, fi, zj, yj, xj, fj;
572 
573  if(IMG_TEST) {
574  printf("imgExtractRange(*img1, r, *img2)\n");
575  printf(" z=[%d,%d] y=[%d,%d] x=[%d,%d] f=[%d,%d]\n",
576  r.z1, r.z2, r.y1, r.y2, r.x1, r.x2, r.f1, r.f2);
577  }
578  /* Check arguments */
579  if(img2==NULL) return(1); else imgSetStatus(img2, STATUS_FAULT);
580  if(img1->status!=IMG_STATUS_OCCUPIED) return(1);
581  if(img2->status==IMG_STATUS_UNINITIALIZED) return(1);
582  if(r.z1<1 || r.z2>img1->dimz || r.z1>r.z2) return(1);
583  if(r.y1<1 || r.y2>img1->dimy || r.y1>r.y2) return(1);
584  if(r.x1<1 || r.x2>img1->dimx || r.x1>r.x2) return(1);
585  if(r.f1<1 || r.f2>img1->dimt || r.f1>r.f2) return(1);
586 
587  /* Allocate memory unless the same size was previously allocated */
589  zi=r.z2-r.z1+1; yi=r.y2-r.y1+1; xi=r.x2-r.x1+1; fi=r.f2-r.f1+1;
590  if(img2->status>=IMG_STATUS_OCCUPIED)
591  if(img2->dimz!=zi || img2->dimy!=yi || img2->dimx!=xi || img2->dimt!=fi)
592  imgEmpty(img2);
593  if(img2->status!=IMG_STATUS_OCCUPIED) {
594  if(imgAllocate(img2, zi, yi, xi, fi)!=0) return(2);
595  }
596 
597  /* Copy data */
598  imgCopyhdr(img1, img2);
599  for(fi=r.f1-1, fj=0; fi<r.f2; fi++, fj++) {
600  img2->start[fj]=img1->start[fi];
601  img2->end[fj]=img1->end[fi];
602  img2->mid[fj]=img1->mid[fi];
603  img2->weight[fj]=img1->weight[fi];
604  img2->sd[fj]=img1->sd[fi];
605  img2->prompts[fj]=img1->prompts[fi];
606  img2->randoms[fj]=img1->randoms[fi];
607  img2->decayCorrFactor[fj]=img1->decayCorrFactor[fi];
608  }
609  for(zi=r.z1-1, zj=0; zi<r.z2; zi++, zj++)
610  img2->planeNumber[zj]=img1->planeNumber[zi];
611  for(zi=r.z1-1, zj=0; zi<r.z2; zi++, zj++)
612  for(yi=r.y1-1, yj=0; yi<r.y2; yi++, yj++)
613  for(xi=r.x1-1, xj=0; xi<r.x2; xi++, xj++)
614  for(fi=r.f1-1, fj=0; fi<r.f2; fi++, fj++)
615  img2->m[zj][yj][xj][fj]=img1->m[zi][yi][xi][fi];
616 
617  imgSetStatus(img2, STATUS_OK);
618  return(0);
619 }
620 /*****************************************************************************/
621 
622 /*****************************************************************************/
float ** column
Definition: img.h:280
float transaxialFOV
Definition: img.h:204
int errstatus
Definition: img.h:317
int imgAllocate(IMG *image, int planes, int rows, int columns, int frames)
Definition: img.c:285
float * sd
Definition: img.h:304
char radiopharmaceutical[32]
Definition: img.h:180
void imgEmpty(IMG *image)
Definition: img.c:216
unsigned short int dimz
Definition: img.h:265
int z1
Definition: img.h:146
char * imgStatus(int status_index)
Definition: img.c:384
Definition: img.h:156
float **** plane
Definition: img.h:276
float * pixel
Definition: img.h:282
float polarmap_ring_position[MAX_POLARMAP_NUM_RINGS]
Definition: img.h:247
int z2
Definition: img.h:146
float gapx
Definition: img.h:214
float sizey
Definition: img.h:210
float * end
Definition: img.h:292
float resolutionz
Definition: img.h:224
unsigned short int dimx
Definition: img.h:261
short int polarmap_start_angle
Definition: img.h:252
float *** _row
Definition: img.h:269
char patientName[32]
Definition: img.h:176
const char * statmsg
Definition: img.h:166
int _dataType
Definition: img.h:226
float axialFOV
Definition: img.h:202
static const char * imgmsg[]
Definition: img.c:113
float * mid
Definition: img.h:294
char status
Definition: img.h:164
float **** m
Definition: img.h:274
int imgCopyhdr(IMG *image1, IMG *image2)
Definition: img.c:501
float sampleDistance
Definition: img.h:206
#define IMG_STATUS_OCCUPIED
Definition: img.h:73
float * randoms
Definition: img.h:308
float *** row
Definition: img.h:278
float sizez
Definition: img.h:212
Definition: img.h:118
int imgExtractRange(IMG *img1, IMG_RANGE r, IMG *img2)
Definition: img.c:570
char studyDescription[32]
Definition: img.h:192
int scanner
Definition: img.h:231
#define MAX_POLARMAP_NUM_RINGS
Definition: img.h:116
#define IMG_STATUS_INITIALIZED
Definition: img.h:72
float * decayCorrFactor
Definition: img.h:314
int polarmap_sectors_per_ring[MAX_POLARMAP_NUM_RINGS]
Definition: img.h:244
float * weight
Definition: img.h:302
int x2
Definition: img.h:142
float ** _col
Definition: img.h:268
int x1
Definition: img.h:142
short int polarmap_ring_angle[MAX_POLARMAP_NUM_RINGS]
Definition: img.h:250
float gapz
Definition: img.h:218
float isotopeHalflife
Definition: img.h:182
void imgInit(IMG *image)
Definition: img.c:163
#define IMG_STATUS_UNINITIALIZED
Definition: img.h:71
int y1
Definition: img.h:144
int imgAllocateWithHeader(IMG *image, int planes, int rows, int columns, int frames, IMG *image_from)
Definition: img.c:357
int _fileFormat
Definition: img.h:229
int f1
Definition: img.h:148
float sizex
Definition: img.h:208
char studyNr[MAX_STUDYNR_LEN+1]
Definition: img.h:174
float resolutionx
Definition: img.h:220
int orientation
Definition: img.h:188
float resolutiony
Definition: img.h:222
char decayCorrected
Definition: img.h:184
float * _pxl
Definition: img.h:267
char * imgUnit(int dunit)
Definition: imgunit.c:365
int IMG_TEST
Definition: img.h:128
time_t scanStart
Definition: img.h:186
char isWeight
Definition: img.h:300
Definition: img.h:140
#define IMG_STATUS_ERROR
Definition: img.h:74
float * _header
Definition: img.h:271
int * planeNumber
Definition: img.h:284
float * start
Definition: img.h:290
char patientID[16]
Definition: img.h:178
unsigned short int dimy
Definition: img.h:263
unsigned short int dimt
Definition: img.h:259
void imgInfo(IMG *image)
Definition: img.c:414
float gapy
Definition: img.h:216
float * prompts
Definition: img.h:306
char userProcessCode[11]
Definition: img.h:190
char type
Definition: img.h:198
int f2
Definition: img.h:148
int y2
Definition: img.h:144
int polarmap_num_rings
Definition: img.h:239
char unit
Definition: img.h:172
float **** _pln
Definition: img.h:270
void imgSetStatus(IMG *img, int status_index)
Definition: img.c:399
float zoom
Definition: img.h:200