[Insight-users] Help with Connected Threshold Filter
Wu Zheying
u0303820 at nus.edu.sg
Sun Jan 21 10:30:45 EST 2007
Hi all,
I am doing connected threshold filter on a Analyze dataset. However, I keep on gettin black outputs no matter what threshold range and seed point i specify. Can someone help me out with this?
my input commands:
ConnectedThresholdImageFilter MRI2.hdr output.hdr 295 221 250 255 95
I initially placed my seed point at (221,250,95) where the image intensity is bright (250-255)
my code attached:
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
#include "itkConnectedThresholdImageFilter.h"
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#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 seedX seedY lowerThreshold upperThreshold seedZ" << std::endl;
return 1;
}
typedef float InternalPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::CastImageFilter< InternalImageType, OutputImageType >
CastFilterType;
CastFilterType::Pointer caster = CastFilterType::New();
typedef itk::ImageFileReader< InternalImageType > ReaderType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( argv[1] );
writer->SetFileName( argv[2] );
typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >
CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType::Pointer smoothing =
CurvatureFlowImageFilterType::New();
typedef itk::ConnectedThresholdImageFilter< InternalImageType,
InternalImageType > ConnectedFilterType;
ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();
smoothing->SetInput( reader->GetOutput() );
connectedThreshold->SetInput( smoothing->GetOutput() );
caster->SetInput (connectedThreshold->GetOutput());
writer->SetInput ( caster->GetOutput());
smoothing->SetNumberOfIterations( 1 );
smoothing->SetTimeStep( 0.0625 );
const InternalPixelType lowerThreshold = atof( argv[5] );
const InternalPixelType upperThreshold = atof( argv[6] );
connectedThreshold->SetLower( lowerThreshold );
connectedThreshold->SetUpper( upperThreshold );
connectedThreshold->SetReplaceValue( 255 );
InternalImageType::IndexType index;
index[0] = atoi( argv[3] );
index[1] = atoi( argv[4] );
index[2] = atoi( argv[7] );
connectedThreshold->SetSeed( index );
try
{
writer->Update();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
return 0;
}
Appreciate the help!
ZHeying
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070121/d32802a5/attachment.html
More information about the Insight-users
mailing list