{"id":13514883,"url":"https://github.com/Algy/fast-slic","last_synced_at":"2025-03-31T03:31:40.385Z","repository":{"id":37663440,"uuid":"180400096","full_name":"Algy/fast-slic","owner":"Algy","description":"20x Real-time superpixel SLIC Implementation with CPU","archived":false,"fork":false,"pushed_at":"2021-09-08T01:13:39.000Z","size":2184,"stargazers_count":263,"open_issues_count":24,"forks_count":34,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-01T18:38:02.397Z","etag":null,"topics":["blazingly-fast","image-segmentation","python","slic","superpixel-algorithms","superpixels"],"latest_commit_sha":null,"homepage":"","language":"C++","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/Algy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-09T15:43:41.000Z","updated_at":"2024-10-30T20:00:44.000Z","dependencies_parsed_at":"2022-07-20T12:32:38.913Z","dependency_job_id":null,"html_url":"https://github.com/Algy/fast-slic","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Algy%2Ffast-slic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Algy%2Ffast-slic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Algy%2Ffast-slic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Algy%2Ffast-slic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Algy","download_url":"https://codeload.github.com/Algy/fast-slic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246413377,"owners_count":20773053,"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":["blazingly-fast","image-segmentation","python","slic","superpixel-algorithms","superpixels"],"created_at":"2024-08-01T05:01:03.102Z","updated_at":"2025-03-31T03:31:35.374Z","avatar_url":"https://github.com/Algy.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# Fast Slic\n\nFast-slic is a SLIC-variant algorithm implementation that aims for significantly low runtime with cpu. It runs 7-20 times faster than existing SLIC implementations. Fast-slic can process 1280x720 image stream at 60fps.\n\nIt started as a part of my hobby project that demanded true \"real time\" capability in video stream processing. Among pipelines of it was a postprocessing pipeline smoothing the result of image with SLIC superpixels and CRF. Unfortunately, there were no satisfying library for real-time(\u003e30fps) goal. [gSLICr](https://github.com/carlren/gSLICr) was the most promising candidate, but I couldn't make use of it due to limited hardware and inflexible license of CUDA. Therefore, I made the blazingly fast variant of SLIC using only CPU.\n\n[Paper preprint](https://github.com/Algy/fast-slic/files/4009304/fastslic.pdf)\n## Demo\n\u003ctable\u003e\n   \u003ctr\u003e\n      \u003ctd\u003e\u003cimg alt=\"demo_clownfish\" src=\"https://user-images.githubusercontent.com/2352985/56845088-8a1e5d00-68f6-11e9-9950-cab56cf32e80.jpg\"\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cimg alt=\"demo_tiger\" src=\"https://user-images.githubusercontent.com/2352985/56845090-8e4a7a80-68f6-11e9-9a51-b1da31d5ef77.jpg\"\u003e\u003c/td\u003e\n   \u003c/tr\u003e\n\u003c/table\u003e\n\n## Installation\n```python\npip install fast_slic\n```\n\n## Basic Usage\n```python\nimport numpy as np\n\nfrom fast_slic import Slic\nfrom PIL import Image\n\nwith Image.open(\"fish.jpg\") as f:\n   image = np.array(f)\n# import cv2; image = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)   # You can convert the image to CIELAB space if you need.\nslic = Slic(num_components=1600, compactness=10)\nassignment = slic.iterate(image) # Cluster Map\nprint(assignment)\nprint(slic.slic_model.clusters) # The cluster information of superpixels.\n```\n\nIf your machine has AVX2 instruction set, you can make it three times faster using `fast_slic.avx2.SlicAvx2` class instead of `fast_slic.Slic`. Haswell and newer Intel cpus, Excavator, and Ryzen support this.\n\n```python\nimport numpy as np\n\n# Much faster than the standard class\nfrom fast_slic.avx2 import SlicAvx2\nfrom PIL import Image\n\nwith Image.open(\"fish.jpg\") as f:\n   image = np.array(f)\n# import cv2; image = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)   # You can convert the image to CIELAB space if you need.\nslic = SlicAvx2(num_components=1600, compactness=10)\nassignment = slic.iterate(image) # Cluster Map\nprint(assignment)\nprint(slic.slic_model.clusters) # The cluster information of superpixels.\n```\n\nIf your machine is ARM with NEON instruction set, which is commonly supported by recent mobile devices and even Raspberry Pi, you can make it two-fold faster by using `fast_slic.neon.SlicNeon` class instead of the original one.\n\n\n## Performance\n\nWith max iteration set to 10, run times of slic implementations for 640x480 image are as follows:\n\n| Implementation                                  | Run time(ms)   |\n| -----------------------------------------       | --------------:|\n| skimage.segment.slic                            | 216ms          |\n| cv2.ximgproc.createSuperpixelSLIC.iterate       | 142ms          |\n| fast_slic.Slic(single core build)               | 20ms           |\n| fast_slic.avx2.SlicAvx2(single core build /w avx2 support)      | 12ms           |\n| **fast_slic.Slic(w/ OpenMP support)**           | **8.8ms**       |\n| **fast_slic.avx2.SlicAvx2(w/ OpenMP, avx2 support)**   | **5.6ms**       |\n\n \n(RGB-to-CIELAB conversion time is not included. Tested with Ryzen 2600x 6C12T 4.0Hz O.C.)\n\n## Known Issues\n * Windows build is quite slower compared to those of linux and mac. Maybe it is due to openmp overhead?\n\n \n## Tips\n * It automatically removes small isolated area of pixels at cost of significant (but not huge) overhead. You can skip denoising process by setting `min_size_factor` to 0. (e.g. `Slic(num_components=1600, compactness=10, min_size_factor=0)`). The setting makes it 20-40% faster. \n * To push to the limit, compile it with `FAST_SLIC_AVX2_FASTER` flag and get more performance gain. (though performance margin was small in my pc)\n \n## TODO\n - [ ] Publish as a research paper\n - [x] Remove or merge small blobs\n - [x] Include simple CRF utilities\n - [x] Add tests\n - [x] Windows build\n - [x] More scalable parallel loop in cluster assignment. I suspect there is false sharing problem in the loop.\n - [x] would be great if I can optimize loop more. SIMD?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlgy%2Ffast-slic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAlgy%2Ffast-slic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlgy%2Ffast-slic/lists"}