Added FFT methods
This commit is contained in:
parent
b8e260affa
commit
a1bd5002ca
1 changed files with 42 additions and 2 deletions
|
@ -4,7 +4,10 @@ from os.path import abspath
|
||||||
import datetime
|
import datetime
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import random
|
import numpy as np
|
||||||
|
import random
|
||||||
|
from PIL import Image
|
||||||
|
import requests
|
||||||
|
|
||||||
# Export's video frames
|
# Export's video frames
|
||||||
def video_to_frames(path):
|
def video_to_frames(path):
|
||||||
|
@ -79,4 +82,41 @@ def list_dir_abs(directory):
|
||||||
|
|
||||||
def pickRandomNum(paths, num):
|
def pickRandomNum(paths, num):
|
||||||
ranPaths = random.choices(paths, k=num)
|
ranPaths = random.choices(paths, k=num)
|
||||||
return ranPaths
|
return ranPaths
|
||||||
|
|
||||||
|
def showImage(path):
|
||||||
|
image = cv2.imread(path)
|
||||||
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||||
|
plt.imshow(image)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
def showDiscreteFFT(image):
|
||||||
|
fftImage = np.fft.fft2(image)
|
||||||
|
fftShift = np.fft.fftshift(fftImage)
|
||||||
|
magnitude = 20 * np.log(np.abs(fftShift))
|
||||||
|
|
||||||
|
fig = plt.figure(figsize=(15, 6))
|
||||||
|
fig.add_subplot(1, 2, 1)
|
||||||
|
plt.imshow(image, cmap="gray")
|
||||||
|
fig.add_subplot(1, 2, 2)
|
||||||
|
plt.imshow(magnitude, cmap="gray")
|
||||||
|
fig.tight_layout()
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
def loadImageFromURL(url):
|
||||||
|
response = requests.get(url)
|
||||||
|
image = Image.open(requests.get(url, stream=True).raw)
|
||||||
|
return image
|
||||||
|
|
||||||
|
def PILToNumpy(image):
|
||||||
|
image = np.array(image)
|
||||||
|
return image
|
||||||
|
|
||||||
|
def URL2FFT(url):
|
||||||
|
image = loadImageFromURL(url)
|
||||||
|
if image.mode == "RGB":
|
||||||
|
image = PILToNumpy(image)
|
||||||
|
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
||||||
|
else:
|
||||||
|
image = PILToNumpy(image)
|
||||||
|
showDiscreteFFT(image)
|
Reference in a new issue