[ITK-users] [ITK] Fwd: itk vector Image pixel value
Timothee Evain
tevain at telecom-paristech.fr
Thu Sep 24 11:21:09 EDT 2015
Well I'm no specialist in registration, but from what I see with your example and with http://www.itk.org/Doxygen/html/classitk_1_1WarpImageFilter.html , it seems that the vector pixel type is here to define an displacement field. Since the doc indicates that each vector represent the distance between a point in the input space and a point in the output space, and that the vectors have to be of N elements where N is the dimension of input image, I guess it maps the distance on each dimension.
So basically if you map 3D data, your displacement field will have vector with 3 components corresponding to X,Y and Z displacement.
Tim
----- Mail original -----
De: "stefano serviddio" <s.serviddio at gmail.com>
À: insight-users at itk.org
Envoyé: Jeudi 24 Septembre 2015 14:46:25
Objet: [ITK] [ITK-users] Fwd: itk vector Image pixel value
---------- Forwarded message ----------
From: stefano serviddio < s.serviddio at gmail.com >
Date: 2015-09-24 14:46 GMT+02:00
Subject: Re: [ITK] [ITK-users] itk vector Image pixel value
To: Timothee Evain < tevain at telecom-paristech.fr >
Hi Tim,
First of all thank you for you time,
Secondly I try to execute a deformation registration between PET and TC image.
I have seen DeformableRegistration2.cxx where Warp Filter execute a particular trasnformation that modifie the space of movingImage.
In this case what is the role of vector pixel type???
#include " itkDemonsRegistrationFilter.h "
#include " itkHistogramMatchingImageFilter.h "
#include " itkCastImageFilter.h "
#include " itkWarpImageFilter.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 " << std::endl;
std::cerr << " [outputDisplacementFieldFile] " << std::endl;
return EXIT_FAILURE;
}
// Software Guide : BeginLatex
//
// Second, we declare the types of the images.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
const unsigned int Dimension = 2;
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::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] );
// Software Guide : BeginLatex
//
// Image file readers are set up in a similar fashion to previous examples.
// To support the re-mapping of the moving image intensity, we declare an
// internal image type with a floating point pixel type and cast the input
// images to the internal image type.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
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() );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The demons algorithm relies on the assumption that pixels representing the
// same homologous point on an object have the same intensity on both the
// fixed and moving images to be registered. In this example, we will
// preprocess the moving image to match the intensity between the images
// using the \doxygen{HistogramMatchingImageFilter}.
//
// \index{itk::HistogramMatchingImageFilter}
//
// The basic idea is to match the histograms of the two images at a
// user-specified number of quantile values. For robustness, the histograms
// are matched so that the background pixels are excluded from both
// histograms. For MR images, a simple procedure is to exclude all gray
// values that are smaller than the mean gray value of the image.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::HistogramMatchingImageFilter <
InternalImageType,
InternalImageType > MatchingFilterType;
MatchingFilterType::Pointer matcher = MatchingFilterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// For this example, we set the moving image as the source or input image and
// the fixed image as the reference image.
//
// \index{itk::HistogramMatchingImageFilter!SetInput()}
// \index{itk::HistogramMatchingImageFilter!SetSourceImage()}
// \index{itk::HistogramMatchingImageFilter!SetReferenceImage()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
matcher->SetInput( movingImageCaster->GetOutput() );
matcher->SetReferenceImage( fixedImageCaster->GetOutput() );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We then select the number of bins to represent the histograms and the
// number of points or quantile values where the histogram is to be
// matched.
//
// \index{itk::HistogramMatchingImageFilter!SetNumberOfHistogramLevels()}
// \index{itk::HistogramMatchingImageFilter!SetNumberOfMatchPoints()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
matcher->SetNumberOfHistogramLevels( 1024 );
matcher->SetNumberOfMatchPoints( 7 );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Simple background extraction is done by thresholding at the mean
// intensity.
//
// \index{itk::HistogramMatchingImageFilter!ThresholdAtMeanIntensityOn()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
matcher->ThresholdAtMeanIntensityOn();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// In the \doxygen{DemonsRegistrationFilter}, the deformation field is
// represented as an image whose pixels are floating point vectors.
//
// \index{itk::DemonsRegistrationFilter}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::Vector< float, Dimension > VectorPixelType;
typedef itk::Image< VectorPixelType, Dimension > DisplacementFieldType;
typedef itk::DemonsRegistrationFilter <
InternalImageType,
InternalImageType,
DisplacementFieldType> RegistrationFilterType;
RegistrationFilterType::Pointer filter = RegistrationFilterType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The input fixed image is simply the output of the fixed image casting
// filter. The input moving image is the output of the histogram matching
// filter.
//
// \index{itk::DemonsRegistrationFilter!SetFixedImage()}
// \index{itk::DemonsRegistrationFilter!SetMovingImage()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
filter->SetFixedImage( fixedImageCaster->GetOutput() );
filter->SetMovingImage( matcher->GetOutput() );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The demons registration filter has two parameters: the number of
// iterations to be performed and the standard deviation of the Gaussian
// smoothing kernel to be applied to the deformation field after each
// iteration.
// \index{itk::DemonsRegistrationFilter!SetNumberOfIterations()}
// \index{itk::DemonsRegistrationFilter!SetStandardDeviations()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
filter->SetNumberOfIterations( 50 );
filter->SetStandardDeviations( 1.0 );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The registration algorithm is triggered by updating the filter. The
// filter output is the computed deformation field.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
filter->Update();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The \doxygen{WarpImageFilter} can be used to warp the moving image with
// the output deformation field. Like the \doxygen{ResampleImageFilter},
// the WarpImageFilter requires the specification of the input image to be
// resampled, an input image interpolator, and the output image spacing and
// origin.
//
// \index{itk::WarpImageFilter}
// \index{itk::WarpImageFilter!SetInput()}
// \index{itk::WarpImageFilter!SetInterpolator()}
// \index{itk::WarpImageFilter!SetOutputSpacing()}
// \index{itk::WarpImageFilter!SetOutputOrigin()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::WarpImageFilter <
MovingImageType,
MovingImageType,
DisplacementFieldType > 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->SetOutputDirection( fixedImage->GetDirection() );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Unlike the ResampleImageFilter, the WarpImageFilter
// warps or transform the input image with respect to the deformation field
// represented by an image of vectors. The resulting warped or resampled
// image is written to file as per previous examples.
//
// \index{itk::WarpImageFilter!SetDisplacementField()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
warper->SetDisplacementField( filter->GetOutput() );
// Software Guide : EndCodeSnippet
// Write warped image out to file
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, 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( argv[3] );
caster->SetInput( warper->GetOutput() );
writer->SetInput( caster->GetOutput() );
writer->Update();
}
2015-09-24 14:12 GMT+02:00 Timothee Evain < tevain at telecom-paristech.fr > :
Hello Stefano
In this case, each pixel have multiples values, not only one, so to represent this, each pixel have for value a vector with multiples components.
Each component of the vector is an individual value.
Maybe an example is easier to understand. Think of a RGB image. You have three colors to represent, namely Red/Green/Blue.
You could represent it with 3 differents images, each with the value of Red, Green or Blue channel, or you could do it with only one image, where each pixel contain a vector. In this vector you will set the value of the Red/Green/Blue channel for the pixel. So you will have the "Red" component, the "Green" one, and the "Blue" at last.
A vector image is just the generalization of this.
HTH
Tim
----- Mail original -----
De: "stefano serviddio" < s.serviddio at gmail.com >
À: insight-users at itk.org
Envoyé: Jeudi 24 Septembre 2015 13:36:27
Objet: [ITK] [ITK-users] itk vector Image pixel value
I have found this itk vector image example, I don't understand the meaning of each component of Vector Pixel type.
For example the code line pixelValue[0] = 1.345; component X refers to a grayscale value or distance from next pixel inside the matrix of Image???
#include "itkVector.h"
// Software Guide : EndCodeSnippet
#include "itkImage.h"
int main(int, char *[])
{
// Software Guide : BeginLatex
//
// The Vector class is templated over the type used to represent
// the coordinate in space and over the dimension of the space. In this example,
// we want the vector dimension to match the image dimension, but this is by
// no means a requirement. We could have defined a four-dimensional image
// with three-dimensional vectors as pixels.
//
// \index{itk::Vector!Instantiation}
// \index{itk::Vector!itk::Image}
// \index{itk::Image!Vector pixel}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::Vector< float, 3 > PixelType;
typedef itk::Image< PixelType, 3 > ImageType;
// Software Guide : EndCodeSnippet
// Then the image object can be created
ImageType::Pointer image = ImageType::New();
// The image region should be initialized
const ImageType::IndexType start = {{0,0,0}}; //First index at {X,Y,Z}
const ImageType::SizeType size = {{200,200,200}}; //Size of {X,Y,Z}
ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
// Pixel data is allocated
image->SetRegions( region );
image->Allocate();
// The image buffer is initialized to a particular value
ImageType::PixelType initialValue;
// A vector can initialize all its components to the
// same value by using the Fill() method.
initialValue.Fill( 0.0 );
// Now the image buffer can be initialized with this
// vector value.
image->FillBuffer( initialValue );
const ImageType::IndexType pixelIndex = {{27,29,37}}; //Position {X,Y,Z}
// Software Guide : BeginLatex
//
// The Vector class inherits the operator \code{[]} from the
// \doxygen{FixedArray} class. This makes it possible to access the
// Vector's components using index notation.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ImageType::PixelType pixelValue;
pixelValue[0] = 1.345; // x component
pixelValue[1] = 6.841; // y component
pixelValue[2] = 3.295; // x component
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We can now store this vector in one of the image pixels by defining an
// index and invoking the \code{SetPixel()} method.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
image->SetPixel( pixelIndex, pixelValue );
// Software Guide : EndCodeSnippet
// The GetPixel method can also be used to read Vectors
// pixels from the image
ImageType::PixelType value = image->GetPixel( pixelIndex );
std::cout << value << std::endl;
// Lets repeat that both \code{SetPixel()} and \code{GetPixel()} are
// inefficient and should only be used for debugging purposes or for
// implementing interactions with a graphical user interface such as
// querying pixel value by clicking with the mouse.
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.php
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://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
Community at itk.org
http://public.kitware.com/mailman/listinfo/community
_____________________________________
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.php
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://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
Community at itk.org
http://public.kitware.com/mailman/listinfo/community
More information about the Insight-users
mailing list