[Insight-users] derivativeImageFilter
robert tamburo
robert.tamburo at gmail.com
Tue Mar 15 11:05:22 EDT 2011
Take a look at your writerType typedef.
On Tue, Mar 15, 2011 at 9:49 AM, john smith <mkitkinsightuser at gmail.com>wrote:
> 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;
> }
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110315/3cf63d0d/attachment.htm>
More information about the Insight-users
mailing list