[Insight-developers] DICOM to TIF or JPEG

Luis Ibanez luis.ibanez at kitware.com
Fri Jan 28 14:50:34 EST 2011


Hi Satish,

A Multi-frame DICOM will be a 3D image,
you here are only reading a 2D image.

You may want to read a 3D image, and then
use the ImageSeriesWriter to save it as a
sequence of TIFFs.


      Luis


--------------------------------------------
On Mon, Jan 24, 2011 at 7:54 AM, Satish <Satish at compusol.in> wrote:
> 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
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>
>


More information about the Insight-developers mailing list