[Insight-users] Zero-padding

alexandre govignon govignon.alexandre at gmail.com
Wed Oct 1 11:30:57 EDT 2008


Hi all,
i have implemented a code for zero-padding that worked well for float,
and generally speaking for dicom formats.
But it doesn't work that well since i use int pixel type in a raw image...
The problem is that the image is not copy in one block in the top left
corner... But it is shared at different part of the image. It never
happens when i used dicom formats...

Have you an idea?

The code of my function is:

void CDose::Padder3D(string Path1,string PathInter)
{	
		
	typedef int Pix;
	typedef itk::Image< Pix, 3 > ImageTy;
	typedef itk::ImageFileReader< ImageTy > ReaderTy;
	typedef itk::ImageFileWriter< ImageTy > WriterTy;
	ImageTy::Pointer inputImage;
	ReaderTy::Pointer reader = ReaderTy::New();
	reader->SetFileName( Path1);
	try
	{
		reader->Update();
		inputImage = reader->GetOutput();
		
	}
	catch ( itk::ExceptionObject &err)
	{
		cout << "ExceptionObject caught !" << endl;
		cout << err << endl;
	}

	ImageTy::RegionType Region = (inputImage->GetRequestedRegion());
	ImageTy::SizeType size;
	ImageTy::IndexType index;
	ImageTy::SpacingType espace;
	index[ 0] = Region.GetIndex()[0 ];
	index[ 1] = Region.GetIndex()[1 ];
	index[ 2] = Region.GetIndex()[2 ];
	size[ 0] = Region.GetSize()[0 ];
	size[ 1] = Region.GetSize()[1 ];
	size[ 2] = Region.GetSize()[2 ];
	espace[ 0] = inputImage->GetSpacing()[0 ];
	espace[ 1] = inputImage->GetSpacing()[1 ];
	espace[ 2] = inputImage->GetSpacing()[2 ];
	const ImageTy::PointType& orgn = inputImage->GetOrigin();
	DIMX=new int(size[0]);
	DIMY=new int(size[1]);
	DIMZ=new int(size[2]);

	for(int i=1;i<18;i++)
	{
		int UN=pow(2.0,i);
		int QU=pow(2.0,i+1);
		if(*DIMX >= UN && *DIMX < QU)
		{
			DX=new int(pow(2.0,i+2));
			i=17;
		}
	}
	for(int i=1;i<18;i++)
	{
		int UN=pow(2.0,i);
		int QU=pow(2.0,i+1);		
		if(*DIMY >= UN && *DIMY < QU)
		{
			DY=new int(pow(2.0,i+2));
			i=17;
		}
	}
	for(int i=1;i<18;i++)
	{
		int UN=pow(2.0,i);
		int QU=pow(2.0,i+1);		
		if(*DIMZ >= UN && *DIMZ < QU)
		{
			DZ=new int(pow(2.0,i+2));
			i=17;
		}
	}
	
	
	cout << *DX << endl;
	cout << *DY << endl;
	cout << *DZ << endl;
	
	typedef itk::Image< Pix, 3 > Image3;
	Image3::Pointer outputImage=Image3::New();
	Image3::SizeType size1;
	Image3::IndexType index1;
	Image3::SpacingType espace1=espace;
	Image3::PointType origin;
	origin[0] = orgn[0]; // coordinates of the
	origin[1] = orgn[1]; // first pixel in N-D
	origin[2] = orgn[2];
	cout << orgn[0] << ", " << orgn[1] << ", " << orgn[2] << std::endl;
	Image3::RegionType Region1;
	index1 [0] = index [0];
	index1 [1] = index [1];
	index1 [2] = index [2];
	size1[ 0] = *DX;
	size1[ 1] = *DY;
	size1[ 2] = *DZ;
	Region1.SetSize(size1);
	Region1.SetIndex(index1);
	//outputImage->SetOrigin(origin);
	outputImage->SetSpacing(espace1);
	outputImage->SetRegions(Region1);
	outputImage->Allocate();
	outputImage->FillBuffer(0.0);
	typedef itk::ImageSliceIteratorWithIndex< ImageTy >  Slice;
	typedef itk::ImageSliceConstIteratorWithIndex< ImageTy >  ConstSlice;
	Slice outputIt1( outputImage, outputImage->GetRequestedRegion() );
	ConstSlice inputIt1( inputImage, inputImage->GetRequestedRegion() );
	outputIt1.GoToBegin();
	inputIt1.GoToBegin();
	outputIt1.SetFirstDirection(0);
	outputIt1.SetSecondDirection(1);
	inputIt1.SetFirstDirection(0);
	inputIt1.SetSecondDirection(1);
	int pos=0;
	double ResteX=0;
	double DivisionY=0;
	double SL=0;
	while( !outputIt1.IsAtEnd())
	{
		while ( !outputIt1.IsAtEndOfSlice() )
		{
			while ( !outputIt1.IsAtEndOfLine() )
			{
				ResteX=pos%*DX;
				DivisionY=pos/(*DX);
				if(ResteX < *DIMX && DivisionY < *DIMY && SL < *DIMZ )
				{
					double value=inputIt1.Get();
					outputIt1.Set(value);
					++outputIt1;
					++inputIt1;
				}
				else
				{
					++outputIt1;
				}
				pos++;
			}
			outputIt1.NextLine();
			inputIt1.NextLine();
		}
		pos=0;
		cout << SL << endl;
		cout << endl;
		cout << endl;
		cout << endl;
		SL++;
		outputIt1.NextSlice();
		inputIt1.NextSlice();
	}
	
	WriterTy::Pointer writer = WriterTy::New();
	writer->SetFileName( PathInter );
	writer->SetInput(outputImage);
	try
	{
		writer->Update();
	}
	catch ( itk::ExceptionObject &err)
	{
		cout << "ExceptionObject caught !" << endl;
		cout << err << endl;
	}
	
	
}


-- 
Cordialement,
Alexandre Govignon.


More information about the Insight-users mailing list