Hi to everyone,<br><br>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?<br>
<br>Thanks in advance<br><br>================DerivativeImageFilter.cxx==========================<br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>
#include "itkDerivativeImageFilter.h"<br> <br><br> <br>int main(int argc, char * argv[])<br>{<br> // Verify command line arguments<br> if( argc < 2 )<br> {<br> std::cerr << "Usage: " << std::endl;<br>
std::cerr << argv[0] << " inputImageFile" << std::endl;<br> return EXIT_FAILURE;<br> }<br> <br> // Parse command line arguments<br> std::string inputFilename = argv[1];<br> <br> // Setup types<br>
typedef itk::Image< float, 2 > FloatImageType;<br> typedef itk::Image< unsigned char, 2 > UnsignedCharImageType;<br> <br> typedef itk::ImageFileReader< UnsignedCharImageType > readerType;<br>
typedef itk::ImageFileReader< UnsignedCharImageType > writerType;<br> <br> typedef itk::DerivativeImageFilter<<br> UnsignedCharImageType, FloatImageType > filterType;<br> <br> // Create and setup a reader<br>
readerType::Pointer reader = readerType::New();<br> reader->SetFileName( inputFilename.c_str() );<br> <br> // Create and setup a derivative filter<br> filterType::Pointer derivativeFilter = filterType::New();<br> derivativeFilter->SetInput( reader->GetOutput() );<br>
derivativeFilter->SetDirection(0); // "x" axis<br> <br> typedef itk::ImageFileWriter< writerType > WriterType;<br> WriterType::Pointer writer = WriterType::New();<br> writer->SetFileName("result.png");<br>
writer->SetInput(derivativeFilter->GetOutput());<br><br> try<br> {<br> writer->Update();<br> }<br> catch( itk::ExceptionObject exp )<br> {<br> std::cerr << "Exception caught !" << std::endl;<br>
std::cerr << exp << std::endl;<br> }<br> <br> return EXIT_SUCCESS;<br>}<br>