[Insight-users] OtsuMultipleThresholdFilter example fails to build in debug with short data type

Emma Ryan eryanvtk at yahoo.com
Thu Dec 15 20:58:00 EST 2011


Hi all,

  I have modified the original Otsu segmentation with multiple thresholds code available here :

http://www.vtk.org/Wiki/ITK/Examples/WishList/Segmentation/OtsuMultipleThresholdsCalculator

to work on Unsigned short image type.  The program builds and executes fine in Release mode till it crashes at Filter->Update(). 

In debug mode I get a compile error :

error C2660: 'itk::LightObject::operator new' : function does not take 4 arguments  for 
ScalarImageToHistogramGenerator


How can I fix this ? I am using itk 3.20. My declarations are as follows:

where ImageType = <unsigned short, 2>
          UCharImageType = <unsigned char, 2>


//code snippet
typedef itk::Statistics::ScalarImageToHistogramGenerator<ImageType >  ScalarImageToHistogramGeneratorType;
    typedef  itk::OtsuMultipleThresholdsCalculator<ScalarImageToHistogramGeneratorType::HistogramType  > CalculatorType;
    typedef itk::BinaryThresholdImageFilter< ImageType, UCharImageType >  FilterType;
    typedef itk::AddImageFilter< UCharImageType, ImageType ,ImageType>  AddFilterType;

    ScalarImageToHistogramGeneratorType::Pointer scalarImageToHistogramGenerator =    ScalarImageToHistogramGeneratorType::New();
    CalculatorType::Pointer calculator = CalculatorType::New();
    FilterType::Pointer filter = FilterType::New();
    AddFilterType::Pointer addFilter = AddFilterType::New();


    int num_of_bins = 128;
    int num_thresholds = 2;
    scalarImageToHistogramGenerator->SetNumberOfBins( num_of_bins );
    calculator->SetNumberOfThresholds(num_thresholds);
    scalarImageToHistogramGenerator->SetInput(mpImage);
    scalarImageToHistogramGenerator->Compute();
    calculator->SetInputHistogram(scalarImageToHistogramGenerator->GetOutput());
    filter->SetInput(mpImage );

    calculator->Update();

    const CalculatorType::OutputType &thresholdVector =  calculator->GetOutput();
    CalculatorType::OutputType::const_iterator itNum =  thresholdVector.begin();

    PixelType min = 0;
    PixelType max = 255;

    const PixelType outsideValue = 0;

    //std::string outputFileBase = argv[2];
    //std::string outputFile;
    //std::string format = argv[2];

    //char outputFilename[1000];
    //outputFile = outputFileBase;
    //outputFile += argv[3];   // filename extension

    PixelType lowerThreshold = min;
    PixelType upperThreshold;

    filter->SetOutsideValue(outsideValue );
    PixelType step =(255/(num_thresholds+1) );
    PixelType count=step;

    for(; itNum < thresholdVector.end(); itNum++)
    {

        const PixelType insideValue = count;
        filter->SetInsideValue( insideValue );

        upperThreshold =static_cast<PixelType>(*itNum);

        filter->SetLowerThreshold( lowerThreshold );
        filter->SetUpperThreshold(upperThreshold );
        filter->Update();

        lowerThreshold = upperThreshold;
        write_to_jpg<unsigned char>(gpResultsDir->GetFullPath("filter_out.jpg"), filter->GetOutput());


        addFilter->SetInput1( filter->GetOutput() );
        addFilter->SetInput2(  sumimage );

        addFilter->Update();
        sumimage = addFilter->GetOutput() ;

        write_to_jpg<unsigned short>(gpResultsDir->GetFullPath("sumimage1.jpg"), sumimage);

        count = count + step;
    }

    PixelType insideValue = 255;

    filter->SetInsideValue( insideValue   );
    filter->SetLowerThreshold( lowerThreshold );
    filter->SetUpperThreshold(max );
   filter->Update();


Thank you for your help.

regards,
Emma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20111215/8c791641/attachment.htm>


More information about the Insight-users mailing list