ITK/Examples/SpectralAnalysis/VnlFFTRealToComplexConjugateImageFilter: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
Daviddoria (talk | contribs) |
Daviddoria (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
#include "itkComplexToRealImageFilter.h" | #include "itkComplexToRealImageFilter.h" | ||
#include "itkComplexToImaginaryImageFilter.h" | #include "itkComplexToImaginaryImageFilter.h" | ||
#include "itkComplexToModulusImageFilter.h" | |||
#include "itkImageFileReader.h" | #include "itkImageFileReader.h" | ||
#include "itkCastImageFilter.h" | #include "itkCastImageFilter.h" | ||
#include "itkPasteImageFilter.h" | |||
#include <itksys/SystemTools.hxx> | #include <itksys/SystemTools.hxx> | ||
Line 15: | Line 17: | ||
#include <itkImageToVTKImageFilter.h> | #include <itkImageToVTKImageFilter.h> | ||
#include " | #include "QuickView.h" | ||
int main(int argc, char*argv[]) | int main(int argc, char*argv[]) | ||
Line 29: | Line 26: | ||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||
} | } | ||
typedef itk::Image<unsigned char, 2> UnsignedCharImageType; | typedef itk::Image<unsigned char, 2> UnsignedCharImageType; | ||
typedef itk::Image<float, 2> FloatImageType; | typedef itk::Image<float, 2> FloatImageType; | ||
typedef itk::ImageFileReader<FloatImageType> ReaderType; | typedef itk::ImageFileReader<FloatImageType> ReaderType; | ||
ReaderType::Pointer reader = ReaderType::New(); | ReaderType::Pointer reader = ReaderType::New(); | ||
reader->SetFileName(argv[1]); | reader->SetFileName(argv[1]); | ||
reader->Update(); | |||
unsigned int powerOfTwo = 0; | |||
for(unsigned int i = 0; i < 10; i++) | |||
{ | |||
if(pow(2, i) > reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] && | |||
pow(2, i) > reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]) | |||
{ | |||
powerOfTwo = i; | |||
break; | |||
} | |||
} | |||
// Create an image bigger than the input image and that has dimensions which are powers of two | |||
itk::Index<2> start; | |||
start.Fill(0); | |||
itk::Size<2> size; | |||
size.Fill(pow(2,powerOfTwo)); | |||
itk::ImageRegion<2> region(start, size); | |||
FloatImageType::Pointer image = FloatImageType::New(); | |||
image->SetRegions(region); | |||
image->Allocate(); | |||
// The image dimensions must be powers of two | |||
typedef itk::PasteImageFilter <FloatImageType, FloatImageType > | |||
PasteImageFilterType; | |||
// The SetDestinationIndex() method prescribes where in the first input to start pasting data from the second input. | |||
// The SetSourceRegion method prescribes the section of the second image to paste into the first. | |||
itk::Index<2> destinationIndex; | |||
destinationIndex.Fill(0); | |||
PasteImageFilterType::Pointer pasteFilter | |||
= PasteImageFilterType::New (); | |||
pasteFilter->SetSourceImage(reader->GetOutput()); | |||
pasteFilter->SetDestinationImage(image); | |||
pasteFilter->SetSourceRegion(reader->GetOutput()->GetLargestPossibleRegion()); | |||
pasteFilter->SetDestinationIndex(destinationIndex); | |||
pasteFilter->Update(); | |||
image->Graft(pasteFilter->GetOutput()); | |||
// Take the FFT | |||
typedef itk::VnlFFTRealToComplexConjugateImageFilter<FloatImageType::PixelType, 2> FFTType; | typedef itk::VnlFFTRealToComplexConjugateImageFilter<FloatImageType::PixelType, 2> FFTType; | ||
FFTType::Pointer fftFilter = FFTType::New(); | FFTType::Pointer fftFilter = FFTType::New(); | ||
fftFilter->SetInput( | fftFilter->SetInput(image); | ||
fftFilter->Update(); | fftFilter->Update(); | ||
// Extract the real part | |||
typedef itk::ComplexToRealImageFilter<FFTType::OutputImageType, UnsignedCharImageType> RealFilterType; | typedef itk::ComplexToRealImageFilter<FFTType::OutputImageType, UnsignedCharImageType> RealFilterType; | ||
RealFilterType::Pointer realFilter = RealFilterType::New(); | RealFilterType::Pointer realFilter = RealFilterType::New(); | ||
Line 47: | Line 92: | ||
realFilter->Update(); | realFilter->Update(); | ||
// Extract the real part | |||
typedef itk::ComplexToImaginaryImageFilter<FFTType::OutputImageType, UnsignedCharImageType> ImaginaryFilterType; | |||
ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New(); | |||
imaginaryFilter->SetInput(fftFilter->GetOutput()); | |||
imaginaryFilter->Update(); | |||
// | |||
typedef itk:: | |||
// | // Compute the magnitude | ||
typedef itk:: | typedef itk::ComplexToModulusImageFilter<FFTType::OutputImageType, UnsignedCharImageType> ModulusFilterType; | ||
ModulusFilterType::Pointer modulusFilter = ModulusFilterType::New(); | |||
modulusFilter->SetInput(fftFilter->GetOutput()); | |||
modulusFilter->Update(); | |||
QuickView viewer; | |||
viewer.AddImage(image.GetPointer()); | |||
viewer.AddImage(realFilter->GetOutput()); | |||
viewer.AddImage(imaginaryFilter->GetOutput()); | |||
viewer.AddImage(modulusFilter->GetOutput()); | |||
viewer.Visualize(); | |||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||
} | } | ||
Line 122: | Line 123: | ||
include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/) | include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/) | ||
include_directories(/home/doriad/ITKWikiExamples/ItkVtkGlue) | |||
FIND_PACKAGE(VTK REQUIRED) | FIND_PACKAGE(VTK REQUIRED) | ||
Line 129: | Line 131: | ||
INCLUDE(${ITK_USE_FILE}) | INCLUDE(${ITK_USE_FILE}) | ||
ADD_EXECUTABLE(VnlFFTRealToComplexConjugateImageFilter VnlFFTRealToComplexConjugateImageFilter.cxx) | ADD_EXECUTABLE(VnlFFTRealToComplexConjugateImageFilter VnlFFTRealToComplexConjugateImageFilter.cxx | ||
/home/doriad/ITKWikiExamples/ItkVtkGlue/QuickView.cxx) | |||
TARGET_LINK_LIBRARIES(VnlFFTRealToComplexConjugateImageFilter vtkHybrid ITKNumerics ITKBasicFilters ITKCommon ITKIO) | TARGET_LINK_LIBRARIES(VnlFFTRealToComplexConjugateImageFilter vtkHybrid ITKNumerics ITKBasicFilters ITKCommon ITKIO) | ||
</source> | </source> |
Revision as of 19:31, 24 January 2011
VnlFFTRealToComplexConjugateImageFilter.cxx
<source lang="cpp">
- include "itkImage.h"
- include "itkRescaleIntensityImageFilter.h"
- include "itkVnlFFTRealToComplexConjugateImageFilter.h"
- include "itkComplexToRealImageFilter.h"
- include "itkComplexToImaginaryImageFilter.h"
- include "itkComplexToModulusImageFilter.h"
- include "itkImageFileReader.h"
- include "itkCastImageFilter.h"
- include "itkPasteImageFilter.h"
- include <itksys/SystemTools.hxx>
- include "vnl/vnl_sample.h"
- include <math.h>
- include <itkImageToVTKImageFilter.h>
- include "QuickView.h"
int main(int argc, char*argv[]) {
if(argc < 2) { std::cerr << "Required: filename" << std::endl; return EXIT_FAILURE; }
typedef itk::Image<unsigned char, 2> UnsignedCharImageType; typedef itk::Image<float, 2> FloatImageType; typedef itk::ImageFileReader<FloatImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); reader->Update();
unsigned int powerOfTwo = 0; for(unsigned int i = 0; i < 10; i++) { if(pow(2, i) > reader->GetOutput()->GetLargestPossibleRegion().GetSize()[0] && pow(2, i) > reader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]) { powerOfTwo = i; break; } }
// Create an image bigger than the input image and that has dimensions which are powers of two itk::Index<2> start; start.Fill(0);
itk::Size<2> size; size.Fill(pow(2,powerOfTwo));
itk::ImageRegion<2> region(start, size); FloatImageType::Pointer image = FloatImageType::New(); image->SetRegions(region); image->Allocate(); // The image dimensions must be powers of two typedef itk::PasteImageFilter <FloatImageType, FloatImageType > PasteImageFilterType;
// The SetDestinationIndex() method prescribes where in the first input to start pasting data from the second input. // The SetSourceRegion method prescribes the section of the second image to paste into the first.
itk::Index<2> destinationIndex; destinationIndex.Fill(0); PasteImageFilterType::Pointer pasteFilter = PasteImageFilterType::New (); pasteFilter->SetSourceImage(reader->GetOutput()); pasteFilter->SetDestinationImage(image); pasteFilter->SetSourceRegion(reader->GetOutput()->GetLargestPossibleRegion()); pasteFilter->SetDestinationIndex(destinationIndex); pasteFilter->Update(); image->Graft(pasteFilter->GetOutput()); // Take the FFT typedef itk::VnlFFTRealToComplexConjugateImageFilter<FloatImageType::PixelType, 2> FFTType; FFTType::Pointer fftFilter = FFTType::New(); fftFilter->SetInput(image); fftFilter->Update(); // Extract the real part typedef itk::ComplexToRealImageFilter<FFTType::OutputImageType, UnsignedCharImageType> RealFilterType; RealFilterType::Pointer realFilter = RealFilterType::New(); realFilter->SetInput(fftFilter->GetOutput()); realFilter->Update();
// Extract the real part typedef itk::ComplexToImaginaryImageFilter<FFTType::OutputImageType, UnsignedCharImageType> ImaginaryFilterType; ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New(); imaginaryFilter->SetInput(fftFilter->GetOutput()); imaginaryFilter->Update();
// Compute the magnitude typedef itk::ComplexToModulusImageFilter<FFTType::OutputImageType, UnsignedCharImageType> ModulusFilterType; ModulusFilterType::Pointer modulusFilter = ModulusFilterType::New(); modulusFilter->SetInput(fftFilter->GetOutput()); modulusFilter->Update();
QuickView viewer; viewer.AddImage(image.GetPointer()); viewer.AddImage(realFilter->GetOutput()); viewer.AddImage(imaginaryFilter->GetOutput()); viewer.AddImage(modulusFilter->GetOutput()); viewer.Visualize();
return EXIT_SUCCESS;
} </source>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
PROJECT(VnlFFTRealToComplexConjugateImageFilter)
include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/) include_directories(/home/doriad/ITKWikiExamples/ItkVtkGlue)
FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE})
FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(VnlFFTRealToComplexConjugateImageFilter VnlFFTRealToComplexConjugateImageFilter.cxx /home/doriad/ITKWikiExamples/ItkVtkGlue/QuickView.cxx) TARGET_LINK_LIBRARIES(VnlFFTRealToComplexConjugateImageFilter vtkHybrid ITKNumerics ITKBasicFilters ITKCommon ITKIO)
</source>