Federalbureauofcognition.files.wordpress.com



from scipy.io import wavfileimport matplotlib.pyplot as pltimport numpy as npimport sysfrom PIL import Image # if PIL is not installed already then run following command in terminal# > pip install pillow# ----------------------------------------------# How to run this script:# Rename file to .py# call from terminal as: # > python decode_audio.py image_filename.png output_audio_filename.wav# make sure the image and python file are in the same directory# make sure the audio_filename you enter ends with .wav#---------------------------------------------------------------------------def decode_image(img_filename, audio_filename): ''' Takes filename of vinyl image and writes decoded audio to specified file. Make sure audio_filename ends in .wav ''' rec_img = np.array(Image.open(img_filename)) plt.figure(1) plt.imshow(rec_img) # can adjust this sample_rate = 8000 t_tot = 60 NSamples = int(t_tot * sample_rate) t2 = np.linspace(0, t_tot, NSamples) audio_arr = np.zeros(len(t2), dtype = np.uint8) # center coordinates ??? center_x = ??? center_y = ??? start_radius = 1900 start_angle = -np.pi/2 # RPM ??? rpm = ??? Nrev = rpm/60 * t_tot # spacing between spirals ??? n_pix = ??? dtheta_dt = -(2*np.pi)* rpm/60 dr_dt = -2 * n_pix * rpm/60 rec_img1 = np.copy(rec_img) for i in range(len(t2)): t = t2[i] # calculate position angle = start_angle + t*dtheta_dt radius = start_radius + t*dr_dt x = center_x + int(radius * np.cos(angle)) y = center_y + int(radius * np.sin(angle)) # retrieve pixel value audio_arr[i] = rec_img[y,x,0] # mark the spiral on copy rec_img1[y,x,:3] = 0 # done! plt.figure(2) plt.imshow(rec_img1) # write to file wavfile.write(audio_filename, sample_rate, audio_arr) plt.show() returnif __name__ == "__main__": img_filename = sys.argv[1] audio_filename = sys.argv[2] decode_image(img_filename, audio_filename) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download