GDCM 3.0.24
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 );
return b;
}
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;
}
Bitmap class.
Definition gdcmBitmap.h:39
const LookupTable & GetLUT() const
Definition gdcmBitmap.h:87
const PixelFormat & GetPixelFormat() const
Get/Set PixelFormat.
Definition gdcmBitmap.h:107
const PhotometricInterpretation & GetPhotometricInterpretation() const
return the photometric interpretation
const DataElement & GetDataElement() const
Definition gdcmBitmap.h:79
void Print(std::ostream &) const override
const unsigned int * GetDimensions() const
Return the dimension of the pixel data, first dimension (x), then 2nd (y), then 3rd (z)....
const TransferSyntax & GetTransferSyntax() const
Definition gdcmBitmap.h:72
Class to represent binary value (array of bytes)
Definition gdcmByteValue.h:35
const char * GetPointer() const
Definition gdcmByteValue.h:110
VL GetLength() const override
Definition gdcmByteValue.h:77
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
const ByteValue * GetByteValue() const
Definition gdcmDataElement.h:133
IconImageFilter.
Definition gdcmIconImageFilter.h:50
unsigned int GetNumberOfIconImages() const
Retrieve extract IconImage (need to call Extract first)
void SetFile(const File &f)
Set/Get File.
Definition gdcmIconImageFilter.h:56
IconImage & GetIconImage(unsigned int i) const
bool Extract()
Extract all Icon found in File.
IconImageGenerator.
Definition gdcmIconImageGenerator.h:42
void SetPixmap(const Pixmap &p)
Set/Get File.
Definition gdcmIconImageGenerator.h:48
void SetOutputDimensions(const unsigned int dims[2])
Set Target dimension of output Icon.
bool Generate()
Generate Icon.
const IconImage & GetIconImage() const
Retrieve generated Icon.
Definition gdcmIconImageGenerator.h:80
void AutoPixelMinMax(bool b)
void SetDimensions(const unsigned int d[3])
virtual void SetPixelFormat(PixelFormat const &pf)
Definition gdcmImageCodec.h:70
void SetLUT(LookupTable const &lut)
Definition gdcmImageCodec.h:89
void SetPhotometricInterpretation(PhotometricInterpretation const &pi)
ImageReader.
Definition gdcmImageReader.h:34
const Image & GetImage() const
Return the read image.
bool Read() override
Image.
Definition gdcmImage.h:47
Class to do PNM.
Definition gdcmPNMCodec.h:30
bool Write(const char *filename, const DataElement &out) const
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
void SetFileName(const char *filename_native)
bool IsEncapsulated() const
@ JPEGBaselineProcess1
Definition gdcmTransferSyntax.h:67
@ JPEGExtendedProcess2_4
Definition gdcmTransferSyntax.h:68