[Insight-users] Reading and writing image files using ITK and Cmake

karali patra kpsr_in at yahoo.co.in
Mon Jan 14 22:46:22 EST 2008


Dear All,
  I am a new user of ITK. I am trying to read and and write image files using the ITK and Cmakesetup (for configuring).I successfully run the helloWorld code(to test the itk is running properly). 
  I have copied the 
  Examples/IO/ImageReadWrite.cxx. 
  file to another directory "ImageReadWrite". I have created the following  'CMakeLists.txt' file in the same directory.
  
PROJECT(ImageReadWrite)
# Find ITK.
FIND_PACKAGE(ITK REQUIRED)
IF(ITK_FOUND)
  INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)
ADD_EXECUTABLE(ImageReadWrite ImageReadWrite.cxx )
TARGET_LINK_LIBRARIES(ImageReadWrite  ITKIO)
  ......
  I have modified the ImageReadWrite.cxx code in the following place
   
  reader->SetFileName( "BrainProtonDensitySlice.png"  );
  writer->SetFileName( "BrainProtonDensitySlice_w.png" );
   
  I have also copied the image file "BrainProtonDensitySlice.png" to the same directory.
   
  Now using the CMakeSetUp, I configured it (source and binary build directing are same). I got the ImageReadWrite.dsw workspace. I opened this in Visual Studio 6 and built all files successfully. I run the ImageReadWrite.exe file. It gave following output
  "
  usage:
  C:\...\ImageReadWrite\Debug\ImageReadWrite.exe inputImageFile outputImageFile"
   
  The program is not reading and writing the image. Please suggest what went wrong and help me correcting the problem
  Thanks
  KPatra
  Singapore
                          
   
   
   
  insight-users-request at itk.org wrote:
  Send Insight-users mailing list submissions to
insight-users at itk.org

To subscribe or unsubscribe via the World Wide Web, visit
http://www.itk.org/mailman/listinfo/insight-users
or, via email, send a message with subject or body 'help' to
insight-users-request at itk.org

You can reach the person managing the list at
insight-users-owner at itk.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Insight-users digest..."


Today's Topics:

1. locally rigid transformations (William Am)
2. Re: How to register 2D RGB images (Jinzhong Yang)


----------------------------------------------------------------------

Message: 1
Date: Mon, 14 Jan 2008 08:39:37 -0800 (PST)
From: William Am 
Subject: [Insight-users] locally rigid transformations
To: insight-users at itk.org
Message-ID: <14805008.post at talk.nabble.com>
Content-Type: text/plain; charset=us-ascii


Hi all,

How might one begin implementing propagation of locally rigid
transformations as described in the work below?

http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1616288

Thanks,
Will
-- 
View this message in context: http://www.nabble.com/locally-rigid-transformations-tp14805008p14805008.html
Sent from the ITK - Users mailing list archive at Nabble.com.



------------------------------

Message: 2
Date: Mon, 14 Jan 2008 11:53:44 -0500
From: "Jinzhong Yang" 
Subject: Re: [Insight-users] How to register 2D RGB images
To: "chunfang wang" 
Cc: "insight-users at itk.org" 
Message-ID:
<9190305b0801140853w26f0491tbae43b21fe2051c3 at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I guess the problem is the metric you used to compare two RGB pixels. You
are not able to use class itkMeanSquaresImageToImageMetric to compare two
pixels in vector format. There is an example to register two RGB images:


http://www.seas.upenn.edu/~jtduda/itkvector.html


Good luck,
Jinzhong


On Jan 14, 2008 9:26 AM, chunfang wang wrote:

