codexx
codexx

Reputation: 75

How to find Fourier transform magnitude of a function in python?

I am calculating energy(value of pixels) of all the frames in a video.

cap= cv2.VideoCapture('video.mp4')
x = []
y = []
def imageEnergy(img):
 img = img / 255  
 return np.sum(np.square(img))
success, image = cap.read()
count = 0
while success: 
 En = imageEnergy(image)
 EnP = En / np.prod(image.shape) 
 print(f"Count: {count} Energy: {EnP}")
 success, image = cap.read()
 x.append(count)
 y.append(EnP)
 count += 1

I want to find the fourier transform magnitude of my energy function i.e Enp. I have tried using fft on y but it is not working.

transform = fft(y)
print (transform)

Can anybody please guide me?

Upvotes: 0

Views: 749

Answers (1)

Bob
Bob

Reputation: 14654

Pythonn don't have a built in fft. There are multiple libraries that provide FFT implementations, the most widely used, I think, is the numpy.

import numpy as np;
transform = abs(np.fft.fft(y))

Upvotes: 1

Related Questions