[Insight-users] WatershedSegmentation1 doesn't work

H-B h4cd at yahoo.com
Fri Nov 12 10:57:01 EST 2010


Hi all,
 i have try to execute the following code but every time i run the exe it stop working:
and the message: a problem caused the program to stop working correctly. windows will close the program and notify you if a solution is available.
 
colud some one try the gode with his .png file
 
 
the source code:
 
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
 
#include <iostream>
#include "itkVectorGradientAnisotropicDiffusionImageFilter.h"
#include "itkVectorGradientMagnitudeImageFilter.h"
#include "itkWatershedImageFilter.h"
#include <conio.h>
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVectorCastImageFilter.h"
#include "itkUnaryFunctorImageFilter.h"
#include "itkScalarToRGBPixelFunctor.h"
int main( int argc, char *argv[] )
{
/*if (argc < 8 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage conductanceTerm diffusionIterations lowerThreshold outputScaleLevel gradientMode " << std::endl;
return 1;
}*/


typedef itk::RGBPixel<unsigned char> RGBPixelType;

typedef itk::Image<RGBPixelType, 2> RGBImageType;
typedef itk::Vector<float, 3> VectorPixelType;
typedef itk::Image<VectorPixelType, 2> VectorImageType;
typedef itk::Image<unsigned long, 2> LabeledImageType;
typedef itk::Image<float, 2> ScalarImageType;

typedef itk::ImageFileReader<RGBImageType> FileReaderType;
typedef itk::VectorCastImageFilter<RGBImageType, VectorImageType> 
CastFilterType;
typedef itk::VectorGradientAnisotropicDiffusionImageFilter<VectorImageType,
VectorImageType> DiffusionFilterType;
typedef itk::VectorGradientMagnitudeImageFilter<VectorImageType>
GradientMagnitudeFilterType; 
typedef itk::WatershedImageFilter<ScalarImageType> WatershedFilterType;

typedef itk::ImageFileWriter<RGBImageType> FileWriterType;
FileReaderType::Pointer reader = FileReaderType::New();
reader->SetFileName("V.png");

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



DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();

diffusion->SetNumberOfIterations( atoi("2") );// more than 5 will get smother
diffusion->SetConductanceParameter( atof("3") );//usually around 3
diffusion->SetTimeStep(0.125);// for 3d and 0.25 for2d
 

GradientMagnitudeFilterType::Pointer 
gradient = GradientMagnitudeFilterType::New();
gradient->SetUsePrincipleComponents(atoi("0"));

WatershedFilterType::Pointer watershed = WatershedFilterType::New();

watershed->SetLevel( atof("0.05") );
watershed->SetThreshold( atof("1") );



typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long>

ColorMapFunctorType;
typedef itk::UnaryFunctorImageFilter<LabeledImageType,
RGBImageType, ColorMapFunctorType> ColorMapFilterType;
ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();
 
 

FileWriterType::Pointer writer = FileWriterType::New();
writer->SetFileName("WatershedSegmentation1Output1.png");
 
caster->SetInput(reader->GetOutput());
diffusion->SetInput(caster->GetOutput());
gradient->SetInput(diffusion->GetOutput());
watershed->SetInput(gradient->GetOutput());
colormapper->SetInput(watershed->GetOutput());
writer->SetInput(colormapper->GetOutput());


 
try 
  { 
      writer->Update();
  }
catch (itk::ExceptionObject &e)
 {
    std::cerr << e << std::endl;
  }
 

return 0;
}


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101112/f3de1264/attachment.htm>


More information about the Insight-users mailing list