Sunday 17 June 2012

Embedding a watermark image into a cover image using Matlab program

Find below the Matlab codes to embed a watermark image into a cover(host) image:

clear all; close all; clc;

[filename1,pathname]=uigetfile('*.*','Select the host image'); 
image1=imread(num2str(filename1));
imshow(image1); title('Original image');% orginal image for watermarking

[ori_row,ori_col]=size(image1)
host_length=ori_row*ori_col;

i=1;
j=1;
k=1;

[filename2,pathname]=uigetfile('*.*','Select the watermark image'); 

wmimage=imread(num2str(filename2));
[wm_row,wm_col] = size(wmimage);
imshow(wmimage); title('Watermark image');

wm=dec2bin(wmimage);
wm_length=wm_row*wm_col*8;

host=dec2bin(image1);

counter=0; 

while i < host_length
        
        counter=counter+1;
        
        if counter > wm_length
            break;
        end
        
        host(i,8)=wm(j,k);
        k=k+1;
        
        if k>8
            k=1;
            j=j+1;
        end
        
        i=i+1;
end

    key1=wm_row
    key2=wm_col
   
im1=bin2dec(host);
im1=reshape(im1,ori_row,ori_col);
image1(1:ori_row,1:ori_col)=im1(1:ori_row,1:ori_col);

display 'After embed';

imwrite(image1,'wmarked.bmp'); % saves the watermarked image as a bmp file
imshow(image1);title('Watermarked image');

Popular Posts