[Insight-users] How could I filter the whole image

Mengqiu Tian tianmengqiu at gmail.com
Wed Jul 6 09:16:17 EDT 2011


Hi all,

I have  a  question.

I have a raw image which contains 125 frames.
The mhd file as follows:

NDims = 3
DimSize = 512 512 125
ElementSpacing = 0.333 0.333 0.333
Position = 0 0 0
ElementByteOrderMSB = False
ElementNumberOfChannels = 1
ElementType = MET_SHORT
ElementDataFile = ctA0-512x512x125x16.raw

I could read it and then write all frames to another image 'test.raw' by
using RawImageIO class.
How could I realize it with MetaImageIO class? My program as follows, and I
added a filter which mulitply the image by a constant 100. However, I could
filter only the first frame and write it to test.raw

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkMetaImageIO.h"
#include "itkWeightedImageFilter.h"
int main( int argc, char ** argv)
{
  typedef unsigned short      PixelType;
  const   unsigned int        Dimension = 2;
  typedef itk::Image< PixelType, Dimension >    ImageType;
  typedef itk::ImageFileReader< ImageType >     ReaderType;
  typedef itk::MetaImageIO                      ImageIOType;

  const char * inputFilename  = "ctA0-512x512x125x16.mhd";
  const char * outputFilename = "test.mhd";
  const short weight = 100;

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

  reader->SetFileName( inputFilename );
  reader->SetImageIO(metaIn);
  reader->Update();

  typedef itk::WeightedImageFilter<ImageType, ImageType>        FilterType;
  FilterType::Pointer  filter = FilterType::New();

  filter->SetInput( reader ->GetOutput());
  filter->SetWeight(weight);
  filter->Update();

  typedef itk::ImageFileWriter< ImageType >     WriterType;
  WriterType::Pointer writer = WriterType::New();
  ImageIOType::Pointer metaOut = ImageIOType::New();

  writer->SetImageIO( metaOut );
  writer->SetFileName( outputFilename );
  writer->SetInput( filter->GetOutput() );
  writer->Update();

  return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110706/6d353e0b/attachment.htm>


More information about the Insight-users mailing list