[Insight-users] VectorConfidenceConnected compilation problem
Stefan Lindenau
stefan . lindenau at gmx . de
Fri, 05 Dec 2003 11:40:00 -0500
Hi Luis,
About your proposal for my second problem:
I am not sure if it is possible but in my eyes the best solution would
be to enforce that the seed points are lying in the range of intensities
as it is done in the "normal" ConfidenceConnectedFilter. In this filter
this is quiet simple since it requires only adjusting the lower and
upper threshold, but I do not know how this could be done with the
Mahalanobis distance that is used in the
VectorConfidenceConnectedImageFilter.
If this is not possible I think the most reasonable solution would be to
throw an exception.
Stefan
Luis Ibanez wrote:
>
> Hi Stefan,
>
> Thanks for pointing this out.
>
> The "return" keyword was actually missing in these two methods.
> A fix has been commited now to the CVS version.
>
> That takes care of the first issue in your message.
>
> About the second problem:
>
> A multiplier of 2.5 gives more tolerance than a multiplier
> value of 1.85. In the second case it may simply happen that
> the seed points do not match the range of intensities (as you
> just suggested). This results in an empty region and in
> divisions by zero when computing mean and covariance.
>
> We should probably throw an exception when no points are
> being left in the segmented region...
>
> This means that your code will have to catch potential
> exceptions when you run this segmentation filter.
>
> Would find this option to be reasonable ?
>
>
>
> Please let us know,
>
> Thanks
>
>
> Luis
>
>
> -------------------------
> Stefan Lindenau wrote:
>
>> 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
>>
>>
>> ------------------------------------------------------------------------
>>
>> #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;
>> }
>
>
>
>
>