Hello everyone,
I need to load some medical images with .img format in my application. But the PxLoadImage() just can load like .jpeg,.bmp,.tif.pcx…not .img format. The .img file I used is a file contain many slices of MRI images, each slice is a 256*256 pixel image. So I intend to read the .img file first and PhCreateImage() and PdDrawImage(). My code is:
unsigned int fbuffer[256][256] = { 0 };
PhPoint_t p = { 300, 0 };
PhDim_t pp = {512, 512 };
static unsigned int slice[150][256][256]={0};
int rc,i,j,n;
FILE* fp;
PhImage_t *img;
PgColor_t plat;
char *bits;
fp=fopen("/root/jack/dcs.img","r");
if( fp == NULL )
{
PtTextModifyText(ABW_inf_text, 0,0,-1,"rom file open failed",20);
}
for (i=0;i<150;i++)
{
//rc=fread(fname, 1, sizeof(fname), fp);
rc=fread(fbuffer, 256, 256, fp);
}/*finally, fbuffer should be the 150th slice of image 256*256*/
img=PhCreateImage(NULL,256,256,Pg_IMAGE_DIRECT_1555,NULL,0,1);
/* bits=img->image;
for (i=0;i<256;i++,bits+=img->bpl)
for (j=0;j>256;j++)
((short*)bits)[j]=fbuffer[i][j];*/
PgSetPalette( img->palette, 0, 0, img->colors, Pg_PALSET_SOFT, 0 );
PgDrawImage( fbuffer, img->type, &p, &img->size, img->bpl, 0 );
At the end, I draw the 150th MRI image with the array fbuffer, I try to write the data in fbuffer to the pointer img->image, but I cannot write in. Can anybody tell me how to write in?
And the image shows un-complete like lost data or maybe have offset, what is the reason? Maybe because I didnot write the data into img->image??
Please help, thank you very much!
Jason