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