import numpy as np from scipy import misc import matplotlib.pyplot as plt from util.io import readvalue def positive_int(s): i = int(s) if(i <= 0): raise ValueError("{} is negative".format(i)) return i file_input_name = readvalue("Input file name > ", str) file_output_name = readvalue("Output file name > ", str) cutoff = readvalue("Frequencies to cut > ", positive_int) fin = misc.imread(file_input_name, flatten=True) transformed = np.fft.fft2(fin) new_transformed = np.zeros(transformed.shape, dtype=np.complex) new_transformed[cutoff:-cutoff, cutoff:-cutoff] = transformed[cutoff:-cutoff, cutoff:-cutoff] new = np.fft.ifft2(new_transformed).real misc.imsave(file_output_name, new)