how can i embed a watermark in an image using least significant bit method?
MATLAB: What is code in matlab to embed and extract a watermark using lsb method
Image Processing Toolboxwatermark
Related Solutions
Well here's my demo. It lets you hide an watermark image, which may be bigger or smaller than a cover image, into a user-specified bitplane of the cover (original) image. If the watermark is bigger than the original image, it scales it down. If the watermark is smaller, it tiles it. The watermark image can be grayscale and you can specify where you want it thresholded at. It uses standard MATLAB demo images. If the images are color, it takes the red channel - I haven't made it to work with color images. At the end it adds noise and recovers the watermark from the noise-free and noisy images, so you can see how lousy this method is as far as being robust to attack.
% Demo to watermark an image by hiding another image in a certain bit
% plane. Sometimes called "LSB Watermarking" or something similar.
% User is asked which bit plane they want to hide the image in.
% By Image Analyst.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 12;% Read in the image what will have another image hidden into it.
baseFileName='moon.tif';% baseFileName='cameraman.tif';
folder = fullfile(matlabroot, '\toolbox\images\imdemos');% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName); uiwait(warndlg(errorMessage)); return; endendoriginalImage = imread(fullFileName);% Get the number of rows and columns in the original image.
[visibleRows visibleColumns numberOfColorChannels] = size(originalImage);if numberOfColorChannels > 1 % If it's color, extract the red channel.
originalImage = originalImage(:,:,1);end% Display the original gray scale image.
subplot(3, 3, 4);imshow(originalImage, []);title('Original Grayscale Starting Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);set(gcf,'name','Demo by ImageAnalyst','numbertitle','off') % read the message image you want to hide in the cover image
baseFileName='cameraman.tif';% baseFileName='moon.tif';
% Get the full filename, with path prepended.fullFileName = fullfile(folder, baseFileName);if ~exist(fullFileName, 'file') % Didn't find it there. Check the search path for it. fullFileName = baseFileName; % No path this time. if ~exist(fullFileName, 'file') % Still didn't find it. Alert user. errorMessage = sprintf('Error: %s does not exist.', fullFileName); uiwait(warndlg(errorMessage)); return; endendhiddenImage = imread(fullFileName);% Get the number of rows and columns in the hidden image.
[hiddenRows hiddenColumns numberOfColorChannels] = size(hiddenImage);if numberOfColorChannels > 1 % If it's color, extract the red channel. hiddenImage = hiddenImage(:,:,1);end% Display the image.
subplot(3, 3, 1);imshow(hiddenImage, []);title('Image to be Hidden', 'FontSize', fontSize);% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(hiddenImage);subplot(3, 3, 2); bar(pixelCount);title('Histogram of image to be hidden', 'FontSize', fontSize);xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;thresholdValue = 70;binaryImage = hiddenImage < thresholdValue;% Display the image.subplot(3, 3, 3);imshow(binaryImage, []);caption = sprintf('Hidden Image Thresholded at %d', thresholdValue);title(caption, 'FontSize', fontSize);% Get the bit plane to hide the image in.
prompt = 'Enter the bit plane you want to hide the image in (1 - 8) ';dialogTitle = 'Enter Bit Plane to Replace';numberOfLines = 1;defaultResponse = {'1'};bitToSet = str2double(cell2mat(inputdlg(prompt, dialogTitle, numberOfLines, defaultResponse)));% If image to be hidden is bigger than the original image, scale it down.
if hiddenRows > visibleRows || hiddenColumns > visibleColumns amountToShrink = min([visibleRows / hiddenRows, visibleColumns / hiddenColumns]); binaryImage = imresize(binaryImage, amountToShrink); % Need to update the number of rows and columns.
[hiddenRows hiddenColumns] = size(binaryImage);end% Tile the hiddenImage, if it's smaller, so that it will cover the original image.
if hiddenRows < visibleRows || hiddenColumns < visibleColumns watermark = zeros(size(originalImage), 'uint8'); for column = 1:visibleColumns for row = 1:visibleRows watermark(row, column) = binaryImage(mod(row,hiddenRows)+1, mod(column,hiddenColumns)+1); end end % Crop it to the same size as the original image.
watermark = watermark(1:visibleRows, 1:visibleColumns);else % Watermark is the same size as the original image.
watermark = binaryImage;end% Display the thresholded binary image - the watermark alone.
subplot(3, 3, 5);imshow(watermark, []);caption = sprintf('Hidden Image\nto be Inserted into Bit Plane %d', bitToSet);title(caption, 'FontSize', fontSize);% Set the bit of originalImage(a copy, actually) to the value of the watermark.
watermarkedImage=originalImage;for column = 1:visibleColumns for row = 1:visibleRows watermarkedImage(row, column)=bitset(originalImage(row, column), bitToSet, watermark(row, column)); endend% Display the image.subplot(3, 3, 6);imshow(watermarkedImage, []);caption = sprintf('Final Watermarked Image\nwithout added Noise');title(caption, 'FontSize', fontSize);% add noise to watermarked image
noisyWatermarkedImage = imnoise(watermarkedImage,'gaussian');% Display the image.subplot(3, 3, 7);imshow(noisyWatermarkedImage, []);caption = sprintf('Watermarked Image\nwith added Noise');title(caption, 'FontSize', fontSize);%====================================================================================
% Now let's pretend we are starting with the watermarked noisy corrupted image.
% We want to recover the watermark.
% Use the known bitplane of watermarked image to recover the watermark.
recoveredWatermark = zeros(size(noisyWatermarkedImage));recoveredNoisyWatermark = zeros(size(noisyWatermarkedImage));for column = 1:visibleColumns for row = 1:visibleRows recoveredWatermark(row, column) = bitget(watermarkedImage(row, column), bitToSet); recoveredNoisyWatermark(row, column) = bitget(noisyWatermarkedImage(row, column), bitToSet); endend% Scale the recovered watermark to 0=255
recoveredWatermark = uint8(255 * recoveredWatermark);recoveredNoisyWatermark = uint8(255 * recoveredNoisyWatermark);% Display the images.
subplot(3, 3, 8);imshow(recoveredWatermark, []);caption = sprintf('Watermark Recovered\nfrom Bit Plane %d of\nNoise-Free Watermarked Image', bitToSet);title(caption, 'FontSize', fontSize);% Display the images.subplot(3, 3, 9);imshow(recoveredNoisyWatermark, []);caption = sprintf('Watermark Recovered\nfrom Bit Plane %d of\nNoisy Watermarked Image', bitToSet);title(caption, 'FontSize', fontSize);msgbox('Done with demo!');
Watermarking might involve using lsb embedding.
The difference between watermarking and steganography is not a big one. Watermarking involves embedding information for the purpose of establishing proof of ownership, or proof that the file has not been altered, or the like. Steganography involves embedding secret information and retrieving it, for whatever reason you might want to do that. Generally speaking, watermarking is permitted to have obvious visible effect on the image but steganography should ideally have no obvious visible effect; however for some of the purposes of watermarking, it is also preferred to have no obvious visible effect. For some of the purposes of watermarking (such as anti-forgery) the embedded information does not have to "convey" anything, it just has to be cross-checks to establish that the image is untouched. Steganography, on the other hand, is always about conveying information. When the purpose of watermarking is to establish ownership, such as hiding a message such as "Copyright 2016 by Jason", then that purpose of watermarking is identical to steganography of hiding the message "Copyright 2016 by Jason".
Steganography concentrates more on hiding information. Watermarking typically concentrates more on authentication and integrity -- and sometimes watermarking wants to be obvious, such as those sample images from Shutterstock that have "Shutterstock" scrawled on them to make it obvious that the sample image has not been paid for. Shutterstock might well have two watermarking procedures, one that it applies to paid images and one that it applies to unpaid images, to allow it to crawl the internet and find people who are not paying and to track the spread of its images.
Other than that, the techniques can be very very similar. It is more a question of what you do with the information you embed than a matter of different ways of embedding.
Best Answer