[Insight-users] Using ImportFilter and PasteImageFilter

Bios5 bios5_dn at hotmail.com
Thu Jun 11 19:56:01 EDT 2009


Hello to everybody!!

Sorry, I needed to use a reply way to make a new post because I wasn't able
to find the new topic button in Nabble!!

I came this time with a PasteImageFilter Issue, I searched across the forum
and I found some examples and discussions about methods, but nothing related
to my issue.

The thing is, that I'm using ITK on XCode with OsiriX, I was already able to
import the image data from OsiriX data to ITK using an ImportFilter pointed
out for Luis Ibanez, and already used some filters to process my images.

the thing is that my next step is to make a 3D Affine registration, to do
so, I need my images on a 3D Volume, so now I tried many times to use a
PasteImageFilter like this:

OsiriX (slices on 2D) ----> ImportFilter 2D Sllices ----> CastFilter (to
cast a pseudo 3D volume with one slice) ----> store the CastImageFilter
output in a 3D itk::Image (sliceImage) ----> give imageVolume as
DestinationImage and sliceImage as SourceImage to pasteFilter using a for
loop to change the index and add the images ----> make imageVolume =
pasteFilter->GetOutput();----> give imageVolme to a DiscreteGaussianFilter
(3D) just for test and finally ----> write the Volume using a
ImageFileWriter.

The program COMPILES, LINKS and RUNS, but got an error when I use the
Update() method in the pasteFilter. This is the error:

Exception thrown while pasting the Images

ITKUAM::InvalidRequestedRegionError (0x1b5c4150)
Location: "virtual void ITKUAM::DataObject::PropagateRequestedRegion()" 
File: /HectorITK/InsightToolkit/Code/Common/itkDataObject.cxx
Line: 397
Description: Requested region is (at least partially) outside the largest
possible region.

And of course another one in the Update() method of gaussianFilter:

terminate called after throwing an instance of 'ITKUAM::ExceptionObject'
  what():  /HectorITK/InsightToolkit/Code/Common/itkMultiThreader.cxx:475:
ITKUAM::ERROR: MultiThreader(0x1e8b5600): Exception occurred during
SingleMethodExecute
/HectorITK/Registro/ITK180/Code/Common/itkConstNeighborhoodIterator.h:287:
In method IsAtEnd, CenterPointer = 0x28 is greater than End = 0x14
  Neighborhood:
    Radius:[5, 0, 0]
    Size:[11, 1, 1]
    DataBuffer:NeighborhoodAllocator { this = 0xbfffd338, begin =
0x199aac60, size=11 }

Program received signal:  “SIGABRT”.


This is my code:

//////////////Iniciamos la imagen para contener el volumen usando datos de
la imagen original
ImageType3D::Pointer	imageVolume=ImageType3D::New();
ImageType3D::IndexType	destVolIndex;
ImageType3D::SizeType	sizeVolImage;
ImageType3D::RegionType regionVolImage; 
	
//////////////Import Filter to take the buffer of OsiriX to ITK
typedef itk::ImportImageFilter< InternalPixelType, 2 > ImportFilterType;
ImportFilterType::Pointer importFilter = ImportFilterType::New();
ImportFilterType::SizeType itksize;
ImportFilterType::IndexType start;
start.Fill( 0 );
ImportFilterType::RegionType region;
double spacing	[2];
double origin	[2];
const bool importFilterWillDeleteTheInputBuffer = false;
	
	
curPix		= [pixList	objectAtIndex: 0]; //Recorremos el set de imagenes
rebanada por rebanada
	
spaceX		= [curPix	pixelSpacingX] ;//Espaciado (Spacing) de la imagen en
X,Y,Z
spaceY		= [curPix	pixelSpacingY] ;
spaceZ		= [curPix	sliceInterval] ;
	
ox			= [curPix	originX];//Datos del origen de la imagen en X,Y,Z
oy			= [curPix	originY];
oz			= [curPix	originZ];
	
imageWidth  = [curPix	pwidth];//Tamanio de la rebanada en X
imageHeight = [curPix	pheight];//Tamanio de la rebanada en Y
	
	
if( spaceZ == 0)
{
	spaceZ = [curPix sliceThickness] ;//En caso de que no haya Z
}
	
/////////////Proporcionar los datos de la imagen al ImportFilter 2D OJO
itksize[0] = imageWidth; // size along X
itksize[1] = imageHeight; // size along Y
	
region.SetIndex( start );//Start fue iniciado en declaraciones pues siempre
es 0
region.SetSize( itksize );
importFilter->SetRegion( region );//Se establecen los parametros de la
imagen a importar
	
spacing[0] = spaceX;//Espaciado o Spacing
spacing[1] = spaceY;
importFilter->SetSpacing( spacing );
	
origin[0] = ox;//Origen de la imagen (aunque hay origen en Z no lo estamos
usando)
origin[1] = oy;
importFilter->SetOrigin( origin );
	
