DEV Community

Cover image for From Stamped to Clean: Transforming Watermarked Images into Clear Visuals
Yash Jivani
Yash Jivani

Posted on

From Stamped to Clean: Transforming Watermarked Images into Clear Visuals

Have you wondered how you can remove watermarks from images using Python? It's very simple! You should know Python and have a basic knowledge of computer vision models like CNN & TensorFlow DL framework to follow architectures if you are interested!! Please make sure that you read the copyright laws of the images you want to remove watermarks before you run the code.


Steps to follow -

  1. Create a new Google Colab notebook. Change the runtime to T4 GPU to enhance computing power to run the inference pipeline.

  2. Install Conda packages, create and activate the Conda environment
    Since Google Colab uses the latest Tensorflow & Python versions and this project uses tensorflow=1.15.0 which is supported by Python 3.6, install miniconda inside the Colab environment

# set pythonpath
%env PYTHONPATH = # /env/python

# Set up miniconda and set the path '/usr/local'
!wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py38_4.12.0-Linux-x86_64.sh
!./Miniconda3-py38_4.12.0-Linux-x86_64.sh -b -f -p /usr/local

import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')

# create a new conda environment using Python 3.3
!conda create -n myenv python=3.6
Enter fullscreen mode Exit fullscreen mode

3.Install Packages inside Env.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
conda install -y tensorflow==1.15 pillow opencv matplotlib pyyaml
conda install -y tensorflow-gpu

pip install --upgrade pip
pip install git+https://github.com/JiahuiYu/neuralgym
Enter fullscreen mode Exit fullscreen mode

4.Clone Repo

!git clone https://github.com/zuruoke/watermark-removal
Enter fullscreen mode Exit fullscreen mode

5.Download Model Files from drive and paste them into the /watermark-removal/model directory.

6.Execute Python code to remove the watermark from your istock image. If you have Alamy, Shutterstock, or your custom watermarked images, please add mask.png inside utils/<watermark-type>/<image-type>.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv

cd watermark-removal
python main.py --image path-to-input-image --output path-to-output-image --checkpoint_dir model/ --watermark_type istock
Enter fullscreen mode Exit fullscreen mode

Reference

Top comments (0)