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) < kdct_block(5,2)=dct_block(5,2)+(k/2);dct_block(4,3)=dct_block(4,3)-(k/2); end elseif dct_block(4,3) - dct_block(5,2) < kdct_block(4,3)=dct_block(4,3)+(k/2);dct_block(5,2)=dct_block(5,2)-(k/2);endend watermarked_image(y:y+blocksize-1,x:x+blocksize-1)=idct2(dct_block); if (x+blocksize) >= Ncx=1;y=y+blocksize;else x=x+blocksize; end endwatermarked_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')
MATLAB: How to convert invisible watermark to visible watermark? Please help
dctMATLAB
Related Question
- ??? Index exceeds matrix dimensions.
- I am trying to implement LSB watermarking in matlab.But i am getting the error=> Assignment has more non-singleton rhs dimensions than non-singleton subscripts Error in ==> watermarked_image(ii,jj)=bitset(watermarked_image,1,watermark(ii,jj))
- How to hide an image into a cover image using LSB
Best Answer