From 5ef06b0e921f2c3dd3f1c33f92845b14eddab123 Mon Sep 17 00:00:00 2001 From: Cris Luengo Date: Mon, 13 May 2024 09:39:37 -0600 Subject: [PATCH] Real-to-Complex Fourier transform of size 2 failed. Fixes #158. --- src/linear/gauss.cpp | 4 +++- src/transform/fourier.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/linear/gauss.cpp b/src/linear/gauss.cpp index f6b3b740..397c644e 100644 --- a/src/linear/gauss.cpp +++ b/src/linear/gauss.cpp @@ -389,7 +389,7 @@ void GaussFT( bool reuseInFT = false; if( inSpatial ) { real = !in.DataType().IsComplex(); - inFT = FourierTransform( in ); + DIP_STACK_TRACE_THIS( inFT = FourierTransform( in )); reuseInFT = true; } else { inFT = in; @@ -417,6 +417,7 @@ void GaussFT( DIP_STACK_TRACE_THIS( FourierTransform( outFT, out, options )); } } else { + DIP_START_STACK_TRACE if( inSpatial == outSpatial ) { out = in; } else if( inSpatial ) { @@ -424,6 +425,7 @@ void GaussFT( } else { FourierTransform( in, out, { S::INVERSE } ); } + DIP_END_STACK_TRACE } } diff --git a/src/transform/fourier.cpp b/src/transform/fourier.cpp index bf998053..46381ee3 100644 --- a/src/transform/fourier.cpp +++ b/src/transform/fourier.cpp @@ -396,6 +396,9 @@ void DFT_R2C_1D_finalize( DIP_ASSERT( !process[ dimension ] ); // the R2C process dimension should not be a C2C process dimension // Input: pixels 0 to size/2 are set dip::uint size = img.Size( dimension ); + if( size <= 2 ) { + return; // We've got nothing to do here + } RangeArray leftWindow( nDims ); if( !( size & 1u )) { // even size: pixels 0 and size/2 stay where they are @@ -540,7 +543,10 @@ void FourierTransform( } else { DIP_THROW_IF( outSize[ ii ] > maximumDFTSize, "Image size too large for DFT algorithm" ); } - if( !process[ optimalDimension ] || ( std::abs( out.Stride( ii )) < std::abs( out.Stride( optimalDimension )))) { + if( !process[ optimalDimension ] || ( + ( outSize[ ii ] > 2 ) && + ( std::abs( in.Stride( ii )) < std::abs( in.Stride( optimalDimension ))) + )) { optimalDimension = ii; } scale /= static_cast< dfloat >( outSize[ ii ] );