I am embedding audio into an DICOM Image using DCT Method .But after extraction am not able to extract the original Audio.
Show older comments
% Embed and Extract Audio using DCT-based Steganography in DICOM Image
% Read the DICOM image file
dicomInfo = dicominfo('ID_0000_AGE_0060_CONTRAST_1_CT.dcm'); % Replace with your DICOM image file
dicomImage = dicomread(dicomInfo);
% Read the audio file
[audio, sampleRate] = audioread('original_audio.wav'); % Replace 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 DICOM image into a single column vector
dicomVector = double(dicomImage(:));
% Calculate the maximum number of audio samples that can be hidden in the image
maxSamples = numel(dicomVector);
% Check if the audio file exceeds the capacity of the DICOM image
if numSamples > maxSamples
error('Audio file too large to hide in the DICOM image.');
end
% Measure insertion time
insertionStartTime = tic;
% Perform DCT on DICOM image blocks
blockSize = 8; % Size of DCT blocks
dctDicomImage = blockproc(dicomVector, [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(dctDicomImage, 1)
for col = 1:blockSize:size(dctDicomImage, 2)
if audioIndex <= numSamples
dctDicomImage(row, col) = dctDicomImage(row, col) + audio(audioIndex)*10; % Multiply by 10 for amplification
audioIndex = audioIndex + 1;
end
end
end
% Perform inverse DCT on modified DCT DICOM image
idctDicomImage = blockproc(dctDicomImage, [blockSize blockSize], @(block_struct) idct2(block_struct.data));
% Clip the pixel values to the valid intensity range [0, 255]
idctDicomImage(idctDicomImage < 0) = 0;
idctDicomImage(idctDicomImage > 255) = 255;
% Reshape the modified DICOM image vector back to its original size
stegoDicomImage = uint8(reshape(idctDicomImage, size(dicomImage)));
% Save the stego DICOM image
dicomwrite(stegoDicomImage, 'stego_dicom_image.dcm', dicomInfo, 'CreateMode', 'copy');
% Measure insertion time
insertionTime = toc(insertionStartTime);
% Extract audio from the stego DICOM image
stegoDicomVector = double(stegoDicomImage(:));
% Measure extraction time
extractionStartTime = tic;
% Perform DCT on stego DICOM image blocks
dctStegoDicomImage = blockproc(stegoDicomVector, [blockSize blockSize], @(block_struct) dct2(block_struct.data));
% Extract audio from the stego DICOM image
dctOrigDicomImage = blockproc(dicomVector, [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(dctStegoDicomImage, 1)
for col = 1:blockSize:size(dctStegoDicomImage, 2)
if audioIndex <= numSamples
extractedAudio(audioIndex) = (dctStegoDicomImage(row, col) - dctOrigDicomImage(row, col))/10; % Divide by 10 to reverse amplification
audioIndex = audioIndex + 1;
end
end
end
% Measure extraction time
extractionTime = toc(extractionStartTime);
% 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_from_dicom.wav', extractedAudio, sampleRate);
% Convert dicomImage to uint8 for PSNR calculation
dicomImage = uint8(dicomImage);
% Compute PSNR, SSIM, and MSE
psnrValue = psnr(stegoDicomImage, dicomImage);
ssimValue = ssim(stegoDicomImage, dicomImage);
mseValue = immse(stegoDicomImage, dicomImage);
% Display PSNR, SSIM, and MSE values
disp(['PSNR: ', num2str(psnrValue)]);
disp(['SSIM: ', num2str(ssimValue)]);
disp(['MSE: ', num2str(mseValue)]);
% Display insertion and extraction times
disp(['Insertion Time: ', num2str(insertionTime), ' seconds']);
disp(['Extraction Time: ', num2str(extractionTime), ' seconds']);
% Display original and stego images
figure;
% Display original image
subplot(2, 2, 1);
imshow(dicomImage, []);
title('Original DICOM Image');
% Display stego image
subplot(2, 2, 2);
imshow(stegoDicomImage, []);
title('Stego DICOM Image');
% Display original audio signal
subplot(2, 2, 3);
plot(audio);
title('Original Audio Signal');
xlabel('Sample Index');
ylabel('Amplitude');
% Display extracted audio signal
subplot(2, 2, 4);
plot(extractedAudio);
title('Extracted Audio Signal');
xlabel('Sample Index');
ylabel('Amplitude');
Accepted Answer
More Answers (0)
Categories
Find more on DICOM Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!