I have just done some image processing using the Python image library (PIL) using a post I found earlier to perform fourier transforms of images and I can't get the save function to work. The whole code works fine but it just wont save the resulting image:
from PIL import Image
import numpy as np
i = Image.open("C:/Users/User/Desktop/mesh.bmp")
i = i.convert("L")
a = np.asarray(i)
b = np.abs(np.fft.rfft2(a))
j = Image.fromarray(b)
j.save("C:/Users/User/Desktop/mesh_trans",".bmp")
The error I get is the following:
save_handler = SAVE[string.upper(format)] # unknown format
KeyError: '.BMP'
How can I save an image with Pythons PIL?
fft2
instead ofrfft2
since for discrete data I don't see the point in using the later. The rest is purely cosmetic, i.e., you wouldn't be able to properly visualize the Fourier transform without applying a log factor to it. Then the normalization is to keep things simple for the conversion to the range [0, 255]. – Nice