This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
f_range = 50 # 低頻範圍 | |
# 圖片來源:https://openhome.cc/Gossip/images/caterpillar.jpg | |
img = cv2.imread('caterpillar.jpg', cv2.IMREAD_GRAYSCALE) | |
rows, cols = img.shape | |
cy, cx = int(rows / 2), int(cols/2) | |
x = np.arange(-cx, cx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
f_range = 15 # 低頻範圍 | |
# 圖片來源:https://openhome.cc/Gossip/images/caterpillar.jpg | |
img = cv2.imread('caterpillar.jpg', cv2.IMREAD_GRAYSCALE) | |
rows, cols = img.shape | |
cy, cx = int(rows / 2), int(cols/2) | |
# 傅立葉轉換後並位移低頻 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# 圖片來源:https://openhome.cc/Gossip/DCHardWay/images/Fourier4-1.JPG | |
img = cv2.imread('Fourier4-1.JPG', cv2.IMREAD_GRAYSCALE) | |
f = cv2.dft(np.float32(img)) | |
shifted = np.fft.fftshift(f) # 將頻率 (0, 0) 位移至中心 | |
freq = cv2.normalize( # 標準化 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# 椒鹽雜訊 | |
def salt_pepper_noise(image, fraction, salt_vs_pepper): | |
img = np.copy(image) | |
size = img.size | |
num_salt = np.ceil(fraction * size * salt_vs_pepper).astype('int') | |
num_pepper = np.ceil(fraction * size * (1 - salt_vs_pepper)).astype('int') | |
row, column = img.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# 圖片來源:https://openhome.cc/Gossip/DCHardWay/images/Fourier4-1.JPG | |
img = cv2.imread('Fourier4-1.JPG', cv2.IMREAD_GRAYSCALE) | |
f = np.fft.fft2(img) | |
shifted = np.fft.fftshift(f) # 將頻率 (0, 0) 位移至中心 | |
amp = np.abs(shifted) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import cm | |
freq = 5 | |
stop = .25 | |
sample_rate = 800 | |
x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False) | |
gray = 125 + np.sin(freq * 2 * np.pi * x) + 125 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from math import floor | |
from random import randint | |
import matplotlib.pyplot as plt | |
def blending(t): | |
return 6 * (t ** 5) - 15 * (t ** 4) + 10 * (t ** 3) | |
blending = np.frompyfunc(blending, 1, 1) | |
def lerp(s1, s2, t): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
t = 2 # 取樣時間 | |
sample_rate = 800 # 取樣率,每秒取幾個樣本 | |
def signal(t, sample_rate): | |
f = 10 | |
x = np.linspace(0, t, int(t * sample_rate), endpoint = False) | |
return (np.sin(f * 2 * np.pi * x) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
t = 2 # 取樣時間 | |
sample_rate = 800 # 取樣率,每秒取幾個樣本 | |
def signal(t, sample_rate): | |
f = 10 | |
x = np.linspace(0, t, int(t * sample_rate), endpoint = False) | |
return (np.sin(f * 2 * np.pi * x) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
freq = 10 # 頻率 | |
stop = .25 # 取樣範圍為 0 ~ stop | |
sample_rate = 800 # 取樣率,單位 x 取樣幾次 | |
x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False) | |
z1 = np.sin(freq * 2 * np.pi * x) # 頻率 10 |