def transform_image(dimensions, image):
        size = dimensions[0]

        image = image.copy() / 255.
        for channel in range(image.shape[2]):
            image[:, :, channel] = fftpack.ifft2(fourier_ellipsoid(fftpack.fft2(image[:, :, channel]), size)).real
        return np.clip(image * 255., 0., 255.)
Beispiel #2
0
 def test_fourier_ellipsoid_1d_complex(self):
     # expected result of 1d ellipsoid is the same as for fourier_uniform
     for shape in [(32, ), (31, )]:
         for type_, dec in zip([numpy.complex64, numpy.complex128],
                               [5, 14]):
             x = numpy.ones(shape, dtype=type_)
             a = ndimage.fourier_ellipsoid(x, 5, -1, 0)
             b = ndimage.fourier_uniform(x, 5, -1, 0)
             assert_array_almost_equal(a, b, decimal=dec)
Beispiel #3
0
 def test_fourier_ellipsoid_complex01(self, shape, dtype, dec):
     a = numpy.zeros(shape, dtype)
     a[0, 0] = 1.0
     a = fft.fft(a, shape[0], 0)
     a = fft.fft(a, shape[1], 1)
     a = ndimage.fourier_ellipsoid(a, [5.0, 2.5], -1, 0)
     a = fft.ifft(a, shape[1], 1)
     a = fft.ifft(a, shape[0], 0)
     assert_almost_equal(ndimage.sum(a.real), 1.0, decimal=dec)
Beispiel #4
0
 def test_fourier_ellipsoid_unimplemented_ndim(self):
     # arrays with ndim > 3 raise NotImplementedError
     x = numpy.ones((4, 6, 8, 10), dtype=numpy.complex128)
     with pytest.raises(NotImplementedError):
         a = ndimage.fourier_ellipsoid(x, 3)
Beispiel #5
0
import scipy.ndimage as ndi
import scipy.misc as misc
import matplotlib.pyplot as plt
import numpy as np

img = misc.ascent()

noisy = img + 0.09 * img.std() * np.random.random(img.shape)

fe = ndi.fourier_ellipsoid(img, 1)
fg = ndi.fourier_gaussian(img, 1)
fs = ndi.fourier_shift(img, 1)
fu = ndi.fourier_uniform(img, 1)
title = ['original', 'Noisy', 'Fourier Ellipsoid', 'Fourier Gaussian', 'Fourier Shift', 'Fourier uniform']
output = [img, noisy, fe, fg, fs, fu]
for i in range(6):
    plt.subplot(2, 3, i + 1)
    plt.imshow(np.float64(output[i]), cmap='gray')
    plt.title(title[i])
    plt.axis('off')
plt.show()
def fourier(img, size=100):
    return [
        ndimage.fourier_ellipsoid(img, size),
        ndimage.fourier_shift(img, size),
        ndimage.fourier_uniform(img, size)
    ]
def fouriert(f):
    f1 = ndimage.fourier_ellipsoid(f, size=1.0)
    return (f1)
from scipy import ndimage, misc
import numpy.fft
import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(1, 2)
plt.gray()  # show the filtered result in grayscale
ascent = misc.ascent()
input_ = numpy.fft.fft2(ascent)
result = ndimage.fourier_ellipsoid(input_, size=20)
result = numpy.fft.ifft2(result)
ax1.imshow(ascent)
ax2.imshow(result.real)  # the imaginary part is an artifact
plt.show()