GDCM  2.2.6
PatchFile.cxx

This is a C++ example on how to use gdcm::Attribute

/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.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 notice for more information.
=========================================================================*/
/*
* The image was a broken file where the Pixel Data element was 8 times too big
* Apparently multiplying the BitsAllocated to 4 and multiplying the number of
* frames by 2 would solve the problem
*
* This C++ code can be used to patch the header.
*/
#include "gdcmReader.h"
#include "gdcmWriter.h"
#include "gdcmDataSet.h"
#include "gdcmAttribute.h"
int main(int argc, char *argv[])
{
if( argc < 3 )
{
return 1;
}
const char *f = argv[1];
const char *out = argv[2];
r.SetFileName( f );
if( !r.Read() )
{
return 1;
}
gdcm::File &file = r.GetFile();
gdcm::DataSet& ds = file.GetDataSet();
// (0028,0100) US 16 # 2, 1 BitsAllocated
// (0028,0101) US 16 # 2, 1 BitsStored
// (0028,0102) US 15 # 2, 1 HighBit
//
{
if( at.GetValue() != 8 )
{
return 1;
}
at.SetValue( 32 );
}
{
if( at.GetValue() != 8 )
{
return 1;
}
at.SetValue( 32 );
}
{
if( at.GetValue() != 7 )
{
return 1;
}
at.SetValue( 31 );
}
// (0028,0008) IS [56] # 2, 1 NumberOfFrames
{
at.SetValue( at.GetValue() * 2 );
}
w.SetFile( file );
w.SetFileName( out );
if( !w.Write() )
{
return 1;
}
// Now let's see if we can read it as an image:
ir.SetFileName( out );
if(!ir.Read())
{
return 1;
}
gdcm::Image &image = ir.GetImage();
unsigned long len = image.GetBufferLength();
const gdcm::ByteValue *bv = ir.GetFile().GetDataSet().GetDataElement( gdcm::Tag(0x7fe0,0x0010) ).GetByteValue();
if( !bv || len != bv->GetLength() )
{
return 1;
}
std::cout << bv->GetLength() << " " << len << std::endl;
std::cout << "Sucess to rewrite image !" << std::endl;
image.Print( std::cout );
return 0;
}

Generated on Sat Dec 21 2013 05:56:15 for GDCM by doxygen 1.8.5
SourceForge.net Logo