Need a help in this code

5 次查看(过去 30 天)
Hi every one,
I wrote this code trying to embed and image as a secret image in a 2nd DWT level cover image by anding the secret image directly in the 2nd HH image
and that is working but reasambling the imag is not working with me, becouse the PSNR and MSE is giving zero and infinity and the images is attached to this Question.
I am donig this code for a reserch for me help is need ASAP
Thanks in advance
the code is :
clc, clear all, close all
%reading the cover image and difene the pixels
I = imread('67.bmp');
cover_image=I(:,:,1);
figure, imshow (cover_image);
% transforming (Cover_imag) into red chanal , later into blue chanal, to
% detected the difference in between.
R_imag = cover_image(:,:,1);
% now detect the eyes to be the madia to cary the information
EyeDetect = vision.CascadeObjectDetector('EyePairsmall');
BB = step(EyeDetect,R_imag);
hold on
rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','b');
Y = imread('10-12.jpg');
Y1 = Y(:,:,3);
figure(4),imshow(uint8(Y1)); title('Stego image');
Y2 = imresize(Y1,[200 200]);
%% Apply the DWT on the left eye to hide the data at the HH2 level of the
% Haar wavelet transformation using addtion directly when detecting the left
% eye which is a croped area from the face
x=length(BB(:,4));
%To detect Eyes
I2 = imcrop(R_imag,BB(x,:));
figure,imshow(I2);
rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','b');
%To detect the left
na1 = I2(:, 1 : floor(end/2.3));
%figure,imshow(na1);
%%here the left eye is the croped area and we can resize the left eye image
% and find the HH2 to make it ready for work
% converting the Left Eye into DWT and get the HH2
cc= imresize (na1,[400 400]); %# resize the image to be squear;
n = 256; %# Number of values per color component
Level = 2; %# Number of decompositions
LL = cell(1,Level); %# Approximation coefficient storage
LH = cell(1,Level); %# Horizontal detail coefficient storage
HL = cell(1,Level); %# Vertical detail coefficient storage
HH = cell(1,Level); %# Diagonal detail coefficient storage
startImage = cc;
for iLevel = 1:Level %# Apply nLevel decompositions
[LL{iLevel},LH{iLevel},HL{iLevel},HH{iLevel}] = dwt2(startImage,'haar');
startImage = LL{iLevel};
end
tiledImage = wcodemat(LL{Level},n);
for iLevel = Level:-1:1
tiledImage = cat(1,cat(2,tiledImage,...
wcodemat(LH{iLevel},n)),...
cat(2,wcodemat(HL{iLevel},n),...
wcodemat(HH{iLevel},n)));
end
figure;
imshow(uint8(tiledImage-1)); %# Convert to unsigned 8-bit integer to display
rr=(HH{1});
whos rr;
whos Y2
%%
rr2 = im2uint8(rr);
figure,imshow(uint8(rr2));
HH_Ori = rr2+ Y2;
figure, imshow (HH_Ori);
rr2 = HH_Ori;
imwrite(rr2,'HH_Ori.bmp')
%%%%%%% try to reconstruct the image %%%%%%%%%%%%%%%%%
HH_Ori = HH{1};
fullRecon =R_imag;
for i = n:1
fullRecon = idwt2(LL{i},LH{i},HL{i},fullRecon,'Haar');
end
whos fullRecon
figure(112),imshow(uint8(fullRecon));
%% Now applying PSNR & MSE %%%%%%%%%%%5
[rows, columns] = size(R_imag);
squaredErrorImage = (double(R_imag) - double(fullRecon)) .^ 2;
subplot(2, 2, 1);
imshow((squaredErrorImage, []));
title('Squared Error Image');
mse = sum(sum(squaredErrorImage)) / (rows * columns);
% Calculate PSNR (Peak Signal to Noise Ratio) from the MSE according to the formula.
PSNR = 20 * log10( (255) / mse);
% Alert user of the answer.
message = sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', mse, PSNR);
msgbox(message);
  2 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2019-10-18
编辑:KALYAN ACHARJYA 2019-10-18
becouse the PSNR and MSE is giving zero
Check the values of image and reference image? It can be easly detect.
Karbala'a Unvi. Science
Hi Sir,
Thank you for your respond to me but I replaced the two lines with function (psnr,immse) and the results is (inf and 0.0 ) and that dont make it right,
hope you see if it is doing the same with you and if the code is doing bad when reterning the 2nd HH image into the R_imag and?
hope you the best
Thank you in advance

请先登录,再进行评论。

采纳的回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019-10-19
Hi,
problem is in your loop set up:
for i = n:1 % <---- ERROR
fullRecon = idwt2(LL{i},LH{i},HL{i},fullRecon,'Haar');
end
Good luck.

更多回答(1 个)

Karbala'a Unvi. Science
编辑:Karbala'a Unvi. Science 2019-10-19
Hi for you to,
thank you for your respond.
Do you mean that the second loop is needed to be for 2 to get the second HH image togeather with the image?
you mean
for i = n:2
fullRecon = idwt2(LL{i},LH{i},HL{i},fullRecon,'Haar');
end
that is the right way to do this part of the code?
Sorry for that question becouse I am not profissional in programing and that is one of may shots to write such code.
and i did what you said but stil giving me the same thing as in the image inf.jpg
Thank for your help

类别

Help CenterFile Exchange 中查找有关 Discrete Multiresolution Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by