Now to use our logic gates to compute something meaningful using the FFT algorithms. We are using a bunch of bits which are associated with an image of a book called Firestar.


In [57]:
%pylab inline
import random
img = imread('imgs/firestar.png')
img[0]
img[1]
img[2]
img[4]


Populating the interactive namespace from numpy and matplotlib
Out[57]:
array([[ 1.        ,  1.        ,  0.96078432],
       [ 1.        ,  1.        ,  0.96078432],
       [ 1.        ,  1.        ,  0.96078432],
       ..., 
       [ 0.64313728,  0.52941179,  0.39607844],
       [ 0.68235296,  0.57254905,  0.42745098],
       [ 0.70980394,  0.59215689,  0.4509804 ]], dtype=float32)

We start out with 2D arrays, that seem to correspond to the number of rows in the image. Each row indicates the RGB value of the underlying pixels


In [58]:
subplot(121)
plot(abs(fft.fft(img[0])))
title('The magnitude spectrum')
subplot(122)
plot(angle(fft.fft(img[0])));
title('The phase spectrum')
gcf().set_figwidth(10)



In [59]:
subplot(121)
plot(abs(fft.fft(img[1])))
title('The magnitude spectrum')
subplot(122)
plot(angle(fft.fft(img[1])));
title('The phase spectrum')
gcf().set_figwidth(10)



In [60]:
subplot(121)
plot(abs(fft.fft(img[2])))
title('The magnitude spectrum')
subplot(122)
plot(angle(fft.fft(img[2])));
title('The phase spectrum')
gcf().set_figwidth(10)



In [61]:
subplot(121)
plot(abs(fft.fft(img[812])))
title('The magnitude spectrum')
subplot(122)
plot(angle(fft.fft(img[812])));
title('The phase spectrum')
gcf().set_figwidth(10)


These are the rows. They differ from one horizontal 'slice' across the image. Since these signals are intended to be taken in parallel, why not mix up our data.


In [62]:
new_img = img[2]

In [63]:
new_img


Out[63]:
array([[ 1.        ,  1.        ,  0.96078432],
       [ 1.        ,  1.        ,  0.96078432],
       [ 1.        ,  1.        ,  0.96078432],
       ..., 
       [ 0.54901963,  0.44705883,  0.31764707],
       [ 0.58039218,  0.47843137,  0.34117648],
       [ 0.58039218,  0.46666667,  0.33333334]], dtype=float32)

In [66]:
new_img[3][1]


Out[66]:
1.0

In [87]:
for each in new_img:
    i = random.randint(0,811)
    for pix in each:
        j = random.randint(0,2)
        pix = img[i][j][j]

In [88]:
subplot(121)
plot(abs(fft.fft(new_img)))
title('The magnitude spectrum')
subplot(122)
plot(angle(fft.fft(new_img)));
title('The phase spectrum')
gcf().set_figwidth(10)



In [89]:
imgplot = plt.imshow(img) # This is what we started with.