[ITK] [ITK-users] Slice Spacing changing when writting series?

Matias matimontg at gmail.com
Thu Mar 9 10:50:24 EST 2017


Hi,

I have a DCM serie that I read, do some Eurler rotation and then save using
the SeriesWritter.

For some reason, the slicespacing is always 1mm, despite the fact that the
original series have its slice spacing set to 2mm 

This causes the Saggital and Coronal views to "be flatted".

Any ideas why this is happening?

Here's my code:

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#include "itkAffineTransform.h"
#include "itkEuler3DTransform.hxx"
#include "itkGDCMImageIO.h"

int main( int argc, char * argv[] )
{
	if( argc < 3 )
	{
		std::cerr << "Usage: " << std::endl;
		std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl;
		return EXIT_FAILURE;
	}

	const unsigned int Dimension = 3; //imagen 3D
	typedef signed short InputPixelType;
	typedef signed short OutputPixelType;
	typedef itk::Image < InputPixelType, Dimension > InputImageType;
	typedef itk::Image < OutputPixelType, Dimension > OutputImageType;
	typedef itk::ImageFileReader < InputImageType > ReaderType;
	typedef itk::ImageFileWriter < OutputImageType > WriterType;
	typedef itk::GDCMImageIO ImageIOTypeGDCM;

	ReaderType::Pointer reader = ReaderType::New(); //lo que lee
	WriterType::Pointer writer = WriterType::New(); //lo que escribe
	reader->SetFileName( argv[1] ); //primer argumento
	writer->SetFileName( argv[2] ); //segundo argumento


	ImageIOTypeGDCM::Pointer gdcmImageIO = ImageIOTypeGDCM::New();
	reader->SetImageIO( gdcmImageIO );
	reader->Update();
	reader->UpdateOutputInformation(); //Sin esto gdcmImageIO no puede leer
tags

	double intercept = gdcmImageIO->GetRescaleIntercept();
	std::cout << "Rescale Intercept value: " << intercept << std::endl;
	std::cout << "rescale slope:    " << gdcmImageIO->GetRescaleSlope() <<
std::endl;
	std::cout << "use compression:  " << gdcmImageIO->GetUseCompression() <<
std::endl;

	//const double angleInDegrees = atof( argv[3] ); //angulo de rotación

	typedef itk::ResampleImageFilter<InputImageType, OutputImageType >
FilterType; //Filtro
	FilterType::Pointer filter = FilterType::New();

	typedef itk::Euler3DTransform< double > TransformType; //TransformType =
Euler
	TransformType::Pointer transform = TransformType::New();

	typedef itk::LinearInterpolateImageFunction<InputImageType, double >
InterpolatorType;
	InterpolatorType::Pointer interpolator = InterpolatorType::New();
	filter->SetInterpolator( interpolator );
	filter->SetDefaultPixelValue(intercept); //Pixel por defecto de lo que
queda fuera de la imagen cuando se rota

	const InputImageType * inputImage = reader->GetOutput();
	const InputImageType::SpacingType & spacing = inputImage->GetSpacing();
	const InputImageType::PointType & origin = inputImage->GetOrigin();
	InputImageType::SizeType size
=inputImage->GetLargestPossibleRegion().GetSize();
	
	filter->SetOutputOrigin( origin );
	filter->SetOutputSpacing( spacing );
	filter->SetOutputDirection( inputImage->GetDirection() );
	filter->SetSize( size );
	filter->SetInput( reader->GetOutput() );

	writer->SetInput( filter->GetOutput() );
	writer->UseInputMetaDataDictionaryOff();
	writer->SetImageIO(gdcmImageIO);

	/*TransformType::OutputVectorType translation1;
	const double imageCenterX = origin[0] + spacing[0] * size[0] / 2.0;
	const double imageCenterY = origin[1] + spacing[1] * size[1] / 2.0;
	translation1[0] = -imageCenterX;
	translation1[1] = -imageCenterY;
	translation1[2] = 0;*/

	//transform->Translate( translation1 );
	
	//std::cout << "imageCenterX = " << imageCenterX << std::endl;
	//std::cout << "imageCenterY = " << imageCenterY << std::endl;

//	const double degreesToRadians = std::atan(1.0) / 45.0;
//	const double angle = angleInDegrees * degreesToRadians;

	transform->SetRotation(-0.0060, 0.0124, -0.0144); //Radianes XYZ
	
	/*TransformType::OutputVectorType translation2;
	translation2[0] = imageCenterX;
	translation2[1] = imageCenterY;
	transform->Translate( translation2, false );*/
	filter->SetTransform( transform );

	try
	{
		writer->Update();
	}
	catch( itk::ExceptionObject & excep )
	{
		std::cerr << "Exception caught !" << std::endl;
		std::cerr << excep << std::endl;
	}
	// Software Guide : EndCodeSnippet
	return EXIT_SUCCESS;
}



--
View this message in context: http://itk-users.7.n7.nabble.com/Slice-Spacing-changing-when-writting-series-tp37975.html
Sent from the ITK - Users mailing list archive at Nabble.com.
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list