- Embedding: Instead of adding the audio samples directly to the DCT coefficients, store the difference between the modified DCT coefficient and the original DCT coefficient.
- Extraction: Extract the audio samples by calculating the difference between the DCT coefficients of the stego image and the original image.
I am embedding and Extracting the audio from the image.I used the following code.But after extracting the audio files from the image.I am not getting same audio file ?Help me.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% Embed and Extract Audio using DCT-based Steganography
% Read the image file
image = imread('glioma.jpg'); % Replace 'glioma.jpg' with your image file
% Read the audio file
[audio, sampleRate] = audioread('button-35.wav'); % Replace 'button-1.wav' with your audio file
% Normalize audio to the range of -1 to 1
audio = audio / max(abs(audio));
% Get the number of audio samples
numSamples = numel(audio);
% Flatten the image into a single column vector
imageVector = double(image(:));
% Calculate the maximum number of audio samples that can be hidden in the image
maxSamples = floor(numel(imageVector) / 2);
% Check if the audio file exceeds the capacity of the image
if numSamples > maxSamples
error('Audio file too large to hide in the image.');
end
% Perform DCT on image blocks
blockSize = 8; % Size of DCT blocks
dctImage = blockproc(imageVector, [blockSize blockSize], @(block_struct) dct2(block_struct.data));
% Embed audio samples in the DCT coefficients
audioIndex = 1; % Index of audio sample
for row = 1:blockSize:size(dctImage, 1)
for col = 1:blockSize:size(dctImage, 2)
if audioIndex <= numSamples
dctImage(row, col) = dctImage(row, col) + audio(audioIndex);
audioIndex = audioIndex + 1;
end
end
end
% Perform inverse DCT on modified DCT image
idctImage = blockproc(dctImage, [blockSize blockSize], @(block_struct) idct2(block_struct.data));
% Clip the pixel values to the valid intensity range [0, 255]
idctImage(idctImage < 0) = 0;
idctImage(idctImage > 255) = 255;
% Reshape the modified image vector back to its original size
stegoImage = uint8(reshape(idctImage, size(image)));
% Save the stego image
imwrite(stegoImage, 'stego_image.png'); % Replace 'stego_image.png' with your desired stego image file name
% Extract audio from the stego image
stegoVector = double(stegoImage(:));
% Perform DCT on stego image blocks
dctStegoImage = blockproc(stegoVector, [blockSize blockSize], @(block_struct) dct2(block_struct.data));
% Extract audio samples from the DCT coefficients
extractedAudio = zeros(numSamples, 1); % Initialize the extracted audio array
audioIndex = 1; % Index of extracted audio sample
for row = 1:blockSize:size(dctStegoImage, 1)
for col = 1:blockSize:size(dctStegoImage, 2)
if audioIndex <= numSamples
extractedAudio(audioIndex) = dctStegoImage(row, col);
audioIndex = audioIndex + 1;
end
end
end
% Rescale extracted audio to the original range
extractedAudio = extractedAudio - mean(extractedAudio);
extractedAudio = extractedAudio / max(abs(extractedAudio));
extractedAudio = extractedAudio * max(abs(audio));
% Save the extracted audio
audiowrite('extracted_audio.wav', extractedAudio, sampleRate);
0 commentaires
Réponse acceptée
Shubh Dhyani
le 8 Août 2023
Hi Ramya,
I understand that you're having issues with audio steganography in an image using DCT coefficients, resulting in discrepancies between the original and extracted audio.
The approach you're using involves embedding audio samples in the DCT coefficients of the image blocks. However, while embedding, you're directly adding the audio samples to the DCT coefficients and then trying to extract the audio samples directly from the DCT coefficients of the stego image.
The main issue here is that the DCT coefficients of the stego image not only contain the embedded audio samples but also the original DCT coefficients of the image. This leads to a discrepancy between the embedded and extracted audio.
Here's how you can modify the code to fix the embedding and extraction process:
Here are the modfications for the embedding and extraction steps:
Embedding:
% Embed audio samples in the DCT coefficients
audioIndex = 1; % Index of audio sample
for row = 1:blockSize:size(dctImage, 1)
for col = 1:blockSize:size(dctImage, 2)
if audioIndex <= numSamples
dctImage(row, col) = dctImage(row, col) + audio(audioIndex)*10; % Multiply by 10 for amplification
audioIndex = audioIndex + 1;
end
end
end
Extraction:
% Extract audio from the stego image
stegoVector = double(stegoImage(:));
dctOrigImage = blockproc(imageVector, [blockSize blockSize], @(block_struct) dct2(block_struct.data));
dctStegoImage = blockproc(stegoVector, [blockSize blockSize], @(block_struct) dct2(block_struct.data));
% Extract audio samples from the difference in DCT coefficients
extractedAudio = zeros(numSamples, 1); % Initialize the extracted audio array
audioIndex = 1; % Index of extracted audio sample
for row = 1:blockSize:size(dctStegoImage, 1)
for col = 1:blockSize:size(dctStegoImage, 2)
if audioIndex <= numSamples
extractedAudio(audioIndex) = (dctStegoImage(row, col) - dctOrigImage(row, col))/10; % Divide by 10 to reverse amplification
audioIndex = audioIndex + 1;
end
end
end
This way, by embedding the difference and extracting using the difference, you should be able to get back the audio with higher fidelity. The amplification factor of 10 is arbitrary and can be adjusted for better results.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!