import numpy as np from imageio import imread import matplotlib.pyplot as plt def sinusBilde(u, v, N, M): bilde = np.zeros((N, M)) for i in range(N): for j in range(M): bilde[i, j] = np.sin( -2*np.pi* ((u*i/np.float(N)) + (v*j/np.float(M))) ) return bilde def cosinusBilde(u, v, N, M): bilde = np.zeros((N, M)) for i in range(N): for j in range(M): bilde[i, j] = np.cos( -2*np.pi* ((u*i/np.float(N)) + (v*j/np.float(M))) ) return bilde M = 256 N = 512 u, v = 10, 10 # Oppgave a sinimage = sinusBilde(u, v, N, M) plt.figure() plt.imshow(sinimage, cmap="gray") plt.colorbar() plt.title('u = {}, v = {}'.format(u, v)) plt.show() # Oppgave b cosimage = cosinusBilde(u, v, N, M) indreprodukt = np.sum(cosimage * sinimage) print(indreprodukt) # Skal bli (tiln?rmet) 0 # Oppgave c c1 = cosinusBilde(10, 10, N, M) c2 = cosinusBilde(14, 15, N, M) s1 = sinusBilde(10, 10, N, M) s2 = sinusBilde(14, 15, N, M) print(np.sum(c1*c2)) print(np.sum(c1*s1)) print(np.sum(c1*s2)) print(np.sum(s1*s2)) # Oppgave d u, v = 3, 5 c1 = cosinusBilde(u, v, N, M) c2 = cosinusBilde(N-u, M-u, N, M) s1 = sinusBilde(u, v, N, M) s2 = sinusBilde(N-u, M-u, N, M) fig = plt.figure() fig.add_subplot(2, 2, 1) plt.imshow(c1, cmap="gray") plt.title('cos | u = {}, v = {}'.format(u, v)) fig.add_subplot(2, 2, 2) plt.imshow(c2, cmap="gray") plt.title('cos | u = {}, v = {}'.format(u, v)) fig.add_subplot(2, 2, 3) plt.imshow(s1, cmap="gray") plt.title('sin | u = {}, v = {}'.format(u, v)) fig.add_subplot(2, 2, 4) plt.imshow(s2, cmap="gray") plt.title('sin | u = {}, v = {}'.format(u, v)) plt.show() # Oppgave e print(N*M/2) print(np.sum(c1*c1)) print(np.sum(c2*c2)) print(np.sum(s1*s1)) print(np.sum(s2*s2))