pyosv.freq.fft
Created on Tue Jun 28 17:50:18 2022
@author: alessandrosebastianelli
1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3""" 4Created on Tue Jun 28 17:50:18 2022 5 6@author: alessandrosebastianelli 7""" 8 9import numpy as np 10 11def fft2d(image): 12 ''' 13 14 Calculates the 2D Fast Fourier Transform of an image 15 16 Input: 17 - image: a WxH image, must be a single band image, with width W, height H 18 Outputs: 19 - fft: 2D spectrum of image 20 ''' 21 22 fft = np.fft.fftshift(np.fft.fft2(image)) 23 24 return fft 25 26def ifft2d(fft): 27 ''' 28 29 Calculates the inverse 2D Fast Fourier Transform of a spectrum of an image 30 31 Input: 32 - fft: 2D spectrum of image 33 Outputs: 34 - ifft: a WxH image 35 ''' 36 37 ifft = np.abs(np.fft.ifft2(np.fft.ifftshift(fft))) 38 39 return ifft 40 41def fft3d(image): 42 ''' 43 44 Calculates the 2D Fast Fourier Transform of an image with multiple bands 45 46 Input: 47 - image: a WxHxB image, with width W, height H and B bands 48 Outputs: 49 - fft: array of 2D spectra of the image 50 ''' 51 52 53 ffts = [] 54 for b in range(image.shape[-1]): 55 ffts.append(fft2d(image[:,:,b])) 56 57 ffts = np.array(ffts) 58 ffts = np.moveaxis(ffts, 0, -1) 59 60 return ffts 61 62def ifft3d(ffts): 63 ''' 64 65 Calculates the inverse 2D Fast Fourier Transform of a vecctor of spectra of a multibands image 66 67 Input: 68 - fft: array of 2D spectra of the image 69 Outputs: 70 - ifft: a WxHxB image, with width W, height H and B bands 71 ''' 72 73 iffts = [] 74 for b in range(ffts.shape[-1]): 75 iffts.append(ifft2d(ffts[:,:,b])) 76 77 iffts = np.array(iffts) 78 iffts = np.moveaxis(iffts, 0, -1) 79 80 return iffts
12def fft2d(image): 13 ''' 14 15 Calculates the 2D Fast Fourier Transform of an image 16 17 Input: 18 - image: a WxH image, must be a single band image, with width W, height H 19 Outputs: 20 - fft: 2D spectrum of image 21 ''' 22 23 fft = np.fft.fftshift(np.fft.fft2(image)) 24 25 return fft
Calculates the 2D Fast Fourier Transform of an image
Input: - image: a WxH image, must be a single band image, with width W, height H Outputs: - fft: 2D spectrum of image
27def ifft2d(fft): 28 ''' 29 30 Calculates the inverse 2D Fast Fourier Transform of a spectrum of an image 31 32 Input: 33 - fft: 2D spectrum of image 34 Outputs: 35 - ifft: a WxH image 36 ''' 37 38 ifft = np.abs(np.fft.ifft2(np.fft.ifftshift(fft))) 39 40 return ifft
Calculates the inverse 2D Fast Fourier Transform of a spectrum of an image
Input: - fft: 2D spectrum of image Outputs: - ifft: a WxH image
42def fft3d(image): 43 ''' 44 45 Calculates the 2D Fast Fourier Transform of an image with multiple bands 46 47 Input: 48 - image: a WxHxB image, with width W, height H and B bands 49 Outputs: 50 - fft: array of 2D spectra of the image 51 ''' 52 53 54 ffts = [] 55 for b in range(image.shape[-1]): 56 ffts.append(fft2d(image[:,:,b])) 57 58 ffts = np.array(ffts) 59 ffts = np.moveaxis(ffts, 0, -1) 60 61 return ffts
Calculates the 2D Fast Fourier Transform of an image with multiple bands
Input: - image: a WxHxB image, with width W, height H and B bands Outputs: - fft: array of 2D spectra of the image
63def ifft3d(ffts): 64 ''' 65 66 Calculates the inverse 2D Fast Fourier Transform of a vecctor of spectra of a multibands image 67 68 Input: 69 - fft: array of 2D spectra of the image 70 Outputs: 71 - ifft: a WxHxB image, with width W, height H and B bands 72 ''' 73 74 iffts = [] 75 for b in range(ffts.shape[-1]): 76 iffts.append(ifft2d(ffts[:,:,b])) 77 78 iffts = np.array(iffts) 79 iffts = np.moveaxis(iffts, 0, -1) 80 81 return iffts
Calculates the inverse 2D Fast Fourier Transform of a vecctor of spectra of a multibands image
Input: - fft: array of 2D spectra of the image Outputs: - ifft: a WxHxB image, with width W, height H and B bands