[Insight-users] JoinImageFilter

Rahul Chander rahulch at interchange.ubc.ca
Sun, 14 Mar 2004 03:17:21 -0800


Hi,
I am trying to combine two 3D images (vtk files) of the same 
dimensions along the z direction.  Image 2 is set of consecutive 
slices in sequence with the Image 1 set.  I am using JoinImageFilter 
for this purpose.  My problem is that I do not know how to specify 
that I want image 2 to be appended to image 1 along the z direction 
rather than some other default direction.  Also my output does not 
seem to be correct.  Is this the right filter for my application?  
Are there any better ways of tackling this problem?

Thanks in advance.
Rahul.

#include "itkImage.h"
#include "itkVTKImageIO.h"
#include "itkJoinImageFilter.h"

int main(int argc, char * argv[])
{

  typedef itk::Image<unsigned char,3> Image3DType;

  typedef itk::JoinImageFilter< Image3DType, Image3DType > 
FilterType;
  typedef itk::ImageFileReader<Image3DType> ReaderType;
  typedef itk::ImageFileWriter<Image3DType> WriterType;
  FilterType::Pointer filter = FilterType::New();

  ReaderType::Pointer reader1 = ReaderType::New();
  ReaderType::Pointer reader2 = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();


   reader1->SetFileName(argv[1]);  // first 3D file 256x256x18
   reader2->SetFileName(argv[2]);  // second 3D file 256x256x18
//
   Image3DType::Pointer Image1= reader1->GetOutput();
   Image3DType::Pointer Image2= reader2->GetOutput();


  filter->SetInput1(Image1);
  filter->SetInput2(Image2);

  writer->SetFileName("output/combined.vtk");  
//output file goes in the folder called "output"

  writer->SetInput((Image3DType*)filter->GetOutput());  
// The output type of the filter is Vector, so I
// am typecasting it to Image3DType.

	try {
		writer->Update();
	}
	catch (itk::ExceptionObject &err) {
		std::cout << "Exception Object caught: " << std::endl;
		std::cout << err << std::endl;
		return -1;
	}

  return 0;
}

-- 
===================================
Rahul Chander
IV Year Electrical Eng.
The University of British Columbia
Registered Linux User:207994
===================================