Description: This homework load a picture and turn it into a sound track.
I used my thumbnail picture on MAT website as the input image.
Firstly, I made a small example that only use a piece of the data in green channel to produce the sound. I did a propotional scale based on the graph of the data. The output soundtrack was named "outsig.wav". But I found it pretty boring and short. The sounds is sharp and like a simple sin wave without harmonics. So I did another try.
I selected the whole picture and chose data in red channel. And I used sqaurt root to clean the data a little bit, then out put. This time it sounds more interesting than the previous one. You could hear a little harmonics inside.
I have also tried to use all 3 color channels. But there were not much differences between this three channels, which was a little bit supprising that even the graphs look diffrent in some ways, the transfered sounds sound identical. Therefore I just kept the original long piece with only red channel data inside.
The code are as follow:
%pylab inline
from __future__ import print_function
from __future__ import division
from scipy.io import wavfile
import numpy as np
Populating the interactive namespace from numpy and matplotlib
img = imread('test.jpeg')
imshow(img)
<matplotlib.image.AxesImage at 0x10af1eb10>
imshow(img[:,:,0])
<matplotlib.image.AxesImage at 0x10ded4b10>
sig = img[70,:, 1]
plot(sig)
[<matplotlib.lines.Line2D at 0x10b29e410>]
sigout = list((sig.astype(int16) - 125) * 200)*30
out2 = np.asarray(sigout,dtype=int16)
wavfile.write('outsig.wav', 44100, out2)
lst = []
for i in range(0,img.shape[0]):
array = img[:,i,0].tolist()
lst.extend(array)
print(len(lst))
sigout2 = ((sqrt(lst) - 8) * 2400).astype(int16)
plot(sigout2)
axis([0,10000,-20000,20000])
10000
[0, 10000, -20000, 20000]
sigout3 = np.asarray(sigout2,dtype=int16)
wavfile.write('outsig2.wav', 44100, sigout3)
import IPython
IPython.display.Audio("outsig2.wav")