Skip to content

Commit

Permalink
Real-to-Complex Fourier transform of size 2 failed. Fixes #158.
Browse files Browse the repository at this point in the history
  • Loading branch information
crisluengo committed May 13, 2024
1 parent bd2b020 commit 5ef06b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/linear/gauss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -417,13 +417,15 @@ void GaussFT(
DIP_STACK_TRACE_THIS( FourierTransform( outFT, out, options ));
}
} else {
DIP_START_STACK_TRACE
if( inSpatial == outSpatial ) {
out = in;
} else if( inSpatial ) {
FourierTransform( in, out );
} else {
FourierTransform( in, out, { S::INVERSE } );
}
DIP_END_STACK_TRACE
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/transform/fourier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ] );
Expand Down

0 comments on commit 5ef06b0

Please sign in to comment.