1
$\begingroup$

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[0], b2-loc[1]
    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:

enter image description here

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:

enter image description here

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).

$\endgroup$
3
  • $\begingroup$ How does the image you start from look like? $\endgroup$ Oct 21 '21 at 20:33
  • $\begingroup$ This is the image that I start with: raw.githubusercontent.com/joefoxva1/CDS468/master/… and then I load it in as gray as the example does. $\endgroup$
    – Lagreeni
    Oct 21 '21 at 22:41
  • 1
    $\begingroup$ What I meant is: if you output the picture as you loaded it, does it also have the inverted brightness scheme? $\endgroup$ Oct 22 '21 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.