How to convert invisible watermark to visible watermark? Please help

clc;
clear all;
start_time=cputime;
k=50;
blocksize=8;
file_name1='C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg';
%cover_object=double(rgb2gray(imread(file_name1)));
cover_image = imread(file_name1);
cover_object = double(cover_image(:,:,1)); %red plane
Mc=size(cover_object,1);
Nc=size(cover_object,2);
max_message = floor(Mc/blocksize) * floor(Nc/blocksize);
%max_message=Mc*Nc/(blocksize^2);
file_name2='C:\Users\Public\Pictures\Sample Pictures\desert1.jpg';
message=double(rgb2gray(imread(file_name2)));
Mm=size(message,1);
Nm=size(message,2);
message=round(reshape(message,Mm*Nm,1)./256);
if (length(message) > 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,'C:\Users\Public\Pictures\Sample Pictures\dct1_watermarked_circuit.jpg','jpg');
elapsed_time=cputime-start_time,
subplot(2,1,1);imshow(cover_image,[]);title('Original Image')
subplot(2,1,2);imshow(watermarked_image,[]);title('Watermarked Image')

6 commentaires

Lester, do you realise that in all of your questions you have:
  1. Stated an ambiguous question in the heading
  2. Pasted a large chunk of code that nobody can run. (we don't have your file_name1, file_name2, etc)
  3. Pasted your code unformatted (I think Walter has come around and cleaned it up each time)
  4. Provided no further text clarifying your question
  5. Provided no further information about what is actually wrong (error messages etc)
It will be a long and tedious process if we need to ask the same questions every time (what do you mean invisible? what have you done? where does it error? what is the error? ...)
Do not remove all loaded functions from the memory by "clear all", when you do not need to waste time by reimporting them slowly from the harddisk. Either use a function to keep your workspace clean, or delete at least the variables only by "clear" without "all".
Lester
Lester le 6 Mar 2013
Modifié(e) : Lester le 6 Mar 2013
Dear sir,
The problem we are facing is as follows:
-When we are embedding the watermark onto an image we are not being able to see if the watermark gets embedded on the image....so we are not really sure if the embedding is taking place.
-file_name1 and file_name2 can be any colored image in bmp format.
Then just compare the image to the original image. If they are different then something has been modified.
okay sir did that. There is this another query. What line of code should we add/remove in order to have the extracted image in the RGB format?
Currently we are getting the extracted image in the gray format.
clc;
clear all;
start_time=cputime;
blocksize=8;
file_name1='C:\Users\Public\Pictures\Sample Pictures\dct1_watermarked_circuit.jpg';
watermarked_image=(imread(file_name1));
cover_object = double(watermarked_image(:,:,1)); %red plane
Mw=size(watermarked_image,1);
Nw=size(watermarked_image,2);
max_message = floor(Mw/blocksize) * floor(Nw/blocksize); % floor rounds of the integer values
% max_message=Mw*Nw/(blocksize^2);
file_name2='C:\Users\Public\Pictures\Sample Pictures\tulips.jpg';
orig_watermark=imread(file_name2);
Mo=size(orig_watermark,1);
No=size(orig_watermark,2);
x=1;
y=1;
for (kk = 1:max_message)
dct_block=dct2(watermarked_image(y:y+blocksize-1,x:x+blocksize-1));
if dct_block(5,2) > dct_block(4,3)
message_vector(kk)=0;
else
message_vector(kk)=1;
end
if (x+blocksize) >= Nw
x=1;
y=y+blocksize;
else
x=x+blocksize;
end
end
message=reshape(message_vector(1:Mo*No),Mo,No);
elapsed_time=cputime-start_time,
subplot(212);imshow(message,[]);title('Recovered Message')
subplot(211);imshow(watermarked_image,[]);title('Watermarked Image')
We went through this earlier. After you have watermarked the red plane, cat(3) it with the original G and B planes in order to get a colour image out.

Connectez-vous pour commenter.

 Réponse acceptée

Instead of affecting the least significant bit, affect a higher bit. Keep going for higher bits until you find the one that makes the watermark acceptably visible.

5 commentaires

Sir,
which line of code should I change inorder to make the watermark visible?
And while embedding the watermark on the host image what does the variable 'k' stand for?
Also the block size is 8 ; why is it only 8?
And Sir can u plz explain to us the if else loop( why are we only taking
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;
Is there any significance in taking only dct_block(5,2)?
thank you
Walter Roberson
Walter Roberson le 7 Mar 2013
Modifié(e) : Walter Roberson le 7 Mar 2013
What did you intend "k" to mean when you wrote the code? Why did you write dct_block(5,2) < dct_block(4,3) if you did not know why you were doing it? Why did you choose a blocksize of 8 ?
Lester
Lester le 7 Mar 2013
Modifié(e) : Lester le 7 Mar 2013
Sir,
I have found this code on mathworks and it was according to my requirements(DCT domain).
This is the first time I am working on matlab.....so I am not really familiar with the functions and tools of matlab
Your help would be most appreciated.
Ask the author of the code you found, or write the code yourself (as you were likely intended to do when you were assigned the project.)
Sir,
Thank you for your help

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 4 Mar 2013
Why don't you just take the average of the two images?

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by