make watermark removing autoencoder in matlab

To create a watermark removing autoencoder in Matlab, follow these steps:

  1. Load the watermarked image on Matlab using the "imread" function.
  2. Convert the image to grayscale using the "rgb2gray" function.
  3. Create a noisy image by adding noise to the watermarked image. You can use the "imnoise" function with Gaussian noise to add noise as follows:
main.m
noisyImg = imnoise(Img,'gaussian',0.01);
41 chars
2 lines
  1. Split the noisy image and the watermarked image into patches using the "im2col" function:
main.m
patchSize = 8; % choose patch size
stride = 4; % choose stride
noisyPatches = im2col(noisyImg, [patchSize patchSize], 'sliding');
watermarkedPatches = im2col(Img, [patchSize patchSize], 'sliding');
198 chars
5 lines
  1. Normalize the patches to have zero mean and unit variance.
  2. Create an autoencoder model using the "trainAutoencoder" function in Matlab. Set the number of hidden layers and the number of nodes in the hidden layers to control the complexity of the model based on the size of the patches.
  3. Train the autoencoder using the noisy patches and the watermarked patches:
main.m
numEpochs = 100;
batchSize = 128;
autoencoder = trainAutoencoder(noisyPatches, watermarkedPatches, ...
'EncoderHiddenSize', 32, 'DecoderHiddenSize', 32, ...
'L2WeightRegularization', 0.004, 'SparsityRegularization', 4, ...
'SparsityProportion', 0.15, 'ScaleData', false, ...
'LearnRate', 0.01, 'MaxEpochs', numEpochs, ...
'MiniBatchSize', batchSize);
351 chars
9 lines
  1. Use the trained autoencoder to remove the watermark from a new image by splitting the image into patches and passing them through the autoencoder:
main.m
testImg = imread('newImage.png'); % load new image to watermark
noisyTestImg = imnoise(testImg,'gaussian',0.01); % add noise
testPatches = im2col(noisyTestImg, [patchSize patchSize], 'sliding'); % split into patches
decodedTestPatches = predict(autoencoder, testPatches); % use autoencoder to remove watermark
decodedTestImg = col2im(decodedTestPatches, [patchSize patchSize], size(noisyTestImg), 'sliding'); % combine patches
imwrite(decodedTestImg, 'newImageWithoutWatermark.png') % save cleaned image
504 chars
7 lines

Note that this method will only work for simple watermarks and may not work well for complex and robust watermarks.

gistlibby LogSnag