Image hidding using DWT

2 vues (au cours des 30 derniers jours)
Karbala'a Unvi. Science
Karbala'a Unvi. Science le 15 Juin 2024
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 commentaires
Image Analyst
Image Analyst le 17 Juin 2024
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
Karbala'a Unvi. Science
Karbala'a Unvi. Science le 17 Juin 2024
Thank you for your responed.
1- The erorr is in the IDWT where the images and the matrix is not compatable
2- PSNR and MSE are not givinig a good values for the hidding
Pleace tell me if the code is not correct or there is a slution for that
Welling to here from you

Connectez-vous pour commenter.

Réponse acceptée

Umar
Umar le 18 Juin 2024
Modifié(e) : Walter Roberson le 19 Juin 2024
% 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 commentaires
Umar
Umar le 19 Juin 2024
the reconstruction of the stego image needs to be corrected. The correct wavelet coefficients should be used to reconstruct the stego image accurately.
Karbala'a Unvi. Science
Karbala'a Unvi. Science le 19 Juin 2024
thank you for the help

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Multiresolution Analysis dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by