[Insight-users] VectorConfidenceConnected compilation problem

Stefan Lindenau stefan . lindenau at gmx . de
Thu, 04 Dec 2003 18:20:37 -0500


This is a multi-part message in MIME format.
--------------000205020801090603030404
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi all,

when I use the GetMean() or the GetCovariance() functions of the 
VectorConfidencConnectedImageFilter I get a runtime error (Release 
Build) or a compiletime error (Debug Release). My Compiler is VC++ 6.0

I use the functions in the following manner:

    const ConnectedFilterType::CovarianceMatrixType &covariance =
                                           connFilter->GetCovariance();
  const ConnectedFilterType::MeanVectorType  &mean =
                                                 connFilter->GetMean();

The compiler in Debug Mode complains about:
C:\Surgical 
Simulator\InsightToolkit-1.4.0\Code\BasicFilters\itkVectorConfidenceConnectedImageFilter.txx(319) 
: error C4716: 
'itk::VectorConfidenceConnectedImageFilter<itk::Image<itk::RGBPixel<unsigned 
char>,3>,itk::Image<unsigned char,3> >::GetMean
' : must return a value

which refers to this function:
template <class TInputImage, class TOutputImage>
const typename
VectorConfidenceConnectedImageFilter<TInputImage,TOutputImage>::MeanVectorType 
&
VectorConfidenceConnectedImageFilter<TInputImage,TOutputImage>
::GetMean() const
{
  m_ThresholdFunction->GetMean();
}

if i put a return before the "m_ThresholdFunction->GetMean()" it compiles.

But if I use for example 1.85 as Value for the multiplier I get this as 
output from the source code I have attached and there is no segmentation 
visible in the output Image.

Mean:

-1.#IND  -1.#IND  -1.#IND 
Covariance:
-1.#IND  -1.#IND  -1.#IND 
-1.#IND  -1.#IND  -1.#IND 
-1.#IND  -1.#IND  -1.#IND

If I use 2.5 for the multiplier everything is fine. My suspicion is that 
the mean and variance are developing away from the seed points and in 
the end the seed point are not matching the criteria any more.

Is it all really an ITK Bug or did I something fundamental wrong?


Thanks
Stefan

--------------000205020801090603030404
Content-Type: text/plain;
 name="VHDConfidenceConnected.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="VHDConfidenceConnected.cxx"

#include "itkRGBPixel.h"
#include "itkImageFileReader.h"
#include "itkImage.h"
#include "itkVectorConfidenceConnectedImageFilter.h"
#include "itkImageFileWriter.h"


//#include "CommandProgress.h"


int main(int argc,char **argv) {
	
	if(argc!=4) {
		std::cerr<<"Incorrect number of arguments:"<<std::endl;
		std::cerr<<"Please use this program in this way:"<<std::endl<<std::endl;
		std::cerr<<argv[0]<<" inputFileName outputFileName multiplier"<<std::endl;
		return -1;
	}
	
	
	/*
	Setting the typedefinitions as required from ITK
	*/
	typedef itk::RGBPixel<unsigned char> InputPixelType;
	typedef itk::Image<InputPixelType,3> InputImageType;
	typedef itk::ImageFileReader<InputImageType> ReaderType;

	typedef unsigned char OutputPixelType;
	typedef itk::Image<OutputPixelType,3> OutputImageType;
	
	typedef itk::VectorConfidenceConnectedImageFilter<InputImageType,OutputImageType>
				ConnectedFilterType;
	
	typedef itk::ImageFileWriter<OutputImageType> WriterType;

	
	/*
	Declaration of necessary pointers - remember ITK uses smartpointers!
	*/
	ReaderType::Pointer	reader = ReaderType::New();
	ConnectedFilterType::Pointer connFilter = ConnectedFilterType::New();
	WriterType::Pointer writer = WriterType::New();
	
	const InputImageType::IndexType index = {48,196,198};
	const InputImageType::IndexType index2 = {29,248,103};

	//CommandProgress::Pointer observer = CommandProgress::New();
	/*
	Setting the filenames
	*/
	std::string input=argv[1];
	std::string output=argv[2];
	std::istringstream iss(argv[3]);
	float multiplier;
	iss >> multiplier;

	/*
	Setting the reader up
	*/
	reader->SetFileName(input.c_str());
	reader->ReleaseDataFlagOn();
	//reader->AddObserver(itk::StartEvent(),observer);
	//reader->AddObserver(itk::EndEvent(),observer);

	/*
	Setting the confidenceConnectedImageFilter up
	*/
	connFilter->SetInput(reader->GetOutput());
	//connFilter->AddObserver(itk::StartEvent(),observer);
	//connFilter->AddObserver(itk::EndEvent(),observer);
	//connFilter->AddObserver(itk::ProgressEvent(),observer);
	
	connFilter->SetSeed(index);
	connFilter->AddSeed(index2);
	connFilter->SetInitialNeighborhoodRadius(3);
	connFilter->SetMultiplier(multiplier);
	connFilter->SetNumberOfIterations(5);
	
	connFilter->SetReplaceValue(255);

	//connFilter->SetSeed
	/*
	Setting the writer up
	*/
	writer->SetFileName(output.c_str());
	//writer->SetInput(reader->GetOutput());
	writer->SetInput(connFilter->GetOutput());
	//writer->AddObserver(itk::StartEvent(),observer);
	//writer->AddObserver(itk::EndEvent(),observer);
	
	
	
	try {
		writer->Update();
	} catch (itk::ExceptionObject &err) {
		std::cerr<< "Exception caught:" << std::endl;
        std::cerr<< err <<std::endl;
		
        return -1;
	}


	const ConnectedFilterType::CovarianceMatrixType &covariance = 
                                           connFilter->GetCovariance();

  const ConnectedFilterType::MeanVectorType  &mean = 
                                                 connFilter->GetMean();


  std::cout << "Mean: " << std::endl;
  // Write the mean and covariance to a file
  for(unsigned int ii=0; ii<3; ii++)
    {
    
    std::cout << mean[ii] << "  ";
    }
  
  std::cout << std::endl;

  std::cout << "Covariance: " << std::endl;
  for(unsigned int ki=0; ki<3; ki++)
    {
    for(unsigned int kj=0; kj<3; kj++)
      {
      
      std::cout << covariance[ki][kj] << "  ";
      }
   
    std::cout << std::endl;
    }
	return 0;
}

--------------000205020801090603030404--