[Dcmlib] offset

Benoit Regrain benoit.regrain at creatis.insa-lyon.fr
Mon May 16 12:22:42 CEST 2005


Hi,

Voici les points incohérents que je vois dans ton code :
 - h->WriteDcmExplVR( output ); // fh-> et non pas h->
 - La spécification des Bits Allocated, etc. devrait être faite
   pour l'image écrite dès la 1ere écriture
 - enfin, lorsque tu fais le SetImageData, tu spécifies dataSize*3...
   c'est FAUX. Tu passe de 16bits vers 8bits et tu passe de greyscale
   vers RGB. Tu devrais donc avoir : (dataSize/2)*3


Si cela ne change rien, peux tu m'envoyer ton projet complet ainsi que l'image test 
dont tu te sers afin que je puisse regarder sur mon ordi.

Benoit



  ----- Original Message ----- 
  From: Olivier Stern 
  To: 'Benoit Regrain' ; Dcmlib at creatis.insa-lyon.fr ; 'Jean-Pierre Roux' ; 'Mathieu Malaterre' 
  Sent: Monday, May 16, 2005 12:04 PM
  Subject: RE: [Dcmlib] offset


   

  Bonjour,

   

  Les trois champs indiqués ont bien la valeur précisée. Je me suis inspiré d'un code que Jean-Pierre Roux m'a envoyé qui transformait un image monochrome 8 bits vers une image RGB 3*8 bits ainsi que une image 16 bits monochrome vers une image 3*16 bits RGB et j'ai effectué la conversion selon ses conseils (d'ailleurs j obtiens un bon résultat visible si je laisse le champ 16 bits allocated, mais l image est beaucoup plus foncée que l'originale). Le else du code suivant correspond au cas ou l'on aurait une image avec 16bits allocated : (L'image sortante de ce code n est pas lisible car Offset + image size > file length)

   

  Merci,

      Olivier Stern

   

  [.]

   

    gdcm::FileHelper *fh = new gdcm::FileHelper( filename );

    size_t dataSize    = fh->GetImageDataSize();

    uint8_t *imageData = fh->GetImageData();

    uint8_t *imageDataRGB = new uint8_t[dataSize*3];

   

  [.]

   

    else {

    

      //fh->GetFile()->InsertValEntry( "8", 0x0028, 0x0100); // Bits Allocated

      //fh->GetFile()->InsertValEntry( "8", 0x0028, 0x0101); // Bits Stored

      //fh->GetFile()->InsertValEntry( "7", 0x0028, 0x0102); // High Bit

      //fh->GetFile()->InsertValEntry( "0", 0x0028, 0x0103); // Pixel Representation

    

      uint16_t maxVal = 0;

      uint16_t minVal = 1000;

      int xSize = fh->GetFile()->GetXSize();

      int ySize = fh->GetFile()->GetYSize();

      // Recherche du pixel à la valeur maximale et minimale

      for (unsigned int i=0;i<dataSize/2;i++) {

        if (((uint16_t *)imageData)[i] > maxVal) {

          maxVal  = ((uint16_t *)imageData)[i];

        }

        if (((uint16_t *)imageData)[i] < minVal) {

          minVal  = ((uint16_t *)imageData)[i];

        }

      }

      for (unsigned int i=0;i<dataSize/2;i++) {

        uint16_t pixel = (((uint16_t *)imageData)[i] - maxVal) * 255  / (maxVal - minVal);

        imageDataRGB[i*3] = imageDataRGB[i*3+1] = imageDataRGB[i*3+2] = ((uint8_t) pixel);

      }

    }

    

    // Samples Per Pixel  

    

    fh->GetFile()->InsertValEntry( "3 " ,0x0028,0x0002);

    fh->GetFile()->InsertValEntry( "RGB ",0x0028,0x0004 ); // Photometric Interpretation

    fh->GetFile()->InsertValEntry( "1 ",0x0028,0x0006 ); // Planar Configuration

     

    // TODO  : free existing PixelData first !

   

     fh->SetImageData(imageDataRGB, dataSize*3);   

    h->WriteDcmExplVR( output );

    // fh->GetFile()->Print();

    gdcm::FileHelper *fh2 = new gdcm::FileHelper( output );

    fh2->GetFile()->InsertValEntry( "8", 0x0028, 0x0100); // Bits Allocated  

    fh2->GetFile()->InsertValEntry( "8", 0x0028, 0x0101); // Bits Stored

    fh2->GetFile()->InsertValEntry( "7", 0x0028, 0x0102); // High Bit

    fh2->GetFile()->InsertValEntry( "0", 0x0028, 0x0103); // Pixel Representation

    fh2->WriteDcmExplVR( output );

   

    return 0 ;

  }

   

   


------------------------------------------------------------------------------

  De : Benoit Regrain [mailto:benoit.regrain at creatis.insa-lyon.fr] 
  Envoyé : lundi 16 mai 2005 11:31
  À : Olivier Stern; Dcmlib at creatis.insa-lyon.fr; 'Jean-Pierre Roux'; 'Mathieu Malaterre'
  Objet : Re: [Dcmlib] offset

   

  Peut-on voir les codes que tu as écrit ?

   

  Lorsque tu veux modifier le taux d'échantillonage de ton image, tu as 3

  champs à modifier : 

     0x0028,0x0100  // Bits Allocted (= 8 dans ton cas)

     0x0028,0x0101); // Bits Stored (= 8 dans ton cas)

     0x0028,0x0102); // High Bit (= 7 dans ton cas)

   

  Si ces trois champs ne sont pas cohérents entre eux, il se peux que 

  l'écriture ne se fasse pas ou que la lecture de l'image soit incorrecte.

   

  Cordialement

  Benoit

   

   

  REMARQUE

  --> aux développeurs... je ne suis pas sur qu'on ait mis des tests

  sur ce point la. JPR, tu pourrais vérifier ca et peut-etre meme les ajouter.

  Surtout à l'écriture.

   



------------------------------------------------------------------------------


  _______________________________________________
  Dcmlib mailing list
  Dcmlib at creatis.insa-lyon.fr
  http://www.creatis.insa-lyon.fr/mailman/listinfo/dcmlib
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.creatis.insa-lyon.fr/pipermail/dcmlib/attachments/20050516/155013ac/attachment.html>


More information about the Dcmlib mailing list