[Insight-users] derivativeImageFilter
john smith
mkitkinsightuser at gmail.com
Tue Mar 15 09:49:37 EDT 2011
Hi to everyone,
I want to read an image and use a derivative image filter.I wrote the
following code, but when I get a failure because I thonk that the types of
reader,writer and derivative image filter do not match each other.Could
somebody help me?
Thanks in advance
================DerivativeImageFilter.cxx==========================
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkDerivativeImageFilter.h"
int main(int argc, char * argv[])
{
// Verify command line arguments
if( argc < 2 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile" << std::endl;
return EXIT_FAILURE;
}
// Parse command line arguments
std::string inputFilename = argv[1];
// Setup types
typedef itk::Image< float, 2 > FloatImageType;
typedef itk::Image< unsigned char, 2 > UnsignedCharImageType;
typedef itk::ImageFileReader< UnsignedCharImageType > readerType;
typedef itk::ImageFileReader< UnsignedCharImageType > writerType;
typedef itk::DerivativeImageFilter<
UnsignedCharImageType, FloatImageType > filterType;
// Create and setup a reader
readerType::Pointer reader = readerType::New();
reader->SetFileName( inputFilename.c_str() );
// Create and setup a derivative filter
filterType::Pointer derivativeFilter = filterType::New();
derivativeFilter->SetInput( reader->GetOutput() );
derivativeFilter->SetDirection(0); // "x" axis
typedef itk::ImageFileWriter< writerType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("result.png");
writer->SetInput(derivativeFilter->GetOutput());
try
{
writer->Update();
}
catch( itk::ExceptionObject exp )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << exp << std::endl;
}
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110315/b267b702/attachment.htm>
More information about the Insight-users
mailing list