{"id":16729871,"url":"https://github.com/dfdx/piecewiseaffinetransforms.jl","last_synced_at":"2026-01-03T04:41:17.104Z","repository":{"id":30795637,"uuid":"34352686","full_name":"dfdx/PiecewiseAffineTransforms.jl","owner":"dfdx","description":"Smooth image transformations for complex shapes","archived":false,"fork":false,"pushed_at":"2020-02-08T16:09:04.000Z","size":1687,"stargazers_count":12,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-22T07:16:49.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dfdx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-21T21:17:34.000Z","updated_at":"2024-05-05T21:35:48.000Z","dependencies_parsed_at":"2022-09-08T16:12:55.351Z","dependency_job_id":null,"html_url":"https://github.com/dfdx/PiecewiseAffineTransforms.jl","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfdx%2FPiecewiseAffineTransforms.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfdx%2FPiecewiseAffineTransforms.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfdx%2FPiecewiseAffineTransforms.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfdx%2FPiecewiseAffineTransforms.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfdx","download_url":"https://codeload.github.com/dfdx/PiecewiseAffineTransforms.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243763237,"owners_count":20344190,"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":[],"created_at":"2024-10-12T23:30:19.129Z","updated_at":"2026-01-03T04:41:17.058Z","avatar_url":"https://github.com/dfdx.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Piecewise Affine Transformations\n\n[![Build Status](https://travis-ci.org/dfdx/PiecewiseAffineTransforms.jl.svg)](https://travis-ci.org/dfdx/PiecewiseAffineTransforms.jl)\n\nPackage for smooth deformation of complex shapes.\n\n## Installation\n\n    Pkg.add(\"PiecewiseAffineTransforms\")\n\n## Usage Overview\n\nPiecewise affine transformation resembles ordinary affine transformation, but instead of warping single region linearly, it splits down area under the question into a set of triangles and warps each such triangle separately.\n\nLet's say, we have an image of a face and want to warp it to have different expression (destination image is here only for demonstration, we will not use it):\n\n    using PiecewiseAffineTransforms\n\n    src_img = ...\n    dst_img = ...\n\n(full version of code is available in `examples/ex.jl`)\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\u003ctd\u003eSource image\u003c/td\u003e\u003ctd\u003eDestination image\u003c/td\u003e\u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/dfdx/PiecewiseAffineTransforms.jl/master/examples/cootes/107_0764.bmp\"/\u003e\n      \u003c/td\u003e\n      \u003ctd\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/dfdx/PiecewiseAffineTransforms.jl/master/examples/cootes/107_0779.bmp\"/\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nWe will also assume that both faces are annotated with corresponding shape landmarks:\n\n    src_shape = ... # should be a Nx2 matrix of Float64,\n                    #  where N is a number of landmarks\n    dst_shape = ...\n\nFirst of all, we need to split the shapes into triangles, i.e. triangulate them:\n\n    trigs = delaunayindexes(src_shape)  # Tx3 matrix of Int, where T is\n                                        #  a number of resuling triangles\n    # needs ImageView installed (Pkg.add(\"ImageView\"))\n    triplot(src_img, src_shape, trigs)\n    triplot(dst_img, dst_shape, trigs)\n\n**WARNING:** Triangulation is based on [VoronoiDelaunay.jl](https://github.com/JuliaGeometry/VoronoiDelaunay.jl/), which currently has a [bug](https://github.com/JuliaGeometry/VoronoiDelaunay.jl/issues/6) resulting in one lost triangle from time to time. To overcome this, just get good sample of triangulation and save it for future use.\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\u003ctd\u003eSource shape\u003c/td\u003e\u003ctd\u003eDestination shape\u003c/td\u003e\u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/dfdx/PiecewiseAffineTransforms.jl/master/examples/processed/triplot_src.png\"/\u003e\n      \u003c/td\u003e\n      \u003ctd\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/dfdx/PiecewiseAffineTransforms.jl/master/examples/processed/triplot_dst.png\"/\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nWarping `src_image` from `src_shape` to `dst_shape` may be as simple as calling this:\n\n    @time warped = pa_warp(src_img, src_shape, dst_shape, trigs)\n    # 1.44 seconds\n\nBut if you are going to repeat warping to `dst_shape` for many source images or just many times, it's worth to prepare warp by creating `PAWarpParams` object and using it for all future transformation to `dst_shape`:\n\n    @time pa_params = pa_warp_params(dst_shape, trigs, (480, 640))\n    # 5.92 seconds\n    @time warped = pa_warp(pa_params, src_img, src_shape)\n    # 0.075 seconds\n\nBut anyway, they both give (almost) the same result:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\u003ctd\u003eOriginal image\u003c/td\u003e\u003ctd\u003eWarped image\u003c/td\u003e\u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/dfdx/PiecewiseAffineTransforms.jl/master/examples/cootes/107_0764.bmp\"/\u003e\n      \u003c/td\u003e\n      \u003ctd\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/dfdx/PiecewiseAffineTransforms.jl/master/examples/processed/warped_prepared.png\"/\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n## Acknowledgement\n\nCode for prepared warp was mostly extracted from ICAAM project by Luca Vezzaro.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfdx%2Fpiecewiseaffinetransforms.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfdx%2Fpiecewiseaffinetransforms.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfdx%2Fpiecewiseaffinetransforms.jl/lists"}