ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
587 stars 161 forks source link

ants.convolve_image bug #498

Open pogos-ed opened 11 months ago

pogos-ed commented 11 months ago

Running ants.convolve_image gives error:

_File ".../venv/lib/python3.9/site-packages/ants/utils/invariant_image_similarity.py", line 247, in convolve_image libfn = utils.get_lib_fn('convolveImageF%i' % image.dimension) File ".../venv/lib/python3.9/site-packages/ants/utils/process_args.py", line 29, in get_libfn return lib.dict[string] KeyError: 'convolveImageF3'

To reproduce the error use the code below and npz file I uploaded:

import numpy as np 
import ants

npzfile = np.load(in_file)
junction_im_thr = npzfile['junction_im_thr']
ants_conv_kernel = ants.make_image([5,5,5], 1, [1,1,1], [5,5,5])
junction_im_convolved = ants.convolve_image( ants.from_numpy(junction_im_thr.astype('double')), ants_conv_kernel)

I used antspyx 0.3.8 and python 3.9. junction_im_thr.npz.zip

ntustison commented 11 months ago

I'm running into issues with the code/input data:

>>> in_file = "junction_im_thr.npz.zip"
>>> npzfile = np.load(in_file)
>>> junction_im_thr = npzfile['junction_im_thr']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ntustison/miniforge3/envs/antsx/lib/python3.8/site-packages/numpy/lib/npyio.py", line 251, in __getitem__
    raise KeyError("%s is not a file in the archive" % key)
KeyError: 'junction_im_thr is not a file in the archive'
pogos-ed commented 11 months ago

Sorry, I did mistake when I save the file. Unzip the new one, then:

in_file = "junction_im_thr.npy"
junction_im_thr = np.load(in_file)

junction_im_thr.npy.zip

ntustison commented 11 months ago

Okay, it would appear that the underlying interface to ITK's convolution image filter is completely absent. So this doesn't work for any image of any dimensionality. This problematic code has been here for awhile so it's obvious that it's not used at all or it would've been discovered previously. You're welcome to work on a pull request to fix it or I might get around to it at some point.

pogos-ed commented 11 months ago

Ok, thanks for clarification.