[Insight-users] RGB Fuzzy Connectedness
Juan Paredes
juanparedeswall at yahoo.com
Tue Feb 20 05:32:49 EST 2007
Hi ITK users,
I'm attempting to run fuzzy connectedness segmentation on a RGB image. Based on ITK documentation examples, I have compiled the code and build the executable but when I run it the program aborts and the following error message it is displayed:
.../vnl_matrix.txx : 1184: matrix has non-finite elements
Any suggestion to fix the problem?.
Here, it is the code:
#include "itkVectorConfidenceConnectedImageFilter.h"
#include "itkSimpleFuzzyConnectednessRGBImageFilter.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVector.h"
#include "itkArray2D.h"
int main( int argc, char *argv[] )
{
if( argc < 7 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage outputmap seedX seedY multiplier " << std::endl;
return 1;
}
typedef unsigned char PixelComponentType;
const unsigned char VDim = 3;
typedef itk::Vector< PixelComponentType, VDim > InputPixelType;
const unsigned int Dimension = 2;
typedef itk::Image< InputPixelType, Dimension > InputImageType;
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::VectorConfidenceConnectedImageFilter< InputImageType,
OutputImageType > ConnectedFilterType;
ConnectedFilterType::Pointer confidenceConnected = ConnectedFilterType::New();
typedef itk::SimpleFuzzyConnectednessRGBImageFilter< InputImageType, OutputImageType > FuzzySegmentationFilterType;
FuzzySegmentationFilterType::Pointer fuzzysegmenter = FuzzySegmentationFilterType::New();
typedef FuzzySegmentationFilterType::FuzzySceneType FuzzySceneType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
typedef itk::ImageFileWriter< FuzzySceneType > FuzzyWriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
FuzzyWriterType::Pointer fwriter = FuzzyWriterType::New();
reader->SetFileName( argv[1] );
writer->SetFileName( argv[2] );
fwriter->SetFileName( argv[3] );
InputImageType::IndexType index;
index[0] = atoi(argv[4]);
index[1] = atoi(argv[5]);
confidenceConnected->SetInput( reader->GetOutput() );
WriterType::Pointer confidenceWriter = WriterType::New();
confidenceWriter->SetInput( confidenceConnected->GetOutput() );
confidenceWriter->SetFileName("confConPre.png");
confidenceWriter->Update();
fuzzysegmenter->SetInput( reader->GetOutput() );
const double multiplier = atof( argv[6] );
confidenceConnected->SetMultiplier( multiplier );
const unsigned int iterations = 2;
confidenceConnected->SetNumberOfIterations( iterations );
confidenceConnected->SetReplaceValue( 255 );
confidenceConnected->SetSeed( index );
//confidenceConnected->AddSeed( index );
confidenceConnected->SetInitialNeighborhoodRadius( 3 );
typedef ConnectedFilterType::MeanVectorType MeanVectorType;
const MeanVectorType & mean = confidenceConnected->GetMean();
typedef ConnectedFilterType::CovarianceMatrixType CovarianceMatrixType;
const CovarianceMatrixType & covariance = confidenceConnected->GetCovariance();
std::cout << "Covariance matrix = " << std::endl;
std::cout << covariance << std::endl;
fuzzysegmenter->SetObjectSeed( index );
const double * mean1 = mean.data_block();
const double * cov1 = covariance.data_block();
double ccov[3][3];
double mmean[3];
int z=0;
for (int x=0; x<3; ++x)
for (int y=0; y<3; ++y)
{
ccov[x][y]= cov1[z];
++z;
}
for (int i=0; i<3; ++i)
mmean[i]= mean1[i];
fuzzysegmenter->SetMean( mmean );
fuzzysegmenter->SetVariance( ccov );
fuzzysegmenter->SetThreshold( 0.5 );
writer->SetInput( fuzzysegmenter->GetOutput() );
fwriter->SetInput( fuzzysegmenter->GetFuzzyScene() );
try
{
fuzzysegmenter->Update();
writer->Update();
fwriter->Update();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
return 0;
}
---------------------------------
No need to miss a message. Get email on-the-go
with Yahoo! Mail for Mobile. Get started.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070220/fd9f50fb/attachment.html
More information about the Insight-users
mailing list