dwt dct steganography code problem

20 views (last 30 days)
Maulana Wahid
Maulana Wahid on 2 Feb 2014
Commented: Image Analyst on 16 Jan 2019
i have problem with my image steganography using dwt and dct. i want to embed image using dct in level 2 dwt. but everytime i extract the image, it only shows noise instead proper image. but if i use level 1 dwt, the image will be extracted properly. in this code i'm using dwt2() to decompose image.
does anyone know how to implement level 2 dwt in this code? in this code i'm using dwt2(), which is single level dwt, to create level 2 dwt but it doesn't work.
here is my embedding process code :
clear;
clc;
cover = imread('airport.jpg');
[a1 h1 v1 d1] = dwt2(cover,'haar');
[a2 h2 v2 d2] = dwt2(h1,'haar');
k=50; % set minimum coeff difference
blocksize=8; % set the size of the block in cover to be used for each bit in watermark
cover_object=h2;
%figure,imshow(cover);title('Original');
% determine size of cover image
Mc=size(cover_object,1); %Height
Nc=size(cover_object,2);
% determine maximum message size based on cover object, and blocksize
max_message=Mc*Nc/(blocksize^2);
% read in the message image
msg='mri.jpg';
message=double(imread(msg));
Mm=size(message,1); %Height
Nm=size(message,2); %Width
% reshape the message to a vector
message=round(reshape(message,Mm*Nm,1)./256);
% check that the message isnt too large for cover
if (length(message) > max_message)
error('Message too large to fit in Cover Object');
% display(length(message));
% display(max_message);
end
% pad the message out to the maximum message size with ones
message_pad=ones(1,max_message);
message_pad(1:length(message))=message;
% generate shell of watermarked image
watermarked_image=cover_object;
% process the image in blocks
% encodes such that (5,2) > (4,3) when message(kk)=0
% and that (5,2) < (4,3) when message(kk)=1
x=1;
y=1;
for (kk = 1:length(message_pad))
% transform block using DCT
dct_block=dct2(cover_object(y:y+blocksize-1,x:x+blocksize-1));
% if message bit is black, (1,2) > (2,1)
if (message_pad(kk) == 0)
% if (1,2) < (1,1) then we need to swap them
if (dct_block(5,2) < dct_block(4,3))
temp=dct_block(4,3);
dct_block(4,3)=dct_block(5,2);
dct_block(5,2)=temp;
end
% if message bit is white, (1,2) < (2,1)
elseif (message_pad(kk) == 1)
% if (1,2) > (2,1) then we need to swap them
if (dct_block(5,2) >= dct_block(4,3))
temp=dct_block(4,3);
dct_block(4,3)=dct_block(5,2);
dct_block(5,2)=temp;
end
end
% now we adjust the two values such that their difference >= k
if dct_block(5,2) > dct_block(4,3)
if dct_block(5,2) - dct_block(4,3) < k
dct_block(5,2)=dct_block(4,3)+(k/2);
dct_block(4,3)=dct_block(5,2)-(k/2);
end
else
if dct_block(4,3) - dct_block(5,2) < k
dct_block(4,3)=dct_block(5,2)+(k/2);
dct_block(5,2)=dct_block(4,3)-(k/2);
end
end
% transform block back into spatial domain
watermarked_image(y:y+blocksize-1,x:x+blocksize-1)=idct2(dct_block);
% move on to next block. At and of row move to next row
if (x+blocksize) >= Nc
x=1;
y=y+blocksize;
else
x=x+blocksize;
end
end
% convert to uint8 and write the watermarked image out to a file
watermarked_image_int=uint8(watermarked_image);
h2 = watermarked_image;
y1=idwt2(a2,h2,v2,d2,'haar');
y2=idwt2(a1,h1,v1,d1,'haar');
imwrite(uint8(y2),'stegano.jpg','jpg');
PSNR(cover,y2)
% display watermarked image
subplot(2,2,1),imshow(cover);title('Original');
subplot(2,2,2),imshow(imread(msg));title('Pesan');
subplot(2,2,3),imshow(y2,[]);title('Stegano Image');
here is my extraction process :
clear;
clc;
cover = imread('stegano.jpg');
[a1 h1 v1 d1]= dwt2(cover,'haar');
[a2 h2 v2 d2]= dwt2(h1,'haar');
start_time=cputime;
blocksize=8;
% determine size of watermarked image
Mw=size(h2,1); %Height
Nw=size(h2,2); %Width
% determine maximum message size based on cover object, and blocksize
max_message=Mw*Nw/(blocksize^2);
% read in original watermark
file_name='logo.jpg';
orig_watermark=double(imread(file_name));
% determine size of original watermark
Mo=size(orig_watermark,1); %Height
No=size(orig_watermark,2); %Width
% process the image in blocks
x=1;
y=1;
for (kk = 1:max_message)
% transform block using DCT
dct_block=dct2(h2(y:y+blocksize-1,x:x+blocksize-1));
% if dct_block(5,2) > dct_block(4,3) then message(kk)=0
% otherwise message(kk)=1
if dct_block(5,2) > dct_block(4,3)
message_vector(kk)=0;
else
message_vector(kk)=1;
end
% move on to next block. At and of row move to next row
if (x+blocksize) >= Nw
x=1;
y=y+blocksize;
else
x=x+blocksize;
end
end
% reshape the embeded message
message=reshape(message_vector(1:Mo*No),Mo,No);
% display processing time
elapsed_time=cputime-start_time,
% display recovered message
figure(2)
imshow(uint8(message),[])
title('Recovered Message')
  1 Comment
vaishali
vaishali on 6 Nov 2014
message=round(reshape(message,Mm*Nm,1)./256); is giving error like "To RESHAPE the number of elements must not change.". What is the solution for that?

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 2 Feb 2014
Try imshow(yourArray, []). Unless you have the [] it's possible the display could look like garbage.
  4 Comments
Image Analyst
Image Analyst on 5 Apr 2015
Sorry, I don't have the wavelet toolbox. I was answering only a possible solution to "it only shows noise instead proper image", which can happen if you have a floating point image instead of a uint8 image. I can't help with wavelet problems. It seems like Wayne King is the only one who does that and he hasn't been too active here lately. You might want to call tech support if you have an error or syntax problem, but not with algorithm development questions.
Animesh Angrish
Animesh Angrish on 8 Nov 2016
Edited: Walter Roberson on 8 Nov 2016
Please ignore if already solved
This is not the correct way for a 2nd level DWT
[a1 h1 v1 d1] = dwt2(cover,'haar');
[a2 h2 v2 d2] = dwt2(h1,'haar');
Use instead
[a1 h1 v1 d1] = dwt2(cover,'haar');
[a2 h2 v2 d2] = dwt2(a1,'haar');
Because 2nd level decomposition happens in the approximation coefficient part not horizontal detailing
hope this would help

Sign in to comment.


Vinod Mangalore
Vinod Mangalore on 13 Nov 2016
Edited: Walter Roberson on 13 Nov 2016
message=double(imread(msg));
Mm=size(message,1);
Nm=size(message,2);
message=round(reshape(message,Mm*Nm,1)./256); ERROR- "To RESHAPE the number of elements must not change."
can anyone tell me the solution??
  5 Comments
rafika brahmi
rafika brahmi on 16 Jan 2019
can someone help me , i run the same code i don't have the same logo in the extraction part please help me
Image Analyst
Image Analyst on 16 Jan 2019
Possibly. Please do something to allow people to help you.

Sign in to comment.

Categories

Find more on Discrete Multiresolution Analysis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!