> Hello Luis,
>
> I am a new user of itk, but no one in my lab have used it. So, when some
> problems comes, I am so sad.
> Looking forward of your help~~~
>
> I have some problems in the registration of RGB images.
> Now I explain my problems in detail:
>
> my work is to register two RGB images using the CenteredRigid2DTransform
> I have set the VectorResampleFilter and VectorInterpolater
> but still the complier error is
>
> d:\program files\itk\insighttoolkit-3.4.0\code\common\itkCovariantVector.h(75)
> : error C2039: 'RealType' : is not a member of 'itk::NumericTraits'
> 1> with
> 1> [
> 1> T=itk::RGBPixel
> 1> ]
> 1> D:\program files\itk\InsightToolkit-
> 3.4.0\Code\Common\itkPixelTraits.h(39) : see reference to class template
> instantiation 'itk::CovariantVector' being compiled
> 1> with
> 1> [
> 1> T=itk::RGBPixel,
> 1> NVectorDimension=2
> 1> ]
>
> I don't know how to settle this problem, please give me some help!
> thanks very much
>
> my code is just refied the examples in itk
>
> #include "itkImageRegistrationMethod.h"
> #include "itkMeanSquaresImageToImageMetric.h"
> #include "itkVectorLinearInterpolateImageFunction.h"
> #include "itkRegularStepGradientDescentOptimizer.h "
> #include "itkImage.h"
> #include "itkRGBPixel.h"
> #include "itkCenteredRigid2DTransform.h"
>
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkVectorResampleImageFilter.h"
> #include "itkSubtractImageFilter.h"
> #include "itkRescaleIntensityImageFilter.h"
>
> 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 [differenceAfterRegistration] ";
> std::cerr << " [differenceBeforeRegistration] ";
> std::cerr << " [initialStepLength] "<< std::endl;
> return EXIT_FAILURE;
> }
>
> const unsigned int Dimension = 2;
> typedef itk::RGBPixel< unsigned char > PixelType;
>
> typedef itk::Image< PixelType, Dimension > FixedImageType;
> typedef itk::Image< PixelType, Dimension > MovingImageType;
> typedef itk::CenteredRigid2DTransform< double > TransformType;
>
> typedef itk::RegularStepGradientDescentOptimizer OptimizerType;
> typedef itk::MeanSquaresImageToImageMetric<
> FixedImageType,
> MovingImageType > MetricType;
> typedef itk:: VectorLinearInterpolateImageFunction<
> MovingImageType,
> double > InterpolatorType;
> typedef itk::ImageRegistrationMethod<
> FixedImageType,
> MovingImageType > RegistrationType;
>
> MetricType::Pointer metric = MetricType::New();
> OptimizerType::Pointer optimizer = OptimizerType::New();
> InterpolatorType::Pointer interpolator = InterpolatorType::New();
> RegistrationType::Pointer registration = RegistrationType::New();
>
> registration->SetMetric( metric );
> registration->SetOptimizer( optimizer );
> registration->SetInterpolator( interpolator );
>
>
> TransformType::Pointer transform = TransformType::New();
> registration->SetTransform( transform );
>
>
> 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] );
>
>
> registration->SetFixedImage( fixedImageReader->GetOutput() );
> registration->SetMovingImage( movingImageReader->GetOutput() );
> fixedImageReader->Update();
>
> registration->SetFixedImageRegion(
> fixedImageReader->GetOutput()->GetBufferedRegion() );
> fixedImageReader->Update();
> movingImageReader->Update();
>
> typedef FixedImageType::SpacingType SpacingType;
> typedef FixedImageType::PointType OriginType;
> typedef FixedImageType::RegionType RegionType;
> typedef FixedImageType::SizeType SizeType;
> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
>
> const SpacingType fixedSpacing = fixedImage->GetSpacing();
> const OriginType fixedOrigin = fixedImage->GetOrigin();
> const RegionType fixedRegion = fixedImage->GetLargestPossibleRegion();
> const SizeType fixedSize = fixedRegion.GetSize();
>
> TransformType::InputPointType centerFixed;
>
> centerFixed[0] = fixedOrigin[0] + fixedSpacing[0] * fixedSize[0] / 2.0;
> centerFixed[1] = fixedOrigin[1] + fixedSpacing[1] * fixedSize[1] / 2.0;
>
> MovingImageType::Pointer movingImage = movingImageReader->GetOutput();
>
> const SpacingType movingSpacing = movingImage->GetSpacing();
> const OriginType movingOrigin = movingImage->GetOrigin();
> const RegionType movingRegion =
> movingImage->GetLargestPossibleRegion();
> const SizeType movingSize = movingRegion.GetSize();
>
> TransformType::InputPointType centerMoving;
>
> centerMoving[0] = movingOrigin[0] + movingSpacing[0] * movingSize[0] /
> 2.0;
> centerMoving[1] = movingOrigin[1] + movingSpacing[1] * movingSize[1] /
> 2.0;
>
> transform->SetCenter( centerFixed );
> transform->SetTranslation( centerMoving - centerFixed );
> transform->SetAngle( 0.0 );
>
>
> registration->SetInitialTransformParameters( transform->GetParameters()
> );
>
> // Software Guide : BeginCodeSnippet
> typedef OptimizerType::ScalesType OptimizerScalesType;
> OptimizerScalesType optimizerScales( transform->GetNumberOfParameters()
> );
> const double translationScale = 1.0 / 1000.0;
>
> optimizerScales[0] = 1.0;
> optimizerScales[1] = translationScale;
> optimizerScales[2] = translationScale;
> optimizerScales[3] = translationScale;
> optimizerScales[4] = translationScale;
>
> optimizer->SetScales( optimizerScales );
>
> double initialStepLength = 0.1;
> // Software Guide : EndCodeSnippet
>
> if( argc > 6 )
> {
> initialStepLength = atof( argv[6] );
> }
>
> // Software Guide : BeginCodeSnippet
> optimizer->SetRelaxationFactor( 0.6 );
> optimizer->SetMaximumStepLength( initialStepLength );
> optimizer->SetMinimumStepLength( 0.001 );
> optimizer->SetNumberOfIterations( 200 );
> // Software Guide : EndCodeSnippet
>
>
> // Create the Command observer and register it with the optimizer.
> //
> CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
> optimizer->AddObserver( itk::IterationEvent(), observer );
>
> try
> {
> registration->StartRegistration();
> }
> catch( itk::ExceptionObject & err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return EXIT_FAILURE;
> }
>
> OptimizerType::ParametersType finalParameters =
> registration->GetLastTransformParameters();
>
> const double finalAngle = finalParameters[0];
> const double finalRotationCenterX = finalParameters[1];
> const double finalRotationCenterY = finalParameters[2];
> const double finalTranslationX = finalParameters[3];
> const double finalTranslationY = finalParameters[4];
>
> const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
>
> const double bestValue = optimizer->GetValue();
>
> typedef itk::VectorResampleImageFilter<
> MovingImageType,
> FixedImageType > ResampleFilterType;
>
> TransformType::Pointer finalTransform = TransformType::New();
>
> finalTransform->SetParameters( finalParameters );
>
> ResampleFilterType::Pointer resample = ResampleFilterType::New();
>
> resample->SetTransform( finalTransform );
> resample->SetInput( movingImageReader->GetOutput() );
>
> resample->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );
> resample->SetOutputOrigin( fixedImage->GetOrigin() );
> resample->SetOutputSpacing( fixedImage->GetSpacing() );
> resample->SetDefaultPixelValue( 100 );
>
> typedef itk::ImageFileWriter< FixedImageType > WriterFixedType;
>
> WriterFixedType::Pointer writer = WriterFixedType::New();
>
> writer->SetFileName( argv[3] );
>
> writer->SetInput( resample->GetOutput() );
>
> try
> {
> writer->Update();
> }
> catch( itk::ExceptionObject & excp )
> {
> std::cerr << "ExceptionObject while writing the resampled image !" <<
> std::endl;
> std::cerr << excp << std::endl;
> return EXIT_FAILURE;
> }
> }
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080114/e938b65f/attachment-0001.html

------------------------------

_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users


End of Insight-users Digest, Vol 45, Issue 14
*********************************************


       
---------------------------------
 Now you can chat without downloading messenger. Click here to know how.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080115/2549ef9a/attachment.htm


More information about the Insight-users mailing list