GDCM  2.2.0
ConvertSingleBitTo8Bits.cxx
/*=========================================================================
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.
=========================================================================*/
#include "vtkImageData.h"
#include "vtkImageCast.h"
#include "vtkPointData.h"
#include "vtkBitArray.h"
#include "vtkUnsignedCharArray.h"
int main(int argc, char *argv[])
{
if( argc < 3 )
{
return 1;
}
const char *filename = argv[1];
const char *outfilename = argv[2];
reader->SetFileName( filename );
reader->Update();
//reader->GetOutput()->Print( std::cout );
vtkDataArray* array = reader->GetOutput()->GetPointData()->GetScalars();
vtkBitArray *barray = vtkBitArray::SafeDownCast( array );
if( !barray ) return false;
vtkIdType nvalues = array->GetNumberOfTuples();
vtkUnsignedCharArray *uarray = vtkUnsignedCharArray::New();
uarray->SetNumberOfTuples( nvalues );
for(vtkIdType i = 0; i < nvalues; ++i)
{
uarray->SetValue( i, barray->GetValue(i) );
}
vtkImageData *copy = vtkImageData::New();
copy->SetScalarType( VTK_UNSIGNED_CHAR );
copy->SetExtent( reader->GetOutput()->GetExtent() );
copy->AllocateScalars();
//uarray->Print( std::cout );
//copy->GetPointData()->GetScalars()->Print( std::cout );
copy->GetPointData()->SetScalars( uarray );
uarray->Delete();
writer->SetFileName( outfilename );
//writer->SetInput( cast->GetOutput() );
writer->SetInput( copy );
writer->SetImageFormat( reader->GetImageFormat() );
writer->SetMedicalImageProperties( reader->GetMedicalImageProperties() );
writer->SetDirectionCosines( reader->GetDirectionCosines() );
writer->SetShift( reader->GetShift() );
writer->SetScale( reader->GetScale() );
writer->SetFileDimensionality( reader->GetFileDimensionality( ) );
writer->Write();
reader->Delete();
copy->Delete();
writer->Delete();
return 0;
}

Generated on Wed Jun 13 2012 20:40:36 for GDCM by doxygen 1.8.1
SourceForge.net Logo