ITK/Examples/SpectralAnalysis/VnlFFTRealToComplexConjugateImageFilter: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
Daviddoria (talk | contribs) No edit summary |
Daviddoria (talk | contribs) No edit summary |
||
Line 21: | Line 21: | ||
int main(int argc, char*argv[]) | int main(int argc, char*argv[]) | ||
{ | { | ||
// Verify input | |||
if(argc < 2) | if(argc < 2) | ||
{ | { | ||
Line 27: | Line 28: | ||
} | } | ||
// Define some types | |||
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; | ||
// Read the image | |||
typedef itk::ImageFileReader<FloatImageType> ReaderType; | typedef itk::ImageFileReader<FloatImageType> ReaderType; | ||
ReaderType::Pointer reader = ReaderType::New(); | ReaderType::Pointer reader = ReaderType::New(); | ||
Line 35: | Line 38: | ||
reader->Update(); | reader->Update(); | ||
// Compute the smallest power of two that is bigger than the image | |||
unsigned int powerOfTwo = 0; | unsigned int powerOfTwo = 0; | ||
for(unsigned int i = 0; i < 10; i++) | for(unsigned int i = 0; i < 10; i++) | ||
Line 62: | Line 66: | ||
typedef itk::PasteImageFilter <FloatImageType, FloatImageType > | typedef itk::PasteImageFilter <FloatImageType, FloatImageType > | ||
PasteImageFilterType; | PasteImageFilterType; | ||
itk::Index<2> destinationIndex; | itk::Index<2> destinationIndex; | ||
destinationIndex.Fill(0); | destinationIndex.Fill(0); | ||
Line 79: | Line 79: | ||
image->Graft(pasteFilter->GetOutput()); | image->Graft(pasteFilter->GetOutput()); | ||
// | // Compute the FFT | ||
typedef itk::VnlFFTRealToComplexConjugateImageFilter<FloatImageType::PixelType, 2> FFTType; | typedef itk::VnlFFTRealToComplexConjugateImageFilter<FloatImageType::PixelType, 2> FFTType; | ||
Line 87: | Line 87: | ||
// Extract the real part | // Extract the real part | ||
typedef itk::ComplexToRealImageFilter<FFTType::OutputImageType, | typedef itk::ComplexToRealImageFilter<FFTType::OutputImageType, FloatImageType> RealFilterType; | ||
RealFilterType::Pointer realFilter = RealFilterType::New(); | RealFilterType::Pointer realFilter = RealFilterType::New(); | ||
realFilter->SetInput(fftFilter->GetOutput()); | realFilter->SetInput(fftFilter->GetOutput()); | ||
realFilter->Update(); | realFilter->Update(); | ||
typedef itk::RescaleIntensityImageFilter< FloatImageType, UnsignedCharImageType > RescaleFilterType; | |||
RescaleFilterType::Pointer realRescaleFilter = RescaleFilterType::New(); | |||
realRescaleFilter->SetInput(realFilter->GetOutput()); | |||
realRescaleFilter->SetOutputMinimum(0); | |||
realRescaleFilter->SetOutputMaximum(255); | |||
realRescaleFilter->Update(); | |||
// Extract the real part | // Extract the real part | ||
typedef itk::ComplexToImaginaryImageFilter<FFTType::OutputImageType, | typedef itk::ComplexToImaginaryImageFilter<FFTType::OutputImageType, FloatImageType> ImaginaryFilterType; | ||
ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New(); | ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New(); | ||
imaginaryFilter->SetInput(fftFilter->GetOutput()); | imaginaryFilter->SetInput(fftFilter->GetOutput()); | ||
imaginaryFilter->Update(); | imaginaryFilter->Update(); | ||
RescaleFilterType::Pointer imaginaryRescaleFilter = RescaleFilterType::New(); | |||
imaginaryRescaleFilter->SetInput(imaginaryFilter->GetOutput()); | |||
imaginaryRescaleFilter->SetOutputMinimum(0); | |||
imaginaryRescaleFilter->SetOutputMaximum(255); | |||
imaginaryRescaleFilter->Update(); | |||
// Compute the magnitude | // Compute the magnitude | ||
typedef itk::ComplexToModulusImageFilter<FFTType::OutputImageType, | typedef itk::ComplexToModulusImageFilter<FFTType::OutputImageType, FloatImageType> ModulusFilterType; | ||
ModulusFilterType::Pointer modulusFilter = ModulusFilterType::New(); | ModulusFilterType::Pointer modulusFilter = ModulusFilterType::New(); | ||
modulusFilter->SetInput(fftFilter->GetOutput()); | modulusFilter->SetInput(fftFilter->GetOutput()); | ||
modulusFilter->Update(); | modulusFilter->Update(); | ||
RescaleFilterType::Pointer magnitudeRescaleFilter = RescaleFilterType::New(); | |||
magnitudeRescaleFilter->SetInput(modulusFilter->GetOutput()); | |||
magnitudeRescaleFilter->SetOutputMinimum(0); | |||
magnitudeRescaleFilter->SetOutputMaximum(255); | |||
magnitudeRescaleFilter->Update(); | |||
QuickView viewer; | QuickView viewer; | ||
viewer.AddImage(image.GetPointer()); | viewer.AddImage(image.GetPointer()); | ||
viewer.AddImage(realRescaleFilter->GetOutput()); | |||
viewer.AddImage( | viewer.AddImage(imaginaryRescaleFilter->GetOutput()); | ||
viewer.AddImage( | viewer.AddImage(magnitudeRescaleFilter->GetOutput()); | ||
viewer.AddImage( | |||
viewer.Visualize(); | viewer.Visualize(); | ||
Revision as of 19:39, 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[]) {
// Verify input if(argc < 2) { std::cerr << "Required: filename" << std::endl; return EXIT_FAILURE; }
// Define some types typedef itk::Image<unsigned char, 2> UnsignedCharImageType; typedef itk::Image<float, 2> FloatImageType;
// Read the image typedef itk::ImageFileReader<FloatImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); reader->Update();
// Compute the smallest power of two that is bigger than the image 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; 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()); // Compute 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, FloatImageType> RealFilterType; RealFilterType::Pointer realFilter = RealFilterType::New(); realFilter->SetInput(fftFilter->GetOutput()); realFilter->Update();
typedef itk::RescaleIntensityImageFilter< FloatImageType, UnsignedCharImageType > RescaleFilterType; RescaleFilterType::Pointer realRescaleFilter = RescaleFilterType::New(); realRescaleFilter->SetInput(realFilter->GetOutput()); realRescaleFilter->SetOutputMinimum(0); realRescaleFilter->SetOutputMaximum(255); realRescaleFilter->Update();
// Extract the real part typedef itk::ComplexToImaginaryImageFilter<FFTType::OutputImageType, FloatImageType> ImaginaryFilterType; ImaginaryFilterType::Pointer imaginaryFilter = ImaginaryFilterType::New(); imaginaryFilter->SetInput(fftFilter->GetOutput()); imaginaryFilter->Update();
RescaleFilterType::Pointer imaginaryRescaleFilter = RescaleFilterType::New(); imaginaryRescaleFilter->SetInput(imaginaryFilter->GetOutput()); imaginaryRescaleFilter->SetOutputMinimum(0); imaginaryRescaleFilter->SetOutputMaximum(255); imaginaryRescaleFilter->Update();
// Compute the magnitude typedef itk::ComplexToModulusImageFilter<FFTType::OutputImageType, FloatImageType> ModulusFilterType; ModulusFilterType::Pointer modulusFilter = ModulusFilterType::New(); modulusFilter->SetInput(fftFilter->GetOutput()); modulusFilter->Update();
RescaleFilterType::Pointer magnitudeRescaleFilter = RescaleFilterType::New(); magnitudeRescaleFilter->SetInput(modulusFilter->GetOutput()); magnitudeRescaleFilter->SetOutputMinimum(0); magnitudeRescaleFilter->SetOutputMaximum(255); magnitudeRescaleFilter->Update();
QuickView viewer; viewer.AddImage(image.GetPointer()); viewer.AddImage(realRescaleFilter->GetOutput()); viewer.AddImage(imaginaryRescaleFilter->GetOutput()); viewer.AddImage(magnitudeRescaleFilter->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>