This is a dct code on watermark embedding. Please fix it

The error I'm encountering is this -->
Warning: Size vector should be a row vector with integer elements.
> In watermarkemb at 27
??? Index exceeds matrix dimensions.
Error in ==> watermarkemb at 36
dct_block=dct2(cover_object(x:x+blocksize-1,y:y+blocksize-1));
This is the code -->
clc;
clear all;
start_time=cputime;
k=50;
blocksize=8;
file_name='scene.jpg';
cover_object=double(rgb2gray(imread(file_name)));
Mc=size(cover_object,1);
Nc=size(cover_object,2);
max_message=Mc*Nc/(blocksize^2);
file_name='fishy.jpg';
message=double(rgb2gray(imread(file_name)));
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);
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')

 채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 27일

0 개 추천

Put in a breakpoint and check the value of max_message

댓글 수: 19

I tweaked the max_message. Now the output is getting cropped.
What did you tweak it to?
Did you resolve the problem with index out of range?
I have no clue how to do with the index problem sir. I tweaked it to this -->
Mc=size(cover_object,1); Nc=size(cover_object,1);
max_message= Mc*Nc/(blocksize^2);
Leave Nc=size(cover_object,2); like you had before, but use
max_message = floor(Mc/blocksize) * floor(Nc/blocksize);
This will also help correct your problem with index out of range.
Thanks a lot sir. It worked. The watermark is invisible. How to make it visible? Is it possible to get the output image in colored format?
Instead of converting to grayscale, you can embed the watermark into one of the color planes, and then put the color planes back together.
Any idea to have a slightly visible watermark sir? As you know the watermark is invisible in our case.
No idea. I do not look at the code about how the watermark is calculated or embedded.
Sir we have done the changes that you had suggested about color planes but what changes should we do in the watermark extraction code so that we get the colored output.
clc;
clear all;
start_time=cputime;
blocksize=8;
file_name='dct1_watermarked_circuit.jpg';
watermarked_image=double(imread(file_name));
Mw=size(watermarked_image,1);
Nw=size(watermarked_image,2);
max_message=Mw*Nw/(blocksize^2);
file_name='lena.jpg';
orig_watermark=double(rgb2gray(imread(file_name)));
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')
No idea. I do not pay attention to how watermarks are calculated or embedded.
this code resulted in the error written below
??? subplot(212);imshow(message,[]);title('Recovered Message') subplot(211);imshow(watermarked_image,[]);title('Watermarked Image')
|
Error: Unexpected MATLAB expression.
please help me rectify it
On the line
elapsed_time=cputime-start_time,
change the comma to semi-colon
elapsed_time=cputime-start_time;
thank you Walter Roberson for your timely response.
Davinderjeet
Davinderjeet 2013년 5월 24일
편집: Davinderjeet 2013년 5월 24일
Walter can you please provide code for DWT watermarking of images.
Davinderjeet
Davinderjeet 2013년 5월 24일
편집: Davinderjeet 2013년 5월 24일
and Walter if you could suggest a good topic related to watermarking that can be persued for m.tech?
As I indicated above, "I do not pay attention to how watermarks are calculated or embedded."
can you please suggest some websites for getting the code???
Davinderjeet
Davinderjeet 2013년 5월 29일
편집: Davinderjeet 2013년 5월 29일
walter roberson please if you could suggest some topic for thesis work or websites which could be of some help. thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Lester
Lester 2013년 2월 27일

0 개 추천

How do you go about embedding the watermark in the color planes? I didn't get you sir

댓글 수: 5

Currently you have
cover_object=double(rgb2gray(imread(file_name)));
Change that to
cover_image = imread(file_name);
cover_object = double(cover_image(:,:,1)); %red plane
Then after you have created watermarked_image but before you write it out,
watermarked_red = cast(watermarked_image, class(cover_image));
watermarked_image = cat(3, watermarked_red, cover_image(:,:,[2 3]));
Lester
Lester 2013년 2월 27일
편집: Lester 2013년 2월 27일
Thank you sir. It worked perfectly fine. You solved all my problems.
hi, m also getting the same error "index exceeds matrix dimensions" in the above code , I have also made the changes told by Walter Roberson i.e.
Currently you have
cover_object=double(rgb2gray(imread(file_name)));
Change that to
cover_image = imread(file_name); cover_object = double(cover_image(:,:,1)); %red plane
Then after you have created watermarked_image but before you write it out,
watermarked_red = cast(watermarked_image, class(cover_image)); watermarked_image = cat(3, watermarked_red, cover_image(:,:,[2 3]));
BUT STILL GETTING THE SAME ERROR. CAN ANYBODY HELP ME.
how to recover watermarking color image?

댓글을 달려면 로그인하십시오.

질문:

2013년 2월 27일

댓글:

2016년 7월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by