[Insight-users] ITK Writer Error

Abayiz abayiz at yahoo.com
Sun Apr 3 14:59:57 EDT 2011


Hello David,

Thank you for your reply.
When I say "inverse", I mean both in X and Y directions. I don't know whether this is the itk writer's error, or vtk viewer's error, since I saved the output as a vtk file, and use vtk to open it. 
Here is the short itk program for only reading and writing, and the error still remains:

**************************
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

int main( int argc, char * argv[] )
{
  
  typedef itk::Image< float, 2 >             ImageType;
  typedef itk::ImageFileReader< ImageType >  ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
  reader->Update();

  typedef itk::ImageFileWriter < ImageType > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(argv[2]);
  writer->SetInput(reader->GetOutput());
  writer->Update();

  return EXIT_SUCCESS;
}
***************************************
And here is my VTK viewer code (sorry, it is a little bit longer):
*****************************
#include <itkImage.h>
#include <itkImageFileReader.h> 
#include <itkImageToVTKImageFilter.h> 
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkImageActor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"
#include "itkRGBPixel.h"
int main(int argc, char *argv[])
{
  if( argc < 2 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile" << std::endl;
    return EXIT_FAILURE;
    }
 
  typedef itk::Image<itk::RGBPixel<unsigned char>, 3> ImageType;
  typedef itk::ImageFileReader<ImageType>             ReaderType;
  typedef itk::ImageToVTKImageFilter<ImageType>       ConnectorType;
 
  ReaderType::Pointer reader = ReaderType::New();
  ConnectorType::Pointer connector = ConnectorType::New();
 
  reader->SetFileName(argv[1]);
  connector->SetInput(reader->GetOutput());

vtkImageViewer * viewer = vtkImageViewer::New();
vtkRenderWindowInteractor * renderWindowInteractor =
vtkRenderWindowInteractor::New();
viewer->SetupInteractor( renderWindowInteractor );
viewer->SetInput( connector->GetOutput() );

viewer->Render();
viewer->SetColorWindow( 255 );
viewer->SetColorLevel( 128 );
renderWindowInteractor->Start();

 
  return EXIT_SUCCESS;
}

************************************
Thank you again. 

--- On Sun, 4/3/11, David Doria <daviddoria at gmail.com> wrote:

> From: David Doria <daviddoria at gmail.com>
> Subject: Re: [Insight-users] ITK Writer Error
> To: "Abayiz" <abayiz at yahoo.com>
> Cc: insight-users at itk.org
> Date: Sunday, April 3, 2011, 1:30 PM
> On Sun, Apr 3, 2011 at 2:01 PM,
> Abayiz <abayiz at yahoo.com>
> wrote:
> > Hello,
> >
> > Just as the title indicates, I encountered an error
> with ITK writer. I found that when I let itk write the
> output as a file, it writes it in the inverse direction,
> i.e, if I try to just read and write an image doing nothing
> else, the result image is the inverse of the input image.
> What is this called? Is there any suggestions?
> > Here is the itk writer I used:
> >
> > ********************************
> > typedef itk::Image< float, 2 >            
> ImageType;
> > typedef itk::ImageFileWriter < ImageType >
> WriterType;
> >  WriterType::Pointer writer = WriterType::New();
> >  writer->SetFileName(argv[2]);
> >  writer->SetInput(output);
> >  writer->Update();
> > *******************************
> > The full code is here:
> > http://www.vtk.org/Wiki/ITK/Examples/Functions/GuassianBlurImageFunction
> 
> I wouldn't use the GuassianBlurImageFunction example as a
> test for
> this. You should just write a short program that reads an
> image and
> then writes it back out. Give this a try and let us know if
> the
> problem still happens. And what do you mean by "inverse
> direction"? Is
> the image flipped in X? Y? Both?
> 
> David
> 


More information about the Insight-users mailing list