/*========================================================================= Program: gdcm Module: $RCSfile: TestBug.cxx,v $ Language: C++ Date: $Date: 2004/11/16 04:28:20 $ Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ // We are trying here to read in a 16bits image and try to write it down as // a 8 bits one #include "gdcm.h" int TestRescaleDicom(int , char* []) { gdcm::File *f1 = new gdcm::File( "/home/malaterre/Creatis/gdcmData/012345.002.050.dcm" ); gdcm::Header *header = f1->GetHeader(); const std::string & bitsAllocated = header->GetEntryByNumber(0x0028,0x0100); const std::string & bitsStored = header->GetEntryByNumber(0x0028,0x0101); const std::string & highBit = header->GetEntryByNumber(0x0028,0x0102); std::cout << "BitsAllocated: " << bitsAllocated << std::endl; std::cout << "BitsStored: " << bitsStored << std::endl; std::cout << "HighBit: " << highBit << std::endl; int dataSize = f1->GetImageDataSize(); std::cout << "DataSize: " << dataSize << std::endl; // Since we know the image is 16bits: uint16_t* imageData = (uint16_t*)f1->GetImageData(); gdcm::File *f2 = new gdcm::File( header ); f2->GetHeader()->ReplaceOrCreateByNumber( "8", 0x0028, 0x0100);// BitsAllocated f2->GetHeader()->ReplaceOrCreateByNumber( "8", 0x0028, 0x0101);// BitsStored f2->GetHeader()->ReplaceOrCreateByNumber( "7", 0x0028, 0x0102);// HighBit int rescaleSize = dataSize / 2; uint8_t *rescaleImage = new uint8_t[rescaleSize]; // We assume the value were from 0 to uint16_t max for(int i=0; iSetImageData(rescaleImage, rescaleSize); f2->WriteDcmExplVR( "/tmp/output.dcm" ); delete f1; delete f2; delete rescaleImage; return 0; }