[Insight-users] Problems with itkImageRegionIteratorWithIndex

PeterW p.worel at ast-jena.de
Mon Nov 23 09:03:48 EST 2009


I get the error myself... I forgot the reader->Update()
Stupid error... sorry for the interruption.


PeterW wrote:
> 
> Hello,
> 
> I have problems to get the ImageRegionIterators to work. I tried to redo
> the expamples given in Examples/Iterators, especially the
> ImageRegionIterator and the ImageRegionIteratorWithIndex. And I tried my
> own example given below. But I always get the same error, a itkLightObject
> Exception. The error occurs when the Iteratorinput was set. I tried to
> work without a copy of the inputimage, but this time the requested region
> was empty. This is the input image I use: 
> http://n2.nabble.com/file/n4051121/seedoutput.png seedoutput.png 
> The goal is to find the index of the first white pixel in the image and
> the first step is a iterator-loop which access every pixel of the image.
> 
> #include <iostream>
> //-----ITK-Includes-----
> #include "itkImage.h"
> #include "itkRGBPixel.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImageToVTKImageFilter.h"
> #include "itkVTKImageToImageFilter.h"
> //ImageFilter
> #include "itkCastImageFilter.h"
> #include "itkImageRegionConstIterator.h"
> #include "itkImageRegionIterator.h"
> #include "itkImageRegionIteratorWithIndex.h"
> //----------------VTK-Includes-------------
> #include "vtkImageViewer.h"
> #include "vtkRenderWindowInteractor.h"
> 
> int main(int argc, char **argv)
> {
> 	const unsigned int Dimension = 2;
> 	typedef unsigned char PixelType;
> 	typedef itk::Image<PixelType, Dimension> ImageType;
> 
> 	typedef itk::ImageFileReader<ImageType> ReaderType;
> 	ReaderType::Pointer reader = ReaderType::New();
> 	reader->SetFileName("D:/Tests/IterTest/src/seedoutput.png");
> 
> 	ImageType::ConstPointer inputImage;
> 	inputImage = reader->GetOutput();
> 
> 	ImageType::Pointer outputImage = ImageType::New();
> 	outputImage->SetRegions(inputImage->GetRequestedRegion());
> 	outputImage->CopyInformation(inputImage);
> 	outputImage->Allocate();
> 
> 
> 	typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
> 	IteratorType outputIt(outputImage, outputImage->GetRequestedRegion());
> 	outputIt.GoToBegin();
> 	
> 	while (!outputIt.IsAtEnd())
> 	{
> 		ImageType::IndexType idx = outputIt.GetIndex();
> 		std::cout<<idx[0]<<":"<<idx[1]<<std::endl;
> 		++outputIt;
> 	}
> 
> 	typedef itk::ImageFileWriter<ImageType> WriterType;
> 	WriterType::Pointer writer = WriterType::New();
> 	writer->SetFileName("D:/Tests/IterTest/src/output.png");
> 	writer->SetInput(outputImage);
> 	writer->Write();
> 
> 
> 	//VTK-Part	
> 
> 	typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
> 	ConnectorType::Pointer connector = ConnectorType::New();
> 	connector->SetInput(outputImage);
> 
> 	vtkImageViewer *viewer = vtkImageViewer::New();
> 
> 	vtkRenderWindowInteractor *renderWindowInteractor =
> vtkRenderWindowInteractor::New();
> 
> 	viewer->SetupInteractor(renderWindowInteractor);
> 	viewer->SetInput(connector->GetOutput());
> 
> 	viewer->Render();
> 	viewer->SetColorWindow(255);
> 	viewer->SetColorLevel(128);
> 	renderWindowInteractor->Start();
> 
> 	viewer->Delete();
> 	renderWindowInteractor->Delete();
> 
> 
>   return 0;
> }
> 
> I don't get any output from the loop or from the viewer/file, cause of the
> lightobject-exception and don't get the point.
> Thanks in advanced.
> 
> Peter
> 
> 

-- 
View this message in context: http://n2.nabble.com/Problems-with-itkImageRegionIteratorWithIndex-tp4051121p4051262.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list