[Insight-users] Problem with watersheds segmentation
Sotiris Dimopoulos
vtksot_dimopoulos at yahoo.gr
Wed Jan 12 12:02:54 EST 2005
Hi!
I use watersheds for the segmentation of a ct slice
(of a simple bone) which is in jpeg format, and in the
vtk window in which i see my results...i get
nothing...( as if my program found nothing to segment)
I,m also a bit confused with the parameters..For
example what parameter do i set in the function
SetUsePrincipleComponents() of the
GradientMagnitudeImageFilter class??
I'm sending tyou the code in case something else goes
wrong...
Thanks in advance
Sotiris
int main( int argc, char *argv[])
{
// types of data
typedef float InternalPixelType;
const unsigned int Dimension = 2;
typedef itk::Image< InternalPixelType, Dimension >
InternalImageType;
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension >
OutputImageType;
// We instantiate reader
typedef itk::ImageFileReader< InternalImageType >
ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( "C:/Documents and
Settings/sotiris/Desktop/OSTA/osta
3,5/JPEG/Img0108.jpg" );
// use the cast filter
typedef itk::CastImageFilter<InternalImageType ,
OutputImageType>
CastingFilterType;
CastingFilterType::Pointer caster =
CastingFilterType::New();
// Extract the roi
typedef itk::RegionOfInterestImageFilter<
InternalImageType,InternalImageType > FilterType;
FilterType::Pointer regionfilter =
FilterType::New();
InternalImageType::IndexType start;
start[0] = 220 ;
start[1] = 220 ;
InternalImageType::SizeType size;
size[0] = 120 ;
size[1] = 120 ;
InternalImageType::RegionType desiredRegion;
desiredRegion.SetSize( size );
desiredRegion.SetIndex( start );
regionfilter->SetRegionOfInterest( desiredRegion );
// The filters for the image.
typedef
itk::GradientAnisotropicDiffusionImageFilter<InternalImageType,
InternalImageType> DiffusionFilterType;
typedef
itk::GradientMagnitudeImageFilter<InternalImageType,InternalImageType>
GradientMagnitudeFilterType;
typedef itk::WatershedImageFilter<InternalImageType>
WatershedFilterType;
// The diffusion filter
DiffusionFilterType::Pointer diffusion =
DiffusionFilterType::New();
diffusion->SetNumberOfIterations( 5 );
diffusion->SetConductanceParameter( 3.0 );
diffusion->SetTimeStep(0.125);
// The ITK gradient magnitude filter
GradientMagnitudeFilterType::Pointer gradient =
GradientMagnitudeFilterType::New();
//gradient->SetUsePrincipleComponents( ?????? ));
// Finally we set up the watershed filter.
WatershedFilterType::Pointer watershed =
WatershedFilterType::New();
watershed->SetLevel( 1.0 );
watershed->SetThreshold( 0.5 );
// Connect a simple, linear pipeline.
regionfilter->SetInput( reader->GetOutput() );
diffusion->SetInput(regionfilter->GetOutput());
gradient->SetInput(diffusion->GetOutput());
watershed->SetInput(gradient->GetOutput());
caster->SetInput( (InternalImageType*)
watershed->GetOutput() );
// Go from ITK to VTK
typedef itk::ImageToVTKImageFilter<OutputImageType>
ConnectorType;
ConnectorType::Pointer connector=
ConnectorType::New();
connector->SetInput(caster ->GetOutput() );
// Create the Image Mapper
vtkImageMapper *mapper = vtkImageMapper::New();
mapper -> SetInput(connector -> GetOutput());
mapper -> SetColorWindow(255);
mapper -> SetColorLevel(128);
// Create the Actor
vtkActor2D *actor = vtkActor2D::New();
actor -> SetMapper(mapper);
// Create the Rendering Window for viewing what
you've done
vtkRenderer *imager = vtkRenderer::New();
imager -> AddActor2D(actor);
vtkRenderWindow *imgWin = vtkRenderWindow::New();
imgWin -> AddRenderer(imager);
vtkRenderWindowInteractor *iren =
vtkRenderWindowInteractor::New();
iren -> SetRenderWindow(imgWin);
imager->SetBackground(1,1,1);
imgWin->SetSize(250,250);
imgWin -> Render();
iren->Start();
// Clean up
mapper -> Delete();
actor -> Delete();
imager -> Delete();
imgWin -> Delete();
iren -> Delete();
return 0;
}
____________________________________________________________
Do You Yahoo!?
Αποκτήστε τη δωρεάν @yahoo.gr διεύθυνση σας στο http://www.otenet.gr
More information about the Insight-users
mailing list