-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "rtkTest.h" | ||
|
||
#include "rtkFFTHilbertImageFilter.h" | ||
/** | ||
* \file rtkhilbertfiltertest.cxx | ||
* | ||
* \brief Functional test for the FFT Hilbert filter. | ||
* | ||
* This test computes the FFT Hilbert transform of the signal t -> sin(20*pi*t). | ||
* The computed Hilbert transform is compared against the known analytic Hilbert transform of the signal. | ||
* | ||
* \author Aurélien Coussat | ||
*/ | ||
|
||
int | ||
main(int, char **) | ||
{ | ||
constexpr unsigned int Dimension = 3; | ||
using OutputPixelType = float; | ||
#ifdef USE_CUDA | ||
using OutputImageType = itk::CudaImage<OutputPixelType, Dimension>; | ||
#else | ||
using OutputImageType = itk::Image<OutputPixelType, Dimension>; | ||
#endif | ||
|
||
OutputImageType::SizeType size; | ||
size[0] = 500; | ||
size[1] = size[2] = 1; | ||
|
||
OutputImageType::SpacingType spacing; | ||
spacing[0] = spacing[1] = spacing[2] = .001; | ||
|
||
OutputImageType::IndexType ix; | ||
|
||
// Build the signal t -> sin(20*pi*t) | ||
OutputImageType::Pointer signal = OutputImageType::New(); | ||
signal->SetSpacing(spacing); | ||
signal->SetRegions(size); | ||
signal->Allocate(); | ||
|
||
itk::ImageRegionIterator<OutputImageType> signalIt(signal, signal->GetLargestPossibleRegion()); | ||
|
||
while (!signalIt.IsAtEnd()) | ||
{ | ||
ix = signalIt.GetIndex(); | ||
double t = ix[0] * spacing[0]; | ||
double v = sin(20 * itk::Math::pi * t); | ||
signalIt.Set(v); | ||
++signalIt; | ||
} | ||
|
||
// Build the analytic Hilbert transform of the signal | ||
// It is t -> -cos(20*pi*t) | ||
OutputImageType::Pointer analyticHilbertSignal = OutputImageType::New(); | ||
analyticHilbertSignal->SetSpacing(spacing); | ||
analyticHilbertSignal->SetRegions(size); | ||
analyticHilbertSignal->Allocate(); | ||
|
||
itk::ImageRegionIterator<OutputImageType> analyticHilbertSignalIt(analyticHilbertSignal, | ||
analyticHilbertSignal->GetLargestPossibleRegion()); | ||
|
||
while (!analyticHilbertSignalIt.IsAtEnd()) | ||
{ | ||
ix = analyticHilbertSignalIt.GetIndex(); | ||
double t = ix[0] * spacing[0]; | ||
double v = -cos(20 * itk::Math::pi * t); | ||
analyticHilbertSignalIt.Set(v); | ||
++analyticHilbertSignalIt; | ||
} | ||
|
||
// Compute the Hilbert transform of the signal using rtkFFTHilbertImageFilter | ||
using HilbertType = rtk::FFTHilbertImageFilter<OutputImageType>; | ||
HilbertType::Pointer hilbert = HilbertType::New(); | ||
hilbert->SetInput(signal); | ||
|
||
using ZeroPadFactorsType = HilbertType::ZeroPadFactorsType; | ||
ZeroPadFactorsType zeroPadFactors; | ||
zeroPadFactors.Fill(1); | ||
hilbert->SetZeroPadFactors(zeroPadFactors); | ||
|
||
TRY_AND_EXIT_ON_ITK_EXCEPTION(hilbert->Update()); | ||
|
||
CheckImageQuality<OutputImageType>(hilbert->GetOutput(), analyticHilbertSignal, .1, 1., 1.); | ||
|
||
std::cout << "\n\nTest PASSED! " << std::endl; | ||
return EXIT_SUCCESS; | ||
} |