brainvisa / aims-free

Analysis of Images and Signal for neuroimaging
Other
6 stars 3 forks source link

filetools.compare_nii_files from soma return False instead of True when images are the same and threshold set to 0 #111

Closed rbregand closed 1 month ago

rbregand commented 1 month ago

I recently used the function filetools.compare_nii_files from soma in order to check if 2 niftis images are exactly the same. I set the input threshold to 0.0 to be inform about any differences but a weird behaviour occurs.

>>> from soma.aims.filetools import compare_nii_files
>>> compare_nii_files('/home/remy.bregand/Bureau/test/3dt1/020000029914IM20170412FU33DT1_CLEAR_GEO_S003.nii.gz', '/home/remy.bregand/Bureau/test/3dt1/020000029914IM_FU3_3DT1_S003_CLEAR_GEO.nii.gz', thresh=0)
False
>>> compare_nii_files('/home/remy.bregand/Bureau/test/3dt1/020000029914IM20170412FU33DT1_CLEAR_GEO_S003.nii.gz', '/home/remy.bregand/Bureau/test/3dt1/020000029914IM_FU3_3DT1_S003_CLEAR_GEO.nii.gz', thresh=0.1)
WARNING, use aims, absolute difference value: 0
True

The compare_nii_files return False even if the absolute difference is 0. In this case the images are the same, I computed the difference between both images to prove it.

>>> import nibabel
>>> diff = nibabel.load('/home/remy.bregand/Bureau/test/3dt1/qualicat_minus_catishared.nii') 
>>> diff_data = diff.get_fdata()
>>> import numpy
>>> numpy.max(diff_data)
0.0
>>> numpy.min(diff_data)
0.0

After looking at the compare_nii_files function, I noticed that the condition abs(np.max(d) - np.min(d)) < thresh is not respected. Is it possible to change it to : abs(np.max(d) - np.min(d)) <= thresh instead ?

Thanks for your time, Rémy

denisri commented 1 month ago

Hi, Oh yes sure, I'm fixing it. Denis

denisri commented 1 month ago

done.