Beispiel #1
0
/* Read an inrimage in fileName */
inrimage *readZInrimage(const char *fileName) {
  _image *img;
  inrimage *inr = NULL;

  img = _readImage(fileName);
  if(img) {
    inr = _image2inrimage(img);
    img->data = NULL;
    _freeImage(img);
    return inr;
  }
  else return NULL;
}
Image<double> InputFileFITS::readImage64f()
{
	Image<double> buff;
	_readImage(buff, TDOUBLE);
	return buff;
}
Image<float> InputFileFITS::readImage32f()
{
	Image<float> buff;
	_readImage(buff, TFLOAT);
	return buff;
}
Image<int64_t> InputFileFITS::readImage64i()
{
	Image<int64_t> buff;
	_readImage(buff, TLONG);
	return buff;
}
Image<int32_t> InputFileFITS::readImage32if()
{
	Image<int32_t> buff;
	_readImage(buff, TINT);
	return buff;
}
Image<int16_t> InputFileFITS::readImage16i()
{
	Image<int16_t> buff;
	_readImage(buff, TSHORT);
	return buff;
}
Image<uint8_t> InputFileFITS::readImageu8i()
{
	Image<uint8_t> buff;
	_readImage(buff, TBYTE);
	return buff;
}
Beispiel #8
0
int main(int argc, char *argv[])
{
  _image *theIm;
  
  if ( argc == 1 ) {
    fprintf( stderr, "Usage: %s input output\n", argv[0] );
    exit( -1 );
  }
  
  theIm = _readImage( argv[1] );
  if ( theIm == NULL ) {
    fprintf( stderr, "%s: unable to read '%s'\n", argv[0], argv[1] );
    exit( -1 );
  }

  fprintf( stderr, "Information on '%s'\n", argv[1] );
  fprintf( stderr, "- image size is %lu x %lu x %lu\n",
	   theIm->xdim, theIm->ydim,  theIm->zdim );
  fprintf( stderr, "- voxel size is %f x %f x %f\n",
	   theIm->vx, theIm->vy,  theIm->vz );
  fprintf( stderr, "- image encoding is " );

  switch( theIm->wordKind ) {
  default :
    fprintf( stderr, "not handled\n" );
    break;
  case WK_FLOAT :
    switch( theIm->wdim ) {
    default :
      fprintf( stderr, "not handled\n" );
      break;
    case 4 :
      fprintf( stderr, "float\n" );
      break;
    case 8 :
      fprintf( stderr, "double\n" );
      break;
    }
    break;
  case WK_FIXED :
    switch( theIm->sign ) {
    default :
      fprintf( stderr, "not handled\n" );
      break;
    case SGN_SIGNED :
      switch( theIm->wdim ) {
      default :
	fprintf( stderr, "not handled\n" );
	break;
      case 1 :
	fprintf( stderr, "signed char\n" );
	break;
      case 2 :
	fprintf( stderr, "signed short int\n" );
	break;
      case 4 :
	fprintf( stderr, "signed int\n" );
	break;
      }
      break;
    case SGN_UNSIGNED :
      switch( theIm->wdim ) {
      default :
	fprintf( stderr, "not handled\n" );
	break;
      case 1 :
	fprintf( stderr, "unsigned char\n" );
	break;
      case 2 :
	fprintf( stderr, "unsigned short int\n" );
	break;
      case 4 :
	fprintf( stderr, "unsigned int\n" );
	break;
      }
      break;
    } /* switch( theIm->sign ) */
    break;
  }

  /* image data is in the buffer 'theIm->data' that is void*, meaning you can not use it directly.
     You have to use a pointer with the right type and cast the data pointer, e.g. for 'signed short int'
     encoding,
     short int *buf = (short int*)theIm->data;
     buf[z*theIm->xdim*theIm->ydim + y*theIm->xdim + x] is then the image value at (x,y,z)
  */

   if ( argc > 2 ) {
     if ( _writeImage( theIm, argv[2] ) != 0 ) {
       fprintf( stderr, "%s: unable to write '%s'\n", argv[0], argv[2] );
       exit( -1 );
     }
   }

   _freeImage( theIm ); 
   exit( 0 );
}
Beispiel #9
0
int VT_ReadInrimage( vt_image *image, char *name )
{
  char *proc = "VT_ReadInrimage";
  _image *inr;

  if ( _VT_DEBUG_ ) {
    fprintf( stderr, "%s: uses LIBINRIMAGE routines\n", proc );
  }

  if ( _flag_init_readers == 0 ) {
    _init_readers();
    _flag_init_readers = 1;
  }

  VT_FreeImage( image );
  /* lecture
   */
  inr = _readImage( name );
  if( !inr ) {
    if ( _VT_VERBOSE_ )
      fprintf( stderr, "%s: unable to read '%s'\n ", proc, name );
    return 0;
  }

  strcpy( image->name, name );
  if ( _decodeInrHeader( inr, image ) != 1 ) {
    _freeImage(inr);
    fprintf( stderr, "%s: unable to decode header of '%s'\n ", proc, name );
    return 0;
  }

  
  
  image->buf = inr->data;

  strcpy( image->name, name );

  {
    unsigned int vol_ptr;
    int i,j;

    switch ( image->type ) {
    case SCHAR :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( s8* );
      vol_ptr += image->dim.z                * sizeof( s8** );
      break;
    case UCHAR :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( u8* );
      vol_ptr += image->dim.z                * sizeof( u8** );
      break;
    case SSHORT :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( s16* );
      vol_ptr += image->dim.z                * sizeof( s16** );
      break;
    case USHORT :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( u16* );
      vol_ptr += image->dim.z                * sizeof( u16** );
      break;
    case FLOAT :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( r32* );
      vol_ptr += image->dim.z                * sizeof( r32** );
      break;
    case DOUBLE :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( r64* );
      vol_ptr += image->dim.z                * sizeof( r64** );
      break;
    case SINT :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( i32* );
      vol_ptr += image->dim.z                * sizeof( i32** );
      break;
    case UINT :
      vol_ptr  = image->dim.z * image->dim.y * sizeof( u32* );
      vol_ptr += image->dim.z                * sizeof( u32** );
      break;
    default :
      if ( _VT_VERBOSE_ )
	fprintf( stderr, "%s: unknown image type", proc );
      _freeImage(inr);
      return 0;
    }

    image->array = (void***) malloc( (unsigned int)(vol_ptr) );
    if ( image->array == NULL ) {
      if ( _VT_VERBOSE_ )
	fprintf( stderr, "%s: private buffer allocation failed", proc );
      _freeImage(inr);
      return 0;
    }

    switch ( image->type ) {
    case SCHAR :
      {
	s8 ***z;
	s8 **zy;
	s8 *zyx;
	
	z = (s8 ***)(image->array);
	zy = (s8 **)(z + image->dim.z);
	zyx = (s8 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    case UCHAR :
      {
	u8 ***z;
	u8 **zy;
	u8 *zyx;
	
	z = (u8 ***)(image->array);
	zy = (u8 **)(z + image->dim.z);
	zyx = (u8 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    case SSHORT :
      {
	s16 ***z;
	s16 **zy;
	s16 *zyx;
	
	z = (s16 ***)(image->array);
	zy = (s16 **)(z + image->dim.z);
	zyx = (s16 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    case USHORT :
      {
	u16 ***z;
	u16 **zy;
	u16 *zyx;
	
	z = (u16 ***)(image->array);
	zy = (u16 **)(z + image->dim.z);
	zyx = (u16 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    case FLOAT :
      {
	r32 ***z;
	r32 **zy;
	r32 *zyx;
	
	z = (r32 ***)(image->array);
	zy = (r32 **)(z + image->dim.z);
	zyx = (r32 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    case DOUBLE :
      {
	r64 ***z;
	r64 **zy;
	r64 *zyx;
	
	z = (r64 ***)(image->array);
	zy = (r64 **)(z + image->dim.z);
	zyx = (r64 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    case SINT :
      {
	i32 ***z;
	i32 **zy;
	i32 *zyx;
	
	z = (i32 ***)(image->array);
	zy = (i32 **)(z + image->dim.z);
	zyx = (i32 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    case UINT :
      {
	u32 ***z;
	u32 **zy;
	u32 *zyx;
	
	z = (u32 ***)(image->array);
	zy = (u32 **)(z + image->dim.z);
	zyx = (u32 *)(image->buf);
	
	/*--- calcul pour le premier indice Z ---*/
  for ( i = 0; i < (int)image->dim.z; i ++ ) {
	  *z = zy;
	  z ++;
	  /*--- calcul pour le deuxieme indice Y ---*/
    for ( j = 0; j < (int)image->dim.y; j ++ ) {
	    *zy = zyx;
	    zy ++;
	    zyx += image->dim.x * image->dim.v;
	  }
	}}
      break;
    default :
      if ( _VT_VERBOSE_ )
	fprintf( stderr, "%s: unknown image type", proc );
      _freeImage(inr);
      return 0;
    }
   

  }
  
  (void)ImageIO_close( inr );
  ImageIO_free( inr );

  return 1;
}