% Simple DCT Based Watermark Embedding
clear all; close all; clc;
% Initialize the Strength factor
alpha=0.001;
% Get The original Input Image
originalImage=imread('cameraman.tif');
watermarkedImage = zeros(512,512) ;
% Resize the Original Image into 512x512 matrix
inputImage= im2double(imresize(originalImage,[512 512],'bilinear'));
figure,imshow(inputImage),title('BASE IMAGE');
% Get The watermark Input Image
% Resize the Watermark Image into 64x64 matrix
xx=imread('bird.gif');
%xx=rgb2gray(xx);
watermarkImage = im2double(imresize(xx,[64 64],'bilinear'));
figure,imshow(watermarkImage),title('WATERMARK IMAGE');
w = watermarkImage(:)';
r1=1;r2=8; % Initialize the watermark Image Sub-Block row values
c1=1;c2=8; % Initialize the watermark Image Sub-Block column values
count = 0;
for i = 1: 64
for j = 1: 64
count = count +1;
% Retrive 8X8 sub-block from original Image
block = inputImage(r1:r2,c1:c2);
% Aplly DCT to Sub-block
f = dct2(block);
% Apply the Watermark formula f(m,n)*w(x,y)*alpha
f(8,8) = w(count) * alpha;
% Aply Inverse DCT to f
out = idct2(f);
% disp(out);
watermarkedImage(r1:r2,c1:c2) = out;
c1=c1+8;
c2=c2+8;
% disp(count);
end
r1=r1+8;
r2=r2+8;
c1=1;c2=8;
end
res = im2uint8(watermarkedImage);
imwrite(res,'DCTwatermarkedImage.tif','tif');
figure,imshow(res),title('IMAGE AFTER WATERMARKING');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Simple DCT Based Watermark Extracting
% Initialize the Strength factor
alpha=0.001;
w1 = zeros(64,64);
inputImage = watermarkedImage;
r1=1;r2=8; % Initialize the watermark Image Sub-Block row values
c1=1;c2=8; % Initialize the watermark Image Sub-Block column values
count = 0;
for i = 1: 64
for j = 1: 64
count = count +1;
% Retrieve 8X8 sub-block from original Image
block = inputImage(r1:r2,c1:c2);
% Apply DCT to Sub-block
f = dct2(block);
% Apply the Watermark formula f(m,n)*w(x,y)*alpha
w1(count) = f(8,8) / alpha;
c1=c1+8;
c2=c2+8;
end
r1=r1+8;
r2=r2+8;
c1=1;c2=8;
end
op = vec2mat(w1,64);
imshow(op,[]),title('Extracted Watermark Image');
1 comment:
thanx man, thanx a lot i has been in search of for this program from many days.also attched code for performing LPC if u have...u can mail me,......thanx again.
Post a Comment