<jupyter_start><jupyter_text>Fourier Transforms on Fake Roads Download Files<jupyter_code>!git clone https://github.com/Max-FM/IAA-Social-Distancing.git

%cd /content/IAA-Social-Distancing/Fourier Analysis/<jupyter_output>Cloning into 'IAA-Social-Distancing'...
remote: Enumerating objects: 25, done.[K
remote: Counting objects: 100% (25/25), done.[K
remote: Compressing objects: 100% (25/25), done.[K
remote: Total 25 (delta 3), reused 0 (delta 0), pack-reused 0[K
Unpacking objects: 100% (25/25), done.
/content/IAA-Social-Distancing/Fourier Analysis<jupyter_text>Import Packages<jupyter_code>%matplotlib inline

import numpy as np

from skimage.io import imread
from skimage.color import rgb2grey

from scipy.fft import fft2, fftshift, ifft2

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D<jupyter_output><empty_output><jupyter_text>Read and Preprocess Image Files<jupyter_code>pathList = [f'Fake Roads/Road_{cars}_TransparentBack.jpg' for cars in ['NoCars', 'FewCars', 'SomeCars', 'ManyCars']]

roadList_rgb = [imread(path) for path in pathList]

# Convert to greyscale.
roadList = [rgb2grey(road) for road in roadList_rgb] 

labels=['(a)', '(b)', '(c)', '(d)']
for i, road in enumerate(roadList):
    plt.figure()
    plt.imshow(road, cmap='Greys')
    plt.xlabel(labels[i], fontsize=14)<jupyter_output><empty_output><jupyter_text>Perform Fast Fourier Transforms<jupyter_code>#Performs FFT and shifts zero frequency to center of image.
roadFFTList = [fftshift(fft2(road)) for road in roadList] 

#Calculates power spectrum.
roadPSList = [abs(roadFFT)**2 for roadFFT in roadFFTList]

#Create pixel grid.
x, y = np.arange(0,640), np.arange(0,640)
x, y = x - np.median(x), y - np.median(y)
X, Y = np.meshgrid(x,y)

#Plot power spectrum.
for i, roadPS in enumerate(roadPSList):
    fig = plt.figure()
    ax = fig.gca(projection='3d')

    ax.plot_surface(X, Y, roadPS);
    ax.set_zlim(0, 1e7)
    ax.set_zlabel(labels[i], fontsize=14)
    plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Create Pixel Mask in Fourier Space<jupyter_code># Create pixel mask.
R =  350
mask = X**2 + Y**2 < R**2

# Apply pixel mask in Fourier space.
roadFFTMaskList = [np.ma.array(roadFFT, mask=mask) for roadFFT in roadFFTList]
roadMaskList = [ifft2(roadFFTMask.filled(0)) for roadFFTMask in roadFFTMaskList]

#Plot pixel mask
plt.figure()
plt.imshow(mask)
plt.xticks([])
plt.yticks([])

#Plot masked frequencies in Fourier space.
fig, ax = plt.subplots(ncols=len(roadList))
for i in range(len(roadList)):
    ax[i].imshow(abs(roadFFTMaskList[i]))
    ax[i].set_yticks([])
    ax[i].set_xticks([])
    ax[i].set_xlabel(labels[i])

#Plot fake roads before and after masking in Fourier space.
fig, ax = plt.subplots(nrows=2, ncols=len(roadList), figsize=(15,8))
for i in range(len(roadMaskList)):
    ax[0, i].imshow(roadList_rgb[i], cmap='Greys')
    ax[1, i].imshow(abs(roadMaskList[i]), cmap='Greys_r')
    
    ax[0, i].set_yticks([])
    ax[0, i].set_xticks([])
    ax[1, i].set_yticks([])
    ax[1, i].set_xticks([])

    ax[1, i].set_xlabel(labels[i], fontsize=18)

plt.tight_layout()
plt.savefig('/content/fftFakeRoads.jpg', dpi=200, bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1501865671641791, 'fraction_numerical': 0.02394278606965174, 'mean_word_length': 5.472837022132797, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 20, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '108532', 'license': 'MIT', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1257, 'n_words': 279, 'path': 'FFT_FakeRoads.ipynb', 'repo_name': 'Max-FM/IAA-Social-Distancing', 'size': '3216'}