[Insight-users] Re sampleImageFilter and VersorRigid3DTranform for 3D images

Kath111 katherine_allen81 at hotmail.com
Sat May 2 04:34:02 EDT 2009


Hi

I've been trying to extract a slice of arbitrary origin and orientation from
a 3D volume, similar to the question asked here
http://www.nabble.com/extracting-2D-oblique-slice-by-itkResampleImageFilter-td11303551.html.  

However, before adding in the versors or translations necessary, I've run
into a problem just trying to connect the ResampleImageFilter and
VersorRigid3DTranform.  I run the following code on a metadata image of the
lung 256x256x264, and I expect to get exactly the same image back, however
the resultant image (which is the same origin, spacing and size) is only
voxels of the default pixel value (ie. in this case 100).  

I'm assuming there's something wrong in the code, however I just can't see
it - and I've tried everything I can think of including substituting the
transform for AffineTransform and Rigid3DTransform, and the interpolator
with NearestNeighbor etc, as well as adding a translation, changing the
spacing, adding a rotation with a versor - all with the same result.  

I'd really really appreciate if anyone could help.  Thanks!


#include <iostream>
#include <stdlib.h>
using namespace std;

#include "itkImage.h"
#include "itkResampleImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkVersorRigid3DTransform.h"

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

using namespace itk;

const unsigned int Dimension = 3;

typedef signed short PixelType;  

typedef itk::Image< PixelType, Dimension > ImageType;
typedef ImageType::Pointer InputImage;		

typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ResampleImageFilter< ImageType,ImageType > ResampleFilterType;
typedef itk::LinearInterpolateImageFunction < ImageType, double >
InterpolatorType;
typedef itk::VersorRigid3DTransform < double > TransformType;

int main(int argc, char* argv[]) {
	// +++++ Verify the number of parameters in the command line +++++ 
  	if( argc < 2 ) {
  		std::cerr << "Usage: " << std::endl;
    	std::cerr << argv[0] << " ImageFile " << std::endl;
 	   return EXIT_FAILURE;
	}

	// +++++ Read Input Image +++++ 
	InputImage inImg = ImageType::New();
	ReaderType::Pointer readerInImg = ReaderType::New();
	readerInImg->SetFileName( argv[1] );

	// Try reading image - catch exceptions
	try {
		readerInImg->Update();
	}
	catch (itk::ExceptionObject &ex) {
		std::cout << ex << std::endl;
		return EXIT_FAILURE;
	}
	inImg = readerInImg->GetOutput();
  	cout << argv[1] << " sucessfully read." << endl;

	ResampleFilterType::Pointer resampler = ResampleFilterType::New();
	InterpolatorType::Pointer interpolator = InterpolatorType::New();
	TransformType::Pointer transform = TransformType::New();

	resampler->SetTransform( transform );
	resampler->SetInterpolator( interpolator );

	// Pixels that fall outside image - default value
	resampler->SetDefaultPixelValue(100);

	// Spacing and is same as input
	resampler->SetOutputSpacing(inImg->GetSpacing());

	// Origin is same as current pixel
	resampler->SetOutputOrigin(inImg->GetOrigin()); 

	resampler->SetSize( inImg->GetLargestPossibleRegion().GetSize() );

	resampler->SetInput( inImg );

    itk::ImageFileWriter< ImageType >::Pointer writer =
itk::ImageFileWriter< ImageType >::New();
	writer->SetFileName("blah.mha");
	writer->SetInput(resampler->GetOutput());

	try{
		resampler->Update();
		writer->Update();
	} catch (itk::ExceptionObject & excp ) {
		std::cerr << "Writer exception thrown " << std::endl;
		std::cerr << excp << std::endl;
	}

}
-- 
View this message in context: http://www.nabble.com/ResampleImageFilter-and-VersorRigid3DTranform-for-3D-images-tp23333755p23333755.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list