Digital image watermarking is the method in which data is embedded in a multimedia file such as an image or a video, so as to verify the credibility of the content or the identity of the owner.
%Digital Image Watermarking
%Unmasked Image f
f = imread('angel.jpg');
w = imread('watermark_sym.jpg');
%Visibility of the watermark
Fw = (1-alpha)*f + alpha.*w;
1. Read the image to be watermarked. In my case it ‘s ‘angel.jpg’
2. Read the watermark. Make sure the image size and the watermark size are same.
3. Adjust the alpha value based on your requirement. Alpha can be between 0 and 1. If alpha is less than 0.5 the watermark will be less visible and if the alpha is more than 0.5, the watermark will be clearly visible.
%Read the Blog logo
Logo = imread('Dwatermark2.jpg');
OIm = f;
alpha = 0.5;
%choose a portion of the Image
Sz = [495 927];
OIm(Sz(1):Sz(1)+m-1,Sz(2):Sz(2)+n-1,:)=(1-alpha)*OIm(Sz(1):Sz(1)+m-1,Sz(2):Sz(2)+n-1,:) + alpha.*Logo;
figure,imshow(OIm);title('Watermark in the centre');
1. Read the blog logo.
2. Note: The size of the input image and the logo are not same.
3. Choose a portion in the input image and apply watermark.
LSB Digital Watermarking
In this method, the watermark is hidden in the input image.
Consider a pixel from the input image; say 249 and a pixel from the watermark say, 155.
Now hide the pixel value of the watermark in the two least significant bits of the input image.
1. The binary representation of 249 is 11111001
2. The binary representation of 155 is 10011011
3. Make the two least significant bits of input image value 249 to zeros i.e. 11111000
4. Find the two Most significant bits of the watermark value 155 i.e. 10
5. Now place the two most significant bits of the watermark at the two least significant bits of the input image.
6. 11111000 + 00000010 = 11111010 i.e. 250
%LSB watermarked Image
Fw1 = 4*(f/4) + w/64;
figure,imshow(Fw1);title('LSB watermarked Image');
How to retrieve the watermark:
Subtract the input image (without watermark) from the watermarked Image.
%Retrieve the Watermark
DMark = (Fw1-f)*64;
figure,imshow(DMark);title('Watermark extracted from the image');
Retrieve the two least significant bits of the image
%Retrieve the Watermark
DMark2 = rem(Fw1,4)*64;
figure,imshow(DMark2);title('Watermark extracted from the image');
We can extend the above techniques for steganography or image coding. In the next upcoming post I will share about how to validate the digital watermark.