%pylab inline
from __future__ import print_function
from __future__ import division
import IPython
import wave
from scipy.io import wavfile
Populating the interactive namespace from numpy and matplotlib
img=imread('gray-step.png') #Reading the image
imshow(img);
img.shape #Displays the shape of the image
(338, 600, 4)
subplot(131)
imshow(img[:,:,0]) #Red
colorbar()
title('Red')
subplot(132)
imshow(img[:,:,1]) #Green
colorbar()
title('Green')
subplot(133)
imshow(img[:,:,2]) #Blue
colorbar()
title('Blue')
gcf().set_figwidth(18)
img.dtype
dtype('float32')
xx=len(img[1,:])
for i in range(20):
if (2**i >xx):
break
dft_point= 2**(i-1) #Also we calculate the maximum dft-point that can be windowed out per row of the image
yy=len(img[:,1])
size=xx*yy #size of image when converted to 1-D is xx*yy
#We assume that the green channel pixel data acts as magnitude spectrum
green=img[:,:,1]
mag_spec=green.reshape(size,1)
#We assume that the blue channel pixel data acts as phase spectrum
blue=img[:,:,2]
phs_spec=blue.reshape(size,1)
td=[]
win_start = arange(0, size, dft_point)
win_len = dft_point
for start in win_start:
#Creating windows...
win_mag = mag_spec[start: start + win_len]
win_phs = phs_spec[start: start + win_len]
if start+win_len>size: #Breaking out from loop if indices of window exceeds the length of the 1-D image
break
X = [np.complex(cos(phs)* mag, -sin(phs)* mag) for mag, phs in zip(win_mag,win_phs)] #Performing inverse real IFFT on each window
x = fft.irfft(X)
td = td + list(x)
plot(td)
gcf().set_figwidth(18)
IPython.display.Audio (data=td, filename=None, url=None, embed=True, rate=8000, autoplay=False) #Plotting the audio