def high_frequency_emphasis(shape, D0, k1, k2): height, width = shape H = np.zeros((height, width), np.float) for u, v in product(range(0, height), range(0, width)): Duv = ((u - height / 2) ** 2 + (v - width / 2) ** 2) ** 0.5 H[u, v] = k1 + k2 * (1 - e ** (-1 * Duv ** 2 / (2 * D0 ** 2))) return H
def dft(img): height, width = img.shape[0], img.shape[1] f = img F = np.zeros((height, width, 1), np.float) for u, v in product(range(0, height), range(0, width)): for x, y in product(range(0, height), range(0, width)): F[u, v] += f[x, y] * e ** (2 * pi * (u * x / height + v * y / width)) * (-1) ** (x + y) return F
def butterworth_filter(shape, D0, n): height, width = shape A = 2 ** 0.5 - 1 H = np.zeros((height, width), np.float) for u, v in product(range(0, height), range(0, width)): Duv = ((u - height / 2) ** 2 + (v - width / 2) ** 2) ** 0.5 H[u, v] = 1 / (1 + A * (Duv / D0) ** (2 * n)) return H
def fft2(img): height, width = img.shape[0], img.shape[1] feq_img = np.zeros((height, width), np.complex) for i in range(0, height): row_data = _sort(img[i], _get_period_order(width)) feq_img[i, :] = _raw_fft(tuple(row_data), 0) for j in range(0, width): col_data = _sort(feq_img[:, j], _get_period_order(height)) feq_img[:, j] = _raw_fft(tuple(col_data), 0) return feq_img