Image to audio using matlab

8 visualizzazioni (ultimi 30 giorni)
Vishnu Prasad
Vishnu Prasad il 23 Ago 2015
Commentato: Walter Roberson il 19 Dic 2021
Hi, This is my first time posting here. I've recently been dumped with some of my prof's work. I have to come up with a matlab code to convert an image file in a jpg format and convert it into an audio file. I also want to know how to convert it back to the original image, using the image as the input. My prof wants me to modulate it in BPSK, he doesn't want OFDM or any amplitude modulation. Basically, he explained it to me as : take an image, convert it into an array form, convert array into sine wave, then to audio, transmit it, receive it in another system, get back original image.
I'm not very good in using matlab, please help...
  4 Commenti
Walter Roberson
Walter Roberson il 23 Ago 2015
It seems to me if that were the task then audio would not have been mentioned.
Sounds to me more like a homework assignment than something a prof would work on, at least not without discussion of number of channels and progressive image encoding techniques and error correction codes...
Jesús Antonio Cubillos Manrique
Hi, Can you make it?, It's my project and I don't have idea how make it, if you can help me, I'll thank with you, I hope that you have a good day!

Accedi per commentare.

Risposte (3)

Image Analyst
Image Analyst il 19 Dic 2019
Did anyone even attempt anything? What happened if you did something similar to this:
% Initialization / clean-up code.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Create the filename where we will save the waveform.
folder = pwd;
baseFileName = 'Test_Wave.wav';
fullFileName = fullfile(folder, baseFileName);
fprintf('Full File Name = %s\n', fullFileName);
titleBarCaption = 'Continue?';
% Set up the time axis:
Fs = 8000;
duration = 2; % seconds.
t = 1 : duration * Fs; % 2 seconds
% Set up the period (pitch, frequency):
T = 13; % Constant pitch if you use this.
% Create the maximum amplitude:
Amplitude = 32767;
% Read in an image.
fileName = 'pout.tif';
grayImage = imread(fileName);
% Display the gray scale image.
subplot(2, 2, 1);
imshow(grayImage);
title(fileName, 'FontSize', fontSize);
% Threshold it
binaryImage = imbinarize(grayImage);
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
% Construct the waveform:
y = int16(Amplitude .* sin(2.*pi.*t./T));
% y = abs(int16(Amplitude .* sin(2.*pi.*x./T)));
% Plot the waveform:
subplot(2, 2, 2);
plot(t, y, 'b-');
title('Original Waveform', 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
fprintf('Writing file %s...\n', fullFileName);
% Play the original sound.
player = audioplayer(y, Fs);
play(player);
% Make the binary signal for BPSK the same size as the image.
phase = imresize(binaryImage(:), [length(y), 1]);
% Invert the signal wherever the binary image is 1
y(phase) = -y(phase);
% Plot the waveform:
subplot(2, 2, 4);
plot(t, y, 'b-');
title('Altered Waveform', 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
grid on;
% Write the waveform to a file:
audiowrite(fullFileName, y, Fs);
promptMessage = sprintf('That was the original sound.\nClick OK to play the altered sound.');
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Quit', 'OK');
if strcmpi(button, 'Quit')
return;
end
% Play the sound as many times as the user wants.
playAgain = true;
counter = 1;
while playAgain
% Play the sound that we just created.
fprintf('Playing file %s %d times...\n', fullFileName, counter);
player = audioplayer(y, Fs);
play(player);
% Ask user if they want to play the sound again.
promptMessage = sprintf('You have played the altered sound %d times.\nDo you want to play the altered sound again?', counter);
button = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
if strcmpi(button, 'No')
playAgain = false;
break;
end
counter = counter + 1;
end
% Alert user that we are done.
message = sprintf('Done playing %s.\n', fullFileName);
fprintf('%s\n', message);
promptMessage = sprintf('Done playing %s.\nClick OK to close the window\nor Cancel to leave it up.', fullFileName);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'OK', 'Cancel', 'OK');
if strcmpi(button, 'OK')
close all; % Close down the figure.
end
  7 Commenti
Sittisat Chaiyahan
Sittisat Chaiyahan il 19 Dic 2021
Modificato: Sittisat Chaiyahan il 19 Dic 2021
sorry to ask But I want to know the frequency of the original waveform what is the value And it depends on which variable? Fs, T please and the last question % Make the binary signal for BPSK the same size as the image. phase = imresize(binaryImage(:), [length(y), 1]); % Invert the signal wherever the binary image is 1 y(phase) = -y(phase); * how it work **
Walter Roberson
Walter Roberson il 19 Dic 2021
Images do not have a frequency.
The audio file is being written according to the value of Fs, which the code arbitrarily assigns as
% Set up the time axis:
Fs = 8000;
You can change the Fs value to change the frequency.
% Make the binary signal for BPSK the same size as the image.
phase = imresize(binaryImage(:), [length(y), 1]);
% Invert the signal wherever the binary image is 1
y(phase) = -y(phase);
At that point, y is the carrier signal, constructed for Fs frequency and duration seconds. length(y) is the number of samples in the carrier frequency. imresize is then told to resize the binary image to have the same number of entries as the carrier signal has entries. This is a "lossy" conversion of the image.
My interpretation of the requirements of the project are quite different than what Image Analyst has implemented, so this is not code that I would write for the purpose.

Accedi per commentare.


Jesús Antonio Cubillos Manrique
Image Analyst, Good Afternoon
I have to make a project in my university where I have to send an image through Audio port. Thanks for you I can use the Transmisor because it generate the principal signal. Now, I have to try make the Receptor. Maybe can you help me please.
Thanks.
Good Wishes.
  1 Commento
Image Analyst
Image Analyst il 22 Gen 2020
I don't have code for that. I'd have to figure it out just like you would.

Accedi per commentare.


Sittisat Chaiyahan
Sittisat Chaiyahan il 27 Ott 2021
Hello Image Analyst,
I'm interested in your code but I have a question.
If I want to convert audio files To return to the original image that I put in, can I do it? please guide me
Thank you very much :) :)
  1 Commento
Walter Roberson
Walter Roberson il 27 Ott 2021
It is something that it is possible to do.
First you write code that takes an array of data samples and converts it back to an image. You test it with an array of data that you converted from image to array but have not yet written to file. Then once you have that working, you put in the step of writing to file and reading it back from file.

Accedi per commentare.

Categorie

Scopri di più su Signal Processing in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by