{"id":13393163,"url":"https://github.com/esimov/caire","last_synced_at":"2025-05-14T23:01:57.595Z","repository":{"id":37390745,"uuid":"116718067","full_name":"esimov/caire","owner":"esimov","description":"Content aware image resize library","archived":false,"fork":false,"pushed_at":"2025-05-02T08:19:39.000Z","size":92414,"stargazers_count":10415,"open_issues_count":3,"forks_count":381,"subscribers_count":167,"default_branch":"master","last_synced_at":"2025-05-07T22:01:59.927Z","etag":null,"topics":["computer-vision","content-aware-resize","content-aware-scaling","edge-detection","face-detection","golang","image-processing","image-resize","machine-learning","seam-carving"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/esimov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"esimov"}},"created_at":"2018-01-08T19:23:04.000Z","updated_at":"2025-05-07T15:04:41.000Z","dependencies_parsed_at":"2023-01-27T01:01:49.499Z","dependency_job_id":"9d48c7d6-8227-44b5-9e5b-b90cc4fbc742","html_url":"https://github.com/esimov/caire","commit_stats":{"total_commits":434,"total_committers":15,"mean_commits":"28.933333333333334","dds":0.06451612903225812,"last_synced_commit":"d6bf15caabefc97961ef6f94b2739524dd134504"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcaire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcaire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcaire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esimov%2Fcaire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esimov","download_url":"https://codeload.github.com/esimov/caire/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243353,"owners_count":22038044,"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-vision","content-aware-resize","content-aware-scaling","edge-detection","face-detection","golang","image-processing","image-resize","machine-learning","seam-carving"],"created_at":"2024-07-30T17:00:44.410Z","updated_at":"2025-05-14T23:01:52.556Z","avatar_url":"https://github.com/esimov.png","language":"Go","funding_links":["https://github.com/sponsors/esimov"],"categories":["Go","Images","Popular","Libraries/tools","开源类库","Digital Image Processing","Open source library","Image Generation \u0026 Editing","其他_机器视觉","Programming Languages","Deep Learning","📦 Legacy \u0026 Inactive Projects"],"sub_categories":["图形处理","Graphics Processing","网络服务_其他","Go","🔍 **Quick Access**"],"readme":"\u003ch1 align=\"center\"\u003e\u003cimg alt=\"Caire Logo\" src=\"https://user-images.githubusercontent.com/883386/51555990-a1762600-1e81-11e9-9a6a-0cd815870358.png\" height=\"180\"\u003e\u003c/h1\u003e\n\n[![build](https://github.com/esimov/caire/actions/workflows/build.yml/badge.svg)](https://github.com/esimov/caire/actions/workflows/build.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/esimov/caire.svg)](https://pkg.go.dev/github.com/esimov/caire)\n[![license](https://img.shields.io/github/license/esimov/caire)](./LICENSE)\n[![release](https://img.shields.io/badge/release-v1.5.0-blue.svg)](https://github.com/esimov/caire/releases/tag/v1.5.0)\n[![homebrew](https://img.shields.io/badge/homebrew-v1.5.0-orange.svg)](https://formulae.brew.sh/formula/caire)\n[![caire](https://snapcraft.io/caire/badge.svg)](https://snapcraft.io/caire)\n\n**Caire** is a content aware image resize library based on *[Seam Carving for Content-Aware Image Resizing](https://inst.eecs.berkeley.edu/~cs194-26/fa16/hw/proj4-seamcarving/imret.pdf)* paper.\n\n## How does it work\n* An energy map (edge detection) is generated from the provided image.\n* The algorithm tries to find the least important parts of the image taking into account the lowest energy values.\n* Using a dynamic programming approach the algorithm will generate individual seams across the image from top to down, or from left to right (depending on the horizontal or vertical resizing) and will allocate for each seam a custom value, the least important pixels having the lowest energy cost and the most important ones having the highest cost.\n* We traverse the image from the second row to the last row and compute the cumulative minimum energy for all possible connected seams for each entry.\n* The minimum energy level is calculated by summing up the current pixel value with the lowest value of the neighboring pixels obtained from the previous row.\n* We traverse the image from top to bottom and compute the minimum energy level. For each pixel in a row we compute the energy of the current pixel plus the energy of one of the three possible pixels above it.\n* Find the lowest cost seam from the energy matrix starting from the last row and remove it.\n* Repeat the process.\n\n#### The process illustrated:\n\n| Original image | Energy map | Seams applied\n|:--:|:--:|:--:|\n| ![original](https://user-images.githubusercontent.com/883386/35481925-de130752-0435-11e8-9246-3950679b4fd6.jpg) | ![sobel](https://user-images.githubusercontent.com/883386/35481899-5d5096ca-0435-11e8-9f9b-a84fefc06470.jpg) | ![debug](https://user-images.githubusercontent.com/883386/35481949-5c74dcb0-0436-11e8-97db-a6169cb150ca.jpg) | ![out](https://user-images.githubusercontent.com/883386/35564985-88c579d4-05c4-11e8-9068-5141714e6f43.jpg) |\n\n## Features\nKey features which differentiates this library from the other existing open source solutions:\n\n- [x] **GUI progress indicator**\n- [x] Customizable command line support\n- [x] Support for both shrinking or enlarging the image\n- [x] Resize image both vertically and horizontally\n- [x] Face detection to avoid face deformation\n- [x] Support for multiple output image type (jpg, jpeg, png, bmp)\n- [x] Support for `stdin` and `stdout` pipe commands\n- [x] Can process whole directories recursively and concurrently\n- [x] Use of sobel threshold for fine tuning\n- [x] Use of blur filter for increased edge detection\n- [x] Support for squaring the image with a single command\n- [x] Support for proportional scaling\n- [x] Support for protective mask\n- [x] Support for removal mask\n- [x] [GUI debug mode support](#masks-support)\n\n## Install\nFirst, install Go, set your `GOPATH`, and make sure `$GOPATH/bin` is on your `PATH`.\n\n```bash\n$ go install github.com/esimov/caire/cmd/caire@latest\n```\n\n## MacOS (Brew) install\nThe library can also be installed via Homebrew.\n\n```bash\n$ brew install caire\n```\n\n## Usage\n\n```bash\n$ caire -in input.jpg -out output.jpg\n```\n\n### Supported commands:\n```bash\n$ caire --help\n```\nThe following flags are supported:\n\n| Flag | Default | Description |\n| --- | --- | --- |\n| `in` | - | Input file |\n| `out` | - | Output file |\n| `width` | n/a | New width |\n| `height` | n/a | New height |\n| `preview` | true | Show GUI window |\n| `perc` | false | Reduce image by percentage |\n| `square` | false | Reduce image to square dimensions |\n| `blur` | 4 | Blur radius |\n| `sobel` | 2 | Sobel filter threshold |\n| `debug` | false | Use debugger |\n| `face` | false | Use face detection |\n| `angle` | float | Plane rotated faces angle |\n| `mask` | string | Mask file path |\n| `rmask` | string | Remove mask file path |\n| `color` | string | Seam color (default `#ff0000`) |\n| `shape` | string | Shape type used for debugging: `circle`,`line` (default `circle`) |\n\n## Face detection\n\nThe library is capable of detecting human faces prior resizing the images by using the lightweight Pigo (https://github.com/esimov/pigo) face detection library.\n\nThe image below illustrates the application capabilities for human face detection prior resizing. It's clearly visible that with face detection activated the algorithm will avoid cropping pixels inside the detected faces, retaining the face zone unaltered.\n\n| Original image | With face detection | Without face detection\n|:--:|:--:|:--:|\n| ![Original](https://user-images.githubusercontent.com/883386/37569642-0c5f49e8-2aee-11e8-8ac1-d096c0387ca0.jpg) | ![With Face Detection](https://user-images.githubusercontent.com/883386/41292871-6ca43280-6e5c-11e8-9d72-5b9a138228b6.jpg) | ![Without Face Detection](https://user-images.githubusercontent.com/883386/41292872-6cc90e8e-6e5c-11e8-8b41-5b4eb5042381.jpg) |\n\n[Sample image source](http://www.lens-rumors.com/wp-content/uploads/2014/12/EF-M-55-200mm-f4.5-6.3-IS-STM-sample.jpg)\n\n### GUI progress indicator\n\n\u003cp align=\"center\"\u003e\u003cimg alt=\"GUI preview\" title=\"GUI preview\" src=\"https://github.com/esimov/caire/raw/master/gui_preview.gif\"\u003e\u003c/p\u003e\n\nA GUI preview mode is also incorporated into the library for in time process visualization. The [Gio](http://gioui.org/) GUI library has been used because of its robustness and modern architecture. Prior running it please make sure that you have installed all the required dependencies noted in the installation section (https://gioui.org/#installation) .\n\nThe preview window is activated by default but you can deactivate it any time by setting the `-preview` flag to false. When the images are processed concurrently from a directory the preview mode is deactivated.\n\n### Face detection to avoid face deformation\nIn order to detect faces prior rescaling, use the `-face` flag. There is no need to provide a face classification file, since it's already embedded into the generated binary file. The sample code below will resize the provided image with 20%, but checks for human faces in order tot avoid face deformations.\n\nFor face detection related settings please check the Pigo [documentation](https://github.com/esimov/pigo/blob/master/README.md).\n\n```bash\n$ caire -in input.jpg -out output.jpg -face=1 -perc=1 -width=20\n```\n\n### Support for `stdin` and `stdout` pipe commands\nYou can also use `stdin` and `stdout` with `-`:\n\n```bash\n$ cat input/source.jpg | caire -in - -out - \u003eout.jpg\n```\n\n`in` and `out` default to `-` so you can also use:\n\n```bash\n$ cat input/source.jpg | caire \u003eout.jpg\n$ caire -out out.jpg \u003c input/source.jpg\n```\n\nYou can provide also an image URL for the `-in` flag or even use **curl** or **wget** as a pipe command in which case there is no need to use the `-in` flag.\n\n```bash\n$ caire -in \u003cimage_url\u003e -out \u003coutput-folder\u003e\n$ curl -s \u003cimage_url\u003e | caire \u003e out.jpg\n```\n\n### Process multiple images from a directory concurrently\nThe library can also process multiple images from a directory **concurrently**. You have to provide only the source and the destination folder and the new width or height in this case.\n\n```bash\n$ caire -in \u003cinput_folder\u003e -out \u003coutput-folder\u003e\n```\n\n### Support for multiple output image type\nThere is no need to define the output file type, just use the correct extension and the library will encode the image to that specific type.\n\n### Other options\nIn case you wish to scale down the image by a specific percentage, it can be used the **`-perc`** boolean flag. In this case the values provided for the `width` and `height` are expressed in percentage and not pixel values. For example to reduce the image dimension by 20% both horizontally and vertically you can use the following command:\n\n```bash\n$ caire -in input/source.jpg -out ./out.jpg -perc=1 -width=20 -height=20 -debug=false\n```\n\nAlso the library supports the **`-square`** option. When this option is used the image will be resized to a square, based on the shortest edge.\n\nWhen an image is resized on both the X and Y axis, the algorithm will first try to rescale it prior resizing, but also will preserve the image aspect ratio. The seam carving algorithm is applied only to the remaining points. Ex. : given an image of dimensions 2048x1536 if we want to resize to the 1024x500, the tool first rescale the image to 1024x768 and then will remove only the remaining 268px.\n\n### Masks support:\n\n- `-mask`: The path to the protective mask. The mask should be in binary format and have the same size as the input image. White areas represent regions where no seams should be carved.\n- `-rmask`: The path to the removal mask. The mask should be in binary format and have the same size as the input image. White areas represent regions to be removed.\n\nMask | Mask removal\n:-: | :-:\n\u003cvideo src='https://user-images.githubusercontent.com/883386/197509861-86733da8-0846-419a-95eb-4fb5a97607d5.mp4' width=180/\u003e | \u003cvideo src='https://user-images.githubusercontent.com/883386/197397857-7b785d7c-2f80-4aed-a5d2-75c429389060.mp4' width=180/\u003e\n\n### Caire integrations\n- [x] Caire can be used as a serverless function via OpenFaaS: https://github.com/esimov/caire-openfaas\n- [x] Caire can also be used as a `snap` function (https://snapcraft.io/caire): `$ snap run caire --h`\n\n\u003ca href=\"https://snapcraft.io/caire\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/snapcore/snap-store-badges/master/EN/%5BEN%5D-snap-store-white-uneditable.png\" alt=\"snapcraft caire\"\u003e\u003c/a\u003e\n\n## Results\n\n#### Shrunk images\n| Original | Shrunk |\n| --- | --- |\n| ![broadway_tower_edit](https://user-images.githubusercontent.com/883386/35498083-83d6015e-04d5-11e8-936a-883e17b76f9d.jpg) | ![broadway_tower_edit](https://user-images.githubusercontent.com/883386/35498110-a4a03328-04d5-11e8-9bf1-f526ef033d6a.jpg) |\n| ![waterfall](https://user-images.githubusercontent.com/883386/35498250-2f31e202-04d6-11e8-8840-a78f40fc1a0c.png) | ![waterfall](https://user-images.githubusercontent.com/883386/35498209-0411b16a-04d6-11e8-9ce2-ec4bce34828a.jpg) |\n| ![dubai](https://user-images.githubusercontent.com/883386/35498466-1375b88a-04d7-11e8-8f8e-9d202da6a6b3.jpg) | ![dubai](https://user-images.githubusercontent.com/883386/35498499-3c32fc38-04d7-11e8-9f0d-07f63a8bd420.jpg) |\n| ![boat](https://user-images.githubusercontent.com/883386/35498465-1317a678-04d7-11e8-9185-ec92ea57f7c6.jpg) | ![boat](https://user-images.githubusercontent.com/883386/35498498-3c0f182c-04d7-11e8-9af8-695bc071e0f1.jpg) |\n\n#### Enlarged images\n| Original | Extended |\n| --- | --- |\n| ![gasadalur](https://user-images.githubusercontent.com/883386/35498662-e11853c4-04d7-11e8-98d7-fcdb27207362.jpg) | ![gasadalur](https://user-images.githubusercontent.com/883386/35498559-87eb6426-04d7-11e8-825c-2dd2abdfc112.jpg) |\n| ![dubai](https://user-images.githubusercontent.com/883386/35498466-1375b88a-04d7-11e8-8f8e-9d202da6a6b3.jpg) | ![dubai](https://user-images.githubusercontent.com/883386/35498827-8cee502c-04d8-11e8-8449-05805f196d60.jpg) |\n### Useful resources\n* https://en.wikipedia.org/wiki/Seam_carving\n* https://inst.eecs.berkeley.edu/~cs194-26/fa16/hw/proj4-seamcarving/imret.pdf\n* http://pages.cs.wisc.edu/~moayad/cs766/download_files/alnammi_cs_766_final_report.pdf\n* https://stacks.stanford.edu/file/druid:my512gb2187/Zargham_Nassirpour_Content_aware_image_resizing.pdf\n\n## Author\n\n* Endre Simo ([@simo_endre](https://twitter.com/simo_endre))\n\n## License\n\nCopyright © 2018 Endre Simo\n\nThis project is under the MIT License. See the LICENSE file for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesimov%2Fcaire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesimov%2Fcaire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesimov%2Fcaire/lists"}