[SciPy-User] Applying fft2 to all NxN blocks of an image
David Coles
coles.david@gmail....
Wed Nov 10 00:10:48 CST 2010
As part of a video processing application I wish to apply the
2-dimensional FFT to 8x8 blocks of a monochrome image (a 2D array of
8-bit ints) such as is done in JPEG. At present I'm using a function
like this to create a list of these blocks:
def subblock(image, N=8):
"""
Divides up a 2D image into list of NxN blocks
"""
w = image.shape[0]
h = image.shape[1]
return [image[n:n+N, m:m+N] for n in range(0,w,N) for m in range(0,h,N)]
Whilst this works quite well for getting the blocks, applying the fft2
to each block in a for-loop doesn't seem particularly efficent way to do
it:
blocks = subblock(image['Y'])
for block in blocks:
ff = numpy.fft.fft2(block)
# Do something to frequency components
block[:] = numpy.fft.ifft2(ff)
Is there a better way to apply the 2D FFT to these blocks? During my
search for a solution I found that Matlab has a blocproc function
( http://www.mathworks.com/help/toolbox/images/ref/blockproc.html ) but
I haven't seen something equivalent for SciPy/NumPy.
One possibility seems to be turning the image into a ZxNxN array since
fft2 seems to only be applied to the last two dimensions of the image,
but I can't think of a nice way to transform this array. Another thought
is if using an iterator/imap would be more efficient.
Cheers,
David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20101110/e7a89cdb/attachment.bin
More information about the SciPy-User
mailing list