[Insight-developers] DICOM to TIF or JPEG

Satish Satish at compusol.in
Mon Jan 24 07:54:25 EST 2011


Hi

 

We're need to read a DICOM file (multi-frame) and write one frame as
JPEG or TIF image.

Tried the following using itkTIFFImageIO.h, but the output tif file does
not display image in tif viewer, whereas when viewed in DICOM viewer it
displays the image.

Here's the code

 

#include "itkImage.h"

#include "itkImageFileReader.h"

#include "itkImageFileWriter.h"

#include "itkImageRegionIterator.h"

#include "itkTIFFImageIO.h"

 

int main(int argc, char *argv[])

{

      if (argc < 3 )

    {

    std::cerr << "Usage: SatReader2 inputFile outputFile" << std::endl;

    return EXIT_FAILURE;

    }

 

  typedef short      PixelType;

  const   unsigned int        Dimension = 2;

  typedef itk::Image< PixelType, Dimension >    ImageType; 

  typedef itk::ImageFileReader< ImageType >  ReaderType;

  typedef itk::ImageFileWriter< ImageType >  WriterType;

  typedef itk::TIFFImageIO ImageIOType;

 

  ReaderType::Pointer reader = ReaderType::New();

  WriterType::Pointer writer = WriterType::New();

  ImageIOType::Pointer tiffIO = ImageIOType::New();

 

  const char * inputFilename  = argv[1];

  const char * outputFilename = argv[2];

 

  reader->SetFileName( inputFilename  );

  writer->SetFileName( outputFilename );

  

  writer->SetInput(reader->GetOutput());  

  writer->SetImageIO(tiffIO);

   

  try 

    { 

    writer->Update(); 

    } 

  catch( itk::ExceptionObject & err ) 

    { 

    std::cerr << "ExceptionObject caught !" << std::endl; 

    std::cerr << err << std::endl; 

    return EXIT_FAILURE;

    }  

  return EXIT_SUCCESS;

}

 

Regards

Satish Kumar B.G

 

Technical Architect

COMPUSOL

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110124/e22027e1/attachment.htm>


More information about the Insight-developers mailing list