//////////////////// ALSO TRYED ALLOCATING THE imageVolume IMAGE!!! before
using it.
//	destVolIndex[0] = 0;
//	destVolIndex[1] = 0;
//	destVolIndex[2] = 0;
//	sizeVolImage[0] = imageWidth;
//	sizeVolImage[1] = imageHeight;
//	sizeVolImage[2] = [pixList count];
//	regionVolImage.SetSize(sizeVolImage);
//	regionVolImage.SetIndex(destVolIndex);
//	imageVolume->SetRegions(regionVolImage);
//	imageVolume->Allocate();
//////	////////////////////////////////////////////////////////////////////
	
/////////////Cast Filter to change the 2D to a pseudo 3D image with just one
slice
typedef itk::CastImageFilter<ImageType2D,ImageType3D> castFilterType;
castFilterType::Pointer caster = castFilterType::New();
	
/////////////Paste Filter to add the 2D slices to a 3D volume
typedef itk::PasteImageFilter<ImageType3D> pasteFilter;
pasteFilter::Pointer paster = pasteFilter::New();	
pasteFilter::InputImageIndexType destIndex;
destIndex[0] = 0;
destIndex[1] = 0;//El destIndex[2] lo iniciamos con valor de i dentro del
for loop
destIndex[2] = 0;
paster -> SetDestinationImage(imageVolume);
paster -> SetSourceImage(sliceImage);
	
////////////Declaramos el DiscreteGaussianFilter para hacer el suavizado OJO
3D
typedef itk::DiscreteGaussianImageFilter<ImageType3D, ImageType3D > 
FilterType;
FilterType::Pointer smooth = FilterType::New();
const double gaussianVariance = atof( "4" );
const unsigned int maxKernelWidth = atoi( "7" );
smooth->SetVariance( gaussianVariance );
smooth->SetMaximumKernelWidth( maxKernelWidth );
	
////////////Declaramos el RescaleIntensityImageFilter para despues del
suavizado
typedef itk::RescaleIntensityImageFilter< ImageType3D, ImageType3D >
RescaleFilterType;
RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
rescaler->SetOutputMinimum(   0 );
rescaler->SetOutputMaximum( 255 );
	
////////////Declaramos el escritor para escribir un nuevo volumen fuera de
OsiriX
typedef itk::ImageFileWriter<ImageType3D >  WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( "/HectorITK/PlantillasyMapas/hectorsmoot.img" );
	
	
	
	
/////////////PROGRAMA//////////////////
id waitWindow = [viewerController startWaitWindow:@"Suavizando Imagen!"];
	
////////////Duplicamos la ventana de visualizacion para ver la diferencia
despues del proceso/////////
new2DViewer = [self duplicateCurrent2DViewerWindow];
[[new2DViewer window] makeKeyAndOrderFront: self];
	
	
	for(i=0; i < [pixList count]; i++)
	{
		curPix		= [pixList	objectAtIndex: i]; // OsiriX Slice by Slice

		fImage=[curPix fImage];//Accedemos a los datos de la imagen en la rebanada
actual
		
		
		/////////////Castear la imagen del buffer de OsiriX hacia ITK
		typedef ImageType2D::PixelType	PixelType;
		PixelType * pixelData = static_cast < PixelType *> (fImage);
		const unsigned int totalNumberOfPixels = imageWidth * imageHeight;
		
		
		/////////////Hechamos a andar el importFilter
    
importFilter->SetImportPointer(pixelData,totalNumberOfPixels,importFilterWillDeleteTheInputBuffer);
		importFilter->Update();//Hasta aqui ya tenemos los datos en 2D en el
import Filter
		
		////////////Solicitamos al importFilter pasar los datos al castFilter
		caster->SetInput(importFilter->GetOutput());
		caster->Update();
		
		///////////Enviamos la imagen 2D casteada a pseudo 3D hacia sliceImage
		sliceImage = caster -> GetOutput();
		
		//////////Iniciamos a formar el volumen 3D con el pasteImageFilter
		destIndex[2] = i;
		paster->SetDestinationIndex(destIndex);
		paster->SetSourceRegion(sliceImage->GetLargestPossibleRegion());//forum
example

		try
		{
			paster->Update();//Here starts the problem!!!! the first error
		}
		catch(itk::ExceptionObject & excp)
		{
		std::cerr <<"Exception thrown while pasting the Images" << std::endl;
		std::cerr <<excp<<std::endl;
		}
		imageVolume = paster->GetOutput();//Or Even outside the for loop
	}
	
	
	///////////Entregamos el volumen completo a imageVolume actualizandolo
fuera del for loop
	//imageVolume = paster->GetOutput();
	//imageVolume->Update();
	///////////Iniciamos el proceso de suavizado del volumen construido
Suavizado 3D!!!
	
        smooth->SetInput(imageVolume);
	//smooth->SetInput(paster-GetOutput()); tried the two options
	smooth->Update();/// Here fails and crash the application
	
	//////////Reescalamos las intensidades de la imagen
	rescaler->SetInput(smooth->GetOutput());
	
	//////////Escribimos el volumen nuevo fuera de OsiriX
	writer->SetInput(rescaler->GetOutput());
	writer->Update();

I've already used all those filters but PasteImageFilter, and is the only
error I found, I really tried on many ways and I don't get it!!!! 

Please!!! if someone can see a mistake I made or ideas to solve it...
PLEASE!!! let me know!!!

Regards

Hector Garza


-- 
View this message in context: http://www.nabble.com/Using-ITK-with-XCode-tp6529684p23990889.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list