项目作者: cawfree

项目描述 :
✂️ Otsu's Method for automated thresholding in JavaScript.
高级语言: JavaScript
项目地址: git://github.com/cawfree/otsu.git
创建时间: 2020-02-05T09:34:47Z
项目社区:https://github.com/cawfree/otsu

开源协议:MIT License

下载


otsu

Otsu’s 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.


code style: prettier






You can find an awesome description of the algorithm, which inspired this repository, here.

🚀 Getting Started

Using npm:

  1. npm install --save otsu

Using yarn:

  1. yarn add otsu

✍️ Usage

It’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, 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.

  1. import otsu from 'otsu';
  2. const intensity = [255, 0, 128, 4, 95 ...];
  3. const t = otsu(intensity);
  4. console.log(t); // i.e. 128
  5. const thresholded = intensity.map(e => (e > t ? 1 : 0));

✌️ License

MIT



Buy @cawfree a coffee