Image to Sound
For a given image, the algorithm creates a sound whose spectrogram looks like the image. It maps the pixel intensities of the image to the amplitudes of the spectrogram and randomizes the phase spectrum. Before the mapping, edge detection is applied to the image in order to make the sound more distinctive and the spectrogram’s features more pronounced.
I worked on this project for Music Hack Day India, 2019, an event that focused on applications of technology in music and sound art.
The code is available on GitHub.
Algorithm
- Convert the image to grayscale (if it’s RGB)
- Resize the image to a fixed height
- Apply edge detection to the image so that the audio is more tone-like
- Scale the pixel intensities of the image to control the loudness of the audio
- Map the pixel intensities to the amplitudes of the spectrogram
- Randomize the phase spectrum of the STFT
- Compute the inverse STFT to produce samples of the audio
- Generate an audio file from the samples