Skip to content

Fix bug related to storing preprocessed images in place

I came across a problem where the output image from a preproc work was not correct. It's fixed by modifying fluidimage.preproc.io.iterate_multiple_imgs such that img_array_in is not modified while being iterated over. I am not sure why storing the result in-place like it was should be a problem.

The problem occured while trying to implement a high-pass filter preprocessing like this:

@iterate_multiple_imgs
def highpass(img=None, k=15):
    """
    Apply high-pass filter to image.

    Parameters
    ----------
    img : array_like
        Single image as numpy array or multiple images as array-like object
    k : int
        Size of the ellipsoid in Fourier space

    """
    img_fft = np.fft.fft2(img)
    img_high = img - np.fft.ifft2(ndi.fourier_ellipsoid(img_fft, size=k)).real
    return img_high

The highpass tool was applied after other tools.

I don't know if there is a reason why it would fail for this function in particular, or if it is just unsafe to modify the numpy array while iterating it, in which case an alternative would be to not use an iterator? but instead a for loop based on the index?

Writing into a new array seems the safest method, but will use more memory.

Merge request reports