[Insight-users] Dangling pointer when computing HistogramGenerator

Robert Maroon robertmaroon at yahoo.com
Wed Dec 1 13:00:50 EST 2004


Hi all,

I am trying to use the ScalarImageToHistogramGenerator
to create an image histogram for a large 3D volume.
Using the following code it works fine for small
volumes, but when I go to a larger one 250*250*100 the
program crashes.


//setup Image type
typedef itk::Image< unsigned char, 3 >
InternalImageType;


//setup image reader
typedef itk::ImageFileReader< InternalImageType > 
ReaderType;
ReaderType::Pointer reader;
char *FN = argv[1];


//setup histogram type
typedef
itk::Statistics::ScalarImageToHistogramGenerator<InternalImageType>
HistogramGeneratorType;
HistogramGeneratorType::Pointer histogramGenerator;
typedef HistogramGeneratorType::HistogramType 
HistogramType;


//setup image
InternalImageType::Pointer image;

//initialize reader
reader = ReaderType::New();

//read in file
reader->SetFileName( FN );

//UPDATE ITK READER
try
{
	reader->Update();
}
catch( itk::ExceptionObject & excp )
{
	std::cerr << "Problem reading the input file" <<
std::endl;
	std::cerr << excp << std::endl;
return -1;
}

//initialize histogram generator
histogramGenerator = HistogramGeneratorType::New();

//read in image
image = InternalImageType::New();
image = reader->GetOutput();

//set image as input for histogram generator
histogramGenerator->SetInput(image);

//set parameters for histogram generator
histogramGenerator->SetNumberOfBins( NUM_GRAYLEVELS );
histogramGenerator->SetMarginalScale(
SIZE_MARGINAL_SCALE );
histogramGenerator->Compute();



It crashes on the histogramGenerator->Compute() line.
I ran a profiler called boundschecker on it and it
came back with the following error reporting a
dangling pointer in
itkScalarImageToHistogramGenerator.txx



Dangling Pointer: Pointer 0x03448FB0, allocated by
global_operator_new, has already been freed.

Current Call Stack - Thread 0 [0x1510]
vector<double,class std::allocator<double> >::size
C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\vector	114
vector<double,class std::allocator<double> >::insert
C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\vector	165
vector<double,class std::allocator<double> >::resize
C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\vector	110
Statistics::Histogram<double,1,class
itk::Statistics::DenseFrequencyContainer<float>
>::Initialize
C:\InsightToolkit-1.6.0\Code\Numerics\Statistics\itkHistogram.txx
78
Statistics::Histogram<double,1,class
itk::Statistics::DenseFrequencyContainer<float>
>::Initialize
C:\InsightToolkit-1.6.0\Code\Numerics\Statistics\itkHistogram.txx
99
Statistics::ListSampleToHistogramGenerator<class
itk::Statistics::ScalarImageToListAdaptor<class
itk::Image<unsigned char,3> >,double,class
itk::Statistics::DenseFrequencyContainer<float>
>::GenerateData
C:\InsightToolkit-1.6.0\Code\Numerics\Statistics\itkListSampleToHistogramGenerator.txx
80
Statistics::ListSampleToHistogramGenerator<class
itk::Statistics::ScalarImageToListAdaptor<class
itk::Image<unsigned char,3> >,double,class
itk::Statistics::DenseFrequencyContainer<float>
>::Update
C:\InsightToolkit-1.6.0\Code\Numerics\Statistics\itkListSampleToHistogramGenerator.h
104
Statistics::ScalarImageToHistogramGenerator<class
itk::Image<unsigned char,3> >::Compute
C:\InsightToolkit-1.6.0\Code\Numerics\Statistics\itkScalarImageToHistogramGenerator.txx
62
main
C:\ReleaseVersions\binbranchlikeliness\BinBranchLikeliness.cxx
152
mainCRTStartup	crtexe.c	338
	C:\WINDOWS\system32\kernel32.dll!0x00021417	


Allocation Call Stack - Thread 0 [0x1510]
_Allocate	C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\xmemory	30
allocator<double>::allocate	C:\Program Files\Microsoft
Visual Studio\VC98\INCLUDE\xmemory	59
vector<double,class std::allocator<double>
>::vector<double,class std::allocator<double> >
C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\vector	50
_Construct	C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\xmemory	34
allocator<class std::vector<double,class
std::allocator<double> > >::construct	C:\Program
Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory	66


Deallocation Call Stack - Thread 0 [0x1510]
allocator<double>::deallocate	C:\Program
Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory	64
vector<double,class std::allocator<double> >::insert
C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\vector	163
vector<double,class std::allocator<double> >::resize
C:\Program Files\Microsoft Visual
Studio\VC98\INCLUDE\vector	110
Statistics::Histogram<double,1,class
itk::Statistics::DenseFrequencyContainer<float>
>::Initialize
C:\InsightToolkit-1.6.0\Code\Numerics\Statistics\itkHistogram.txx
78
Statistics::Histogram<double,1,class
itk::Statistics::DenseFrequencyContainer<float>
>::Initialize
C:\InsightToolkit-1.6.0\Code\Numerics\Statistics\itkHistogram.txx
99





Any ideas on how I can fix this?

Thanks!

Robert



		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 


More information about the Insight-users mailing list