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

Luis Ibanez luis.ibanez at kitware.com
Fri Feb 5 13:46:29 EST 2010


Hi Marco,

You need to verify if the pixel value at "index" is
inside of the range that you are defining with
Upper and Lower threshold.

If the pixel value is outside of the range, then
no pixel can be added to the region.


     Luis


-----------------------------
On Tue, Feb 2, 2010 at 5:29 AM, Marco Gheza
<marcogheza4mailinglists at gmail.com> wrote:
> 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
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list