import numpy as np
import matplotlib.pyplot as plt
import cv2
import utilities

# TODO: The Image

img = cv2.imread(
    '/Users/ariazare/Projects/Python/DEP_C4/Fig0441(a)(characters_test_pattern).tif'
)
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

img_padded = np.zeros((img.shape[0] * 2, img.shape[1] * 2), 'float32')
img_padded[:img.shape[0], :img.shape[1]] = img

img_padded = utilities.center_frequency(img_padded)

complex_img = [img_padded, np.zeros(img_padded.shape, 'float32')]
complex_img = cv2.merge(complex_img)
cv2.dft(complex_img, complex_img)

# MARK: The Filter


def creat_butterworth_filter(full_shape, radius, power):
    butterworth_filter = np.zeros(full_shape, 'float32')
    filter_p, filter_q = butterworth_filter.shape[0], butterworth_filter.shape[
        1]
    half_p = filter_p // 2
    half_q = filter_q // 2
    for i in range(filter_p):
Exemplo n.º 2
0
import numpy as np
import matplotlib.pyplot as plt
import cv2
import utilities

# MARK: the image

img = cv2.imread(
    '/Users/ariazare/Projects/Python/DEP_C4/Fig0462(a)(PET_image).tif')
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

img_padded = np.zeros((img.shape[0] * 2, img.shape[1] * 2), 'float32')
img_padded[:img.shape[0], :img.shape[1]] = img

img_padded = utilities.center_frequency(img_padded)

complex_img = [img_padded, np.zeros(img_padded.shape, 'float32')]
complex_img = cv2.merge(complex_img)
cv2.dft(complex_img, complex_img)

# MARK: the filter


def creat_homomorphic_filter(full_shape, yh, yl, c, radius):
    homomorphic_filter = np.zeros(full_shape, 'float32')
    filter_p, filter_q = homomorphic_filter.shape[0], homomorphic_filter.shape[
        1]
    half_p = filter_p // 2
    half_q = filter_q // 2
    for i in range(filter_p):
        for j in range(filter_q):
Exemplo n.º 3
0
import numpy as np
import cv2
import matplotlib.pyplot as plt
import utilities
from mpl_toolkits.mplot3d import axes3d

# MARK: image
img = cv2.imread(
    '/Users/ariazare/Projects/Python/DEP_C4/Fig0438(a)(bld_600by600).tif')
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img_padded = np.zeros((602, 602), 'float32')
img_padded[:-2, 0:-2] = img

img_centered = utilities.center_frequency(img_padded)
complex_img = [
    np.array(img_centered, 'float32'),
    np.zeros(img_centered.shape, 'float32')
]
complex_img = cv2.merge(complex_img)
cv2.dft(complex_img, complex_img)

# img_mag = utilities.get_magnitude(complex_img)
# img_mag = cv2.log(img_mag,img_mag)
# img_phase = utilities.get_phase_angel(complex_img)

# plt.imshow(img_mag, 'Greys')
# plt.show()

# MARK: sobel filter kernal
sobel_filter = np.array(
    [[0, 0, 0, 0], [0, -1, 0, 1], [0, -2, 0, 2], [0, -1, 0, 1]], 'float32')