[Insight-users] can anyone help me find the error in this code?
Julien Jomier
jjomier at cs.unc.edu
Mon Feb 7 16:06:38 EST 2005
Hi Changhua,
The main issue with your code is the pixel type which is now RGBPixel.
An image of RGBPixel is treated as an image of vectors (dimensionality
3). You should be able to modify your code using the
itkRGBToVectorImageAdaptor class.
Couple of things to try:
1) Add #include "itkNumericTraitsRGBPixel.h"
2) Use the itk::WarpVectorImageFilter instead of WarpImageFilter
3) Use the itk::VectorLinearInterpolateImageFunction instead of
itk::LinearInterpolateImageFunction
4) Modify the caster because you cannot cast from itkRGBPixel to a float
That said, some filters are not supporting images of vectors/RGBPixel so
you may need to convert your RGB image to a scalar image.
Hope that helps,
Julien
Changhua Wu wrote:
> hi,
>
> i am a itk newbie. i made some small
> modification(about 10 lines) based on
> DeformableRegistration2.cxx to try the registration on
> 3D volume kept in a set of png files and save the
> result to files.
>
> I spend several hours and can't make it pass compiling
> phase. the error report is too long and complex to me.
> the code and cmakelist.txt are attached.
>
> Can anyone help me out? Thanks very much.
>
> james
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - now with 250MB free storage. Learn more.
> http://info.mail.yahoo.com/mail_250
>
>
> ------------------------------------------------------------------------
>
> #include "itkImageSeriesReader.h"
> #include "itkImageSeriesWriter.h"
> #include "itkRGBPixel.h"
> #include "itkDemonsRegistrationFilter.h"
> #include "itkHistogramMatchingImageFilter.h"
> #include "itkCastImageFilter.h"
> #include "itkWarpImageFilter.h"
> #include "itkLinearInterpolateImageFunction.h"
> #include "itkNumericSeriesFileNames.h"
> #include "itkPNGImageIO.h"
> #include <vector>
> #include <string>
>
> int main( int argc, char *argv[] )
> {
> if( argc < 3 )
> {
> std::cerr << "Missing Parameters " << std::endl;
> std::cerr << "Usage: " << argv[0];
> std::cerr << " fixedImageFile movingImageFile ";
> std::cerr << " outputImageFile " << std::endl;
> return 1;
> }
>
> typedef itk::RGBPixel< unsigned char > PixelType;
>
> std::vector <std::string> MovingImageName;
> std::vector <std::string> FixedImageName;
> std::vector <std::string> OutPutFileName;
>
> const unsigned int Dimension = 3;
> //typedef unsigned short PixelType;
>
> typedef itk::Image< PixelType, Dimension > FixedImageType;
> typedef itk::Image< PixelType, Dimension > MovingImageType;
> // Software Guide : EndCodeSnippet
>
> // Set up the file readers
> typedef itk::ImageSeriesReader< FixedImageType > FixedImageReaderType;
> typedef itk::ImageSeriesReader< MovingImageType > MovingImageReaderType;
>
> FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
> MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();
>
> typedef itk::NumericSeriesFileNames NameGeneratorType;
> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
> nameGenerator->SetStartIndex(0);
> nameGenerator->SetEndIndex( 40 );
> nameGenerator->SetIncrementIndex( 1 );
> nameGenerator->SetSeriesFormat( "vwe%04d.png" );
>
> fixedImageReader->SetFileNames(nameGenerator->GetFileNames() );
> movingImageReader->SetFileNames( nameGenerator->GetFileNames() );
>
> 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() );
>
> 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::Vector< float, Dimension > VectorPixelType;
> typedef itk::Image< VectorPixelType, Dimension > DeformationFieldType;
> typedef itk::DemonsRegistrationFilter<
> InternalImageType,
> InternalImageType,
> DeformationFieldType> RegistrationFilterType;
> RegistrationFilterType::Pointer filter = RegistrationFilterType::New();
>
> filter->SetFixedImage( fixedImageCaster->GetOutput() );
> filter->SetMovingImage( matcher->GetOutput() );
>
> filter->SetNumberOfIterations( 150 );
> filter->SetStandardDeviations( 1.0 );
>
> filter->Update();
>
> typedef itk::WarpImageFilter<
> MovingImageType,
> MovingImageType,
> DeformationFieldType > WarperType;
> typedef itk::LinearInterpolateImageFunction<
> MovingImageType,
> double > InterpolatorType;
> WarperType::Pointer warper = WarperType::New();
> InterpolatorType::Pointer interpolator = InterpolatorType::New();
> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
>
> warper->SetInput( movingImageReader->GetOutput() );
> warper->SetInterpolator( interpolator );
> warper->SetOutputSpacing( fixedImage->GetSpacing() );
> warper->SetOutputOrigin( fixedImage->GetOrigin() );
>
> warper->SetDeformationField( filter->GetOutput() );
>
> typedef itk::Image< PixelType, Dimension > OutputImageType;
> typedef itk::CastImageFilter<
> MovingImageType,
> OutputImageType > CastFilterType;
> typedef itk::ImageFileWriter< OutputImageType > WriterType;
>
> WriterType::Pointer writer = WriterType::New();
> CastFilterType::Pointer caster = CastFilterType::New();
>
> writer->SetFileName("output.png");
>
> caster->SetInput( warper->GetOutput() );
> writer->SetInput( caster->GetOutput() );
> writer->Update();
>
>
> return 0;
> }
>
>
>
> ------------------------------------------------------------------------
>
> PROJECT(deform_registration)
> 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(deform_registration DeformableRegistration2.cxx )
> TARGET_LINK_LIBRARIES(deform_registration ITKAlgorithms ITKFEM ITKStatistics ITKIO ITKBasicFilters ITKCommon)
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list