Effacer les filtres
Effacer les filtres

Watermarking using DCT: For embedding an image into another image and extracting the same.

2 vues (au cours des 30 derniers jours)
I am getting following error while executing my code.
Error:
Index exceeds matrix dimensions.
Error in sheza (line 42)
dct_block=dct2(cover_object(y:y+blocksize-1,x:x+blocksize-1));
My code is:
clc;
clear all;
start_time=cputime;
k=50;
blocksize=8;
file_name='leena.jpg';
% cover_object=double(rgb2gray(imread(file_name)));
cover_image = imread(file_name);
cover_object = double(cover_image(:,:,1)); %red plane
Mc=size(cover_object,1);
Nc=size(cover_object,2);
max_message=Mc*Nc/(blocksize^2);
file_name='football.jpg';
message=double(rgb2gray(imread(file_name)));
Mm=size(message,1);
Nm=size(message,2);
len=length(message);
message=round(reshape(message,Mm*Nm,1)./256);
if (len > max_message)
error('Message too large to fit in Cover Object')
end
message_pad=ones(1,max_message);
message_pad(1:length(message))=message;
watermarked_image_r=cover_object;
x=1;
y=1;
for(kk = 1:length(message_pad))
dct_block=dct2(cover_object(y:y+blocksize-1,x:x+blocksize-1));
if (message_pad(kk) == 0)
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
elseif (message_pad(kk) == 1)
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
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(5,2)+(k/2);
dct_block(4,3)=dct_block(4,3)-(k/2);
end
else
if dct_block(4,3) - dct_block(5,2) < k
dct_block(4,3)=dct_block(4,3)+(k/2);
dct_block(5,2)=dct_block(5,2)-(k/2);
end
end
watermarked_image(y:y+blocksize-1,x:x+blocksize-1)=idct2(dct_block);
if (x+blocksize) >= Nc
x=1;
y=y+blocksize;
else
x=x+blocksize;
end
end
watermarked_image_int=uint8(watermarked_image);
watermarked_red = cast(watermarked_image, class(cover_image));
watermarked_image = cat(3, watermarked_red, cover_image(:,:,[2 3]));
imwrite(watermarked_image_int,'dct1_watermarked_circuit.jpg','jpg');
elapsed_time=cputime-start_time;
subplot(211);imshow(cover_object,[]);title('Original Image')
subplot(212);imshow(watermarked_image,[]);title('Watermarked Image')
Kindly help to get out of this or plz provide me some code for watermarking using DCT for embedding an image into another image.
  3 commentaires
mustafa khalil
mustafa khalil le 19 Mar 2022
Please provide the code for the return process?
DGM
DGM le 20 Mar 2022
An account that was used once and has since been inactive for 8 years isn't going to come back to life and give you a complete working solution.
I'm pretty sure there are examples on the File Exchange, if there aren't on the forum.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by