{"id":17038212,"url":"https://github.com/bchao1/fast-poisson-image-editing","last_synced_at":"2025-07-16T08:41:18.466Z","repository":{"id":113819524,"uuid":"494348811","full_name":"bchao1/fast-poisson-image-editing","owner":"bchao1","description":"Fast, scalable, and extensive implementations of Poisson image editing algorithms.","archived":false,"fork":false,"pushed_at":"2022-06-10T06:37:29.000Z","size":12556,"stargazers_count":41,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T13:59:19.098Z","etag":null,"topics":["computer-graphics","computer-vision","gradient","gradient-domain-image-processing","image-blending","image-cloning","image-processing","laplacian","poisson-equation","poisson-image-editing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"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/bchao1.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-20T06:33:12.000Z","updated_at":"2024-10-15T13:43:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"4ce6c41f-d9b1-4cc9-a013-a8bb1d5da458","html_url":"https://github.com/bchao1/fast-poisson-image-editing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bchao1/fast-poisson-image-editing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bchao1%2Ffast-poisson-image-editing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bchao1%2Ffast-poisson-image-editing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bchao1%2Ffast-poisson-image-editing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bchao1%2Ffast-poisson-image-editing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bchao1","download_url":"https://codeload.github.com/bchao1/fast-poisson-image-editing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bchao1%2Ffast-poisson-image-editing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265497949,"owners_count":23777092,"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":["computer-graphics","computer-vision","gradient","gradient-domain-image-processing","image-blending","image-cloning","image-processing","laplacian","poisson-equation","poisson-image-editing"],"created_at":"2024-10-14T08:56:16.539Z","updated_at":"2025-07-16T08:41:18.458Z","avatar_url":"https://github.com/bchao1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Poisson image editing\n\nA fast, scalable, and extensive implementation of the [Poisson Image Editing](https://dl.acm.org/doi/10.1145/882262.882269) paper by Perez et al. 2003.\n\n![teaser](data/teaser.png)\n\n## Features\n- Poisson image editing functionalities\n    - Seamless cloning - importing gradients\n    - Seamless cloning - mixing gradients\n    - Seamless tiling\n    - Texture flattening\n    - Local illumination change\n    - Local color change\n- Supports all sparse linear system solvers in `scipy.sparse.linalg`\n- Acceleration of large input problems using multigrid approaches\n- An Object-Oriented Programming approach for Poisson image editing - see branch `oop` for more details\n    - All editing functions inherit the abstract `PoissonImageEditor` class\n\n## Comparison with other implementations\nThere are many open source Python implementations of Poisson image editing. However, most implementations only focus on image *blending*, while ignoring other Poisson image editing applications listed in the paper. This implementation aims to faithfully reproduce all experiments and results presented in the paper. The following table shows the implemented functionalities:\n   \n| |[Src. 1](https://github.com/rinsa318/poisson-image-editing)|[Src. 2](https://github.com/willemmanuel/poisson-image-editing)|[Src. 3](https://github.com/PPPW/poisson-image-editing)|This|\n|---|---|---|---|---|\n|Seamless cloning|✅|✅|✅|✅|\n|Seamless tiling|❌|❌|❌|✅|\n|Texture flattening|✅|❌|❌|✅|\n|Local illumination change|❌|❌|❌|✅|\n|Local color change|❌|❌|❌|✅|\n\nFurthermore, this implementation is signifacantly *faster* and scales much better than others. The following table shows the profiled run time of seamless cloning on different datasets (in seconds):\n\n| |[Src. 1](https://github.com/rinsa318/poisson-image-editing)|[Src. 2](https://github.com/willemmanuel/poisson-image-editing)|[Src. 3](https://github.com/PPPW/poisson-image-editing)|This|\n|---|---|---|---|---|\n|test1|32.064|312.930|6.755|**1.799**|\n|test2|13.634|59.875|1.775|**1.389**|\n|test3|36.575|565.466|3.401|**1.818**|\n|test4|19.866|42.592|1.542|**1.419**|\n   \nThe following figure shows the scaling performance of this implementation compared to that of Src. 3. For fair comparison, both implementations are modified to use the same solver `scipy.sparse.linalg.spsolve`.\n![scaling perf](./data/scale_profiling.png)\n   \nBy using multigrid solvers, editing a 1080p image can be done in less than 30 seconds, a **6.7x** speedup compared to the current fastest open source Python implementation: \n\n| |[Src. 3](https://github.com/PPPW/poisson-image-editing)|This (multigrid approach)|\n|---|---|---|\n|1080p image|134.896|20.814|\n\n\n## Usage\n\nTo run all experiments using the given datasets (contains testing images in the paper and this README file), run\n```\n./run_experiments.sh\n```\n\n### Seamless cloning\nTo test on your own dataset, run\n```\npython3 seamless_cloning.py --help\n```\n\n- `data_dir`: Folder that contains the input image files. The folder should contain image files named `mask`, `target`, and `source`. The file extension of the files can be arbitrary, as long as the files are valid image files.\n- `grayscale`: Whether to perform blending on the grayscale images.\n- `solver`: Linear solver to use when solving the poisson blending problem. The value of `solver` should either be function names in the `scipy.sparse.linalg` library, or `\"multigrid\"`. Default is `spsolve`. \n- `gradient_mixing_mode`: Method to mix source and target image gradients. `max` implements *3. Seamless cloning - Mixing gradients* section in the paper, while `alpha` + `gradient_mixing_alpha == 1.0` implements *3. Seamless cloning - Importing gradients* section. \n- `gradient_mixing_alpha`: Alpha to blend source and target image gradients. Has an effect only when `gradient_mixing_mode == \"alpha\"`. \n\n### Seamless tiling\nTo test on your own dataset, run\n```\npython3 seamless_tiling.py --help\n```\n\n### Texture flattening\nTo test on your own dataset, run\n```\npython3 texture_flattening.py --help\n```\n- `use_edge`: Use `edge.*` edge map image file in the folder specified in the `data_dir` folder. If this flag is not set, then computes the edge map from provided source image using Canny edge detector and binary dilation.\n- `canny_threshold`: Thresholding parameters for Canny edge detector. You can play with this parameter for different flattening results. See the [documentation](https://docs.opencv.org/4.x/da/d22/tutorial_py_canny.html) for more information.\n- `edge_dilation_kernel`: Kernel size to dilate detected edges. The kernel is a square box filter filled with ones.\n\n### Local illumination change\nTo test on your own dataset, run\n```\npython3 local_illumination_change.py --help\n```\n- `data_dir`: Folder that contains the input image files. The folder should contain image files named `mask` and `source`. The file extension of the files can be arbitrary, as long as the files are valid image files. The illumination of the regions specified by the mask will be modified.\n\n### Local color change\nTo test on your own dataset, run\n```\npython3 local_color_change.py --help\n```\n- `mode`: Color change mode. If `mode == \"gray_background\"`, then pixels outside the masked region will be converted to grayscale. If `mode == \"color_change\"`, the hue of the masked region is increased by the value specified by `change_hue` parameter. \n- `change_hue`: Value added to the hue channel of the masked region.\n\n## Results\n### Seamless cloning\n|Source|Target|Mask|Result|\n|---|---|---|---|\n|![src](data/test1/source.png)|![src](data/test1/target.png)|![src](data/test1/mask.png)|![src](data/test1/result.png)|\n|![src](data/test2/source.jpg)|![src](data/test2/target.jpg)|![src](data/test2/mask.jpg)|![src](data/test2/result.png)|\n|![src](data/test3/source.png)|![src](data/test3/target.png)|![src](data/test3/mask.png)|![src](data/test3/result.png)|\n|\u003cimg src=\"data/test4/source.png\" width=\"200\"/\u003e|\u003cimg src=\"data/test4/target.png\" width=\"200\"/\u003e|\u003cimg src=\"data/test4/mask.png\" width=\"200\"/\u003e|\u003cimg src=\"data/test4/result.png\" width=\"200\"/\u003e|\n\n### Seamless tiling\n|Texture|Naive tile|Seamless tile|\n|---|---|---|\n|![](data/texture2/texture.jpg)|![](data/texture2/orig_tile.png)|![](data/texture2/new_tile.png)|\n|![](data/texture3/texture.jpg)|![](data/texture3/orig_tile.png)|![](data/texture3/new_tile.png)|\n\n### Texture flattening\n|Source|Mask|Edge|Flattened|\n|---|---|---|---|\n|![](data/test5/source.jpg)|![](./data/test5/mask.png)|![](data/test5/edge_canny.png)|![](data/test5/result.png)|\n\n### Local illumination change\n|Source|Mask|Modified|\n|---|---|---|\n|![](data/illum1/source.jpg)|![](./data/illum1/mask.jpg)|![](data/illum1/result.png)|\n\n### Local color change\n|Source|Green-ish|Blue-ish|Gray background|\n|---|---|---|---|\n|\u003cimg src=\"data/color1/source.jpg\" width=\"200\"/\u003e|\u003cimg src=\"data/color1/result_color_change_60.0.png\" width=\"200\"/\u003e|\u003cimg src=\"data/color1/result_color_change_120.0.png\" width=\"200\"/\u003e|\u003cimg src=\"data/color1/result_gray_background_0.png\" width=\"200\"/\u003e|\n\n## Notes\n- Faster solvers: `spsolve`, `cgs`, `bicg`\n- `minres` gives bad results.\n- If you want to use conjugate gradient solvers, use `bicg`, `bicgstab` or `cgs`. Do not use `solver == \"cg\"` since the A matrix is not hermitian (or symmetric since A is real).\n- Iterative least-squares solvers `lsqr`, `lsmr` tend to be much slower.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbchao1%2Ffast-poisson-image-editing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbchao1%2Ffast-poisson-image-editing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbchao1%2Ffast-poisson-image-editing/lists"}