[Insight-users] problem with VED

Wen Shi wsa18 at sfu.ca
Wed Apr 8 00:54:49 EDT 2009


Hi Guys,

I am using VED to process image data.
I don't have 3D image data in hand, So I tried to read several 2D vessel images into VED using imageSeriesRead, 
Then I use imageSeriesWrite to write the processed image back to 2D slices.
Then I got some errors.
My codes are as following:

/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkMultiScaleHessianSmoothed3DToVesselnessMeasureImageFilterTest.cxx,v $
  Language:  C++
  Date:      $Date: 2007/04/01 21:19:46 $
  Version:   $Revision: 1.5 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif


#include "itkMultiScaleHessianSmoothed3DToVesselnessMeasureImageFilter.h"
//#include "itkImageFileReader.h"
//#include "itkImageFileWriter.h"
#include "itkImageSeriesWriter.h"
#include "itkImageSeriesReader.h"
#include "itkNumericSeriesFileNames.h"
#include "itkBMPImageIO.h"


#include "itkRescaleIntensityImageFilter.h"

int main(int argc, char* argv [] )
{
  argc=4;
	if ( argc < 3 )
    {
    std::cerr << "Missing Parameters: " 
              << argv[0]
              << " Input_Image"
              << " Vessel_Enhanced_Output_Image [SigmaMin SigmaMax NumberOfScales]" << std::endl; 
    return EXIT_FAILURE;
    }
 
 
  // Define the dimension of the images
  const unsigned int Dimension = 3;
  typedef short      InputPixelType;
  typedef double     OutputVesselnessPixelType;

  // Declare the types of the images
  typedef itk::Image< InputPixelType, Dimension>            InputImageType;

  typedef itk::Image< OutputVesselnessPixelType, Dimension> VesselnessOutputImageType;

  typedef itk::ImageSeriesReader< InputImageType >  ReaderType;

  ReaderType::Pointer   reader = ReaderType::New();
   
  const unsigned int first =001;
  const unsigned int last  =005;

  typedef itk::NumericSeriesFileNames    NameGeneratorType;
  NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
  nameGenerator->SetSeriesFormat( "vessel-%03d.bmp" );
  nameGenerator->SetStartIndex( first );
  nameGenerator->SetEndIndex( last );
  nameGenerator->SetIncrementIndex( 1 );

  reader->SetImageIO( itk::BMPImageIO::New() );
  reader->SetFileNames(nameGenerator->GetFileNames() );

  //reader->SetFileName ( "CT-Head.pvm" ); 

/*typedef itk::ImageFileReader< InputImageType  >      ImageReaderType;
  ImageReaderType::Pointer reader = ImageReaderType::New();
  reader->SetFileName( "vessel-001.bmp" );*/

  std::cout << "Reading input image : " << "vessel-.bmp" << std::endl;
  try
    {
    reader->Update();
    }
  catch ( itk::ExceptionObject &err )
    {
    std::cerr << "Exception thrown: " << err << std::endl;
    return EXIT_FAILURE;
    }


  // Declare the type of multiscale vesselness filter
  typedef itk::MultiScaleHessianSmoothed3DToVesselnessMeasureImageFilter<
                                            InputImageType,
                                            VesselnessOutputImageType>  
                                            MultiScaleVesselnessFilterType;

  // Create a vesselness Filter
  MultiScaleVesselnessFilterType::Pointer MultiScaleVesselnessFilter = 
                                      MultiScaleVesselnessFilterType::New();

  MultiScaleVesselnessFilter->SetInput( reader->GetOutput() );

 // if ( argc >= 4 ) 
   // { 
    MultiScaleVesselnessFilter->SetSigmaMin( 0.5  ); 
   // }
 
  //if ( argc >= 5 )
  //  {
    MultiScaleVesselnessFilter->SetSigmaMax( 1.0 ); 
  //  }

 // if ( argc >= 6 )
  //  {
    MultiScaleVesselnessFilter->SetNumberOfSigmaSteps( 5 ); 
 //   }

  try
    {
    MultiScaleVesselnessFilter->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "Exception caught: " << err << std::endl;
    return EXIT_FAILURE;
    }

  std::cout << "Writing out the enhanced image to " <<  "vessel(enhanced).png"  << std::endl;

  //Rescale the output of the vesslness image
  typedef itk::Image<unsigned char, 2>              OutputImageType; 
  typedef itk::RescaleIntensityImageFilter< VesselnessOutputImageType,
                                            OutputImageType> 
                                            RescaleFilterType;

  RescaleFilterType::Pointer rescale = RescaleFilterType::New();
  rescale->SetInput( MultiScaleVesselnessFilter->GetOutput() );
  rescale->SetOutputMinimum(   0 );
  rescale->SetOutputMaximum( 255 );
  rescale->Update();

  typedef itk::ImageSeriesWriter< InputImageType, OutputImageType  >      ImageWriterType;
  ImageWriterType::Pointer writer = ImageWriterType::New();


  typedef itk::NumericSeriesFileNames    NameGeneratorType;
  NameGeneratorType::Pointer nameGenerator1 = NameGeneratorType::New();
 
  std::string format = 'output';
  format += "%03d.";
  format += 'bmp';   // filename extension
  nameGenerator1->SetSeriesFormat( format.c_str() );

  //writer->SetFileName( "vessel(enhanced).png"  );
  writer->SetInput ( rescale->GetOutput() );

  InputImageType::ConstPointer inputImage = rescale->GetOutput();
  InputImageType::RegionType   region     = inputImage->GetLargestPossibleRegion();
  InputImageType::IndexType    start      = region.GetIndex(); 
  InputImageType::SizeType     size       = region.GetSize(); 
 
  const unsigned int firstSlice = start[2];
  const unsigned int lastSlice  = start[2] + size[2] - 1;

  nameGenerator1->SetStartIndex( firstSlice );
  nameGenerator1->SetEndIndex( lastSlice );
  nameGenerator1->SetIncrementIndex( 1 );

  writer->SetFileNames( nameGenerator1->GetFileNames() );

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

  return EXIT_SUCCESS;

}

The errors are :
std::string format = 'output';(I picked up the error line)
error C2015: too many characters in constant

writer->SetInput ( rescale->GetOutput() );
error C2664: 'itk::ImageSeriesWriter<TInputImage,TOutputImage>::SetInput' : cannot convert parameter 1 from 'itk::Image<TPixel,VImageDimension> *' to 'const itk::Image<TPixel,VImageDimension> *'

InputImageType::ConstPointer inputImage = rescale->GetOutput();
error C2440: 'initializing' : cannot convert from 'itk::Image<TPixel,VImageDimension> *' to 'itk::SmartPointer<TObjectType>'

Thanks a lot

Wen Shi








More information about the Insight-users mailing list