auto encoder for watermark remove from picture in matlab

To use autoencoder for watermark removal from an image in Matlab, follow these steps:

  1. Load the image into Matlab using the imread function.
main.m
I = imread('image_with_watermark.png');
40 chars
2 lines
  1. Convert the image to grayscale using the rgb2gray function.
main.m
grayImage = rgb2gray(I);
25 chars
2 lines
  1. Prepare the data for the autoencoder. The input data will be the original image with watermark and the output data will be the original image without watermark.
main.m
data = double(reshape(grayImage, [], 1));
outputData = double(reshape(grayImageWithoutWatermark, [], 1));
106 chars
3 lines
  1. Define the autoencoder architecture using the autoencoder function.
main.m
hiddenSize = 1000;
autoenc = autoencoder(size(data, 1), hiddenSize);
69 chars
3 lines
  1. Train the autoencoder using the trainAutoencoder function.
main.m
numEpochs = 100;
L2Weight = 0.0001;
autoenc = trainAutoencoder(data', hiddenSize, ...
    'EncoderTransferFunction', 'logsig', ...
    'DecoderTransferFunction', 'logsig', ...
    'L2WeightRegularization', L2Weight, ...
    'SparsityRegularization', 4, ...
    'SparsityProportion', 0.25, ...
    'ScaleData', false, ...
    'MaxEpochs', numEpochs, ...
    'UseGPU', false);
375 chars
12 lines
  1. Use the trained autoencoder to remove the watermark from the image.
main.m
watermarkRemovedData = predict(autoenc, data');
48 chars
2 lines
  1. Reshape the watermark removed data to the original image size and convert it to uint8.
main.m
watermarkRemovedImage = reshape(watermarkRemovedData, size(grayImage)) / 255;
watermarkRemovedImage = mat2gray(watermarkRemovedImage);
watermarkRemovedImage = uint8(watermarkRemovedImage * 255);
195 chars
4 lines
  1. Display the watermark removed image using the imshow function.
main.m
imshow(watermarkRemovedImage);
31 chars
2 lines

gistlibby LogSnag