[vtkusers] Problem using ExtractImageFilter

Trond Valen trondvalen at gmail.com
Mon Nov 14 08:18:46 EST 2005


Hi!

I have a 3-D image (read using meta header) with 10 slices and want to
extract one slice from this volume and display it, (for now). I run
into a problem when updating my extractImageFilter, on the line
filter->Update(). My debugger says that the stack around
outputDirection was corrupted. It seems it cannot read the direction
of the filter's input image. Anyone who can see the error?

	//Typedefs
	typedef  unsigned char   InputPixelType;
  typedef  unsigned short  OutputPixelType;
  typedef itk::Image< InputPixelType, 3 >   InputImageType;
  typedef itk::Image< OutputPixelType, 2 >   OutputImageType;
	typedef itk::ImageFileReader< InputImageType > ReaderType;
	typedef itk::ExtractImageFilter< InputImageType, OutputImageType > FilterType;
	typedef itk::ImageToVTKImageFilter< OutputImageType > VTKFilterType;
	
	//Reading input volume
	ReaderType::Pointer reader = ReaderType::New();
	reader->SetFileName("D:/clip01.mha");
	reader->Update();

	//Creating filter
	FilterType::Pointer filter = FilterType::New();

  //Setting desired region to be the desired slice in the input volume
	InputImageType::RegionType inputRegion =
           reader->GetOutput()->GetLargestPossibleRegion();
	InputImageType::SizeType size = inputRegion.GetSize();
  printf("Size: [%d, %d, %d]\n", size[0], size[1], size[2]);
	size[2] = 0;
	InputImageType::IndexType start = inputRegion.GetIndex();
	printf("Start: [%d, %d, %d]\n", start[0], start[1], start[2]);
  start[2] = 1;
	InputImageType::RegionType desiredRegion;
  desiredRegion.SetSize(  size  );
  desiredRegion.SetIndex( start );
	filter->SetExtractionRegion(desiredRegion);

	//Directing the output from the reader to the filter and updating filter
	filter->SetInput(reader->GetOutput());
	printf("%s",reader->GetOutput()->GetNameOfClass());
	filter->Update();


	//Connecting the extractImageFilter to a VTK filter
	VTKFilterType::Pointer connector = VTKFilterType::New();
	connector->SetInput(filter->GetOutput());
	connector->Update();

	//Setting up viewer
	vtkImageViewer * viewer = vtkImageViewer::New();
	vtkRenderWindowInteractor * renderWindowInteractor =
vtkRenderWindowInteractor::New();
	viewer->SetupInteractor(renderWindowInteractor);	
	viewer->SetInput(connector->GetOutput());

	//printf("Connector output: %s\n", connector->GetOutput()->GetNameOfClass());
	//Rendering
	viewer->Render();
	viewer->SetColorWindow(255);
	viewer->SetColorLevel(256);
	renderWindowInteractor->Start();

Trond

	//Connecting the extractImageFilter to a VTK filter
	VTKFilterType::Pointer connector = VTKFilterType::New();
	connector->SetInput(filter->GetOutput());
	connector->Update();

	//Setting up viewer
	vtkImageViewer * viewer = vtkImageViewer::New();
	vtkRenderWindowInteractor * renderWindowInteractor =
vtkRenderWindowInteractor::New();
	viewer->SetupInteractor(renderWindowInteractor);	
	viewer->SetInput(connector->GetOutput());

	//printf("Connector output: %s\n", connector->GetOutput()->GetNameOfClass());
	//Rendering
	viewer->Render();
	viewer->SetColorWindow(255);
	viewer->SetColorLevel(256);
	renderWindowInteractor->Start();



More information about the vtkusers mailing list