Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - How to load images with .img format in Phab?: Page 1 of 13 (13 Items)
   
How to load images with .img format in Phab?  
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: 


Code:

                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,512,512,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 ); 


Any thing wrong with the code please? And 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