diff --git a/docs/project-demo/demo-material/helper-functions.py b/docs/project-demo/demo-material/helper-functions.py index 55fecdf..e67e16e 100644 --- a/docs/project-demo/demo-material/helper-functions.py +++ b/docs/project-demo/demo-material/helper-functions.py @@ -4,7 +4,10 @@ from os.path import abspath import datetime import matplotlib.pyplot as plt from tqdm import tqdm -import random +import numpy as np +import random +from PIL import Image +import requests # Export's video frames def video_to_frames(path): @@ -79,4 +82,41 @@ def list_dir_abs(directory): def pickRandomNum(paths, num): ranPaths = random.choices(paths, k=num) - return ranPaths \ No newline at end of file + 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) \ No newline at end of file