DIPlib / diplib

Quantitative Image Analysis in C++, MATLAB and Python
https://diplib.org
Apache License 2.0
222 stars 49 forks source link

gaussf: error when first time usage #158

Closed AndreZeug closed 4 months ago

AndreZeug commented 4 months ago

Component Matlab R2024a DIPimage toolbox for quantitative image analysis Version 3.4.3 10-May-2024

Describe the bug I try to use GAUSSF to smooth a 100x2 matrix AA.zip (containing x,y coordinates) in the 1. dimension only. When calling AA(:,:,2) = single(gaussf(AA,[0 .5])); I receive the following error:

Error using dip_filtering
Index out of range
in function: Fix (Z:\GIT\DIPimage\include\diplib/library/types.h at line number 545)
in function: View (Z:\GIT\DIPimage\src\library\image_views.cpp at line number 74)
in function: At (Z:\GIT\DIPimage\include\diplib/library/image_views.h at line number 1391)
in function: FourierTransform (Z:\GIT\DIPimage\src\transform\fourier.cpp at line number 579)
in function: Gauss (Z:\GIT\DIPimage\src\linear\derivative.cpp at line number 75)
in function: Derivative (Z:\GIT\DIPimage\src\linear\derivative.cpp at line number 107)
Error in gaussf (line 58)
   image_out = dip_filtering('derivative',image_in,0,sigma); 
58     image_out = dip_filtering('derivative',image_in,0,sigma);

When executing the same command AA(:,:,2) = single(gaussf(AA(:,:,1),[0 .5])); a second time the error does not occur and the returned data are as expected.

The error does not occur at all when using AA(:,:,2) = single(gaussf(AA(:,:,1),[0 .8])); since another method ('fir' instead of 'ft') is used as default? When using AA(:,:,2) = single(gaussf(AA(:,:,1),[0 .5],'fir')); I receive no error.

This behaviour changed with DIPimage 3.x and was not present in DIPimage 2.9

System information: Win10, Matlab2024a, DIPimage 3.4

crisluengo commented 4 months ago

Thank you! I have been able to reproduce this, and found the bug. It is caused when the Fourier transform of a real image picks a dimension of size 2 to do the R2C transform along. For such a short input, there are no pixels that are conjugate symmetric, and so no copying of data is needed. The function tries to copy 0 pixels and fails.

The real mystery is why it works the second time!