Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cawfree/otsu
✂️ Otsu's Method for automated thresholding in JavaScript.
https://github.com/cawfree/otsu
image processing segmentation threshold
Last synced: 3 months ago
JSON representation
✂️ Otsu's Method for automated thresholding in JavaScript.
- Host: GitHub
- URL: https://github.com/cawfree/otsu
- Owner: cawfree
- License: mit
- Created: 2020-02-05T09:34:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-02T17:35:22.000Z (about 1 year ago)
- Last Synced: 2024-09-17T15:28:53.962Z (5 months ago)
- Topics: image, processing, segmentation, threshold
- Language: JavaScript
- Homepage:
- Size: 1.07 MB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# otsu
[Otsu's Method](https://en.wikipedia.org/wiki/Otsu%27s_method) is way of implementing automatic thresholding. It is a binarization algorithm which can be used to select the optimal threshold between foreground and background quantities based on finding the minimum point of cross variance. This is particularly useful when performing segmentation in [image processing](https://en.wikipedia.org/wiki/Digital_image_processing).
![]()
You can find an awesome description of the algorithm, which inspired this repository, [here](http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html).
## 🚀 Getting Started
Using [`npm`](https://www.npmjs.com/):
```bash
npm install --save otsu
```Using [`yarn`](https://yarnpkg.com/):
```bash
yarn add otsu
```
## ✍️ UsageIt's really simple to find the threshold of your image. All you have to do is supply the data!
In the example below, we have a one-dimensional array of intensity data. Most greyscale image formats, such as [MNIST](http://yann.lecun.com/exdb/mnist/), can be fed directly into otsu this way. However, images that consist of multiple attributes per pixel (such as `(r,g,b)`) will first require pre-processing.
```javascript
import otsu from 'otsu';const intensity = [255, 0, 128, 4, 95 ...];
const t = otsu(intensity);console.log(t); // i.e. 128
const thresholded = intensity.map(e => (e > t ? 1 : 0));
```## ✌️ License
[MIT](https://opensource.org/licenses/MIT)