[Insight-users] Help on Watershed Segmentation

Sotiris Dimopoulos vtksot_dimopoulos at yahoo.gr
Tue Jan 18 06:29:56 EST 2005


Hi!
I use watershed for the segmentation of a ct slice
(of a simple bone) which is in jpeg format(i have it
in dicom too), and in the
vtk window in which i see my results...i get
nothing...( as if my program found nothing to
segment).
The code appears to be flawles during the building
procedure.

I,m also a bit confused with the parameters..For
example what parameter do i set in the function
SetUsePrincipleComponents() of the
GradientMagnitudeImageFilter class??
How do i define the SetLevel(),SetThreshhold()
function s of the WatershedImageFilter class? By trial
and error?

I'm sending tyou the code in case something else goes
wrong...

Many Thanks in advance

Sotiris


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

  //  We declare the image types 
  
  typedef unsigned char          PixelType;
  const unsigned int             Dimension1 = 2;

  typedef itk::Image< PixelType, Dimension1 >  
ImageType;


  typedef   float           InternalPixelType;
   const     unsigned int    Dimension = 2;
  typedef itk::Image< InternalPixelType, Dimension > 
InternalImageType;
 

  typedef unsigned char OutputPixelType;
  typedef itk::Image< OutputPixelType, Dimension >
OutputImageType;
  
                        

  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" );
 
   

//declare the filters

  typedef
itk::GradientAnisotropicDiffusionImageFilter<InternalImageType,
    InternalImageType>  DiffusionFilterType;
  typedef
itk::GradientMagnitudeImageFilter<InternalImageType,InternalImageType>
    GradientMagnitudeFilterType; 
  typedef itk::WatershedImageFilter<InternalImageType>
WatershedFilterType;
  typedef itk::CastImageFilter< InternalImageType,
OutputImageType >
    CastingFilterType;
  
  

   DiffusionFilterType::Pointer diffusion =
DiffusionFilterType::New();
  diffusion->SetNumberOfIterations( 5.0 );
  diffusion->SetConductanceParameter( 9.0 );
  diffusion->SetTimeStep(0.0625);
  

  GradientMagnitudeFilterType::Pointer gradient =
GradientMagnitudeFilterType::New();
  //gradient->SetUsePrincipleComponents(????????????);
  

  WatershedFilterType::Pointer watershed =
WatershedFilterType::New();
  watershed->SetLevel( 1) ;
  watershed->SetThreshold( 0 );

    CastingFilterType::Pointer caster =
CastingFilterType::New();

  //  Now it is time to connect a simple, linear
pipeline. A file reader is
  //  added at the beginning of the pipeline and a
cast filter 
  //  is added at the end. The cast filter is required
to convert
  //  \code{float} pixel types to integer types since
only a few image file
  //  formats support \code{float} types.

  diffusion->SetInput( reader->GetOutput() );
  gradient->SetInput( diffusion->GetOutput() );
  watershed->SetInput( gradient->GetOutput() );
 
caster->SetInput((InternalImageType*)watershed->GetOutput()
);


  
    //Exit the itk pipeline and enter the vtk pipeline

   typedef itk::ImageToVTKImageFilter<ImageType>
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(550,550);


    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