示例#1
0
void write_analyze_image(const char *filename, float *im, int nx, int ny, int nz, float dx, float dy, float dz)
{
	FILE *fp;
	char hdrfile[1024];
	char imgfile[1024];
	float min, max;
	int nv;

	struct dsr hdr;

	nv = nx*ny*nz;

	get_analyze_file_names(filename, hdrfile, imgfile);

	printf("\nWriting %s ...\n",imgfile);

	create_analyze_hdr(&hdr, nx, ny, nz, 16, dx, dy, dz);

	minmax(im, nv, min, max);
	hdr.dime.glmin=(int)min;
	hdr.dime.glmax=(int)max;

   fp=fopen(imgfile,"w");
   if(fp==NULL) file_open_error(imgfile);
   fwrite(im,sizeof(float),nv,fp);
   fclose(fp);

   fp=fopen(hdrfile,"w");
   if(fp==NULL) file_open_error(hdrfile);
   fwrite(&hdr,sizeof(struct dsr),1,fp);
   fclose(fp);
}
示例#2
0
void write_analyze_image(const char *filename, unsigned char *im, int nx, int ny, int nz, float dx, float dy, float dz, int v)
{
	FILE *fp;
	char hdrfile[1024];
	char imgfile[1024];
	unsigned char min, max;
	int nv;

	struct dsr hdr;

	nv = nx*ny*nz;

	get_analyze_file_names(filename, hdrfile, imgfile);

	if(v) printf("\nWriting %s ...\n",imgfile);

	create_analyze_hdr(&hdr, nx, ny, nz, 2, dx, dy, dz);

	minmax(im, nv, min, max);
	hdr.dime.glmin=min;
	hdr.dime.glmax=max;

	fp=fopen(imgfile,"w");
	fwrite(im,sizeof(unsigned char),nv,fp);
	fclose(fp);

	fp=fopen(hdrfile,"w");
	fwrite(&hdr,sizeof(struct dsr),1,fp);
	fclose(fp);
}
示例#3
0
// assumes that the *.img and *.hdr files exist and we have read permission.
char *read_analyze_image(const char *filename, int *nx, int *ny, int *nz, float *dx, float *dy, float *dz)
{
	char hdrfile[1024];
	char imgfile[1024];
	int nv;
	short dataType;
	char *im;

	struct dsr analyzehdr;

	get_analyze_file_names(filename, hdrfile, imgfile);

    if( !check_F_R_permission(hdrfile) )
    {
        printf("\nError: cannot read %s\n",hdrfile);
		return(NULL);
    }

    if( !check_F_R_permission(imgfile) )
    {
        printf("\nError: cannot read %s\n",imgfile);
		return(NULL);
    }

	printf("\nReading:");
	printf("\n\t%s",hdrfile);
	printf("\n\t%s",imgfile);

	read_analyze_hdr(&analyzehdr, hdrfile);
	setDimensions(analyzehdr, nx, ny, nz, dx, dy, dz, &dataType);

	nv = (*nx)*(*ny)*(*nz);

	if(dataType==4)
	{
		im= read_image(imgfile,nv*2);

		if(im==NULL) return(NULL);

		if ( analyzehdr.hk.sizeof_hdr != 348 )
			swapN( (char *)im, 2*nv);

		return(im);
	}

	if(dataType==2)
	{
		im = read_image(imgfile,nv);
		return(im);
	}

	printf("\n\nSorry, but this program cannot handle this data type! Aborting ...\n\n");
	return(NULL);
}
示例#4
0
int read_datatype(char *filename)
{
	struct dsr hdr;
	char hdrfile[1024];
	char imgfile[1024];

	get_analyze_file_names(filename, hdrfile, imgfile);

	read_analyze_hdr(&hdr, hdrfile);

	if ( hdr.hk.sizeof_hdr != 348 )
	{
		swapByteOrder( (char *) &hdr.dime.datatype, sizeof(short) );
	}

	return( (int)(hdr.dime.datatype) );
}
示例#5
0
int read_nz(const char *filename)
{
	struct dsr hdr;
	char hdrfile[1024];
	char imgfile[1024];

	get_analyze_file_names(filename, hdrfile, imgfile);

	read_analyze_hdr(&hdr, hdrfile);

	if ( hdr.hk.sizeof_hdr != 348 )
	{
		swapN( (char *) hdr.dime.dim , 16);
	}

	return( hdr.dime.dim[3] );
}
示例#6
0
float read_dz(const char *filename)
{
	struct dsr hdr;
	char hdrfile[1024];
	char imgfile[1024];

	get_analyze_file_names(filename, hdrfile, imgfile);

	read_analyze_hdr(&hdr, hdrfile);

	if ( hdr.hk.sizeof_hdr != 348 )
	{
		for(int i=0; i<8; i++)
			swapByteOrder( (char *) &hdr.dime.pixdim[i], sizeof(float) );
	}

	return( hdr.dime.pixdim[3] );
}
示例#7
0
// assumes that the *.img and *.hdr files exist and we have read permission.
void read_analyze_image(const char *filename, short *im)
{
	char hdrfile[1024];
	char imgfile[1024];
	int nv;
	int nx,ny,nz;
	float dx,dy,dz;
	short dataType;

	struct dsr analyzehdr;

	if(im==NULL) return;

	get_analyze_file_names(filename, hdrfile, imgfile);

    if( !check_F_R_permission(hdrfile) )
    {
        printf("\nError: cannot read %s\n",hdrfile);
		return;
    }

    if( !check_F_R_permission(imgfile) )
    {
        printf("\nError: cannot read %s\n",imgfile);
		return;
    }

	read_analyze_hdr(&analyzehdr, hdrfile);
	setDimensions(analyzehdr, &nx, &ny, &nz, &dx, &dy, &dz, &dataType, 0);

	nv = nx*ny*nz;

	if(dataType!=4) return;

	read_image(imgfile, (char *)im, nv*2);

	if ( analyzehdr.hk.sizeof_hdr != 348 )
		swapN( (char *)im, 2*nv);
}
示例#8
0
// assumes that the *.img and *.hdr files exist and we have read permission.
char *read_analyze_image(const char *filename, DIM *dim, int *type, int v)
{
	char hdrfile[1024];
	char imgfile[1024];
	int nv;
	short dataType;
	char *im=NULL;

	struct dsr analyzehdr;

	get_analyze_file_names(filename, hdrfile, imgfile);

	if( !check_F_R_permission(hdrfile) )
	{
		printf("\nError: cannot read %s\n\n",hdrfile);
		return(NULL);
	}

	if( !check_F_R_permission(imgfile) )
	{
		printf("\nError: cannot read %s\n\n",imgfile);
		return(NULL);
	}

	if(v)
	{
		printf("\nReading:");
		printf("\n\t%s",hdrfile);
		printf("\n\t%s",imgfile);
	}

	read_analyze_hdr(&analyzehdr, hdrfile);
	setDimensions(analyzehdr, &(dim->nx), &(dim->ny), &(dim->nz), &(dim->dx), &(dim->dy), &(dim->dz), &dataType,v);

	nv = (dim->nx)*(dim->ny)*(dim->nz);

	*type = dataType;

	if(dataType==16)
	{
		im = read_image(imgfile,(int)(nv*sizeof(float)));

		if ( im!=NULL && analyzehdr.hk.sizeof_hdr != 348 )
		for(int i=0; i<nv; i += sizeof(float))
			swapByteOrder( im+i, sizeof(float));
	}
	else if(dataType==4)
	{
		im= read_image(imgfile,nv*sizeof(short));

		if (im!=NULL &&  analyzehdr.hk.sizeof_hdr != 348 )
			swapN( im, 2*nv);
	}
	else if(dataType==2)
	{
		im = read_image(imgfile,nv);
	}
	else
	{
		printf("\nSorry, but this program cannot handle this data type! Aborting ...\n\n");
		return(NULL);
	}

	return(im);
}