<jupyter_start><jupyter_text>DD2423 Image Analysis and Computr Visions  Name:  Program:--- LAB 1: FILTERING OPERATIONS ObjectivesThe **goal** of this lab is to help you to  - get an understanding of frequency analysis in image data by using the Fourier transform, expressed spatially or in the Fourier domain,  - become familiar with the two-dimensiona Fourier transform, by studying and testing its properties in practice,  - learn the relation between the continuous and discrete Fourier transform, and design a smoothing filter for Gaussian convolution,  - understand the effect of different smoothing operations on various kinds of noise,  - understand the effect of smoothing on different image resolutions generated by subsampling,  - get practical experience of differences between synthetic and real data.  IntroductionThe purpose of **exercise 1** is for you to become familiar with characteristics of the **Fourier transform**. The purpose of **exercise 2** is for you to design a **Gaussian smoothing** filter using the Fourier transform and to understand the relation between continuous and discrete cases. The purpose of **exercise 3** is to study different **smoothing filters** and their effects on noise and subsampling. Remaining exercises are more problem-oriented and experimental in nature and formulations are thus more concise. If you happen to have **difficulties** with Python or the Colab environment in general, contact the **lab assistants** during the **scheduled lab hours**.  ReportFor you to efficiently report your labs, you need to write code scripts in this notebook and reproduce the experimental results. You should also summarize results and conclusions from your experiments, writing down answers to explicitly stated questions in the answer parts. For many exercises it is recommended that you create illustrations with multiple image.  NoteAs **prerequisties** to this lab exercise, you should have studied the course material regarding spatial filtering and image restoration.   Properties of discrete Fourier transform The continuous and discrete Fourier transformFrom the definitions used during the leactures the continuous Fourier transform $\hat{f}:\mathbb{R}^2 \rightarrow  \mathbb{C}$ of a two-dimensional signal $\hat{f}:\mathbb{R}^2 \rightarrow  \mathbb{R}$ is> $\hat{f}(\omega)=\mathcal{F}_{C}(f)(\omega)=\int_{x\in \mathbb{R}^2}f(x)e^{(-i\omega^Tx)}dx$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

def showgray(F:np.array) -> np.array:
    F = F - np.min(F)
    Fmax = np.max(F)
    F /= Fmax
    
    return F
    
def fftwave(u:int, v:int, sz:int=128):
    Fhat = np.zeros((sz, sz))
    Fhat[u, v] = 1
    Fhat_fftshift = np.fft.fftshift(Fhat)
    F = np.fft.ifft2(Fhat)
    Freal = np.real(F)
    Fimag = np.imag(F)
    Fabs = np.abs(F)
    Fangle = np.angle(F)
    
    '''
    Question: 
        What is done by these instructions?
            uc = u if u <= sz/2 else uc = u -sz
            vc = v if v <= sz/2 else vc = v -sz
    Answer:
        Write your answer here ...
    '''
    
    uc = u if u <= sz/2 else u - sz
    vc = v if v <= sz/2 else v - sz
    
    wavelength = 0.0 # Replace by correct expression
    amplitude = 0.0 # Replace by correct expression
    
    # Visualization
    fig, axes = plt.subplots(1, 2)
    
    axes[0].imshow(showgray(Fhat), cmap='gray')
    axes[0].title.set_text('Fhat:(u, v) = ({}, {})'.format(u, v))
    axes[0].axis('off')
    
    axes[1].imshow(showgray(Fhat_fftshift), cmap='gray')
    axes[1].title.set_text('(uc, vc) = ({}, {})'.format(uc, vc))
    axes[1].axis('off')
    
    fig, axes = plt.subplots(1, 2)
    axes[0].imshow(showgray(Freal), cmap='gray')
    axes[0].title.set_text('real(F)')
    axes[0].axis('off')
    
    axes[1].imshow(showgray(Fimag), cmap='gray')
    axes[1].title.set_text('imag(F)')
    axes[1].axis('off')
    
    fig, axes = plt.subplots(1, 2)
    axes[0].imshow(showgray(Fabs), cmap='gray')
    axes[0].title.set_text('amplitude = {}'.format(amplitude))
    axes[0].axis('off')

    axes[1].imshow(showgray(Fangle), cmap='gray')
    axes[1].title.set_text('wavelength = {}'.format(wavelength))
    axes[1].axis('off')
from google.colab import drive
drive.mount('/content/drive')

fftwave(4, 8)
fftwave(8, 4)
fftwave(16, 8)
fftwave(16, 120)
fftwave(4, 0)
fftwave(124, 0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11732355637030248, 'fraction_numerical': 0.015123739688359304, 'mean_word_length': 3.7757111597374178, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '656790', 'license': 'MIT', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1312, 'n_words': 480, 'path': 'lab1_filtering_operations.ipynb', 'repo_name': 'YIN95/Image-Analysis-and-Computer-Vision-Python', 'size': '4364'}