{"id":13468931,"url":"https://github.com/rohitrango/automatic-watermark-detection","last_synced_at":"2025-05-16T12:02:22.543Z","repository":{"id":26996389,"uuid":"104101334","full_name":"rohitrango/automatic-watermark-detection","owner":"rohitrango","description":"Project for Digital Image Processing","archived":false,"fork":false,"pushed_at":"2022-05-22T16:03:19.000Z","size":39412,"stargazers_count":1211,"open_issues_count":6,"forks_count":399,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-04-09T07:03:35.126Z","etag":null,"topics":["image-matting","image-processing","irls","numpy","poisson-reconstruction","python","scipy-stack","watermark","watermark-detection"],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rohitrango.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-19T16:43:49.000Z","updated_at":"2025-04-08T13:18:08.000Z","dependencies_parsed_at":"2022-08-07T12:01:24.485Z","dependency_job_id":null,"html_url":"https://github.com/rohitrango/automatic-watermark-detection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitrango%2Fautomatic-watermark-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitrango%2Fautomatic-watermark-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitrango%2Fautomatic-watermark-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitrango%2Fautomatic-watermark-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rohitrango","download_url":"https://codeload.github.com/rohitrango/automatic-watermark-detection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527074,"owners_count":22085918,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image-matting","image-processing","irls","numpy","poisson-reconstruction","python","scipy-stack","watermark","watermark-detection"],"created_at":"2024-07-31T15:01:22.164Z","updated_at":"2025-05-16T12:02:22.412Z","avatar_url":"https://github.com/rohitrango.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"readme":"## Automatic watermark detection and removal\nThis was a project that was built as part of project for CS663 (Digital Image Processing).\nThis is a crude Python implementation of the paper \"On The Effectiveness Of Visible Watermarks\", Tali Dekel, Michael Rubinstein, Ce Liu and William T. Freeman,\nConference on Computer Vision and Pattern Recongnition (CVPR), 2017.\n\n### Rough sketch of the algorithm\nA watermarked image `J` is obtained by imposing a watermark `W` over an unwatermarked image `I` with a blend factor \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=\\alpha\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\alpha\" title=\"\\alpha\" /\u003e\u003c/a\u003e. Specifically, we have the following equation:\n\n\u003cdiv align=\"center\"\u003e\n\u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=J(p)\u0026space;=\u0026space;\\alpha(p)W(p)\u0026space;\u0026plus;\u0026space;(1-\\alpha(p))I(p)\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?J(p)\u0026space;=\u0026space;\\alpha(p)W(p)\u0026space;\u0026plus;\u0026space;(1-\\alpha(p))I(p)\" title=\"J(p) = \\alpha(p)W(p) + (1-\\alpha(p))I(p)\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\nWhere `p = (x, y)` is the pixel location. For a set of `K` images, we have:\n\u003cdiv align=\"center\"\u003e\u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=J_k\u0026space;=\u0026space;\\alpha\u0026space;W\u0026space;\u0026plus;\u0026space;(1-\\alpha)I_k,\\quad\u0026space;k=1,2....K\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?J_k\u0026space;=\u0026space;\\alpha\u0026space;W\u0026space;\u0026plus;\u0026space;(1-\\alpha)I_k,\\quad\u0026space;k=1,2....K\" title=\"J_k = \\alpha W + (1-\\alpha)I_k,\\quad k=1,2....K\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\nAlthough we have a lot of unknown quantities (\u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=J_k,\u0026space;W,\u0026space;\\alpha\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?J_k,\u0026space;W,\u0026space;\\alpha\" title=\"J_k, W, \\alpha\" /\u003e\u003c/a\u003e), we can make use of the structural properties of the image to determine its location and estimate its structure. The coherency of \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=\\alpha\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\alpha\" title=\"\\alpha\" /\u003e\u003c/a\u003e and W over all the images can be exploited to solve the above problem with good accuracy. The steps followed to determine these values are:\n- Initial watermark estimation and detection\n- Estimating the matted watermark\n- Compute the median of the watermarked image gradients, independently in the `x` and `y` directions, at every pixel location `p`.\n\n\u003cdiv align=\"center\"\u003e\u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=\\nabla{\\hat{W_m}(p)}\u0026space;=\u0026space;median_k(\\nabla{J_k(p)})\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\nabla{\\hat{W_m}(p)}\u0026space;=\u0026space;median_k(\\nabla{J_k(p)})\" title=\"\\nabla{\\hat{W_m}(p)} = median_k(\\nabla{J_k(p)})\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\n- Crop `W_m` to remove boundary regions by computing its magnitude and taking the bounding box of the edge map. The initial estimated watermark \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=\\hat{W}_m\u0026space;\\approx\u0026space;W_m\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\hat{W}_m\u0026space;\\approx\u0026space;W_m\" title=\"\\hat{W}_m \\approx W_m\" /\u003e\u003c/a\u003e is estimated using Poisson reconstruction. Here is an estimated watermark using a dataset of 450+ Fotolia images.\n\u003cimg src=\"https://github.com/rohitrango/automatic-watermark-detection/blob/master/watermark.png?raw=True\" alt=\"watermark_est\"/\u003e\n\n- Watermark detection: Obtain a verbose edge map (using Canny edge detector) and compute\nits Euclidean distance transform, which is then correlated with \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=\\nabla{\\hat{W_m}}\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\nabla{\\hat{W_m}}\" title=\"\\nabla{\\hat{W_m}}\" /\u003e\u003c/a\u003e\nto get the Chamfer distance from each pixel to the closest edge.\nLastly, the watermark position is taken to be the pixel with minimum\ndistance in the map.\n\n#### Multi-image matting and reconstruction\n- Estimate \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=I_k,\u0026space;W_k\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?I_k,\u0026space;W_k\" title=\"I_k, W_k\" /\u003e\u003c/a\u003e keeping \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=W,\u0026space;\\alpha\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?W,\u0026space;\\alpha\" title=\"W, \\alpha\" /\u003e\u003c/a\u003e fixed.\n- Watermark update - Update the value of \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=W,\u0026space;\\alpha\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?W\" title=\"W\" /\u003e\u003c/a\u003e keeping the rest fixed.\n- Matte update - Update the value of \u003ca href=\"https://www.codecogs.com/eqnedit.php?latex=W,\u0026space;\\alpha\" target=\"_blank\"\u003e\u003cimg src=\"https://latex.codecogs.com/gif.latex?\\alpha\" title=\"\\alpha\" /\u003e\u003c/a\u003e keeping the rest fixed.\n\t\nPlease refer to the paper and supplementary for a more in-depth description and derivation of the algorithm. \n\nResults\n--------\nHere are some of the results for watermarked and watermark removed images: \n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://github.com/rohitrango/automatic-watermark-detection/blob/master/final/fotolia_137840668.jpg?raw=True\" width=\"45%\"\u003e\n\u003cimg src=\"https://github.com/rohitrango/automatic-watermark-detection/blob/master/final/137840668.jpg?raw=True\" width=\"45%\"\u003e \u003cbr\u003e\n\n\u003cimg src=\"https://github.com/rohitrango/automatic-watermark-detection/blob/master/final/fotolia_168668046.jpg?raw=True\" width=\"45%\"\u003e\n\u003cimg src=\"https://github.com/rohitrango/automatic-watermark-detection/blob/master/final/168668046.jpg?raw=True\" width=\"45%\"\u003e \u003cbr\u003e\n\n\u003cimg src=\"https://github.com/rohitrango/automatic-watermark-detection/blob/master/final/fotolia_168668150.jpg?raw=True\" width=\"45%\"\u003e\n\u003cimg src=\"https://github.com/rohitrango/automatic-watermark-detection/blob/master/final/168668150.jpg?raw=True\" width=\"45%\"\u003e \u003cbr\u003e\n\u003c/div\u003e\n\nHowever, this is a rough implementation and the removal of watermark leaves some \"traces\" in form of texture distortion or artifacts. I believe this can be corrected by appropriate parameter tuning. \n\nMore information\n-------\nFor more information, refer to the original paper [here](http://openaccess.thecvf.com/content_cvpr_2017/papers/Dekel_On_the_Effectiveness_CVPR_2017_paper.pdf)\n\nDisclaimer\n--------\nI do not encourage or endorse piracy by making this project public. The code is free for academic/research purpose. Please feel free to send pull requests for bug fixes/optimizations, etc.\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohitrango%2Fautomatic-watermark-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frohitrango%2Fautomatic-watermark-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohitrango%2Fautomatic-watermark-detection/lists"}