[Insight-users] Fw: problem
Sarah Waldron
sarah.waldron11 at yahoo.com
Mon Oct 5 13:41:42 EDT 2009
Thank you so much for replying. You were right, I didn't include ITKStatistics in the Cmakelist.txt.
I tried to write another program that applies a histogram filter on an input and reference image and it seems to be giving me trouble as well. I get this error:
Scanning dependencies of target histogram
[100%] Building CXX object CMakeFiles/histogram.dir/histogram.o
/home/sarah/Desktop/histogramONLY/histogram.cxx: In function ‘int main(int, char**)’:
/home/sarah/Desktop/histogramONLY/histogram.cxx:75: error: no matching function for call to ‘itk::ImageFileWriter<itk::Image<unsigned int, 2u> >::SetInput(itk::Image<float, 2u>*)’
/home/sarah/InsightToolkit-3.10.2/Code/IO/itkImageFileWriter.txx:56: note: candidates are: void itk::ImageFileWriter<TInputImage>::SetInput(const TInputImage*) [with TInputImage = itk::Image<unsigned int, 2u>]
make[2]: *** [CMakeFiles/histogram.dir/histogram.o] Error 1
make[1]: *** [CMakeFiles/histogram.dir/all] Error 2
make: *** [all] Error 2
I attached the code and cmakelists.txt.
I would appreciate any help.
Thanks,
Sarah
--- On Mon, 10/5/09, Gabriele Arnulfo <tartuz at gmail.com> wrote:
From: Gabriele Arnulfo <tartuz at gmail.com>
Subject: Re: [Insight-users] Fw: problem
To: "Sarah Waldron" <sarah.waldron11 at yahoo.com>
Cc: insight-users at itk.org
Date: Monday, October 5, 2009, 3:52 PM
Looking deeper in the log you posted I ve figured out that you miss to
include itkStatistics in your cmakelists i think.
On Mon, Oct 05, 2009 at 07:21:13AM -0700, Sarah Waldron wrote:
> Did everyone get this email? I'm not getting any response from anyone
> Thanks
>
> insight-users at itk.org
>
> --- On Fri, 10/2/09, Sarah Waldron <sarah.waldron11 at yahoo.com> wrote:
>
> From: Sarah Waldron <sarah.waldron11 at yahoo.com>
> Subject: [Insight-users] problem
> To: insight-users at itk.org
> Date: Friday, October 2, 2009, 6:01 PM
>
> Hi ,
> Im new to ITK and I'm having some trouble with this program I'm writing. I want the program to perform rigid registration (translation only) but perform histogram matching first. The code performs a linking error. I've attached the *.cxx and cmakelists file.
> Thanks,
> Sarah
>
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.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
>
>
>
>
> #include "itkImageRegistrationMethod.h"
> #include "itkTranslationTransform.h"
> #include "itkMeanSquaresImageToImageMetric.h"
> #include "itkLinearInterpolateImageFunction.h"
> #include "itkRegularStepGradientDescentOptimizer.h"
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkResampleImageFilter.h"
> #include "itkCastImageFilter.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkSubtractImageFilter.h"
> #include "itkHistogramMatchingImageFilter.h"
>
>
>
> class CommandIterationUpdate : public itk::Command
> {
> public:
> typedef CommandIterationUpdate Self;
> typedef itk::Command Superclass;
> typedef itk::SmartPointer<Self> Pointer;
> itkNewMacro( Self );
>
> protected:
> CommandIterationUpdate() {};
>
> public:
>
> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
> typedef const OptimizerType *OptimizerPointer;
>
> void Execute(itk::Object *caller, const itk::EventObject & event)
> {
> Execute( (const itk::Object *)caller, event);
> }
>
> void Execute(const itk::Object * object, const itk::EventObject & event)
> {
> OptimizerPointer optimizer =
> dynamic_cast< OptimizerPointer >( object );
>
> if( ! itk::IterationEvent().CheckEvent( &event ) )
> {
> return;
> }
>
> std::cout << optimizer->GetCurrentIteration() << " = ";
> std::cout << optimizer->GetValue() << " : ";
> std::cout << optimizer->GetCurrentPosition() << std::endl;
> }
>
> };
>
>
> int main( int argc, char *argv[] )
> {
> if( argc < 4 )
> {
> std::cerr << "Missing Parameters " << std::endl;
> std::cerr << "Usage: " << argv[0];
> std::cerr << " fixedImageFile movingImageFile ";
> std::cerr << "outputImagefile [differenceImageAfter]";
> std::cerr << "[differenceImageBefore]" << std::endl;
> return EXIT_FAILURE;
> }
>
> const unsigned int Dimension = 2;
> typedef unsigned int PixelType;
> typedef itk::Image< PixelType, Dimension > FixedImageType;
> typedef itk::Image< PixelType, Dimension > MovingImageType;
>
> typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
> typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
> FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
> MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();
> fixedImageReader->SetFileName( argv[1] );
> movingImageReader->SetFileName( argv[2] );
> fixedImageReader->Update();
> movingImageReader->Update();
>
> typedef float InternalPixelType;
> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
> typedef itk::CastImageFilter< FixedImageType, InternalImageType > FixedImageCasterType;
> typedef itk::CastImageFilter< MovingImageType, InternalImageType > MovingImageCasterType;
> FixedImageCasterType::Pointer fixedImageCaster = FixedImageCasterType::New();
> MovingImageCasterType::Pointer movingImageCaster = MovingImageCasterType::New();
>
> fixedImageCaster->SetInput( fixedImageReader->GetOutput() );
> movingImageCaster->SetInput( movingImageReader->GetOutput() );
>
> fixedImageCaster->Update();
> movingImageCaster->Update();
>
> typedef itk::HistogramMatchingImageFilter< InternalImageType, InternalImageType > MatchingFilterType;
> MatchingFilterType::Pointer matcher = MatchingFilterType::New();
> matcher->SetInput( movingImageCaster->GetOutput() );
> matcher->SetReferenceImage( fixedImageCaster->GetOutput() );
> matcher->SetNumberOfHistogramLevels( 1024 );
> matcher->SetNumberOfMatchPoints( 7 );
> matcher->ThresholdAtMeanIntensityOn();
>
>
> typedef itk::TranslationTransform< double, Dimension > TransformType;
> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
> typedef itk::MeanSquaresImageToImageMetric< InternalImageType, InternalImageType > MetricType;
> typedef itk:: LinearInterpolateImageFunction< InternalImageType, double > InterpolatorType;
> typedef itk::ImageRegistrationMethod< InternalImageType, InternalImageType > RegistrationType;
>
> MetricType::Pointer metric = MetricType::New();
> TransformType::Pointer transform = TransformType::New();
> OptimizerType::Pointer optimizer = OptimizerType::New();
> InterpolatorType::Pointer interpolator = InterpolatorType::New();
> RegistrationType::Pointer registration = RegistrationType::New();
>
> registration->SetMetric( metric );
> registration->SetOptimizer( optimizer );
> registration->SetTransform( transform );
> registration->SetInterpolator( interpolator );
>
>
> registration->SetFixedImage( fixedImageCaster->GetOutput() );
> registration->SetMovingImage( matcher->GetOutput() );
>
>
> typedef RegistrationType::ParametersType ParametersType;
> ParametersType initialParameters( transform->GetNumberOfParameters() );
>
> initialParameters[0] = 0.0; // Initial offset in mm along X
> initialParameters[1] = 0.0; // Initial offset in mm along Y
>
> registration->SetInitialTransformParameters( initialParameters );
>
> // It is usually desirable to fine tune the parameters of the optimizer.
> // Each optimizer has particular parameters that must be interpreted in the
> // context of the optimization strategy it implements. The optimizer used in
> // this example is a variant of gradient descent that attempts to prevent it
> // from taking steps that are too large. At each iteration, this optimizer
> // will take a step along the direction of the \doxygen{ImageToImageMetric}
> // derivative. The initial length of the step is defined by the user. Each
> // time the direction of the derivative abruptly changes, the optimizer
> // assumes that a local extrema has been passed and reacts by reducing the
> // step length by a half. After several reductions of the step length, the
> // optimizer may be moving in a very restricted area of the transform
> // parameter space. The user can define how small the step length should be
> // to consider convergence to have been reached. This is equivalent to defining
> // the precision with which the final transform should be known.
> //
> // The initial step length is defined with the method
> // \code{SetMaximumStepLength()}, while the tolerance for convergence is
> // defined with the method \code{SetMinimumStepLength()}.
>
> optimizer->SetMaximumStepLength( 4.00 );
> optimizer->SetMinimumStepLength( 0.01 );
> optimizer->SetNumberOfIterations( 200 );
> // Connect an observer
> CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
> optimizer->AddObserver( itk::IterationEvent(), observer );
>
> try
> {
> registration->Update();
> }
> catch( itk::ExceptionObject & err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return EXIT_FAILURE;
> }
> // The result of the registration process is an array of parameters that
> // defines the spatial transformation in an unique way. This final result is
> // obtained using the \code{GetLastTransformParameters()} method.
> ParametersType finalParameters = registration->GetLastTransformParameters();
>
> // In the case of the \doxygen{TranslationTransform}, there is a
> // straightforward interpretation of the parameters. Each element of the
> // array corresponds to a translation along one spatial dimension.
> const double TranslationAlongX = finalParameters[0];
> const double TranslationAlongY = finalParameters[1];
> const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
>
> // The value of the image metric corresponding to the last set of parameters
> // can be obtained with the \code{GetValue()} method of the optimizer.
> const double bestValue = optimizer->GetValue();
>
> std::cout << "Result = " << std::endl;
> std::cout << " Translation X = " << TranslationAlongX << std::endl;
> std::cout << " Translation Y = " << TranslationAlongY << std::endl;
> std::cout << " Iterations = " << numberOfIterations << std::endl;
> std::cout << " Metric value = " << bestValue << std::endl;
>
> typedef itk::ResampleImageFilter< MovingImageType, FixedImageType > ResampleFilterType;
>
> ResampleFilterType::Pointer resampler = ResampleFilterType::New();
> resampler->SetInput( movingImageReader->GetOutput() );
> resampler->SetTransform( registration->GetOutput()->Get() );
> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
> resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );
> resampler->SetOutputOrigin( fixedImage->GetOrigin() );
> resampler->SetOutputSpacing( fixedImage->GetSpacing() );
> resampler->SetOutputDirection( fixedImage->GetDirection() );
> resampler->SetDefaultPixelValue( 100 );
>
> typedef unsigned char OutputPixelType;
> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
> typedef itk::CastImageFilter< FixedImageType, OutputImageType > CastFilterType;
> typedef itk::ImageFileWriter< OutputImageType > WriterType;
>
> WriterType::Pointer writer = WriterType::New();
> CastFilterType::Pointer caster = CastFilterType::New();
> writer->SetFileName( argv[3] );
>
> caster->SetInput( resampler->GetOutput() );
> writer->SetInput( caster->GetOutput() );
> writer->Update();
> typedef itk::SubtractImageFilter< FixedImageType, FixedImageType, FixedImageType > DifferenceFilterType;
>
> DifferenceFilterType::Pointer difference = DifferenceFilterType::New();
>
> difference->SetInput1( fixedImageReader->GetOutput() );
> difference->SetInput2( resampler->GetOutput() );
> typedef itk::RescaleIntensityImageFilter< FixedImageType, OutputImageType > RescalerType;
>
> RescalerType::Pointer intensityRescaler = RescalerType::New();
>
> intensityRescaler->SetInput( difference->GetOutput() );
> intensityRescaler->SetOutputMinimum( 0 );
> intensityRescaler->SetOutputMaximum( 255 );
>
> resampler->SetDefaultPixelValue( 1 );
> WriterType::Pointer writer2 = WriterType::New();
> writer2->SetInput( intensityRescaler->GetOutput() );
>
> if( argc > 4 )
> {
> writer2->SetFileName( argv[4] );
> writer2->Update();
> }
>
> TransformType::Pointer identityTransform = TransformType::New();
> identityTransform->SetIdentity();
> resampler->SetTransform( identityTransform );
>
> if( argc > 5 )
> {
> writer2->SetFileName( argv[5] );
> writer2->Update();
> }
>
> return EXIT_SUCCESS;
> }
>
> PROJECT(ImageRegistration1)
> FIND_PACKAGE(ITK)
> IF(ITK_FOUND)
> INCLUDE(${ITK_USE_FILE})
> ELSE(ITK_FOUND)
> MESSAGE(FATAL_ERROR
> "ITK not found. Please set ITK_DIR.")
> ENDIF(ITK_FOUND)
>
> ADD_EXECUTABLE(ImageRegistration1 ImageRegistration1.cxx )
> TARGET_LINK_LIBRARIES(ImageRegistration1 ITKIO ITKNumerics)
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.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
--
=============================================
Gabriele Arnulfo
BioEngineering Phd Student.
Bio-Lab, DIST - University of Genoa
Viale Causa 13, 16145 Genova - ITALY
Tel : (+39) 010-353-2789
Fax : (+39) 010-353-2948
Email : gabriele.arnulfo_at_gmail.com
Web : http://ga.mtvl.org
------------------------------------
In a world without wall,
who needs WindowS?
------------------------------------
=============================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091005/f783466f/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: histogram.cxx
Type: text/x-c++src
Size: 2628 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091005/f783466f/attachment-0001.cxx>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMakeLists.txt
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091005/f783466f/attachment-0001.txt>
More information about the Insight-users
mailing list