Python code for basic fft of grid image -


I am trying to get an image of an image in Python, changing the transfected image and taking reverse FFT. Specifically, I have a picture of a grid that I want to change, then black out all, but a central, narrow vertical wall of the transformations, then take a reverse FFT.

To change no change to the code I plane:

  Import os oschdir ('/ user / terra / desktop') import image, numpy i = Image.open ('grid.png') I = i.convert ('L') # to convert grayscale a = numpy.asarray (i) # a read only b = abs (numpy.fft.rfft2 (A)) j = Image.fromarray (b) j .seven ('grid2.png')   

As of now, I get an error message:

Traceback (most recent call final): file "/ user / terra / document / pic2.py", line 11, in j.save ('grid2.png') Hail "/ Library / Framework / photo". File "/ library / frames / python / framework work in version 2/7 / lib / python2.7 / site-package / PIL / Image.py", line 1439, save_handler (auto, fp, file name). Framework / version -7.7 / lib / python2.7 / site-package / PIL / pinimage plugin ", line 506, _save increase in IOError," mode can not write% s as PNG "% mode IO error: PNG I can not write mode F.

I am very new to programming and Fourier transformation, so I have found that most related threads are on my head, very specific help is greatly appreciated. Thanks!

The main problem is That's the float after FFT in the array, but for this useful PNG output, you should have uint8 s.

The simplest thing is to directly uint8 < / Code>:

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

This Perhaps you will not give the image you want, so before you convert values ​​into the array by assuming that the values ​​are normal,

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -