[Insight-users] problem with ConnectedThresholdImageFilter.cxx on a 3D mhd image file

Marco Gheza marcogheza4mailinglists at gmail.com
Tue Feb 2 05:29:19 EST 2010


Hi,
I'm trying to use ConnectedThresholdImageFilter.cxx on a 3D image (a .mhd
file). I inserted one seed point with 3 coordinates an tried different
values of threshold. When I run the program, I save the output results in a
.mhd file but i obtain only a black image. So i don't obtain a true
segmentation.
The code is this:


#include "itkConnectedThresholdImageFilter.h"


#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.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 seedX seedY seedZ lowerThreshold
upperThreshold" << std::endl;
    return 1;
    }

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


  typedef unsigned char                            OutputPixelType;
  typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
  typedef itk::CastImageFilter< InternalImageType, OutputImageType >
                                                   CastingFilterType;
  CastingFilterType::Pointer caster = CastingFilterType::New();


  typedef  itk::ImageFileReader< InternalImageType > ReaderType;
  typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  reader->SetFileName( argv[1] );
  writer->SetFileName( argv[2] );
  typedef itk::CurvatureFlowImageFilter< InternalImageType,
InternalImageType >
    CurvatureFlowImageFilterType;

  CurvatureFlowImageFilterType::Pointer smoothing =
                         CurvatureFlowImageFilterType::New();

  typedef itk::ConnectedThresholdImageFilter< InternalImageType,
                                    InternalImageType > ConnectedFilterType;

  ConnectedFilterType::Pointer connectedThreshold =
ConnectedFilterType::New();


  smoothing->SetInput( reader->GetOutput() );
  connectedThreshold->SetInput( smoothing->GetOutput() );
  caster->SetInput( connectedThreshold->GetOutput() );
  writer->SetInput( caster->GetOutput() );

  smoothing->SetNumberOfIterations( 5 );
  smoothing->SetTimeStep( 0.125 );

  const InternalPixelType lowerThreshold = atof( argv[6] );
  const InternalPixelType upperThreshold = atof( argv[7] );

 connectedThreshold->SetLower(  lowerThreshold  );
  connectedThreshold->SetUpper(  upperThreshold  );

  connectedThreshold->SetReplaceValue( 255 );

  InternalImageType::IndexType  index;
  index[0] = atoi( argv[3] );
  index[1] = atoi( argv[4] );
  index[2] = atoi( argv[5] );
  connectedThreshold->SetSeed( index );

  //InternalImageType::IndexType  index1;
  //index1[0] = atoi( argv[3] );
  //index1[1] = atoi( argv[4] );
  //connectedThreshold->AddSeed( index1 );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
    }
return 0;
}


Can someone explain me if this is a problem of thresholding or a problem of
image format?! I don't really know what to do.
Thanks,
Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100202/fb90543e/attachment.htm>


More information about the Insight-users mailing list