Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent failing of CPU 3D median filter when array of incorrect data type is passed #24

Open
yousefmoazzam opened this issue Nov 30, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@yousefmoazzam
Copy link
Collaborator

When testing for tomopy/tomopy#594, it was discovered that passing a python numpy array of values whose data type is not supported by the CPU median filter module https://github.com/dkazanc/larix/blob/master/src/Core/CPU_modules/MedianFilt_core.c causes the python wrapper function to simply return None.

For example, when the input array has dtype=np.float64 (64-bit float arrays aren't supported by Larix's CPU 3D median filter), there is no error and it instead silently fails:

>>> import numpy as np
>>> from larix.methods.misc import MEDIAN_FILT
>>> float64_data = np.ones(shape=(100, 100, 100), dtype=np.float64)
>>> float64_res = MEDIAN_FILT(float64_data, 3, 4)
>>> float64_res
>>> type(float64_res)
<class 'NoneType'>

but when the input array has dtype=np.uint16 (16-bit unsigned integer arrays are supported by Larix's CPU 3D median filter), it works as expected:

>>> uint16_data = np.ones(shape=(100, 100, 100), dtype=np.uint16)
>>> uint16_res = MEDIAN_FILT(uint16_data, 3, 4)
>>> uint16_res
array([[[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]],

       [[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]],

       [[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]],

       ...,

       [[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]],

       [[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]],

       [[1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        ...,
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1],
        [1, 1, 1, ..., 1, 1, 1]]], dtype=uint16)
>>> type(uint16_res)
<class 'numpy.ndarray'>

This is possibly something in the python wrapper that needs to be amended, rather than the median filter C code itself?

@yousefmoazzam yousefmoazzam added the bug Something isn't working label Nov 30, 2022
@namannimmo10
Copy link

MEDIAN_FILT is here:

def MEDIAN_FILT(Input, radius, ncores=0):
input_type = Input.dtype
if ((Input.ndim == 2) and (input_type == 'float32')):
return MEDIAN_FILT_float32_2D(Input, radius, ncores)
elif ((Input.ndim == 2) and (input_type == 'uint16')):
return MEDIAN_FILT_uint16_2D(Input, radius, ncores)
elif ((Input.ndim == 3) and (input_type == 'float32')):
return MEDIAN_FILT_float32_3D(Input, radius, ncores)
elif ((Input.ndim == 3) and (input_type == 'uint16')):
return MEDIAN_FILT_uint16_3D(Input, radius, ncores)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants