Image hidding using DWT
2 次查看(过去 30 天)
显示 更早的评论
Hello every one
I am finding a problime in my code for hidding 325*325 image into 2300*2300 image after decompose it using into HH{3} to get the best PSNR and MSE
and the erroe say that the matrix in not matching.
the code is as follow:-
% Main code
clc
close all;
clear all;
%
a=imgetfile();
coverImage1 = imread(a);
coverImages = imresize(coverImage1,[2600 2600]);
R=coverImages(:,:,1); %red = 1, green = 2, blue = 3
G=coverImages(:,:,2);
B=coverImages(:,:,3);
coverImage=B;
% figure;
% imshow(coverImage);
% title('Blue Image');
%%%%%
b=imgetfile();
secretImage1 = imread(b);
%secretImage=B1;
secretImage= rgb2gray(secretImage1);
secretImage = imresize(secretImage,[1300 1300]);
row = size(secretImage,1);
col = size(secretImage,2);
s = row*col;
%secretImage = imresize(secretImage,[280 280]);
% figure(1); imshow (coverImages)
% figure(2); imshow (secretImage)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Perform DNA encryption on the secret image
key = randi([0, 255], size(secretImage)); % Generate random key
encryptedImage = DNAEncrypt(secretImage, key);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nColors = 256;
n =3 ; %# Number of decompositions
LL = cell(1,n); %# Approximation coefficient storage
LH = cell(1,n); %# Horizontal detail coefficient storage
HL = cell(1,n); %# Vertical detail coefficient storage
HH = cell(1,n); %# Diagonal detail coefficient storage
X = coverImage ;
for i = 1:n %# %# Apply nLevel decompositions
[LL{i},LH{i},HL{i},HH{i}] = dwt2(X,'Haar');
X = LL{i}; % gives you the last quarter of the image
end
%coverImage = LL{i}; % gives you the last quarter of the image
%alpha = 0.02; % Embedding strength
OO= HH{1}; OOO = HH{2}; OOOO=HH{3};% here I want to get the need HH{1,2,3} for the good hidding
%%
HH_embedded = HH{1} + ( encryptedImage);
stegoImage = idwt2(LL{i}, LH{i}, HL{i}, HH_embedded, 'haar');
imshow(uint8(stegoImage));
% %%
% tiledImage = wcodemat(LL{n},nColors);
% for i = n:-1:1
% tiledImage = cat(1,cat(2,tiledImage,...
% wcodemat(LH{i},nColors)),...
% cat(2,wcodemat(HL{i},nColors),...
% wcodemat(HH{i},nColors)));
% end
% figure(1);imshow(uint8(tiledImage-1));
%%
B2=uint8(stegoImage);
RGB= cat(3, R, G, B2);
stg= double(im2gray(RGB));
% figure (5)
% subplot(1, 2, 1);
% imshow(RGB);
% title('RGB after Analysis');
%%%%
% Display the stego image
figure;
subplot(1, 2, 1);
imshow(coverImages);
title('Cover Image');
subplot(1, 2, 2);
imshow(RGB);
title('Stego Image');
%%%%%%%%%%%%%
%TT = immse(stg, double(coverImage));
mse = sum(sum((coverImage - uint8(stg)) .^ 2)) / numel(coverImage);
% Display the MSE
fprintf('Mean Squared Error (MSE): %.4f\n', mse);
%CC = mse(stgcoverImage);
C = psnr((uint8(stg)),coverImage);
%fprintf('\n The Mean Sq. Erorr value is %0.4f', CC );
fprintf('\n PSNR value is %0.6f', C);
%%
%
I will write the code here and provide you the images, hope to get it down
2 个评论
Image Analyst
2024-6-17
I'm not familiar with your algorithm. Does it expect the cover image and secret image to have the same dimensions? Which line throws the error?
By the way, there is a function for mse: immse
采纳的回答
Umar
2024-6-18
编辑:Walter Roberson
2024-6-19
% Main code
clc
close all; clear all;
a = imgetfile(); coverImage1 = imread(a); coverImages = imresize(coverImage1, [2600 2600]); R = coverImages(:,:,1);
%red = 1, green = 2, blue = 3
G = coverImages(:,:,2); B = coverImages(:,:,3); coverImage = B;
b = imgetfile(); secretImage1 = imread(b); secretImage = rgb2gray(secretImage1); secretImage = imresize(secretImage, [1300 1300]); row = size(secretImage, 1); col = size(secretImage, 2); s = row * col;
key = randi([0, 255], size(secretImage));
% Generate random key
encryptedImage = DNAEncrypt(secretImage, key);
nColors = 256; n = 3; %# Number of decompositions
LL = cell(1, n); %# Approximation coefficient storage
LH = cell(1, n); %# Horizontal detail coefficient storage
HL = cell(1, n); %# Vertical detail coefficient storage
HH = cell(1, n); %# Diagonal detail coefficient storage
X = coverImage;
for i = 1:n %# Apply nLevel decompositions
[LL{i}, LH{i}, HL{i}, HH{i}] = dwt2(X, 'Haar'); X = LL{i};
% gives you the last quarter of the image
end
% Ensure the sizes of LL, LH, HL, and HH match the cover image
LL = cellfun(@(x) imresize(x, size(coverImage)), LL, 'UniformOutput', false); LH = cellfun(@(x) imresize(x, size(coverImage)), LH, 'UniformOutput', false); HL = cellfun(@(x) imresize(x, size(coverImage)), HL, 'UniformOutput', false); HH = cellfun(@(x) imresize(x, size(coverImage)), HH, 'UniformOutput', false);
HH_embedded = HH{1} + encryptedImage; stegoImage = idwt2(LL{i}, LH{i}, HL{i}, HH_embedded, 'haar'); imshow(uint8(stegoImage));
B2 = uint8(stegoImage); RGB = cat(3, R, G, B2); stg = double(im2gray(RGB));
figure; subplot(1, 2, 1); imshow(coverImages); title('Cover Image'); subplot(1, 2, 2); imshow(RGB); title('Stego Image');
mse = sum(sum((coverImage - uint8(stg)) .^ 2)) / numel(coverImage); fprintf('Mean Squared Error (MSE): %.4f\n', mse);
C = psnr(uint8(stg), coverImage); fprintf('\n PSNR value is %0.6f', C);
14 个评论
Umar
2024-6-19
the reconstruction of the stego image needs to be corrected. The correct wavelet coefficients should be used to reconstruct the stego image accurately.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Multiresolution Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!