"""Testing a lowpass filter on audio"""

from utility import audio_processing
from utility import file_prompt
import numpy as np
from numpy.fft import fft, ifft
from dft import dft
from processing.audio import filters

input_file_path = file_prompt.choose_file([file_prompt.FileTypes.WAV])
output_file_path = file_prompt.save_to_file(file_prompt.FileTypes.WAV)

strength = float(input("Lowpass Strength (0 - 100): ")) / 100 * 2.5


def process(channels, sample_rate):
    for i_channel in range(len(channels)):
        # dft_values = dft.dft(channels[i_channel])  # Too slow
        dft_values = fft(channels[i_channel])
        dft_values = filters.apply_gaussian_low_pass(dft_values, strength)
        # channels[i_channel] = dft.dft_inverse(dft_values)
        channels[i_channel] = np.real(ifft(dft_values))


audio_processing.process_wav(input_file_path,
                             output_file_path,
                             process,
                             1024,
                             enable_progress_bar=True)
Exemple #2
0
"""Try compression on larger images using the fft"""

import numpy as np
from numpy.fft import fft, ifft
from tqdm import tqdm
from utility import image_formats, plotting, file_prompt
from PIL import Image
from processing.image.compression import compress

# Loading Image
image_path = file_prompt.choose_file([file_prompt.FileTypes.PNG, file_prompt.FileTypes.JPG])
plot_image_path = file_prompt.save_to_file(file_prompt.FileTypes.PNG)
image = Image.open(image_path)
red, grn, blu = image_formats.image_to_color_channel_pixel_arrays(image)

# FFT
red_fft = fft(red)
grn_fft = fft(grn)
blu_fft = fft(blu)

# Compress and IFFT
compression_rates = [5, 10, 20]
images = [image]
for rate in tqdm(compression_rates):
    result_red = np.real(ifft(compress(red_fft, rate)))
    result_grn = np.real(ifft(compress(grn_fft, rate)))
    result_blu = np.real(ifft(compress(blu_fft, rate)))
    images.append(image_formats.combine_color_channels(result_red, result_grn, result_blu))

# Plot
width, height = image.size