<jupyter_start><jupyter_text>Homework 7 Problem 2 <NAME> First, our import statements.<jupyter_code>import matplotlib.pyplot as plt
import matplotlib.image as mping
import numpy as np
from PIL import Image, ImageOps<jupyter_output><empty_output><jupyter_text>Next, lets read in a `.jpg` picture that we want to investigate.<jupyter_code>image = mping.imread("pattern.jpg")
imgplot = plt.imshow(image)
plt.show()<jupyter_output><empty_output><jupyter_text>Converting the jpg to useable data If you look closely, you can see a white grid pattern. Let's try to remove this. First, let's put it to a greyscale to we dont have to worry about the color data.<jupyter_code>img = np.array(ImageOps.grayscale(Image.open('pattern.jpg')))
plt.imshow(img, "gray")<jupyter_output><empty_output><jupyter_text>Next, we can take the 2D FFT of the grid and center it.<jupyter_code>fimg = np.fft.fft2(img)
fimgcenter = np.fft.fftshift(fimg)
plt.imshow(np.log(1+np.abs(fimgcenter)), "gray")<jupyter_output><empty_output><jupyter_text>The center point seems to show a 2D fourier frequency peak that we want to remove. Since `fimgcenter` is a numpy array of numpy arrays, what my plan would be is to remove the arrays assigned to the pixels with x values close to 2000 and y values close to 1500 that form this cross shape. I didn't make much progress in trying to remove this section.  Padding the data I've never dealt with tuples before, so this is me mucking around trying to figure out how to pad.<jupyter_code>fimgcenter.shape
pad = ()
pad_size = len(fimgcenter[1] - fimgcenter[0])
len(fimgcenter[0])
for entry in range(0,pad_size):
    pad  = pad + (0,)
for entry in range(0,4032 - 3024):
    pad  = pad + (0,)
fimgcenter.shape
type(fimgcenter[0][0])
a = np.complex128(0)
type(a)
def loop(pad):
    for entry in range(0,4032 - 3024):
        pad  = pad + np.complex128(0)
        return pad
a = loop(pad)
len(a)
print(len(fimgcenter[1]))<jupyter_output>4032<jupyter_text>I thought I can concatenate tuples like this, but the structure of `fimgcenter` must be more complicated, like tuples with entries in the tuples being lists? Let's try to make a filter. This next line will give me an error if I run it.<jupyter_code># fimgcenter[0] = fimgcenter[0] + pad<jupyter_output><empty_output><jupyter_text>Making the Filter<jupyter_code>y_len = len(fimgcenter[0])
x_len = len(fimgcenter[1])
print(y_len)
print(x_len)
x = np.linspace(-10, 10, x_len)
y = np.linspace(-10, 10, y_len)<jupyter_output>4032
4032<jupyter_text>Let's try a filter that removes half of the white line we saw in the image. We can do that with a $y = -x$ type of 2d grid.<jupyter_code>R = 0.00001
xx, yy = np.meshgrid(x, y, sparse=True)
lowpass = (np.sqrt(xx**2 + yy**2) >= R)*1

lowpass_rect = ((xx * yy) <= R)*1
lowpass_half = ((yy > xx))*1

plt.imshow(lowpass_half, "gray")<jupyter_output><empty_output><jupyter_text>Applying my filter Because the dimensionality is wrong between $x$ and $y$, I can't apply the filter. I Don't quite understand the composition of `fimgcenter`. Let's walk through what I would have done. Next, I apply the filter to the FFT image.<jupyter_code># plt.imshow(np.log(1+np.abs(lowpass_half*fimgcenter_new)), "gray")<jupyter_output><empty_output><jupyter_text>And then I would take the iFFT of the filtered image and display it here.<jupyter_code># filtered = np.fft.ifft2(lowpass_half*fimgcenter)
# plt.imshow(np.log(1+np.abs(filtered)), "gray")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11133603238866396, 'fraction_numerical': 0.025448235974551765, 'mean_word_length': 5.526415094339622, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '548685', 'license': 'Apache-2.0', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1231, 'n_words': 396, 'path': 'Austin_Marga_HW7_2_New.ipynb', 'repo_name': 'admarga/CP1_2DFFT', 'size': '3464'}