예제 #1
0
MRI_IMAGE *mri_new( int nx , int ny , MRI_TYPE kind )
{
   MRI_IMAGE *newim ;

   newim = mri_new_7D_generic( nx,ny , 1,1,1,1,1 , kind , TRUE ) ;
   return newim ;
}
예제 #2
0
MRI_IMAGE *mri_new_vol_empty( int nx , int ny , int nz , MRI_TYPE kind )
{
   MRI_IMAGE *newim ;
   newim = mri_new_7D_generic( nx,ny,nz , 1,1,1,1 , kind , FALSE ) ;
   return newim ;
}
예제 #3
0
/*-------------------------------------------------------------------------
 * read data into image array, based on mosaic (fill image and image array)
 * (from mri_read_dicom.c                               22 Dec 2010 [rickr]
 *
 * - fp         : open file pointer                     (input/output)
 * - im         : current image                         (output)
 * - imar       : mosaic image array                    (output)
 * - flip_slices: whether to reverse slice order        (output)
 * - mi         : mosaic info                           (input)
 * - datum      : type for image array                  (input)
 * - bpp        : bytes per pixel                       (input)
 * - kor        : slice direction orientation           (input)
 * - swap       : whether to byte swap data             (input)
 * - dx,y,z     : slice dimensions                      (input)
 * - dt         : TR, if > 0                            (input)
 *
 * return 0 on success
 *        1 on error
 */
int read_mosaic_data( FILE *fp, MRI_IMAGE *im, MRI_IMARR *imar,
   int * flip_slices, Siemens_extra_info *mi, int datum, int bpp, int kor,
   int swap, float dx, float dy, float dz, float dt)
{   /*-- 28 Oct 2002:  is a 2D mosaic --*******************/

   char * dar=NULL, * iar ;
   int    nvox, yy, xx, nxx, ii, jj, slice ;
   int    mos_nx, mos_ny, mos_nz, mos_ix, mos_iy, mosaic_num;
   int    verb = g_dicom_ctrl.verb;  /* typing ease, default level is 1 */

   ENTRY("read_mosaic_data");

   if( !mi->good ) {
      if( verb ) fprintf(stderr,"** apply_z_orient but not mosaic");
      RETURN(1);
   }

   /* determine if slices should be reversed */
   *flip_slices = flip_slices_mosaic(mi, kor);

   /* just to make it a little easier to read */
   mos_nx = mi->mos_nx;   mos_ny = mi->mos_ny;
   mos_ix = mi->mos_ix;   mos_iy = mi->mos_ix; /* always square */
   mos_nz = mos_ix * mos_iy ;   /* number of slices in mosaic */

   if( verb > 1 )
      fprintf(stderr, "-- read_mosaic_data flip_slices %d "
                      "mos_nx,ny,nz = %d,%d,%d  mos_ix = %d\n",
              *flip_slices,mos_nx,mos_ny,mos_nz, mos_ix);

   mosaic_num = mi->mosaic_num;

   nvox = mos_nx*mos_ny*mos_nz ;         /* total number of voxels */

   if( g_dicom_ctrl.read_data ) {
      dar = (char*)calloc(bpp,nvox) ; /* make space for super-image */
      if(dar==NULL)  {  /* exit if can't allocate memory */
         ERROR_message("Could not allocate memory for mosaic volume");
         RETURN(1);
      }

      fread( dar , bpp , nvox , fp ) ;    /* read data directly into it */

      if( swap ){                        /* swap bytes? */
        switch( bpp ){
          default: break ;
          case 2:  swap_twobytes (   nvox, dar ) ; break ;  /* short */
          case 4:  swap_fourbytes(   nvox, dar ) ; break ;  /* int, float */
          case 8:  swap_fourbytes( 2*nvox, dar ) ; break ;  /* complex */
        }
      }
   }

   /* load data from dar into images */
   nxx = mos_nx * mos_ix ;              /* # pixels per mosaic line */

   for (ii=0;ii<mosaic_num;ii++) {
      /* find right slice - may be reading the series of slices backwards */
      if(*flip_slices) slice = mosaic_num - ii -1;
      else slice = ii;
      xx = slice % mos_ix; /* xx,yy are indices for position in mosaic matrix */
      yy = slice / mos_iy;
      /* im = mri_new( mos_nx , mos_ny , datum ) ; */
      im = mri_new_7D_generic(mos_nx,mos_ny, 1,1,1,1,1, datum,
                              g_dicom_ctrl.read_data);
      if( !im ) {
         fprintf(stderr,"** RMD: failed to allocate %d voxel image\n",
                 mos_nx * mos_ny);
         RETURN(1);
      }

      /* if reading data, actually copy data into MRI image */
      if( g_dicom_ctrl.read_data ) {
         iar = mri_data_pointer( im ) ;             /* sub-image array */

         for( jj=0 ; jj < mos_ny ; jj++ )  /* loop over rows inside sub-image */
           memcpy( iar + jj*mos_nx*bpp ,
                   dar + xx*mos_nx*bpp + (jj+yy*mos_ny)*nxx*bpp ,
                   mos_nx*bpp                                    ) ;
       }

       if( dx > 0.0 && dy > 0.0 && dz > 0.0 ){
         im->dx = dx; im->dy = dy; im->dz = dz; im->dw = 1.0;
       }
       if( dt > 0.0 ) im->dt = dt ;
       if( swap ) im->was_swapped = 1 ;

       ADDTO_IMARR(imar,im) ;
   } /* end of ii sub-image loop */

   if( dar )
      free(dar); /* don't need no more; copied all data out of it now */

   /* truncate zero images out of tail of mosaic */
   if( mosaic_num < IMARR_COUNT(imar) )
       TRUNCATE_IMARR(imar,mosaic_num) ;

   if( verb > 1 )
      fprintf(stderr,"\nmri_read_dicom Mosaic: mos_nx=%d mos_ny=%d mos_ix=%d"
                     " mos_iy=%d slices=%d\n",
              mos_nx,mos_ny,mos_ix,mos_iy,IMARR_COUNT(imar)) ;
      /* MCHECK ; */

   RETURN(0);
}