GDCM  2.2.6
ExtractIconFromFile.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.
=========================================================================*/
/*
* This example shows how to either retrieve an Icon if present somewhere
* in the file, or else generate one.
*/
#include "gdcmPNMCodec.h"
bool WriteIconAsPNM(const char* filename, const gdcm::IconImage& icon)
{
pnm.SetLUT( icon.GetLUT() );
const gdcm::DataElement& in = icon.GetDataElement();
bool b = pnm.Write( filename, in );
assert( b ); (void)b;
return true;
}
int main(int argc, char *argv [])
{
if( argc < 2 ) return 1;
const char *filename = argv[1];
reader.SetFileName( filename );
if( !reader.Read() )
{
std::cerr << "Failed to read (or not image): " << filename << std::endl;
return 1;
}
iif.SetFile( reader.GetFile() );
bool b = iif.Extract();
if( b )
{
const gdcm::IconImage &icon = iif.GetIconImage(0);
icon.Print( std::cout );
{
// Let's write out this icon as PNM file
WriteIconAsPNM("icon.ppm", icon);
}
)
{
const gdcm::DataElement& in = icon.GetDataElement();
const gdcm::ByteValue *bv = in.GetByteValue();
assert( bv );
std::ofstream out( "icon.jpg", std::ios::binary );
out.write( bv->GetPointer(), bv->GetLength() );
out.close();
}
}
else
{
assert( iif.GetNumberOfIconImages() == 0 );
std::cerr << "No Icon Found anywhere in file" << std::endl;
const gdcm::Image &img = reader.GetImage();
iig.AutoPixelMinMax(true);
iig.SetPixmap( img );
const unsigned int idims[2] = { 64, 64 };
iig.SetOutputDimensions( idims );
//iig.SetPixelMinMax(60, 868);
if( !iig.Generate() ) return 1;
const gdcm::IconImage & icon = iig.GetIconImage();
WriteIconAsPNM("icon.ppm", icon);
}
return 0;
}

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