I'm following this low-pass filter example in the text "Image Operators: Image Processing in Python 1st Edition" by Jason M. Kinser, but can't seem to duplicate their results.
The text's code:
import imageio import scipy.fftpack as ft import mgcreate as mgc amg = imageio.imread('data/reschartsmall.png', as_gray=True) bmg = 1 - amg/amg.max() cmg = ft.fftshift(ft.fft2(bmg)) V,H = cmg.shape circ = mgc.Circle((V,H), (V/2,H/2), 10) dmg = ft.ifft2(ft.fftshift(circ*cmg)) imageio.imsave('figure.png', -dmg.real)
where the Circle function is given by
# mgcreate.py def Circle(size, loc, rad): b1,b2 = np.indices(size) b1,b2 = b1-loc, b2-loc mask = b1*b1 + b2*b2 mask = (mask <= rad*rad).astype(int) return mask
The following is the original image and the final image after the low-pass filter code above is applied:
I load in the image from https://raw.githubusercontent.com/joefoxva1/CDS468/master/Lectures10_11_12/USAF1951w.jpg but otherwise, I'm using the same code. This is the image I'm producing:
My image appears to be inverted (apparently fixed by saving the image as dmg.real instead of -dmg.real) and nonuniform (the two FFT procedures together are creating a band in the center of the image). I don't understand why I'm observing different behavior of the same code. My guesses were that maybe the Scipy fftpack functions have changed since the publishing of the text or that the image I'm importing isn't the same somehow (doesn't seem likely, the code produces similar behavior with other images).