[Insight-users] Still having Problems taking a vtk dataset into itk
Luis Ibanez
luis.ibanez@kitware.com
Fri, 17 Jan 2003 12:56:11 -0500
This is a multi-part message in MIME format.
--------------040801040203060506050901
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi John,
Your code looks ok for the most part.
Here are some hints that can help to get it running.
1) The VTKImageToImage and ImageToVTKImage filters
are not really "filters" they just put together
an itk+vtk importer and exporter and connect
their callbacks. These are just convenience
classes to simplify the connectivity.
The consequence is that when you call Update()
on them, nothing happens. You may have to call
their method "GetImporter()" and on the importer
filter call "Update()".
This is not a concern when you plug them in a
pipeline since in this case the actual two internal
filters are the ones that become plugged in.
So, all the update calls propagate normally.
Now that, this is not the reason for your code
to fail. It simply explains something about the
debugging output you are getting. The two Update()
calls on the vtk+itk connectors have to be seen
as null operations.
2) When running your code in an actual TIFF image
I found an exception thrown indicating that the
input TIFF image has four components and the output
is supposed to be only one. (like a grayscale image).
The importer/exporter are not supporting color
images at this point. If you actually want to
process color images, you could get around this
limitation by converting your TIFF image to PNG
or MetaImage color format and then using the native
ITK ImageFileReader that is capable of reading
color images from this formats into an image of
type:
itk::Image< itk::RGBPixel< unsigned char > , 2 >
You will find an example on reading writing
color images on the SoftwareGuide.pdf in section 6.2
The associated example is in
Insight/Examples/IO/
3) As an easy test, I replaced your vtkTIFF reader
and writer with PNG ones, and provided a grayscale
image as input. For example:
Insight/Examples/Data/BrainProtonDensitySlice.png
With this change the code is running fine.
Please find attached the modified .cxx file.
Let us know if you have further questions.
Thanks
Luis
--------------------------------------
John David Fleig wrote:
> We updated our copy of itk through cvs here and I tried the following
> code:
>
> typedef itk::Image<unsigned char,2> CharType;
>
> vtkTIFFReader* imageReader = vtkTIFFReader::New();
> imageReader->SetFileName("Wrath.tif");
> imageReader->Update();
>
> imageReader->Print(cerr);
>
--------------040801040203060506050901
Content-Type: text/plain;
name="vtkTest.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="vtkTest.cxx"
#include "itkImage.h"
#include "itkVTKImageToImageFilter.h"
#include "itkImageToVTKImageFilter.h"
#include "itkRGBAPixel.h"
#include "vtkTIFFWriter.h"
#include "vtkImageCast.h"
#include "vtkTIFFReader.h"
#include "vtkPNGWriter.h"
#include "vtkPNGReader.h"
int main()
{
typedef unsigned char PixelType;
typedef itk::Image< PixelType, 2 > CharType;
vtkPNGReader* imageReader = vtkPNGReader::New();
imageReader->SetFileName("test.png");
typedef itk::VTKImageToImageFilter<CharType> ImporterToITK;
ImporterToITK::Pointer movingItkImporter = ImporterToITK::New();
movingItkImporter->SetInput(imageReader->GetOutput());
movingItkImporter->Update(); // <---- Does nothing !
typedef itk::ImageToVTKImageFilter<CharType> ImporterToVTK;
ImporterToVTK::Pointer vtkimporter = ImporterToVTK::New();
vtkimporter->SetInput( movingItkImporter->GetOutput() );
vtkimporter->Update(); // << --- Does nothing !
vtkImageCast *caster = vtkImageCast::New();
caster->SetInput( vtkimporter->GetOutput() );
caster->SetOutputScalarTypeToUnsignedChar();
vtkPNGWriter* imageWriter = vtkPNGWriter::New();
imageWriter->SetInput(caster->GetOutput());
imageWriter->SetFileName("test_copy.png");
try {
imageWriter->Write(); // Triggers the pipeline execution
}
catch( itk::ExceptionObject & exp )
{
std::cerr << "Exception caught" << std::endl;
std::cerr << exp << std::endl;
}
return 0;
}
--------------040801040203060506050901--