Fft and convert array to image / image to array

I want to do a Fourier transform of an image. But how can I change the image to an array? And after that I think you need to use numpy.fft.rfft2 for the conversion. And how to move from an array to an image? Thanks in advance.

+3
source share
1 answer

You can use the PIL library to load / save images and convert to / from numpy arrays.

import Image, numpy
i = Image.open('img.png')
i = i.convert('L')    #convert to grayscale
a = numpy.asarray(i) # a is readonly

b = abs(numpy.fft.rfft2(a))

j = Image.fromarray(b)
j.save('img2.png')

abs , FFT , . , FFT - axes rfft2, .

Edit:

FFT , :

import Image, numpy
i = Image.open('img.png')
i = i.convert('L')    #convert to grayscale
a = numpy.asarray(i)

b = numpy.fft.rfft2(a)
c = numpy.fft.irfft2(b)

j = Image.fromarray(c.astype(numpy.uint8))
j.save('img2.png')
+12

Source: https://habr.com/ru/post/1741430/


All Articles