1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| import numpy as np import math import matplotlib.pyplot as plt import cv2
start_X = -np.pi end_x = np.pi slice_num = 200 X = np.linspace(start_X, end_x, slice_num, endpoint=True) wave1 = 10*np.sin(X) + np.append(np.random.rand(len(X)-100), np.zeros(100)) wave1 = X + wave1 * 1j wave1_real = np.real(wave1) wave1_imag = np.imag(wave1)
wave2 = 10*np.sin(X) + np.append(np.random.rand(len(X)-100), np.zeros(100)) wave2 = X + wave2 * 1j wave2_real = np.real(wave1) wave2_imag = np.imag(wave1)
plt.title('original data1') plt.plot(np.real(wave1), np.imag(wave1)) fig = plt.figure() plt.title('original data2') plt.plot(np.real(wave2), np.imag(wave2)) plt.show()
wave = [wave1, wave2] wave3 = [] filter1 = [[0.5,0.5], [0.5,0.5]] for i in range(len(wave1) - len(filter1) + 1): point = 0 for j in range(len(filter1)): for k in range(len(filter1[0])): point += filter1[j][k] * wave[j][i+k] wave3.append(point) wave3 = np.array(wave3) fig = plt.figure() plt.title('filter data') plt.plot(np.real(wave3), np.imag(wave3)) plt.show()
fig = plt.figure() plt.title('original image') img = plt.imread("0.jpg") plt.imshow(img)
kernel = np.array([ [1, -2, 1], [1, -2, 1], [1, -2, 1]])
res = cv2.filter2D(img, -1, kernel) fig = plt.figure() plt.title('filter image') plt.imshow(res)
|