[Insight-users] ConfidenceConnected 3d
inparanoia
inparanoia at yahoo.it
Thu Mar 3 07:29:05 EST 2011
in 2d it's like itk software guide, in 3d with a mhd float file [1.0 1.0
1.0] spacing and a seed right(checked in paraview,3dslicer,itksnap)
segmentation it's liche a spot white by a pet, it takes the outside
instead of the spot and also
confidenceConnectedFilter->GetMean();
confidenceConnectedFilter->GetVariance();
give the outside (black uniform mean=0 variance=0)
it's a bug?
i've noticed especally in fuzzyconnect
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include "itkSimpleFuzzyConnectednessScalarImageFilter.h"
#include "itkImage.h"
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Since the FuzzyConnectednessImageFilter requires an estimation of the
// gray level mean and variance for the region to be segmented, we use
here the
// \doxygen{ConfidenceConnectedImageFilter} as a preprocessor that
produces a
// rough segmentation and estimates from it the values of the mean and the
// variance.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkConfidenceConnectedImageFilter.h"
// Software Guide : EndCodeSnippet
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
int main( int argc, char *argv[] )
{
if( argc < 8 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage outputAffinityMap " << std::endl;
std::cerr << " seedX seedY seedz multiplier " << std::endl;
return 1;
}
// Software Guide : BeginLatex
//
// Next, we declare the pixel type and image dimension and
// specify the image type to be used as input.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef float InputPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< InputPixelType, Dimension > InputImageType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Fuzzy connectedness computes first the affinity map and then
thresholds
// its values in order to get a binary image as output. The type of the
// binary image is provided as the second template parameter of the
filter.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef unsigned char BinaryPixelType;
typedef itk::Image< BinaryPixelType, Dimension > BinaryImageType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The Confidence connected filter type is instantiated using the input
// image type and a binary image type for output.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::ConfidenceConnectedImageFilter<
InputImageType,
BinaryImageType
>
ConfidenceConnectedFilterType;
ConfidenceConnectedFilterType::Pointer confidenceConnectedFilter =
ConfidenceConnectedFilterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The fuzzy segmentation filter type is instantiated here using the
input
// and binary image types as template parameters.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::SimpleFuzzyConnectednessScalarImageFilter<
InputImageType,
BinaryImageType
>
FuzzySegmentationFilterType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The fuzzy connectedness segmentation filter is created by invoking the
// \code{New()} method and assigning the result to a
// \doxygen{SmartPointer}.
//
// \index{itk::SimpleFuzzy\-Connectedness\-Scalar\-Image\-Filter!New()}
// \index{itk::SimpleFuzzy\-Connectedness\-Scalar\-Image\-Filter!Pointer}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
FuzzySegmentationFilterType::Pointer fuzzysegmenter =
FuzzySegmentationFilterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The affinity map can be accessed through the type
\code{FuzzySceneType}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef FuzzySegmentationFilterType::FuzzySceneType FuzzySceneType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We instantiate reader and writer types
//
// Software Guide : EndLatex
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::ImageFileWriter< BinaryImageType > 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]);
index[1] = atoi(argv[6]);
const double varianceMultiplier = atof( argv[7] );
// Software Guide : BeginLatex
//
// The output of the reader is passed as input to the
ConfidenceConnected image filter.
// Then the filter is executed in order to obtain estimations of the
mean and variance
// gray values for the region to be segmented.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
confidenceConnectedFilter->SetInput( reader->GetOutput() );
confidenceConnectedFilter->SetMultiplier( varianceMultiplier );
confidenceConnectedFilter->SetNumberOfIterations( 2 );
confidenceConnectedFilter->AddSeed( index );
confidenceConnectedFilter->SetInitialNeighborhoodRadius( 1 );//MIO
confidenceConnectedFilter->Update();
// Software Guide : EndCodeSnippet
//it takes outside BUT SEED IS RIGHT!!!!!!!!!!!!
confidenceConnectedFilter->SetReplaceValue( 40 );//MIO
const double meanEstimation = confidenceConnectedFilter->GetMean();
const double varianceEstimation =
confidenceConnectedFilter->GetVariance();
WriterType::Pointer confidenceWriter = WriterType::New();
confidenceWriter->SetInput( confidenceConnectedFilter->GetOutput() );
confidenceWriter->SetFileName("confidenceConnectedPreprocessing.mhd");
confidenceWriter->Update();
// Software Guide : BeginLatex
//
// The input that is passed to the fuzzy segmentation filter is taken
from
// the reader.
//
//
\index{itk::Simple\-Fuzzy\-Connectedness\-Scalar\-Image\-Filter!SetInput()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
fuzzysegmenter->SetInput( reader->GetOutput() );
// Software Guide : EndCodeSnippet
std::cout << "Mean estimation = " << meanEstimation <<
std::endl;//VENGONO 0 E 0 MI PARE STRANO
std::cout << "Variance estimation = " << varianceEstimation << std::endl;
// Software Guide : BeginLatex
//
// The parameters of the fuzzy segmentation filter are defined here.
A seed
// point is provided with the method \code{SetObjectsSeed()} in order to
// initialize the region to be grown. Estimated values for the mean and
// variance of the object intensities are also provided with the methods
// \code{SetMean()} and \code{SetVariance()}, respectively. A threshold
// value for generating the binary object is preset with the method
// \code{SetThreshold()}. For details describing the role of the
mean and
// variance on the computation of the segmentation, please see
// \cite{Udupa1996}.
//
//
\index{itk::Simple\-Fuzzy\-Connectedness\-Scalar\-Image\-Filter!SetObjectsSeed()}
//
\index{itk::Simple\-Fuzzy\-Connectedness\-Scalar\-Image\-Filter!SetMean()}
//
\index{itk::Simple\-Fuzzy\-Connectedness\-Scalar\-Image\-Filter!SetVariance()}
//
\index{itk::Simple\-Fuzzy\-Connectedness\-Scalar\-Image\-Filter!SetThreshold()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
fuzzysegmenter->SetObjectSeed( index );
fuzzysegmenter->SetMean( meanEstimation );
fuzzysegmenter->SetVariance( varianceEstimation );
fuzzysegmenter->SetThreshold( 0.5 );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The execution of the fuzzy segmentation filter is triggered by the
// \code{Update()} method.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
fuzzysegmenter->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginCodeSnippet
writer->SetInput( fuzzysegmenter->GetOutput() );
writer->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginCodeSnippet
fwriter->SetInput( fuzzysegmenter->GetFuzzyScene() );
fwriter->Update();
// Software Guide : EndCodeSnippet
return 0;
More information about the Insight-users
mailing list