[Insight-users] regiongrowing... : connecting ITK and VTK
Luis Ibanez
luis . ibanez at kitware . com
Tue, 16 Dec 2003 18:58:51 -0500
This is a multi-part message in MIME format.
--------------090603090507040306070807
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi Yasser,
You will find detailed instruction on how to
connect ITK and VTK pipelines in the
tutorials:
http://www . itk . org/HTML/Tutorials . htm
in particular:
http://www . itk . org/CourseWare/Training/GettingStarted-II . pdf
The attached program is a typical example of
how to connect an ITK Region Growing filter
with a VTK pipeline. This program is doing:
itkReader---> itkSmoother---> itkRegionGrowing->
--> itkCast --> ITK-to-VTK--
->vtkContour... VTK visualization pipeline
The ITK processing is equivalent to what is described
in the SoftwareGuide
http://www . itk . org/ItkSoftwareGuide . pdf
Section 9.1.3, pdf-page 348.
Regards,
Luis
------------------------
yasser salman wrote:
> hi luis..,
> if u plz i had an image visualized using vtk i wanna
> to segment it using itk and visualize the result using
> vtk again , can u write me the few lines to tell me
> how can i do that..,
> thanx luis.,
> yasser..,
>
---------------------------------------------------------
--------------090603090507040306070807
Content-Type: text/plain;
name="SegmenterViewer2.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="SegmenterViewer2.cxx"
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkConfidenceConnectedImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
int main( int argc, char ** argv )
{
if( argc < 6 )
{
std::cerr << "Usage: viewer1 imagefilename xseed yseed zseed neighborhoodsize" << std::endl;
return -1;
}
typedef signed short InputPixelType;
typedef float InternalPixelType;
typedef unsigned char SegmentedPixelType;
typedef itk::Image< InputPixelType, 3 > InputImageType;
typedef itk::Image< InternalPixelType, 3 > InternalImageType;
typedef itk::Image< SegmentedPixelType, 3 > SegmentedImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::CastImageFilter<
InputImageType,
InternalImageType > CastImageFilterType;
typedef itk::CurvatureFlowImageFilter<
InternalImageType,
InternalImageType > CurvatureFlowImageFilterType;
typedef itk::ConfidenceConnectedImageFilter<
InternalImageType,
SegmentedImageType > ConfidenceConnectedImageFilterType;
typedef itk::ImageToVTKImageFilter< SegmentedImageType > ConnectorFilterType;
//----------------------------------
// ITK Pipeline
//----------------------------------
ReaderType::Pointer reader = ReaderType::New();
CastImageFilterType::Pointer cast = CastImageFilterType::New();
CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New();
ConfidenceConnectedImageFilterType::Pointer confidence = ConfidenceConnectedImageFilterType::New();
ConnectorFilterType::Pointer connector = ConnectorFilterType::New();
reader->SetFileName( argv[1] );
cast->SetInput( reader->GetOutput() );
smoothing->SetInput( cast->GetOutput() );
confidence->SetInput( smoothing->GetOutput() );
smoothing->SetTimeStep( 0.125 );
smoothing->SetNumberOfIterations( 2 );
confidence->SetMultiplier( 5.0 );
confidence->SetNumberOfIterations( 2 );
confidence->SetReplaceValue( 250 );
typedef ConfidenceConnectedImageFilterType::IndexType IndexType;
IndexType seed;
seed[0] = atoi( argv[2] );
seed[1] = atoi( argv[3] );
seed[2] = atoi( argv[4] );
std::cout << "Using seed = " << seed << std::endl;
confidence->SetSeed( seed );
confidence->SetInitialNeighborhoodRadius( atoi( argv[5] );
connector->SetInput( confidence->GetOutput() );
connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
//----------------------------------
// VTK Pipeline
//----------------------------------
vtkRenderer * renderer = vtkRenderer::New();
vtkRenderWindow * renderWindow = vtkRenderWindow::New();
vtkRenderWindowInteractor * renderWindowInteractor = vtkRenderWindowInteractor::New();
renderWindow->AddRenderer( renderer );
renderWindow->SetInteractor( renderWindowInteractor );
vtkContourFilter * contour = vtkContourFilter::New();
contour->SetInput( connector->GetOutput() );
contour->SetValue( 0, 127.0 );
vtkPolyDataMapper * polyDataMapper = vtkPolyDataMapper::New();
polyDataMapper->SetInput( contour->GetOutput() );
polyDataMapper->SetScalarRange( 0.0, 250.0 );
vtkActor * actor = vtkActor::New();
actor->SetMapper( polyDataMapper );
actor->GetProperty()->SetColor( 0.8, 0.8, 1.0 );
renderer->AddActor( actor );
renderer->SetBackground( 0.1, 0.2, 0.4 );
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}
--------------090603090507040306070807--