[Dcmlib] TestRescaleDicom

jean-michel.rouet at philips.com jean-michel.rouet at philips.com
Wed Nov 17 11:01:16 CET 2004


Mathieu,

ca ca fonctionne chez moi... 
La boucle for est un peu tricky, mais ca fonctionne car on passe de 16 a 8 
et pas de 8 a 16 bits. Si tel etait le cas, il faudrait faire une boucle 
decroissante de rescaleSize a 0 !!! :p

int TestRescaleDicom(char *input)
{
   gdcm::File *f1 = new gdcm::File( input );
   gdcm::Header *header = f1->GetHeader();

   int dataSize    = f1->GetImageDataSize();
   int rescaleSize = dataSize / 2;

   // Since we know the image is 16bits:
   uint16_t* imageData = (uint16_t*)f1->GetImageData();

   header->ReplaceOrCreateByNumber( "8", 0x0028, 0x0100);// BitsAllocated
   header->ReplaceOrCreateByNumber( "8", 0x0028, 0x0101);// BitsStored
   header->ReplaceOrCreateByNumber( "7", 0x0028, 0x0102);// HighBit
   header->SetImageDataSize(rescaleSize);

   // modify grayvalues: We assume the value were from 0 to 4*uint8_t max
   // and convert from 16 bits to 8 bits...
   uint8_t* tmp = (uint8_t *)imageData;
   for(int i=0; i<rescaleSize; i++) tmp[i] = imageData[i]/4;

   // write the image to a new file
   f1->WriteDcmExplVR( "/tmp/output.dcm" );

   // free memory
   delete f1;

   return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.creatis.insa-lyon.fr/pipermail/dcmlib/attachments/20041117/89591fa2/attachment.html>


More information about the Dcmlib mailing list