Watermark is a pretty common thing you will find in many pictures or documents these days. Sometimes they are annoying for reading. Here I am going to show you a simple way to remove watermark with Matlab. In this example, the watermark is a single colored text in a document (mostly black and white with some limited colors). The script basically replace the gray watermark color (with some tolerance of errors in RGB values) with white color.

    pic = imread(['./orig/',fn]);      % fn is the name of the file to be converted. 
    
    water_mark = [235, 236, 236];
    
    wm1 = repmat( water_mark, size(pic,1)*size(pic,2), 1);
    wm = reshape(wm1, size(pic,1), size(pic,2), size(pic,3));
    
    pic0 = reshape( pic, size(pic,1)*size(pic,2), size(pic,3) );
    pic1 = zeros( size(pic0) );
    for i=1:size(pic0,1)
        pic1(i,:) = pic0(i,:);
    end
    
    err = pic1 - wm1 ;
    
    posr = find( abs(err(:,1)) < 8);
    posg = find( abs(err(:,2)) < 8);
    posb = find( abs(err(:,3)) < 8);
    
    pos = [];
    for i=1:length(posr)
        if length(find(posg== posr(i))) ~=0 & length(find(posb==posr(i))) ~= 0
            pos = [pos posr(i)];
        end
    end
    
    pic2 = pic;
    
    pic2( pos ) = 255;
    pic2( pos + size(pic,1)*size(pic,2) ) = 255;
    pic2( pos + 2 * size(pic,1)*size(pic,2) ) = 255;
    
    
    
    imwrite(pic2, ['./converted/', fn] );
    


How to remove a simple watermark from a picture with Matlab
Tagged on:

One thought on “How to remove a simple watermark from a picture with Matlab

Please tell us what's in your mind ...

%d bloggers like this: