0

I'm exploring SimpleCV as an imaging library in Python, and it seems pretty good. However, I'm stumped at how to perform an FFT on an image within SimpleCV. It seems I'd have to convert to an numpy array first, and then use the numpy facilities:

import SimpleCV as SV
im = Image('image.png')
img = im.getGrayNumpy()
imf = np.fft.fftshift(np.fft.fft2(img))
plt.imshow(log(abs(imf)+1),cmap=cm.gray)

Or maybe this is the best way? And of course if I want to convert the log of the fft spectrum into a SimpleCV image for later use, that's another issue...

Alasdair
  • 1,300
  • 4
  • 16
  • 28

1 Answers1

0

You can bring numpy matrices back to SimpleCV using the Image() constructor:

import scipy
import numpy as np
import SimpleCV as scv

cam = scv.Camera()
disp = scv.Display()

while disp.isNotDone():
    current = cam.getImage().resize(w=768)

    matrix = current.getGrayNumpy()
    spectrum = np.abs(np.log(np.fft.fftshift(np.fft.fft2(matrix))))

    spectrum *= 255 / spectrum.max()

    scv.Image(spectrum).show()

    if disp.mouseLeft:
        break
Nils Werner
  • 34,832
  • 7
  • 76
  • 98