[Insight-users] ITK Writer Error
David Doria
daviddoria at gmail.com
Sun Apr 3 15:06:05 EDT 2011
On Sun, Apr 3, 2011 at 2:59 PM, Abayiz <abayiz at yahoo.com> wrote:
> 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;
> }
"This is a common problem. VTK and ITK use different conventions. ITK
uses image convention where the first pixel in memory if shown in the
upper left of the displayed image. VTK uses computer graphics
convention where the first pixel in memory is shown in the lower left
of the displayed image.
The ITK convention conforms to radiology convention.
You can use vtkImageFlip to flip the vtk images about the y axis.
Bill"
Here is an example of how to do that:
http://www.itk.org/Wiki/ITK/Examples/Images/FlipImageFilter
David
More information about the Insight-users
mailing list